| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 const int kWindowWidth = 123; | 109 const int kWindowWidth = 123; |
| 110 const int kWindowHeight = 45; | 110 const int kWindowHeight = 45; |
| 111 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 111 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
| 112 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 112 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
| 113 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 113 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
| 114 delegate1.get(), -1234, bounds1, root_window())); | 114 delegate1.get(), -1234, bounds1, root_window())); |
| 115 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 115 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
| 116 delegate2.get(), -5678, bounds2, root_window())); | 116 delegate2.get(), -5678, bounds2, root_window())); |
| 117 | 117 |
| 118 // Send a mouse event to window1. | 118 // Send a mouse event to window1. |
| 119 gfx::Point point(101, 201); | 119 gfx::PointF point(101.f, 201.f); |
| 120 ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point, point, | 120 ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point, point, |
| 121 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 121 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 122 ui::EF_LEFT_MOUSE_BUTTON); | 122 ui::EF_LEFT_MOUSE_BUTTON); |
| 123 DispatchEventUsingWindowDispatcher(&event1); | 123 DispatchEventUsingWindowDispatcher(&event1); |
| 124 | 124 |
| 125 // Event was tested for non-client area for the target window. | 125 // Event was tested for non-client area for the target window. |
| 126 EXPECT_EQ(1, delegate1->non_client_count()); | 126 EXPECT_EQ(1, delegate1->non_client_count()); |
| 127 EXPECT_EQ(0, delegate2->non_client_count()); | 127 EXPECT_EQ(0, delegate2->non_client_count()); |
| 128 // The non-client component test was in local coordinates. | 128 // The non-client component test was in local coordinates. |
| 129 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); | 129 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
| 130 // Mouse event was received by target window. | 130 // Mouse event was received by target window. |
| 131 EXPECT_EQ(1, delegate1->mouse_event_count()); | 131 EXPECT_EQ(1, delegate1->mouse_event_count()); |
| 132 EXPECT_EQ(0, delegate2->mouse_event_count()); | 132 EXPECT_EQ(0, delegate2->mouse_event_count()); |
| 133 // Event was in local coordinates. | 133 // Event was in local coordinates. |
| 134 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); | 134 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); |
| 135 // Non-client flag was set. | 135 // Non-client flag was set. |
| 136 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); | 136 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(WindowEventDispatcherTest, RepostEvent) { | 139 TEST_F(WindowEventDispatcherTest, RepostEvent) { |
| 140 // Test RepostEvent in RootWindow. It only works for Mouse Press. | 140 // Test RepostEvent in RootWindow. It only works for Mouse Press. |
| 141 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 141 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 142 gfx::Point point(10, 10); | 142 gfx::PointF point(10.f, 10.f); |
| 143 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, point, point, | 143 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, point, point, |
| 144 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 144 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 145 ui::EF_LEFT_MOUSE_BUTTON); | 145 ui::EF_LEFT_MOUSE_BUTTON); |
| 146 host()->dispatcher()->RepostEvent(event); | 146 host()->dispatcher()->RepostEvent(event); |
| 147 RunAllPendingInMessageLoop(); | 147 RunAllPendingInMessageLoop(); |
| 148 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 148 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Check that we correctly track the state of the mouse buttons in response to | 151 // Check that we correctly track the state of the mouse buttons in response to |
| 152 // button press and release events. | 152 // button press and release events. |
| 153 TEST_F(WindowEventDispatcherTest, MouseButtonState) { | 153 TEST_F(WindowEventDispatcherTest, MouseButtonState) { |
| 154 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 154 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 155 | 155 |
| 156 gfx::Point location; | 156 gfx::PointF location; |
| 157 scoped_ptr<ui::MouseEvent> event; | 157 scoped_ptr<ui::MouseEvent> event; |
| 158 | 158 |
| 159 // Press the left button. | 159 // Press the left button. |
| 160 event.reset(new ui::MouseEvent( | 160 event.reset(new ui::MouseEvent( |
| 161 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 161 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 162 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 162 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 163 DispatchEventUsingWindowDispatcher(event.get()); | 163 DispatchEventUsingWindowDispatcher(event.get()); |
| 164 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 164 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 165 | 165 |
| 166 // Additionally press the right. | 166 // Additionally press the right. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 190 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 190 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 191 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON)); | 191 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON)); |
| 192 DispatchEventUsingWindowDispatcher(event.get()); | 192 DispatchEventUsingWindowDispatcher(event.get()); |
| 193 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 193 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(WindowEventDispatcherTest, TranslatedEvent) { | 196 TEST_F(WindowEventDispatcherTest, TranslatedEvent) { |
| 197 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 197 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, |
| 198 gfx::Rect(50, 50, 100, 100), root_window())); | 198 gfx::Rect(50, 50, 100, 100), root_window())); |
| 199 | 199 |
| 200 gfx::Point origin(100, 100); | 200 gfx::PointF origin(100.f, 100.f); |
| 201 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, | 201 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, |
| 202 ui::EventTimeForNow(), 0, 0); | 202 ui::EventTimeForNow(), 0, 0); |
| 203 | 203 |
| 204 EXPECT_EQ("100,100", root.location().ToString()); | 204 EXPECT_EQ(gfx::PointF(100.f, 100.f), root.location_f()); |
| 205 EXPECT_EQ("100,100", root.root_location().ToString()); | 205 EXPECT_EQ(gfx::PointF(100.f, 100.1), root.root_location_f()); |
| 206 | 206 |
| 207 ui::MouseEvent translated_event( | 207 ui::MouseEvent translated_event( |
| 208 root, static_cast<Window*>(root_window()), w1.get(), | 208 root, static_cast<Window*>(root_window()), w1.get(), |
| 209 ui::ET_MOUSE_ENTERED, root.flags()); | 209 ui::ET_MOUSE_ENTERED, root.flags()); |
| 210 EXPECT_EQ("50,50", translated_event.location().ToString()); | 210 EXPECT_EQ(gfx::PointF(50.f, 50.f), translated_event.location_f()); |
| 211 EXPECT_EQ("100,100", translated_event.root_location().ToString()); | 211 EXPECT_EQ(gfx::PointF(100.f, 100.f), translated_event.root_location_f()); |
| 212 } | 212 } |
| 213 | 213 |
| 214 namespace { | 214 namespace { |
| 215 | 215 |
| 216 class TestEventClient : public client::EventClient { | 216 class TestEventClient : public client::EventClient { |
| 217 public: | 217 public: |
| 218 static const int kNonLockWindowId = 100; | 218 static const int kNonLockWindowId = 100; |
| 219 static const int kLockWindowId = 200; | 219 static const int kLockWindowId = 200; |
| 220 | 220 |
| 221 explicit TestEventClient(Window* root_window) | 221 explicit TestEventClient(Window* root_window) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 371 |
| 372 w1->RemovePreTargetHandler(&handler); | 372 w1->RemovePreTargetHandler(&handler); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // Tests that touch-events that are beyond the bounds of the root-window do get | 375 // Tests that touch-events that are beyond the bounds of the root-window do get |
| 376 // propagated to the event filters correctly with the root as the target. | 376 // propagated to the event filters correctly with the root as the target. |
| 377 TEST_F(WindowEventDispatcherTest, TouchEventsOutsideBounds) { | 377 TEST_F(WindowEventDispatcherTest, TouchEventsOutsideBounds) { |
| 378 ui::test::TestEventHandler handler; | 378 ui::test::TestEventHandler handler; |
| 379 root_window()->AddPreTargetHandler(&handler); | 379 root_window()->AddPreTargetHandler(&handler); |
| 380 | 380 |
| 381 gfx::Point position = root_window()->bounds().origin(); | 381 auto position = gfx::PointF(root_window()->bounds().origin()); |
| 382 position.Offset(-10, -10); | 382 position.Offset(-10.f, -10.f); |
| 383 ui::TouchEvent press( | 383 ui::TouchEvent press( |
| 384 ui::ET_TOUCH_PRESSED, position, 0, ui::EventTimeForNow()); | 384 ui::ET_TOUCH_PRESSED, position, 0, ui::EventTimeForNow()); |
| 385 DispatchEventUsingWindowDispatcher(&press); | 385 DispatchEventUsingWindowDispatcher(&press); |
| 386 EXPECT_EQ(1, handler.num_touch_events()); | 386 EXPECT_EQ(1, handler.num_touch_events()); |
| 387 | 387 |
| 388 position = root_window()->bounds().origin(); | 388 position = gfx::PointF(root_window()->bounds().origin()); |
| 389 position.Offset(root_window()->bounds().width() + 10, | 389 position.Offset(root_window()->bounds().width() + 10.f, |
| 390 root_window()->bounds().height() + 10); | 390 root_window()->bounds().height() + 10.f); |
| 391 ui::TouchEvent release( | 391 ui::TouchEvent release( |
| 392 ui::ET_TOUCH_RELEASED, position, 0, ui::EventTimeForNow()); | 392 ui::ET_TOUCH_RELEASED, position, 0, ui::EventTimeForNow()); |
| 393 DispatchEventUsingWindowDispatcher(&release); | 393 DispatchEventUsingWindowDispatcher(&release); |
| 394 EXPECT_EQ(2, handler.num_touch_events()); | 394 EXPECT_EQ(2, handler.num_touch_events()); |
| 395 root_window()->RemovePreTargetHandler(&handler); | 395 root_window()->RemovePreTargetHandler(&handler); |
| 396 } | 396 } |
| 397 | 397 |
| 398 // Tests that scroll events are dispatched correctly. | 398 // Tests that scroll events are dispatched correctly. |
| 399 TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) { | 399 TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) { |
| 400 base::TimeDelta now = ui::EventTimeForNow(); | 400 base::TimeDelta now = ui::EventTimeForNow(); |
| 401 ui::test::TestEventHandler handler; | 401 ui::test::TestEventHandler handler; |
| 402 root_window()->AddPreTargetHandler(&handler); | 402 root_window()->AddPreTargetHandler(&handler); |
| 403 | 403 |
| 404 test::TestWindowDelegate delegate; | 404 test::TestWindowDelegate delegate; |
| 405 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 405 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
| 406 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); | 406 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); |
| 407 | 407 |
| 408 // A scroll event on the root-window itself is dispatched. | 408 // A scroll event on the root-window itself is dispatched. |
| 409 ui::ScrollEvent scroll1(ui::ET_SCROLL, | 409 ui::ScrollEvent scroll1(ui::ET_SCROLL, gfx::PointF(10.f, 10.f), now, 0, 0, |
| 410 gfx::Point(10, 10), | 410 -10, 0, -10, 2); |
| 411 now, | |
| 412 0, | |
| 413 0, -10, | |
| 414 0, -10, | |
| 415 2); | |
| 416 DispatchEventUsingWindowDispatcher(&scroll1); | 411 DispatchEventUsingWindowDispatcher(&scroll1); |
| 417 EXPECT_EQ(1, handler.num_scroll_events()); | 412 EXPECT_EQ(1, handler.num_scroll_events()); |
| 418 | 413 |
| 419 // Scroll event on a window should be dispatched properly. | 414 // Scroll event on a window should be dispatched properly. |
| 420 ui::ScrollEvent scroll2(ui::ET_SCROLL, | 415 ui::ScrollEvent scroll2(ui::ET_SCROLL, gfx::PointF(25.f, 30.f), now, 0, -10, |
| 421 gfx::Point(25, 30), | 416 0, -10, 0, 2); |
| 422 now, | |
| 423 0, | |
| 424 -10, 0, | |
| 425 -10, 0, | |
| 426 2); | |
| 427 DispatchEventUsingWindowDispatcher(&scroll2); | 417 DispatchEventUsingWindowDispatcher(&scroll2); |
| 428 EXPECT_EQ(2, handler.num_scroll_events()); | 418 EXPECT_EQ(2, handler.num_scroll_events()); |
| 429 root_window()->RemovePreTargetHandler(&handler); | 419 root_window()->RemovePreTargetHandler(&handler); |
| 430 } | 420 } |
| 431 | 421 |
| 432 namespace { | 422 namespace { |
| 433 | 423 |
| 434 // FilterFilter that tracks the types of events it's seen. | 424 // FilterFilter that tracks the types of events it's seen. |
| 435 class EventFilterRecorder : public ui::EventHandler { | 425 class EventFilterRecorder : public ui::EventHandler { |
| 436 public: | 426 public: |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // Set capture on |window| generate a mouse event (that is reposted) and not | 610 // Set capture on |window| generate a mouse event (that is reposted) and not |
| 621 // over |window| and verify |window| gets it (|window| gets it because it has | 611 // over |window| and verify |window| gets it (|window| gets it because it has |
| 622 // capture). | 612 // capture). |
| 623 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 613 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 624 EventFilterRecorder recorder; | 614 EventFilterRecorder recorder; |
| 625 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 615 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 626 window->SetBounds(gfx::Rect(20, 20, 40, 30)); | 616 window->SetBounds(gfx::Rect(20, 20, 40, 30)); |
| 627 window->AddPreTargetHandler(&recorder); | 617 window->AddPreTargetHandler(&recorder); |
| 628 window->SetCapture(); | 618 window->SetCapture(); |
| 629 const ui::MouseEvent press_event( | 619 const ui::MouseEvent press_event( |
| 630 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 620 ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(), ui::EventTimeForNow(), |
| 631 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 621 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 632 host()->dispatcher()->RepostEvent(press_event); | 622 host()->dispatcher()->RepostEvent(press_event); |
| 633 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). | 623 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). |
| 634 // Mouse moves/enters may be generated. We only care about a pressed. | 624 // Mouse moves/enters may be generated. We only care about a pressed. |
| 635 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != | 625 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != |
| 636 std::string::npos) << EventTypesToString(recorder.events()); | 626 std::string::npos) << EventTypesToString(recorder.events()); |
| 637 } | 627 } |
| 638 | 628 |
| 639 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { | 629 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { |
| 640 EventFilterRecorder recorder; | 630 EventFilterRecorder recorder; |
| 641 root_window()->AddPreTargetHandler(&recorder); | 631 root_window()->AddPreTargetHandler(&recorder); |
| 642 | 632 |
| 643 test::TestWindowDelegate delegate; | 633 test::TestWindowDelegate delegate; |
| 644 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 634 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 645 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 635 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 646 | 636 |
| 647 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 637 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::PointF(0.f, 0.f), |
| 648 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 638 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), |
| 649 0); | 639 0, 0); |
| 650 DispatchEventUsingWindowDispatcher(&mouse_move_event); | 640 DispatchEventUsingWindowDispatcher(&mouse_move_event); |
| 651 // Discard MOUSE_ENTER. | 641 // Discard MOUSE_ENTER. |
| 652 recorder.Reset(); | 642 recorder.Reset(); |
| 653 | 643 |
| 654 host()->dispatcher()->HoldPointerMoves(); | 644 host()->dispatcher()->HoldPointerMoves(); |
| 655 | 645 |
| 656 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. | 646 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. |
| 657 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), | 647 ui::MouseEvent mouse_dragged_event( |
| 658 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 648 ui::ET_MOUSE_DRAGGED, gfx::PointF(0.f, 0.f), gfx::PointF(0.f, 0.f), |
| 659 0); | 649 ui::EventTimeForNow(), 0, 0); |
| 660 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 650 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 661 EXPECT_TRUE(recorder.events().empty()); | 651 EXPECT_TRUE(recorder.events().empty()); |
| 662 | 652 |
| 663 // Check that we do dispatch the held MOUSE_DRAGGED event before another type | 653 // Check that we do dispatch the held MOUSE_DRAGGED event before another type |
| 664 // of event. | 654 // of event. |
| 665 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 655 ui::MouseEvent mouse_pressed_event( |
| 666 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 656 ui::ET_MOUSE_PRESSED, gfx::PointF(0.f, 0.f), gfx::PointF(0.f, 0.f), |
| 667 0); | 657 ui::EventTimeForNow(), 0, 0); |
| 668 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 658 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 669 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 659 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 670 EventTypesToString(recorder.events())); | 660 EventTypesToString(recorder.events())); |
| 671 recorder.Reset(); | 661 recorder.Reset(); |
| 672 | 662 |
| 673 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and | 663 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and |
| 674 // elsewhere in this test) we re-define each event prior to dispatch so that | 664 // elsewhere in this test) we re-define each event prior to dispatch so that |
| 675 // it has the correct state (phase, handled, target, etc.). | 665 // it has the correct state (phase, handled, target, etc.). |
| 676 mouse_dragged_event = | 666 mouse_dragged_event = |
| 677 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 667 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(0.f, 0.f), |
| 678 ui::EventTimeForNow(), 0, 0); | 668 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 679 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 669 ui::MouseEvent mouse_dragged_event2( |
| 680 gfx::Point(10, 10), ui::EventTimeForNow(), | 670 ui::ET_MOUSE_DRAGGED, gfx::PointF(10.f, 10.f), gfx::PointF(10.f, 10.f), |
| 681 0, 0); | 671 ui::EventTimeForNow(), 0, 0); |
| 682 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 672 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 683 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 673 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 684 EXPECT_TRUE(recorder.events().empty()); | 674 EXPECT_TRUE(recorder.events().empty()); |
| 685 mouse_pressed_event = | 675 mouse_pressed_event = |
| 686 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), | 676 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(0.f, 0.f), |
| 687 ui::EventTimeForNow(), 0, 0); | 677 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 688 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 678 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 689 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 679 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 690 EventTypesToString(recorder.events())); | 680 EventTypesToString(recorder.events())); |
| 691 recorder.Reset(); | 681 recorder.Reset(); |
| 692 | 682 |
| 693 // Check that on ReleasePointerMoves, held events are not dispatched | 683 // Check that on ReleasePointerMoves, held events are not dispatched |
| 694 // immediately, but posted instead. | 684 // immediately, but posted instead. |
| 695 mouse_dragged_event = | 685 mouse_dragged_event = |
| 696 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 686 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(0.f, 0.f), |
| 697 ui::EventTimeForNow(), 0, 0); | 687 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 698 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 688 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 699 host()->dispatcher()->ReleasePointerMoves(); | 689 host()->dispatcher()->ReleasePointerMoves(); |
| 700 EXPECT_TRUE(recorder.events().empty()); | 690 EXPECT_TRUE(recorder.events().empty()); |
| 701 RunAllPendingInMessageLoop(); | 691 RunAllPendingInMessageLoop(); |
| 702 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 692 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
| 703 recorder.Reset(); | 693 recorder.Reset(); |
| 704 | 694 |
| 705 // However if another message comes in before the dispatch of the posted | 695 // However if another message comes in before the dispatch of the posted |
| 706 // event, check that the posted event is dispatched before this new event. | 696 // event, check that the posted event is dispatched before this new event. |
| 707 host()->dispatcher()->HoldPointerMoves(); | 697 host()->dispatcher()->HoldPointerMoves(); |
| 708 mouse_dragged_event = | 698 mouse_dragged_event = |
| 709 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 699 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(0.f, 0.f), |
| 710 ui::EventTimeForNow(), 0, 0); | 700 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 711 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 701 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 712 host()->dispatcher()->ReleasePointerMoves(); | 702 host()->dispatcher()->ReleasePointerMoves(); |
| 713 mouse_pressed_event = | 703 mouse_pressed_event = |
| 714 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), | 704 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(0.f, 0.f), |
| 715 ui::EventTimeForNow(), 0, 0); | 705 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 716 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 706 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 717 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 707 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 718 EventTypesToString(recorder.events())); | 708 EventTypesToString(recorder.events())); |
| 719 recorder.Reset(); | 709 recorder.Reset(); |
| 720 RunAllPendingInMessageLoop(); | 710 RunAllPendingInMessageLoop(); |
| 721 EXPECT_TRUE(recorder.events().empty()); | 711 EXPECT_TRUE(recorder.events().empty()); |
| 722 | 712 |
| 723 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce | 713 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce |
| 724 // them. | 714 // them. |
| 725 host()->dispatcher()->HoldPointerMoves(); | 715 host()->dispatcher()->HoldPointerMoves(); |
| 726 mouse_dragged_event = | 716 mouse_dragged_event = |
| 727 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 717 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(0.f, 0.f), |
| 728 ui::EventTimeForNow(), 0, 0); | 718 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 729 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 719 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 730 host()->dispatcher()->ReleasePointerMoves(); | 720 host()->dispatcher()->ReleasePointerMoves(); |
| 731 mouse_dragged_event2 = | 721 mouse_dragged_event2 = |
| 732 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 722 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(10.f, 10.f), |
| 733 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 723 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), 0, 0); |
| 734 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 724 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 735 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 725 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
| 736 recorder.Reset(); | 726 recorder.Reset(); |
| 737 RunAllPendingInMessageLoop(); | 727 RunAllPendingInMessageLoop(); |
| 738 EXPECT_TRUE(recorder.events().empty()); | 728 EXPECT_TRUE(recorder.events().empty()); |
| 739 | 729 |
| 740 // Check that synthetic mouse move event has a right location when issued | 730 // Check that synthetic mouse move event has a right location when issued |
| 741 // while holding pointer moves. | 731 // while holding pointer moves. |
| 742 mouse_dragged_event = | 732 mouse_dragged_event = |
| 743 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 733 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(0.f, 0.f), |
| 744 ui::EventTimeForNow(), 0, 0); | 734 gfx::PointF(0.f, 0.f), ui::EventTimeForNow(), 0, 0); |
| 745 mouse_dragged_event2 = | 735 mouse_dragged_event2 = |
| 746 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 736 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::PointF(10.f, 10.f), |
| 747 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 737 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), 0, 0); |
| 748 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), | 738 ui::MouseEvent mouse_dragged_event3( |
| 749 gfx::Point(28, 28), ui::EventTimeForNow(), | 739 ui::ET_MOUSE_DRAGGED, gfx::PointF(28.f, 28.f), gfx::PointF(28.f, 28.f), |
| 750 0, 0); | 740 ui::EventTimeForNow(), 0, 0); |
| 751 host()->dispatcher()->HoldPointerMoves(); | 741 host()->dispatcher()->HoldPointerMoves(); |
| 752 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 742 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 753 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 743 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 754 window->SetBounds(gfx::Rect(15, 15, 80, 80)); | 744 window->SetBounds(gfx::Rect(15, 15, 80, 80)); |
| 755 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); | 745 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); |
| 756 RunAllPendingInMessageLoop(); | 746 RunAllPendingInMessageLoop(); |
| 757 EXPECT_TRUE(recorder.events().empty()); | 747 EXPECT_TRUE(recorder.events().empty()); |
| 758 host()->dispatcher()->ReleasePointerMoves(); | 748 host()->dispatcher()->ReleasePointerMoves(); |
| 759 RunAllPendingInMessageLoop(); | 749 RunAllPendingInMessageLoop(); |
| 760 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(recorder.events())); | 750 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(recorder.events())); |
| 761 EXPECT_EQ(gfx::Point(13, 13), recorder.mouse_location(0)); | 751 EXPECT_EQ(gfx::Point(13, 13), recorder.mouse_location(0)); |
| 762 recorder.Reset(); | 752 recorder.Reset(); |
| 763 root_window()->RemovePreTargetHandler(&recorder); | 753 root_window()->RemovePreTargetHandler(&recorder); |
| 764 } | 754 } |
| 765 | 755 |
| 766 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { | 756 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { |
| 767 EventFilterRecorder recorder; | 757 EventFilterRecorder recorder; |
| 768 root_window()->AddPreTargetHandler(&recorder); | 758 root_window()->AddPreTargetHandler(&recorder); |
| 769 | 759 |
| 770 test::TestWindowDelegate delegate; | 760 test::TestWindowDelegate delegate; |
| 771 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 761 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 772 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 762 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 773 | 763 |
| 774 // Starting the touch and throwing out the first few events, since the system | 764 // Starting the touch and throwing out the first few events, since the system |
| 775 // is going to generate synthetic mouse events that are not relevant to the | 765 // is going to generate synthetic mouse events that are not relevant to the |
| 776 // test. | 766 // test. |
| 777 ui::TouchEvent touch_pressed_event( | 767 ui::TouchEvent touch_pressed_event( |
| 778 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); | 768 ui::ET_TOUCH_PRESSED, gfx::PointF(10.f, 10.f), 0, ui::EventTimeForNow()); |
| 779 DispatchEventUsingWindowDispatcher(&touch_pressed_event); | 769 DispatchEventUsingWindowDispatcher(&touch_pressed_event); |
| 780 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); | 770 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); |
| 781 recorder.Reset(); | 771 recorder.Reset(); |
| 782 | 772 |
| 783 host()->dispatcher()->HoldPointerMoves(); | 773 host()->dispatcher()->HoldPointerMoves(); |
| 784 | 774 |
| 785 // Check that we don't immediately dispatch the TOUCH_MOVED event. | 775 // Check that we don't immediately dispatch the TOUCH_MOVED event. |
| 786 ui::TouchEvent touch_moved_event( | 776 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, gfx::PointF(10.f, 10.f), |
| 787 ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); | 777 0, ui::EventTimeForNow()); |
| 788 ui::TouchEvent touch_moved_event2( | 778 ui::TouchEvent touch_moved_event2(ui::ET_TOUCH_MOVED, gfx::PointF(11.f, 10.f), |
| 789 ui::ET_TOUCH_MOVED, gfx::Point(11, 10), 0, ui::EventTimeForNow()); | 779 0, ui::EventTimeForNow()); |
| 790 ui::TouchEvent touch_moved_event3( | 780 ui::TouchEvent touch_moved_event3(ui::ET_TOUCH_MOVED, gfx::PointF(12.f, 10.f), |
| 791 ui::ET_TOUCH_MOVED, gfx::Point(12, 10), 0, ui::EventTimeForNow()); | 781 0, ui::EventTimeForNow()); |
| 792 | 782 |
| 793 DispatchEventUsingWindowDispatcher(&touch_moved_event); | 783 DispatchEventUsingWindowDispatcher(&touch_moved_event); |
| 794 EXPECT_TRUE(recorder.events().empty()); | 784 EXPECT_TRUE(recorder.events().empty()); |
| 795 | 785 |
| 796 // Check that on ReleasePointerMoves, held events are not dispatched | 786 // Check that on ReleasePointerMoves, held events are not dispatched |
| 797 // immediately, but posted instead. | 787 // immediately, but posted instead. |
| 798 DispatchEventUsingWindowDispatcher(&touch_moved_event2); | 788 DispatchEventUsingWindowDispatcher(&touch_moved_event2); |
| 799 host()->dispatcher()->ReleasePointerMoves(); | 789 host()->dispatcher()->ReleasePointerMoves(); |
| 800 EXPECT_TRUE(recorder.events().empty()); | 790 EXPECT_TRUE(recorder.events().empty()); |
| 801 | 791 |
| 802 RunAllPendingInMessageLoop(); | 792 RunAllPendingInMessageLoop(); |
| 803 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events())); | 793 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events())); |
| 804 recorder.Reset(); | 794 recorder.Reset(); |
| 805 | 795 |
| 806 // If another touch event occurs then the held touch should be dispatched | 796 // If another touch event occurs then the held touch should be dispatched |
| 807 // immediately before it. | 797 // immediately before it. |
| 808 ui::TouchEvent touch_released_event( | 798 ui::TouchEvent touch_released_event( |
| 809 ui::ET_TOUCH_RELEASED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); | 799 ui::ET_TOUCH_RELEASED, gfx::PointF(10.f, 10.f), 0, ui::EventTimeForNow()); |
| 810 recorder.Reset(); | 800 recorder.Reset(); |
| 811 host()->dispatcher()->HoldPointerMoves(); | 801 host()->dispatcher()->HoldPointerMoves(); |
| 812 DispatchEventUsingWindowDispatcher(&touch_moved_event3); | 802 DispatchEventUsingWindowDispatcher(&touch_moved_event3); |
| 813 DispatchEventUsingWindowDispatcher(&touch_released_event); | 803 DispatchEventUsingWindowDispatcher(&touch_released_event); |
| 814 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END", | 804 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END", |
| 815 EventTypesToString(recorder.events())); | 805 EventTypesToString(recorder.events())); |
| 816 recorder.Reset(); | 806 recorder.Reset(); |
| 817 host()->dispatcher()->ReleasePointerMoves(); | 807 host()->dispatcher()->ReleasePointerMoves(); |
| 818 RunAllPendingInMessageLoop(); | 808 RunAllPendingInMessageLoop(); |
| 819 EXPECT_TRUE(recorder.events().empty()); | 809 EXPECT_TRUE(recorder.events().empty()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 830 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( | 820 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( |
| 831 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); | 821 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
| 832 window_first->Show(); | 822 window_first->Show(); |
| 833 window_first->AddPreTargetHandler(&recorder_first); | 823 window_first->AddPreTargetHandler(&recorder_first); |
| 834 | 824 |
| 835 scoped_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( | 825 scoped_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( |
| 836 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); | 826 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); |
| 837 window_second->Show(); | 827 window_second->Show(); |
| 838 window_second->AddPreTargetHandler(&recorder_second); | 828 window_second->AddPreTargetHandler(&recorder_second); |
| 839 | 829 |
| 840 const gfx::Point event_location(22, 33); | 830 const gfx::PointF event_location(22.f, 33.f); |
| 841 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 831 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 842 ui::EventTimeForNow(), 0, 0); | 832 ui::EventTimeForNow(), 0, 0); |
| 843 DispatchEventUsingWindowDispatcher(&mouse); | 833 DispatchEventUsingWindowDispatcher(&mouse); |
| 844 | 834 |
| 845 EXPECT_TRUE(recorder_first.events().empty()); | 835 EXPECT_TRUE(recorder_first.events().empty()); |
| 846 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", | 836 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", |
| 847 EventTypesToString(recorder_second.events())); | 837 EventTypesToString(recorder_second.events())); |
| 848 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); | 838 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); |
| 849 EXPECT_EQ(gfx::Point(2, 3).ToString(), | 839 EXPECT_EQ(gfx::Point(2, 3).ToString(), |
| 850 recorder_second.mouse_locations()[0].ToString()); | 840 recorder_second.mouse_locations()[0].ToString()); |
| 851 } | 841 } |
| 852 | 842 |
| 853 // Tests that a mouse exit is dispatched to the last mouse location when | 843 // Tests that a mouse exit is dispatched to the last mouse location when |
| 854 // the window is hiddden. | 844 // the window is hiddden. |
| 855 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { | 845 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { |
| 856 EventFilterRecorder recorder; | 846 EventFilterRecorder recorder; |
| 857 | 847 |
| 858 test::TestWindowDelegate delegate; | 848 test::TestWindowDelegate delegate; |
| 859 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 849 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 860 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 850 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 861 window->Show(); | 851 window->Show(); |
| 862 window->AddPreTargetHandler(&recorder); | 852 window->AddPreTargetHandler(&recorder); |
| 863 | 853 |
| 864 // Dispatch a mouse move event into the window. | 854 // Dispatch a mouse move event into the window. |
| 865 const gfx::Point event_location(22, 33); | 855 const gfx::PointF event_location(22.f, 33.f); |
| 866 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 856 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 867 ui::EventTimeForNow(), 0, 0); | 857 ui::EventTimeForNow(), 0, 0); |
| 868 DispatchEventUsingWindowDispatcher(&mouse); | 858 DispatchEventUsingWindowDispatcher(&mouse); |
| 869 EXPECT_FALSE(recorder.events().empty()); | 859 EXPECT_FALSE(recorder.events().empty()); |
| 870 recorder.Reset(); | 860 recorder.Reset(); |
| 871 | 861 |
| 872 // Hide the window and verify a mouse exit event's location. | 862 // Hide the window and verify a mouse exit event's location. |
| 873 window->Hide(); | 863 window->Hide(); |
| 874 EXPECT_FALSE(recorder.events().empty()); | 864 EXPECT_FALSE(recorder.events().empty()); |
| 875 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); | 865 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 recorder.touch_locations()[1].ToString()); | 941 recorder.touch_locations()[1].ToString()); |
| 952 root_window()->RemovePreTargetHandler(&recorder); | 942 root_window()->RemovePreTargetHandler(&recorder); |
| 953 } | 943 } |
| 954 | 944 |
| 955 // Tests that a 'held' touch-event does contribute to gesture event when it is | 945 // Tests that a 'held' touch-event does contribute to gesture event when it is |
| 956 // dispatched. | 946 // dispatched. |
| 957 TEST_F(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) { | 947 TEST_F(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) { |
| 958 EventFilterRecorder recorder; | 948 EventFilterRecorder recorder; |
| 959 root_window()->AddPreTargetHandler(&recorder); | 949 root_window()->AddPreTargetHandler(&recorder); |
| 960 | 950 |
| 961 const gfx::Point location(20, 20); | 951 const gfx::PointF location(20.f, 20.f); |
| 962 ui::TouchEvent press( | 952 ui::TouchEvent press( |
| 963 ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow()); | 953 ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow()); |
| 964 DispatchEventUsingWindowDispatcher(&press); | 954 DispatchEventUsingWindowDispatcher(&press); |
| 965 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED)); | 955 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED)); |
| 966 recorder.Reset(); | 956 recorder.Reset(); |
| 967 | 957 |
| 968 host()->dispatcher()->HoldPointerMoves(); | 958 host()->dispatcher()->HoldPointerMoves(); |
| 969 | 959 |
| 970 ui::TouchEvent move(ui::ET_TOUCH_MOVED, | 960 ui::TouchEvent move(ui::ET_TOUCH_MOVED, |
| 971 location + gfx::Vector2d(100, 100), | 961 location + gfx::Vector2dF(100.f, 100.f), 0, |
| 972 0, | |
| 973 ui::EventTimeForNow()); | 962 ui::EventTimeForNow()); |
| 974 DispatchEventUsingWindowDispatcher(&move); | 963 DispatchEventUsingWindowDispatcher(&move); |
| 975 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); | 964 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); |
| 976 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN)); | 965 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 977 recorder.Reset(); | 966 recorder.Reset(); |
| 978 | 967 |
| 979 host()->dispatcher()->ReleasePointerMoves(); | 968 host()->dispatcher()->ReleasePointerMoves(); |
| 980 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); | 969 EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); |
| 981 RunAllPendingInMessageLoop(); | 970 RunAllPendingInMessageLoop(); |
| 982 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); | 971 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 994 | 983 |
| 995 test::TestWindowDelegate delegate; | 984 test::TestWindowDelegate delegate; |
| 996 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 985 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 997 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 986 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 998 window->Show(); | 987 window->Show(); |
| 999 window->SetCapture(); | 988 window->SetCapture(); |
| 1000 | 989 |
| 1001 test::TestCursorClient cursor_client(root_window()); | 990 test::TestCursorClient cursor_client(root_window()); |
| 1002 | 991 |
| 1003 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 992 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 1004 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 993 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 1005 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 994 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), 0, 0); |
| 1006 DispatchEventUsingWindowDispatcher(&mouse1); | 995 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1007 EXPECT_FALSE(recorder.events().empty()); | 996 EXPECT_FALSE(recorder.events().empty()); |
| 1008 recorder.Reset(); | 997 recorder.Reset(); |
| 1009 | 998 |
| 1010 // Dispatch a synthetic mouse event when mouse events are enabled. | 999 // Dispatch a synthetic mouse event when mouse events are enabled. |
| 1011 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1000 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 1012 gfx::Point(10, 10), ui::EventTimeForNow(), | 1001 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), |
| 1013 ui::EF_IS_SYNTHESIZED, 0); | 1002 ui::EF_IS_SYNTHESIZED, 0); |
| 1014 DispatchEventUsingWindowDispatcher(&mouse2); | 1003 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1015 EXPECT_FALSE(recorder.events().empty()); | 1004 EXPECT_FALSE(recorder.events().empty()); |
| 1016 recorder.Reset(); | 1005 recorder.Reset(); |
| 1017 | 1006 |
| 1018 // Dispatch a synthetic mouse event when mouse events are disabled. | 1007 // Dispatch a synthetic mouse event when mouse events are disabled. |
| 1019 cursor_client.DisableMouseEvents(); | 1008 cursor_client.DisableMouseEvents(); |
| 1020 DispatchEventUsingWindowDispatcher(&mouse2); | 1009 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1021 EXPECT_TRUE(recorder.events().empty()); | 1010 EXPECT_TRUE(recorder.events().empty()); |
| 1022 root_window()->RemovePreTargetHandler(&recorder); | 1011 root_window()->RemovePreTargetHandler(&recorder); |
| 1023 } | 1012 } |
| 1024 | 1013 |
| 1025 // Tests that a mouse-move event is not synthesized when a mouse-button is down. | 1014 // Tests that a mouse-move event is not synthesized when a mouse-button is down. |
| 1026 TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { | 1015 TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { |
| 1027 EventFilterRecorder recorder; | 1016 EventFilterRecorder recorder; |
| 1028 test::TestWindowDelegate delegate; | 1017 test::TestWindowDelegate delegate; |
| 1029 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1018 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1030 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1019 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1031 window->Show(); | 1020 window->Show(); |
| 1032 | 1021 |
| 1033 window->AddPreTargetHandler(&recorder); | 1022 window->AddPreTargetHandler(&recorder); |
| 1034 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1023 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 1035 ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1024 ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), |
| 1036 gfx::Point(10, 10), ui::EventTimeForNow(), | 1025 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), |
| 1037 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1026 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1038 DispatchEventUsingWindowDispatcher(&mouse1); | 1027 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1039 ASSERT_EQ(1u, recorder.events().size()); | 1028 ASSERT_EQ(1u, recorder.events().size()); |
| 1040 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]); | 1029 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]); |
| 1041 window->RemovePreTargetHandler(&recorder); | 1030 window->RemovePreTargetHandler(&recorder); |
| 1042 recorder.Reset(); | 1031 recorder.Reset(); |
| 1043 | 1032 |
| 1044 // Move |window| away from underneath the cursor. | 1033 // Move |window| away from underneath the cursor. |
| 1045 root_window()->AddPreTargetHandler(&recorder); | 1034 root_window()->AddPreTargetHandler(&recorder); |
| 1046 window->SetBounds(gfx::Rect(30, 30, 100, 100)); | 1035 window->SetBounds(gfx::Rect(30, 30, 100, 100)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1065 test::TestWindowDelegate delegate; | 1054 test::TestWindowDelegate delegate; |
| 1066 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1055 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1067 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1056 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1068 window->Show(); | 1057 window->Show(); |
| 1069 window->SetCapture(); | 1058 window->SetCapture(); |
| 1070 | 1059 |
| 1071 EventFilterRecorder recorder; | 1060 EventFilterRecorder recorder; |
| 1072 window->AddPreTargetHandler(&recorder); | 1061 window->AddPreTargetHandler(&recorder); |
| 1073 | 1062 |
| 1074 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. | 1063 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. |
| 1075 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1064 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 1076 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1065 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), 0, 0); |
| 1077 DispatchEventUsingWindowDispatcher(&mouse); | 1066 DispatchEventUsingWindowDispatcher(&mouse); |
| 1078 EXPECT_FALSE(recorder.events().empty()); | 1067 EXPECT_FALSE(recorder.events().empty()); |
| 1079 recorder.Reset(); | 1068 recorder.Reset(); |
| 1080 | 1069 |
| 1081 // Update the window bounds so that cursor is now outside the window. | 1070 // Update the window bounds so that cursor is now outside the window. |
| 1082 // This should trigger a synthetic MOVED event. | 1071 // This should trigger a synthetic MOVED event. |
| 1083 gfx::Rect bounds1(20, 20, 100, 100); | 1072 gfx::Rect bounds1(20, 20, 100, 100); |
| 1084 window->SetBounds(bounds1); | 1073 window->SetBounds(bounds1); |
| 1085 RunAllPendingInMessageLoop(); | 1074 RunAllPendingInMessageLoop(); |
| 1086 ASSERT_FALSE(recorder.events().empty()); | 1075 ASSERT_FALSE(recorder.events().empty()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 root_window()->AddPreTargetHandler(&recorder); | 1108 root_window()->AddPreTargetHandler(&recorder); |
| 1120 | 1109 |
| 1121 test::TestWindowDelegate delegate; | 1110 test::TestWindowDelegate delegate; |
| 1122 gfx::Point window_origin(7, 18); | 1111 gfx::Point window_origin(7, 18); |
| 1123 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1112 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1124 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1113 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
| 1125 root_window())); | 1114 root_window())); |
| 1126 window->Show(); | 1115 window->Show(); |
| 1127 | 1116 |
| 1128 // Dispatch a mouse move event into the window. | 1117 // Dispatch a mouse move event into the window. |
| 1129 gfx::Point mouse_location(gfx::Point(15, 25)); | 1118 gfx::PointF mouse_location(15., 25.f); |
| 1130 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1119 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, |
| 1131 ui::EventTimeForNow(), 0, 0); | 1120 ui::EventTimeForNow(), 0, 0); |
| 1132 EXPECT_TRUE(recorder.events().empty()); | 1121 EXPECT_TRUE(recorder.events().empty()); |
| 1133 DispatchEventUsingWindowDispatcher(&mouse1); | 1122 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1134 EXPECT_FALSE(recorder.events().empty()); | 1123 EXPECT_FALSE(recorder.events().empty()); |
| 1135 recorder.Reset(); | 1124 recorder.Reset(); |
| 1136 | 1125 |
| 1137 // Hide the cursor and verify a mouse exit was dispatched. | 1126 // Hide the cursor and verify a mouse exit was dispatched. |
| 1138 host()->OnCursorVisibilityChanged(false); | 1127 host()->OnCursorVisibilityChanged(false); |
| 1139 EXPECT_FALSE(recorder.events().empty()); | 1128 EXPECT_FALSE(recorder.events().empty()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1156 root_window()->AddPreTargetHandler(&recorder); | 1145 root_window()->AddPreTargetHandler(&recorder); |
| 1157 | 1146 |
| 1158 test::TestWindowDelegate delegate; | 1147 test::TestWindowDelegate delegate; |
| 1159 gfx::Point window_origin(7, 18); | 1148 gfx::Point window_origin(7, 18); |
| 1160 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1149 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1161 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1150 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
| 1162 root_window())); | 1151 root_window())); |
| 1163 window->Show(); | 1152 window->Show(); |
| 1164 | 1153 |
| 1165 // Dispatch a mouse move event into the window. | 1154 // Dispatch a mouse move event into the window. |
| 1166 gfx::Point mouse_location(gfx::Point(15, 25)); | 1155 gfx::PointF mouse_location(15.f, 25.f); |
| 1167 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1156 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, |
| 1168 ui::EventTimeForNow(), 0, 0); | 1157 ui::EventTimeForNow(), 0, 0); |
| 1169 EXPECT_TRUE(recorder.events().empty()); | 1158 EXPECT_TRUE(recorder.events().empty()); |
| 1170 DispatchEventUsingWindowDispatcher(&mouse1); | 1159 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1171 EXPECT_FALSE(recorder.events().empty()); | 1160 EXPECT_FALSE(recorder.events().empty()); |
| 1172 recorder.Reset(); | 1161 recorder.Reset(); |
| 1173 | 1162 |
| 1174 test::TestCursorClient cursor_client(root_window()); | 1163 test::TestCursorClient cursor_client(root_window()); |
| 1175 cursor_client.DisableMouseEvents(); | 1164 cursor_client.DisableMouseEvents(); |
| 1176 | 1165 |
| 1177 gfx::Point mouse_exit_location(gfx::Point(150, 150)); | 1166 gfx::Point mouse_exit_location(gfx::Point(150, 150)); |
| 1178 ui::MouseEvent mouse2(ui::ET_MOUSE_EXITED, gfx::Point(150, 150), | 1167 ui::MouseEvent mouse2(ui::ET_MOUSE_EXITED, gfx::PointF(150.f, 150.f), |
| 1179 gfx::Point(150, 150), ui::EventTimeForNow(), | 1168 gfx::PointF(150.f, 150.f), ui::EventTimeForNow(), |
| 1180 ui::EF_IS_SYNTHESIZED, 0); | 1169 ui::EF_IS_SYNTHESIZED, 0); |
| 1181 DispatchEventUsingWindowDispatcher(&mouse2); | 1170 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1182 | 1171 |
| 1183 EXPECT_FALSE(recorder.events().empty()); | 1172 EXPECT_FALSE(recorder.events().empty()); |
| 1184 // We get the mouse exited event twice in our filter. Once during the | 1173 // We get the mouse exited event twice in our filter. Once during the |
| 1185 // predispatch phase and during the actual dispatch. | 1174 // predispatch phase and during the actual dispatch. |
| 1186 EXPECT_EQ("MOUSE_EXITED MOUSE_EXITED", EventTypesToString(recorder.events())); | 1175 EXPECT_EQ("MOUSE_EXITED MOUSE_EXITED", EventTypesToString(recorder.events())); |
| 1187 | 1176 |
| 1188 // Verify the mouse exit was dispatched at the correct location | 1177 // Verify the mouse exit was dispatched at the correct location |
| 1189 // (in the correct coordinate space). | 1178 // (in the correct coordinate space). |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 : root_(root), | 1642 : root_(root), |
| 1654 mouse_event_count_(0) {} | 1643 mouse_event_count_(0) {} |
| 1655 ~DontResetHeldEventWindowDelegate() override {} | 1644 ~DontResetHeldEventWindowDelegate() override {} |
| 1656 | 1645 |
| 1657 int mouse_event_count() const { return mouse_event_count_; } | 1646 int mouse_event_count() const { return mouse_event_count_; } |
| 1658 | 1647 |
| 1659 // TestWindowDelegate: | 1648 // TestWindowDelegate: |
| 1660 void OnMouseEvent(ui::MouseEvent* event) override { | 1649 void OnMouseEvent(ui::MouseEvent* event) override { |
| 1661 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && | 1650 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && |
| 1662 mouse_event_count_++ == 0) { | 1651 mouse_event_count_++ == 0) { |
| 1663 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1652 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), |
| 1664 gfx::Point(10, 10), ui::EventTimeForNow(), | 1653 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), |
| 1665 ui::EF_SHIFT_DOWN, 0); | 1654 ui::EF_SHIFT_DOWN, 0); |
| 1666 root_->GetHost()->dispatcher()->RepostEvent(mouse_event); | 1655 root_->GetHost()->dispatcher()->RepostEvent(mouse_event); |
| 1667 } | 1656 } |
| 1668 } | 1657 } |
| 1669 | 1658 |
| 1670 private: | 1659 private: |
| 1671 Window* root_; | 1660 Window* root_; |
| 1672 int mouse_event_count_; | 1661 int mouse_event_count_; |
| 1673 | 1662 |
| 1674 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); | 1663 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); |
| 1675 }; | 1664 }; |
| 1676 | 1665 |
| 1677 } // namespace | 1666 } // namespace |
| 1678 | 1667 |
| 1679 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1668 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
| 1680 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1669 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
| 1681 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1670 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
| 1682 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1671 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
| 1683 // schedule another reposted event. | 1672 // schedule another reposted event. |
| 1684 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { | 1673 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { |
| 1685 DontResetHeldEventWindowDelegate delegate(root_window()); | 1674 DontResetHeldEventWindowDelegate delegate(root_window()); |
| 1686 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1675 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
| 1687 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1676 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1688 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1677 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), |
| 1689 gfx::Point(10, 10), ui::EventTimeForNow(), | 1678 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), |
| 1690 ui::EF_SHIFT_DOWN, 0); | 1679 ui::EF_SHIFT_DOWN, 0); |
| 1691 root_window()->GetHost()->dispatcher()->RepostEvent(pressed); | 1680 root_window()->GetHost()->dispatcher()->RepostEvent(pressed); |
| 1692 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1681 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), |
| 1693 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1682 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), 0, 0); |
| 1694 // Dispatch an event to flush event scheduled by way of RepostEvent(). | 1683 // Dispatch an event to flush event scheduled by way of RepostEvent(). |
| 1695 DispatchEventUsingWindowDispatcher(&pressed2); | 1684 DispatchEventUsingWindowDispatcher(&pressed2); |
| 1696 // Delegate should have seen reposted event (identified by way of | 1685 // Delegate should have seen reposted event (identified by way of |
| 1697 // EF_SHIFT_DOWN). Dispatch another event to flush the second | 1686 // EF_SHIFT_DOWN). Dispatch another event to flush the second |
| 1698 // RepostedEvent(). | 1687 // RepostedEvent(). |
| 1699 EXPECT_EQ(1, delegate.mouse_event_count()); | 1688 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 1700 DispatchEventUsingWindowDispatcher(&pressed2); | 1689 DispatchEventUsingWindowDispatcher(&pressed2); |
| 1701 EXPECT_EQ(2, delegate.mouse_event_count()); | 1690 EXPECT_EQ(2, delegate.mouse_event_count()); |
| 1702 } | 1691 } |
| 1703 | 1692 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event | 1728 // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event |
| 1740 // we don't crash. | 1729 // we don't crash. |
| 1741 TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { | 1730 TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { |
| 1742 // Should be deleted by |delegate|. | 1731 // Should be deleted by |delegate|. |
| 1743 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); | 1732 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); |
| 1744 h2->InitHost(); | 1733 h2->InitHost(); |
| 1745 DeleteHostFromHeldMouseEventDelegate delegate(h2); | 1734 DeleteHostFromHeldMouseEventDelegate delegate(h2); |
| 1746 // Owned by |h2|. | 1735 // Owned by |h2|. |
| 1747 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); | 1736 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); |
| 1748 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1737 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1749 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1738 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), |
| 1750 gfx::Point(10, 10), ui::EventTimeForNow(), | 1739 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), |
| 1751 ui::EF_SHIFT_DOWN, 0); | 1740 ui::EF_SHIFT_DOWN, 0); |
| 1752 h2->dispatcher()->RepostEvent(pressed); | 1741 h2->dispatcher()->RepostEvent(pressed); |
| 1753 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. | 1742 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. |
| 1754 RunAllPendingInMessageLoop(); | 1743 RunAllPendingInMessageLoop(); |
| 1755 EXPECT_TRUE(delegate.got_mouse_event()); | 1744 EXPECT_TRUE(delegate.got_mouse_event()); |
| 1756 EXPECT_TRUE(delegate.got_destroy()); | 1745 EXPECT_TRUE(delegate.got_destroy()); |
| 1757 } | 1746 } |
| 1758 | 1747 |
| 1759 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { | 1748 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { |
| 1760 EventFilterRecorder recorder; | 1749 EventFilterRecorder recorder; |
| 1761 root_window()->AddPreTargetHandler(&recorder); | 1750 root_window()->AddPreTargetHandler(&recorder); |
| 1762 | 1751 |
| 1763 test::TestWindowDelegate delegate; | 1752 test::TestWindowDelegate delegate; |
| 1764 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1753 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1765 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1754 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 1766 | 1755 |
| 1767 gfx::Point position1 = root_window()->bounds().origin(); | 1756 auto position1 = gfx::PointF(root_window()->bounds().origin()); |
| 1768 ui::TouchEvent press( | 1757 ui::TouchEvent press( |
| 1769 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); | 1758 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); |
| 1770 DispatchEventUsingWindowDispatcher(&press); | 1759 DispatchEventUsingWindowDispatcher(&press); |
| 1771 | 1760 |
| 1772 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", | 1761 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", |
| 1773 EventTypesToString(recorder.GetAndResetEvents())); | 1762 EventTypesToString(recorder.GetAndResetEvents())); |
| 1774 | 1763 |
| 1775 window->Hide(); | 1764 window->Hide(); |
| 1776 | 1765 |
| 1777 EXPECT_EQ(ui::ET_TOUCH_CANCELLED, recorder.events()[0]); | 1766 EXPECT_EQ(ui::ET_TOUCH_CANCELLED, recorder.events()[0]); |
| 1778 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_TAP_CANCEL)); | 1767 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_TAP_CANCEL)); |
| 1779 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_END)); | 1768 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_END)); |
| 1780 EXPECT_EQ(3U, recorder.events().size()); | 1769 EXPECT_EQ(3U, recorder.events().size()); |
| 1781 root_window()->RemovePreTargetHandler(&recorder); | 1770 root_window()->RemovePreTargetHandler(&recorder); |
| 1782 } | 1771 } |
| 1783 | 1772 |
| 1784 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { | 1773 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { |
| 1785 EventFilterRecorder recorder; | 1774 EventFilterRecorder recorder; |
| 1786 root_window()->AddPreTargetHandler(&recorder); | 1775 root_window()->AddPreTargetHandler(&recorder); |
| 1787 | 1776 |
| 1788 test::TestWindowDelegate delegate; | 1777 test::TestWindowDelegate delegate; |
| 1789 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1778 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1790 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1779 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 1791 | 1780 |
| 1792 gfx::Point position1 = root_window()->bounds().origin(); | 1781 auto position1 = gfx::PointF(root_window()->bounds().origin()); |
| 1793 gfx::Point position2 = root_window()->bounds().CenterPoint(); | 1782 auto position2 = gfx::PointF(root_window()->bounds().CenterPoint()); |
| 1794 ui::TouchEvent press( | 1783 ui::TouchEvent press( |
| 1795 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); | 1784 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); |
| 1796 DispatchEventUsingWindowDispatcher(&press); | 1785 DispatchEventUsingWindowDispatcher(&press); |
| 1797 | 1786 |
| 1798 ui::TouchEvent move( | 1787 ui::TouchEvent move( |
| 1799 ui::ET_TOUCH_MOVED, position2, 0, ui::EventTimeForNow()); | 1788 ui::ET_TOUCH_MOVED, position2, 0, ui::EventTimeForNow()); |
| 1800 DispatchEventUsingWindowDispatcher(&move); | 1789 DispatchEventUsingWindowDispatcher(&move); |
| 1801 | 1790 |
| 1802 ui::TouchEvent press2( | 1791 ui::TouchEvent press2( |
| 1803 ui::ET_TOUCH_PRESSED, position1, 1, ui::EventTimeForNow()); | 1792 ui::ET_TOUCH_PRESSED, position1, 1, ui::EventTimeForNow()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 EventFilterRecorder recorder2; | 1830 EventFilterRecorder recorder2; |
| 1842 scoped_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL)); | 1831 scoped_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL)); |
| 1843 window1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1832 window1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1844 | 1833 |
| 1845 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); | 1834 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); |
| 1846 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); | 1835 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); |
| 1847 | 1836 |
| 1848 window1->AddPreTargetHandler(&recorder1); | 1837 window1->AddPreTargetHandler(&recorder1); |
| 1849 window2->AddPreTargetHandler(&recorder2); | 1838 window2->AddPreTargetHandler(&recorder2); |
| 1850 | 1839 |
| 1851 gfx::Point position = window1->bounds().origin(); | 1840 auto position = gfx::PointF(window1->bounds().origin()); |
| 1852 ui::TouchEvent press( | 1841 ui::TouchEvent press( |
| 1853 ui::ET_TOUCH_PRESSED, position, 0, ui::EventTimeForNow()); | 1842 ui::ET_TOUCH_PRESSED, position, 0, ui::EventTimeForNow()); |
| 1854 DispatchEventUsingWindowDispatcher(&press); | 1843 DispatchEventUsingWindowDispatcher(&press); |
| 1855 | 1844 |
| 1856 gfx::Point position2 = window1->bounds().CenterPoint(); | 1845 auto position2 = gfx::PointF(window1->bounds().CenterPoint()); |
| 1857 ui::TouchEvent move( | 1846 ui::TouchEvent move( |
| 1858 ui::ET_TOUCH_MOVED, position2, 0, ui::EventTimeForNow()); | 1847 ui::ET_TOUCH_MOVED, position2, 0, ui::EventTimeForNow()); |
| 1859 DispatchEventUsingWindowDispatcher(&move); | 1848 DispatchEventUsingWindowDispatcher(&move); |
| 1860 | 1849 |
| 1861 window2->SetCapture(); | 1850 window2->SetCapture(); |
| 1862 | 1851 |
| 1863 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " | 1852 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " |
| 1864 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " | 1853 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " |
| 1865 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END", | 1854 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END", |
| 1866 EventTypesToString(recorder1.events())); | 1855 EventTypesToString(recorder1.events())); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 | 1933 |
| 1945 void RunTest() { | 1934 void RunTest() { |
| 1946 // Reset any event the window may have received when bringing up the window | 1935 // Reset any event the window may have received when bringing up the window |
| 1947 // (e.g. mouse-move events if the mouse cursor is over the window). | 1936 // (e.g. mouse-move events if the mouse cursor is over the window). |
| 1948 handler_.Reset(); | 1937 handler_.Reset(); |
| 1949 | 1938 |
| 1950 // Start a nested message-loop, post an event to be dispatched, and then | 1939 // Start a nested message-loop, post an event to be dispatched, and then |
| 1951 // terminate the message-loop. When the message-loop unwinds and gets back, | 1940 // terminate the message-loop. When the message-loop unwinds and gets back, |
| 1952 // the reposted event should not have fired. | 1941 // the reposted event should not have fired. |
| 1953 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( | 1942 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
| 1954 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), | 1943 ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), gfx::PointF(10.f, 10.f), |
| 1955 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); | 1944 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); |
| 1956 message_loop()->PostTask( | 1945 message_loop()->PostTask( |
| 1957 FROM_HERE, | 1946 FROM_HERE, |
| 1958 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, | 1947 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, |
| 1959 host()->dispatcher(), | 1948 host()->dispatcher(), |
| 1960 base::Passed(&mouse))); | 1949 base::Passed(&mouse))); |
| 1961 message_loop()->PostTask(FROM_HERE, message_loop()->QuitClosure()); | 1950 message_loop()->PostTask(FROM_HERE, message_loop()->QuitClosure()); |
| 1962 | 1951 |
| 1963 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); | 1952 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); |
| 1964 base::RunLoop loop; | 1953 base::RunLoop loop; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, | 2019 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, |
| 2031 1234, gfx::Rect(20, 20, 100, 100), root_window())); | 2020 1234, gfx::Rect(20, 20, 100, 100), root_window())); |
| 2032 child->Show(); | 2021 child->Show(); |
| 2033 | 2022 |
| 2034 ui::test::TestEventHandler handler_child; | 2023 ui::test::TestEventHandler handler_child; |
| 2035 ui::test::TestEventHandler handler_root; | 2024 ui::test::TestEventHandler handler_root; |
| 2036 root_window()->AddPreTargetHandler(&handler_root); | 2025 root_window()->AddPreTargetHandler(&handler_root); |
| 2037 child->AddPreTargetHandler(&handler_child); | 2026 child->AddPreTargetHandler(&handler_child); |
| 2038 | 2027 |
| 2039 { | 2028 { |
| 2040 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(30, 30), | 2029 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::PointF(30.f, 30.f), |
| 2041 gfx::Point(30, 30), ui::EventTimeForNow(), ui::EF_NONE, | 2030 gfx::PointF(30.f, 30.f), ui::EventTimeForNow(), |
| 2042 ui::EF_NONE); | 2031 ui::EF_NONE, ui::EF_NONE); |
| 2043 DispatchEventUsingWindowDispatcher(&move); | 2032 DispatchEventUsingWindowDispatcher(&move); |
| 2044 EXPECT_EQ(0, handler_child.num_mouse_events()); | 2033 EXPECT_EQ(0, handler_child.num_mouse_events()); |
| 2045 EXPECT_EQ(1, handler_root.num_mouse_events()); | 2034 EXPECT_EQ(1, handler_root.num_mouse_events()); |
| 2046 } | 2035 } |
| 2047 | 2036 |
| 2048 { | 2037 { |
| 2049 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), | 2038 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::PointF(50.f, 50.f), |
| 2050 gfx::Point(50, 50), ui::EventTimeForNow(), ui::EF_NONE, | 2039 gfx::PointF(50.f, 50.f), ui::EventTimeForNow(), |
| 2051 ui::EF_NONE); | 2040 ui::EF_NONE, ui::EF_NONE); |
| 2052 DispatchEventUsingWindowDispatcher(&move); | 2041 DispatchEventUsingWindowDispatcher(&move); |
| 2053 // The child receives an ENTER, and a MOVED event. | 2042 // The child receives an ENTER, and a MOVED event. |
| 2054 EXPECT_EQ(2, handler_child.num_mouse_events()); | 2043 EXPECT_EQ(2, handler_child.num_mouse_events()); |
| 2055 // The root receives both the ENTER and the MOVED events dispatched to | 2044 // The root receives both the ENTER and the MOVED events dispatched to |
| 2056 // |child|, as well as an EXIT event. | 2045 // |child|, as well as an EXIT event. |
| 2057 EXPECT_EQ(3, handler_root.num_mouse_events()); | 2046 EXPECT_EQ(3, handler_root.num_mouse_events()); |
| 2058 } | 2047 } |
| 2059 | 2048 |
| 2060 child->RemovePreTargetHandler(&handler_child); | 2049 child->RemovePreTargetHandler(&handler_child); |
| 2061 root_window()->RemovePreTargetHandler(&handler_root); | 2050 root_window()->RemovePreTargetHandler(&handler_root); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 | 2119 |
| 2131 // Tests that if dispatching a 'held' event triggers a nested message loop, then | 2120 // Tests that if dispatching a 'held' event triggers a nested message loop, then |
| 2132 // the events that are dispatched from the nested message loop are transformed | 2121 // the events that are dispatched from the nested message loop are transformed |
| 2133 // correctly. | 2122 // correctly. |
| 2134 TEST_F(WindowEventDispatcherTestInHighDPI, | 2123 TEST_F(WindowEventDispatcherTestInHighDPI, |
| 2135 EventsTransformedInRepostedEventTriggeredNestedLoop) { | 2124 EventsTransformedInRepostedEventTriggeredNestedLoop) { |
| 2136 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 2125 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 2137 // Make sure the window is visible. | 2126 // Make sure the window is visible. |
| 2138 RunAllPendingInMessageLoop(); | 2127 RunAllPendingInMessageLoop(); |
| 2139 | 2128 |
| 2140 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::Point(80, 80), | 2129 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::PointF(80.f, 80.f), |
| 2141 gfx::Point(80, 80), ui::EventTimeForNow(), | 2130 gfx::PointF(80.f, 80.f), ui::EventTimeForNow(), |
| 2142 ui::EF_NONE, ui::EF_NONE); | 2131 ui::EF_NONE, ui::EF_NONE); |
| 2143 const base::Closure callback_on_right_click = base::Bind( | 2132 const base::Closure callback_on_right_click = base::Bind( |
| 2144 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), | 2133 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), |
| 2145 base::Unretained(this), base::Unretained(&mouse_move)); | 2134 base::Unretained(this), base::Unretained(&mouse_move)); |
| 2146 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); | 2135 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); |
| 2147 window->AddPreTargetHandler(&handler); | 2136 window->AddPreTargetHandler(&handler); |
| 2148 | 2137 |
| 2149 scoped_ptr<ui::MouseEvent> mouse( | 2138 scoped_ptr<ui::MouseEvent> mouse( |
| 2150 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 2139 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(10.f, 10.f), |
| 2151 gfx::Point(10, 10), ui::EventTimeForNow(), | 2140 gfx::PointF(10.f, 10.f), ui::EventTimeForNow(), |
| 2152 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 2141 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
| 2153 host()->dispatcher()->RepostEvent(*mouse); | 2142 host()->dispatcher()->RepostEvent(*mouse); |
| 2154 EXPECT_EQ(0, handler.num_mouse_events()); | 2143 EXPECT_EQ(0, handler.num_mouse_events()); |
| 2155 | 2144 |
| 2156 base::RunLoop run_loop; | 2145 base::RunLoop run_loop; |
| 2157 run_loop.RunUntilIdle(); | 2146 run_loop.RunUntilIdle(); |
| 2158 // The window should receive the mouse-press and the mouse-move events. | 2147 // The window should receive the mouse-press and the mouse-move events. |
| 2159 EXPECT_EQ(2, handler.num_mouse_events()); | 2148 EXPECT_EQ(2, handler.num_mouse_events()); |
| 2160 // The mouse-move event location should be transformed because of the DSF | 2149 // The mouse-move event location should be transformed because of the DSF |
| 2161 // before it reaches the window. | 2150 // before it reaches the window. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2183 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); | 2172 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); |
| 2184 }; | 2173 }; |
| 2185 | 2174 |
| 2186 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { | 2175 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { |
| 2187 ui::test::EventGenerator generator(root_window()); | 2176 ui::test::EventGenerator generator(root_window()); |
| 2188 generator.MoveMouseTo(10, 10); | 2177 generator.MoveMouseTo(10, 10); |
| 2189 EXPECT_EQ("10,10", | 2178 EXPECT_EQ("10,10", |
| 2190 Env::GetInstance()->last_mouse_location().ToString()); | 2179 Env::GetInstance()->last_mouse_location().ToString()); |
| 2191 | 2180 |
| 2192 // Synthesized event should not update the mouse location. | 2181 // Synthesized event should not update the mouse location. |
| 2193 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 2182 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::PointF(), gfx::PointF(), |
| 2194 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0); | 2183 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0); |
| 2195 generator.Dispatch(&mouseev); | 2184 generator.Dispatch(&mouseev); |
| 2196 EXPECT_EQ("10,10", | 2185 EXPECT_EQ("10,10", |
| 2197 Env::GetInstance()->last_mouse_location().ToString()); | 2186 Env::GetInstance()->last_mouse_location().ToString()); |
| 2198 | 2187 |
| 2199 generator.MoveMouseTo(0, 0); | 2188 generator.MoveMouseTo(0, 0); |
| 2200 EXPECT_EQ("0,0", | 2189 EXPECT_EQ("0,0", |
| 2201 Env::GetInstance()->last_mouse_location().ToString()); | 2190 Env::GetInstance()->last_mouse_location().ToString()); |
| 2202 | 2191 |
| 2203 // Make sure the location gets updated when a syntheiszed enter | 2192 // Make sure the location gets updated when a syntheiszed enter |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2278 explicit DispatchEventHandler(Window* target) | 2267 explicit DispatchEventHandler(Window* target) |
| 2279 : target_(target), | 2268 : target_(target), |
| 2280 dispatched_(false) {} | 2269 dispatched_(false) {} |
| 2281 ~DispatchEventHandler() override {} | 2270 ~DispatchEventHandler() override {} |
| 2282 | 2271 |
| 2283 bool dispatched() const { return dispatched_; } | 2272 bool dispatched() const { return dispatched_; } |
| 2284 private: | 2273 private: |
| 2285 // ui::EventHandler: | 2274 // ui::EventHandler: |
| 2286 void OnMouseEvent(ui::MouseEvent* mouse) override { | 2275 void OnMouseEvent(ui::MouseEvent* mouse) override { |
| 2287 if (mouse->type() == ui::ET_MOUSE_MOVED) { | 2276 if (mouse->type() == ui::ET_MOUSE_MOVED) { |
| 2288 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), | 2277 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 2289 target_->bounds().CenterPoint(), | 2278 gfx::PointF(target_->bounds().CenterPoint()), |
| 2279 gfx::PointF(target_->bounds().CenterPoint()), |
| 2290 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 2280 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 2291 ui::EventDispatchDetails details = | 2281 ui::EventDispatchDetails details = |
| 2292 target_->GetHost()->dispatcher()->OnEventFromSource(&move); | 2282 target_->GetHost()->dispatcher()->OnEventFromSource(&move); |
| 2293 ASSERT_FALSE(details.dispatcher_destroyed); | 2283 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2294 EXPECT_FALSE(details.target_destroyed); | 2284 EXPECT_FALSE(details.target_destroyed); |
| 2295 EXPECT_EQ(target_, move.target()); | 2285 EXPECT_EQ(target_, move.target()); |
| 2296 dispatched_ = true; | 2286 dispatched_ = true; |
| 2297 } | 2287 } |
| 2298 ui::EventHandler::OnMouseEvent(mouse); | 2288 ui::EventHandler::OnMouseEvent(mouse); |
| 2299 } | 2289 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 // when |second| receives an event. | 2342 // when |second| receives an event. |
| 2353 MoveWindowHandler move_window(first.get(), second_root); | 2343 MoveWindowHandler move_window(first.get(), second_root); |
| 2354 second->AddPreTargetHandler(&move_window); | 2344 second->AddPreTargetHandler(&move_window); |
| 2355 | 2345 |
| 2356 // Some sanity checks: |first| is inside |root_window()|'s tree. | 2346 // Some sanity checks: |first| is inside |root_window()|'s tree. |
| 2357 EXPECT_EQ(root_window(), first->GetRootWindow()); | 2347 EXPECT_EQ(root_window(), first->GetRootWindow()); |
| 2358 // The two root windows are different. | 2348 // The two root windows are different. |
| 2359 EXPECT_NE(root_window(), second_root); | 2349 EXPECT_NE(root_window(), second_root); |
| 2360 | 2350 |
| 2361 // Dispatch an event to |first|. | 2351 // Dispatch an event to |first|. |
| 2362 ui::MouseEvent move(ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(), | 2352 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 2363 first->bounds().CenterPoint(), ui::EventTimeForNow(), | 2353 gfx::PointF(first->bounds().CenterPoint()), |
| 2364 ui::EF_NONE, ui::EF_NONE); | 2354 gfx::PointF(first->bounds().CenterPoint()), |
| 2355 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 2365 ui::EventDispatchDetails details = | 2356 ui::EventDispatchDetails details = |
| 2366 host()->dispatcher()->OnEventFromSource(&move); | 2357 host()->dispatcher()->OnEventFromSource(&move); |
| 2367 ASSERT_FALSE(details.dispatcher_destroyed); | 2358 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2368 EXPECT_TRUE(details.target_destroyed); | 2359 EXPECT_TRUE(details.target_destroyed); |
| 2369 EXPECT_EQ(first.get(), move.target()); | 2360 EXPECT_EQ(first.get(), move.target()); |
| 2370 EXPECT_TRUE(dispatch_event.dispatched()); | 2361 EXPECT_TRUE(dispatch_event.dispatched()); |
| 2371 EXPECT_EQ(second_root, first->GetRootWindow()); | 2362 EXPECT_EQ(second_root, first->GetRootWindow()); |
| 2372 | 2363 |
| 2373 first->RemovePreTargetHandler(&dispatch_event); | 2364 first->RemovePreTargetHandler(&dispatch_event); |
| 2374 second->RemovePreTargetHandler(&move_window); | 2365 second->RemovePreTargetHandler(&move_window); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2450 window_second->SetCapture(); | 2441 window_second->SetCapture(); |
| 2451 EXPECT_EQ(window_second.get(), | 2442 EXPECT_EQ(window_second.get(), |
| 2452 client::GetCaptureWindow(root_window())); | 2443 client::GetCaptureWindow(root_window())); |
| 2453 | 2444 |
| 2454 // Send an event to the first host. Make sure it goes to |window_second| in | 2445 // Send an event to the first host. Make sure it goes to |window_second| in |
| 2455 // |second_host| instead (since it has capture). | 2446 // |second_host| instead (since it has capture). |
| 2456 EventFilterRecorder recorder_first; | 2447 EventFilterRecorder recorder_first; |
| 2457 window_first->AddPreTargetHandler(&recorder_first); | 2448 window_first->AddPreTargetHandler(&recorder_first); |
| 2458 EventFilterRecorder recorder_second; | 2449 EventFilterRecorder recorder_second; |
| 2459 window_second->AddPreTargetHandler(&recorder_second); | 2450 window_second->AddPreTargetHandler(&recorder_second); |
| 2460 const gfx::Point event_location(25, 15); | 2451 const gfx::PointF event_location(25.f, 15.f); |
| 2461 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, event_location, event_location, | 2452 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, event_location, event_location, |
| 2462 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2453 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 2463 ui::EF_LEFT_MOUSE_BUTTON); | 2454 ui::EF_LEFT_MOUSE_BUTTON); |
| 2464 DispatchEventUsingWindowDispatcher(&mouse); | 2455 DispatchEventUsingWindowDispatcher(&mouse); |
| 2465 EXPECT_TRUE(recorder_first.events().empty()); | 2456 EXPECT_TRUE(recorder_first.events().empty()); |
| 2466 ASSERT_EQ(1u, recorder_second.events().size()); | 2457 ASSERT_EQ(1u, recorder_second.events().size()); |
| 2467 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); | 2458 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); |
| 2468 EXPECT_EQ(event_location.ToString(), | 2459 EXPECT_EQ(event_location.ToString(), |
| 2469 recorder_second.mouse_locations()[0].ToString()); | 2460 recorder_second.mouse_locations()[0].ToString()); |
| 2470 } | 2461 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2526 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), | 2517 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), |
| 2527 recorder.gesture_locations()[0].ToString()); | 2518 recorder.gesture_locations()[0].ToString()); |
| 2528 root_window()->RemovePreTargetHandler(&recorder); | 2519 root_window()->RemovePreTargetHandler(&recorder); |
| 2529 } | 2520 } |
| 2530 | 2521 |
| 2531 // Tests that a scroll-generating touch-event is marked as such. | 2522 // Tests that a scroll-generating touch-event is marked as such. |
| 2532 TEST_F(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) { | 2523 TEST_F(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) { |
| 2533 EventFilterRecorder recorder; | 2524 EventFilterRecorder recorder; |
| 2534 root_window()->AddPreTargetHandler(&recorder); | 2525 root_window()->AddPreTargetHandler(&recorder); |
| 2535 | 2526 |
| 2536 const gfx::Point location(20, 20); | 2527 const gfx::PointF location(20.f, 20.f); |
| 2537 ui::TouchEvent press( | 2528 ui::TouchEvent press( |
| 2538 ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow()); | 2529 ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow()); |
| 2539 DispatchEventUsingWindowDispatcher(&press); | 2530 DispatchEventUsingWindowDispatcher(&press); |
| 2540 EXPECT_FALSE(recorder.LastTouchMayCauseScrolling()); | 2531 EXPECT_FALSE(recorder.LastTouchMayCauseScrolling()); |
| 2541 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED)); | 2532 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED)); |
| 2542 recorder.Reset(); | 2533 recorder.Reset(); |
| 2543 | 2534 |
| 2544 ui::TouchEvent move(ui::ET_TOUCH_MOVED, | 2535 ui::TouchEvent move(ui::ET_TOUCH_MOVED, |
| 2545 location + gfx::Vector2d(100, 100), | 2536 location + gfx::Vector2dF(100.f, 100.f), 0, |
| 2546 0, | |
| 2547 ui::EventTimeForNow()); | 2537 ui::EventTimeForNow()); |
| 2548 DispatchEventUsingWindowDispatcher(&move); | 2538 DispatchEventUsingWindowDispatcher(&move); |
| 2549 EXPECT_TRUE(recorder.LastTouchMayCauseScrolling()); | 2539 EXPECT_TRUE(recorder.LastTouchMayCauseScrolling()); |
| 2550 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); | 2540 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); |
| 2551 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN)); | 2541 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 2552 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE)); | 2542 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE)); |
| 2553 recorder.Reset(); | 2543 recorder.Reset(); |
| 2554 | 2544 |
| 2555 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, | 2545 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, |
| 2556 location + gfx::Vector2d(200, 200), | 2546 location + gfx::Vector2dF(200.f, 200.f), 0, |
| 2557 0, | |
| 2558 ui::EventTimeForNow()); | 2547 ui::EventTimeForNow()); |
| 2559 DispatchEventUsingWindowDispatcher(&move2); | 2548 DispatchEventUsingWindowDispatcher(&move2); |
| 2560 EXPECT_TRUE(recorder.LastTouchMayCauseScrolling()); | 2549 EXPECT_TRUE(recorder.LastTouchMayCauseScrolling()); |
| 2561 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); | 2550 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED)); |
| 2562 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE)); | 2551 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE)); |
| 2563 recorder.Reset(); | 2552 recorder.Reset(); |
| 2564 | 2553 |
| 2565 // Delay the release to avoid fling generation. | 2554 // Delay the release to avoid fling generation. |
| 2566 ui::TouchEvent release( | 2555 ui::TouchEvent release( |
| 2567 ui::ET_TOUCH_RELEASED, | 2556 ui::ET_TOUCH_RELEASED, location + gfx::Vector2dF(200.f, 200.f), 0, |
| 2568 location + gfx::Vector2dF(200, 200), | |
| 2569 0, | |
| 2570 ui::EventTimeForNow() + base::TimeDelta::FromSeconds(1)); | 2557 ui::EventTimeForNow() + base::TimeDelta::FromSeconds(1)); |
| 2571 DispatchEventUsingWindowDispatcher(&release); | 2558 DispatchEventUsingWindowDispatcher(&release); |
| 2572 EXPECT_FALSE(recorder.LastTouchMayCauseScrolling()); | 2559 EXPECT_FALSE(recorder.LastTouchMayCauseScrolling()); |
| 2573 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_RELEASED)); | 2560 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_RELEASED)); |
| 2574 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_END)); | 2561 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_END)); |
| 2575 | 2562 |
| 2576 root_window()->RemovePreTargetHandler(&recorder); | 2563 root_window()->RemovePreTargetHandler(&recorder); |
| 2577 } | 2564 } |
| 2578 | 2565 |
| 2579 // OnCursorMovedToRootLocation() is sometimes called instead of | 2566 // OnCursorMovedToRootLocation() is sometimes called instead of |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2601 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. | 2588 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. |
| 2602 test_screen()->SetDeviceScaleFactor(2.f); | 2589 test_screen()->SetDeviceScaleFactor(2.f); |
| 2603 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); | 2590 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); |
| 2604 RunAllPendingInMessageLoop(); | 2591 RunAllPendingInMessageLoop(); |
| 2605 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); | 2592 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); |
| 2606 | 2593 |
| 2607 w->RemovePreTargetHandler(&recorder); | 2594 w->RemovePreTargetHandler(&recorder); |
| 2608 } | 2595 } |
| 2609 | 2596 |
| 2610 } // namespace aura | 2597 } // namespace aura |
| OLD | NEW |