Commit 7a4fa927 authored by sadrul@chromium.org's avatar sadrul@chromium.org

aura: Do not synthesize a mouse-move event during a drag.

Synthesizing a mouse-move event during a drag can cause an inconsistent sequence
of events to be dispatched (e.g. pressed, dragged, dragged, moved, dragged ...
released). So do not synthesize mouse-move events when a drag is in progress. The
alternate is to synthesize mouse-dragged event instead of a mouse-move event, but
in multi-display/multi-host setting, the wrong dispatcher may end up synthesizing
the event. So avoid doing that.

BUG=389424, 369247, 366096
R=oshima@chromium.org

Review URL: https://codereview.chromium.org/387863003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282805 0039d316-1c4b-4281-b951-d872f2087c98
parent a5d20a27
...@@ -694,6 +694,15 @@ ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() { ...@@ -694,6 +694,15 @@ ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() {
if (!synthesize_mouse_move_) if (!synthesize_mouse_move_)
return details; return details;
synthesize_mouse_move_ = false; synthesize_mouse_move_ = false;
// If one of the mouse buttons is currently down, then do not synthesize a
// mouse-move event. In such cases, aura could synthesize a DRAGGED event
// instead of a MOVED event, but in multi-display/multi-host scenarios, the
// DRAGGED event can be synthesized in the incorrect host. So avoid
// synthesizing any events at all.
if (Env::GetInstance()->mouse_button_flags())
return details;
gfx::Point root_mouse_location = GetLastMouseLocationInRoot(); gfx::Point root_mouse_location = GetLastMouseLocationInRoot();
if (!window()->bounds().Contains(root_mouse_location)) if (!window()->bounds().Contains(root_mouse_location))
return details; return details;
......
...@@ -917,6 +917,34 @@ TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { ...@@ -917,6 +917,34 @@ TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) {
root_window()->RemovePreTargetHandler(&recorder); root_window()->RemovePreTargetHandler(&recorder);
} }
// Tests that a mouse-move event is not synthesized when a mouse-button is down.
TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) {
EventFilterRecorder recorder;
test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
&delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
window->Show();
window->AddPreTargetHandler(&recorder);
// Dispatch a non-synthetic mouse event when mouse events are enabled.
ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10),
gfx::Point(10, 10), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
DispatchEventUsingWindowDispatcher(&mouse1);
ASSERT_EQ(1u, recorder.events().size());
EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]);
window->RemovePreTargetHandler(&recorder);
recorder.Reset();
// Move |window| away from underneath the cursor.
root_window()->AddPreTargetHandler(&recorder);
window->SetBounds(gfx::Rect(30, 30, 100, 100));
EXPECT_TRUE(recorder.events().empty());
RunAllPendingInMessageLoop();
EXPECT_TRUE(recorder.events().empty());
root_window()->RemovePreTargetHandler(&recorder);
}
#if defined(OS_WIN) && defined(ARCH_CPU_X86) #if defined(OS_WIN) && defined(ARCH_CPU_X86)
#define MAYBE(x) DISABLED_##x #define MAYBE(x) DISABLED_##x
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment