Merge to M65: Fix compatibility between Select-to-Speak and large mouse cursor.

The event rewriter needs to allow mouse movement events to pass even
when those events are used by Select-to-Speak. It should only cancel
mouse click events used by Select-to-Speak.

Another solution would be to re-write all used "drag" events to be
simply "move" events, which may reduce the likelyhood that these
events will be used by any other part of Chrome / Chrome OS besides
Select-to-Speak and drawing the mouse.

This bug also impacted some devices (like snappy) even without
large mouse cursor on.

Note: The additional "drag" and "move" events were manually tested
and do not appear to cause any behavior problems on tabs, the
launcher, system windows, etc.

TBR=dmazzoni@chromium.org

Bug: 818329
Change-Id: I466a15a0f7a5ba0abe4f082a9cfb9b59760d690c
Reviewed-on: https://chromium-review.googlesource.com/947210
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#540714}(cherry picked from commit 8f6ebbb1d897c9ead6e241195f8604b412bb4b17)
Reviewed-on: https://chromium-review.googlesource.com/949542
Reviewed-by: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#661}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter.cc b/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter.cc
index 0759b35..7273f4b 100644
--- a/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter.cc
+++ b/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter.cc
@@ -210,8 +210,13 @@
       event.type() == ui::ET_MOUSE_MOVED) {
     const ui::MouseEvent mouse_event =
         static_cast<const ui::MouseEvent&>(event);
-    if (OnMouseEvent(&mouse_event))
+    if (OnMouseEvent(&mouse_event) && (event.type() == ui::ET_MOUSE_PRESSED ||
+                                       event.type() == ui::ET_MOUSE_RELEASED)) {
+      // Cancel only click events if they were consumed by Select-to-Speak.
+      // Mouse move and drag should still happen or the mouse cursor may
+      // not be drawn in the right place.
       return ui::EVENT_REWRITE_DISCARD;
+    }
   }
 
   return ui::EVENT_REWRITE_CONTINUE;
diff --git a/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter_unittest.cc b/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter_unittest.cc
index 1dbe478..7ec50ea 100644
--- a/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter_unittest.cc
+++ b/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter_unittest.cc
@@ -11,6 +11,7 @@
 #include "ash/test/ash_test_helper.h"
 #include "ash/test/ash_test_views_delegate.h"
 #include "base/macros.h"
+#include "chrome/browser/chromeos/ash_config.h"
 #include "chrome/browser/chromeos/events/event_rewriter_controller.h"
 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
 #include "chrome/test/base/testing_profile.h"
@@ -178,11 +179,13 @@
   generator_->PressLeftButton();
   EXPECT_EQ(click_location, mouse_event_delegate_->last_mouse_event_location());
 
+  // Drags are not blocked.
   gfx::Point drag_location = gfx::Point(120, 32);
   generator_->DragMouseTo(drag_location);
   EXPECT_EQ(drag_location, mouse_event_delegate_->last_mouse_event_location());
   EXPECT_TRUE(mouse_event_delegate_->CapturedMouseEvent(ui::ET_MOUSE_DRAGGED));
-  EXPECT_FALSE(event_capturer_.last_mouse_event());
+  EXPECT_TRUE(event_capturer_.last_mouse_event());
+  event_capturer_.Reset();
 
   generator_->ReleaseLeftButton();
   EXPECT_EQ(drag_location, mouse_event_delegate_->last_mouse_event_location());
@@ -192,6 +195,10 @@
 }
 
 TEST_F(SelectToSpeakEventRewriterTest, SearchPlusDragOnLargeDisplay) {
+  // TODO: Failing in mus_unit_tests, see https://crbug.com/818362.
+  if (ash::Shell::GetAshConfig() == ash::Config::MUS) {
+    return;
+  }
   // This display has twice the number of pixels per DIP. THis means that
   // each event coming in in px needs to be divided by two to be converted
   // to DIPs.
@@ -209,7 +216,8 @@
   EXPECT_EQ(gfx::Point(drag_location_px.x() / 2, drag_location_px.y() / 2),
             mouse_event_delegate_->last_mouse_event_location());
   EXPECT_TRUE(mouse_event_delegate_->CapturedMouseEvent(ui::ET_MOUSE_DRAGGED));
-  EXPECT_FALSE(event_capturer_.last_mouse_event());
+  EXPECT_TRUE(event_capturer_.last_mouse_event());
+  event_capturer_.Reset();
 
   generator_->ReleaseLeftButton();
   EXPECT_EQ(gfx::Point(drag_location_px.x() / 2, drag_location_px.y() / 2),