| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const int kWindowHeight = 45; | 119 const int kWindowHeight = 45; |
| 120 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 120 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
| 121 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 121 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
| 122 std::unique_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 122 std::unique_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
| 123 delegate1.get(), -1234, bounds1, root_window())); | 123 delegate1.get(), -1234, bounds1, root_window())); |
| 124 std::unique_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 124 std::unique_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
| 125 delegate2.get(), -5678, bounds2, root_window())); | 125 delegate2.get(), -5678, bounds2, root_window())); |
| 126 | 126 |
| 127 // Send a mouse event to window1. | 127 // Send a mouse event to window1. |
| 128 gfx::Point point(101, 201); | 128 gfx::Point point(101, 201); |
| 129 ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point, point, | 129 ui::MouseEvent event1( |
| 130 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 130 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
| 131 ui::EF_LEFT_MOUSE_BUTTON); | 131 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 132 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 132 DispatchEventUsingWindowDispatcher(&event1); | 133 DispatchEventUsingWindowDispatcher(&event1); |
| 133 | 134 |
| 134 // Event was tested for non-client area for the target window. | 135 // Event was tested for non-client area for the target window. |
| 135 EXPECT_EQ(1, delegate1->non_client_count()); | 136 EXPECT_EQ(1, delegate1->non_client_count()); |
| 136 EXPECT_EQ(0, delegate2->non_client_count()); | 137 EXPECT_EQ(0, delegate2->non_client_count()); |
| 137 // The non-client component test was in local coordinates. | 138 // The non-client component test was in local coordinates. |
| 138 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); | 139 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
| 139 // Mouse event was received by target window. | 140 // Mouse event was received by target window. |
| 140 EXPECT_EQ(1, delegate1->mouse_event_count()); | 141 EXPECT_EQ(1, delegate1->mouse_event_count()); |
| 141 EXPECT_EQ(0, delegate2->mouse_event_count()); | 142 EXPECT_EQ(0, delegate2->mouse_event_count()); |
| 142 // Event was in local coordinates. | 143 // Event was in local coordinates. |
| 143 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); | 144 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); |
| 144 // Non-client flag was set. | 145 // Non-client flag was set. |
| 145 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); | 146 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); |
| 146 } | 147 } |
| 147 | 148 |
| 148 TEST_P(WindowEventDispatcherTest, RepostEvent) { | 149 TEST_P(WindowEventDispatcherTest, RepostEvent) { |
| 149 // Test RepostEvent in RootWindow. It only works for Mouse Press and touch | 150 // Test RepostEvent in RootWindow. It only works for Mouse Press and touch |
| 150 // press. | 151 // press. |
| 151 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 152 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 152 gfx::Point point(10, 10); | 153 gfx::Point point(10, 10); |
| 153 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, point, point, | 154 ui::MouseEvent event( |
| 154 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 155 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
| 155 ui::EF_LEFT_MOUSE_BUTTON); | 156 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 157 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 156 host()->dispatcher()->RepostEvent(&event); | 158 host()->dispatcher()->RepostEvent(&event); |
| 157 RunAllPendingInMessageLoop(); | 159 RunAllPendingInMessageLoop(); |
| 158 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 160 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 159 | 161 |
| 160 ui::TouchEvent touch_pressed_event( | 162 ui::TouchEvent touch_pressed_event( |
| 161 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), ui::EventTimeForNow(), | 163 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), ui::EventTimeForNow(), |
| 162 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); | 164 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); |
| 163 host()->dispatcher()->RepostEvent(&touch_pressed_event); | 165 host()->dispatcher()->RepostEvent(&touch_pressed_event); |
| 164 RunAllPendingInMessageLoop(); | 166 RunAllPendingInMessageLoop(); |
| 165 EXPECT_TRUE(Env::GetInstance()->is_touch_down()); | 167 EXPECT_TRUE(Env::GetInstance()->is_touch_down()); |
| 166 } | 168 } |
| 167 | 169 |
| 168 // Check that we correctly track the state of the mouse buttons in response to | 170 // Check that we correctly track the state of the mouse buttons in response to |
| 169 // button press and release events. | 171 // button press and release events. |
| 170 TEST_P(WindowEventDispatcherTest, MouseButtonState) { | 172 TEST_P(WindowEventDispatcherTest, MouseButtonState) { |
| 171 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 173 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 172 | 174 |
| 173 gfx::Point location; | 175 gfx::Point location; |
| 174 std::unique_ptr<ui::MouseEvent> event; | 176 std::unique_ptr<ui::MouseEvent> event; |
| 175 | 177 |
| 176 // Press the left button. | 178 // Press the left button. |
| 177 event.reset(new ui::MouseEvent( | 179 event.reset(new ui::MouseEvent( |
| 178 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 180 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 179 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 181 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 182 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 180 DispatchEventUsingWindowDispatcher(event.get()); | 183 DispatchEventUsingWindowDispatcher(event.get()); |
| 181 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 184 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 182 | 185 |
| 183 // Additionally press the right. | 186 // Additionally press the right. |
| 184 event.reset(new ui::MouseEvent( | 187 event.reset(new ui::MouseEvent( |
| 185 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 188 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 186 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, | 189 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
| 187 ui::EF_RIGHT_MOUSE_BUTTON)); | 190 ui::EF_RIGHT_MOUSE_BUTTON, |
| 191 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 188 DispatchEventUsingWindowDispatcher(event.get()); | 192 DispatchEventUsingWindowDispatcher(event.get()); |
| 189 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 193 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 190 | 194 |
| 191 // Release the left button. | 195 // Release the left button. |
| 192 event.reset(new ui::MouseEvent( | 196 event.reset(new ui::MouseEvent( |
| 193 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), | 197 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
| 194 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 198 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 199 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 195 DispatchEventUsingWindowDispatcher(event.get()); | 200 DispatchEventUsingWindowDispatcher(event.get()); |
| 196 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 201 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 197 | 202 |
| 198 // Release the right button. We should ignore the Shift-is-down flag. | 203 // Release the right button. We should ignore the Shift-is-down flag. |
| 199 event.reset(new ui::MouseEvent(ui::ET_MOUSE_RELEASED, location, location, | 204 event.reset(new ui::MouseEvent( |
| 200 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, | 205 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
| 201 ui::EF_RIGHT_MOUSE_BUTTON)); | 206 ui::EF_SHIFT_DOWN, ui::EF_RIGHT_MOUSE_BUTTON, |
| 207 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 202 DispatchEventUsingWindowDispatcher(event.get()); | 208 DispatchEventUsingWindowDispatcher(event.get()); |
| 203 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 209 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 204 | 210 |
| 205 // Press the middle button. | 211 // Press the middle button. |
| 206 event.reset(new ui::MouseEvent( | 212 event.reset(new ui::MouseEvent( |
| 207 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 213 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 208 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON)); | 214 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON, |
| 215 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 209 DispatchEventUsingWindowDispatcher(event.get()); | 216 DispatchEventUsingWindowDispatcher(event.get()); |
| 210 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 217 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 211 } | 218 } |
| 212 | 219 |
| 213 TEST_P(WindowEventDispatcherTest, TranslatedEvent) { | 220 TEST_P(WindowEventDispatcherTest, TranslatedEvent) { |
| 214 std::unique_ptr<Window> w1(test::CreateTestWindowWithDelegate( | 221 std::unique_ptr<Window> w1(test::CreateTestWindowWithDelegate( |
| 215 NULL, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 222 NULL, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 216 | 223 |
| 217 gfx::Point origin(100, 100); | 224 gfx::Point origin(100, 100); |
| 218 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, | 225 ui::MouseEvent root( |
| 219 ui::EventTimeForNow(), 0, 0); | 226 ui::ET_MOUSE_PRESSED, origin, origin, ui::EventTimeForNow(), 0, 0, |
| 227 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 220 | 228 |
| 221 EXPECT_EQ("100,100", root.location().ToString()); | 229 EXPECT_EQ("100,100", root.location().ToString()); |
| 222 EXPECT_EQ("100,100", root.root_location().ToString()); | 230 EXPECT_EQ("100,100", root.root_location().ToString()); |
| 223 | 231 |
| 224 ui::MouseEvent translated_event( | 232 ui::MouseEvent translated_event( |
| 225 root, static_cast<Window*>(root_window()), w1.get(), | 233 root, static_cast<Window*>(root_window()), w1.get(), |
| 226 ui::ET_MOUSE_ENTERED, root.flags()); | 234 ui::ET_MOUSE_ENTERED, root.flags()); |
| 227 EXPECT_EQ("50,50", translated_event.location().ToString()); | 235 EXPECT_EQ("50,50", translated_event.location().ToString()); |
| 228 EXPECT_EQ("100,100", translated_event.root_location().ToString()); | 236 EXPECT_EQ("100,100", translated_event.root_location().ToString()); |
| 229 } | 237 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // over |window| and verify |window| gets it (|window| gets it because it has | 647 // over |window| and verify |window| gets it (|window| gets it because it has |
| 640 // capture). | 648 // capture). |
| 641 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 649 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 642 EventFilterRecorder recorder; | 650 EventFilterRecorder recorder; |
| 643 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 651 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 644 window->SetBounds(gfx::Rect(20, 20, 40, 30)); | 652 window->SetBounds(gfx::Rect(20, 20, 40, 30)); |
| 645 window->AddPreTargetHandler(&recorder); | 653 window->AddPreTargetHandler(&recorder); |
| 646 window->SetCapture(); | 654 window->SetCapture(); |
| 647 const ui::MouseEvent press_event( | 655 const ui::MouseEvent press_event( |
| 648 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 656 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 649 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 657 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 658 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 650 host()->dispatcher()->RepostEvent(&press_event); | 659 host()->dispatcher()->RepostEvent(&press_event); |
| 651 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). | 660 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). |
| 652 // Mouse moves/enters may be generated. We only care about a pressed. | 661 // Mouse moves/enters may be generated. We only care about a pressed. |
| 653 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != | 662 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != |
| 654 std::string::npos) << EventTypesToString(recorder.events()); | 663 std::string::npos) << EventTypesToString(recorder.events()); |
| 655 } | 664 } |
| 656 | 665 |
| 657 TEST_P(WindowEventDispatcherTest, MouseMovesHeld) { | 666 TEST_P(WindowEventDispatcherTest, MouseMovesHeld) { |
| 658 EventFilterRecorder recorder; | 667 EventFilterRecorder recorder; |
| 659 root_window()->AddPreTargetHandler(&recorder); | 668 root_window()->AddPreTargetHandler(&recorder); |
| 660 | 669 |
| 661 test::TestWindowDelegate delegate; | 670 test::TestWindowDelegate delegate; |
| 662 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 671 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 663 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 672 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 664 | 673 |
| 665 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 674 ui::MouseEvent mouse_move_event( |
| 666 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 675 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 667 0); | 676 ui::EventTimeForNow(), 0, 0, |
| 677 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 668 DispatchEventUsingWindowDispatcher(&mouse_move_event); | 678 DispatchEventUsingWindowDispatcher(&mouse_move_event); |
| 669 // Discard MOUSE_ENTER. | 679 // Discard MOUSE_ENTER. |
| 670 recorder.Reset(); | 680 recorder.Reset(); |
| 671 | 681 |
| 672 host()->dispatcher()->HoldPointerMoves(); | 682 host()->dispatcher()->HoldPointerMoves(); |
| 673 | 683 |
| 674 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. | 684 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. |
| 675 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), | 685 ui::MouseEvent mouse_dragged_event( |
| 676 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 686 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 677 0); | 687 ui::EventTimeForNow(), 0, 0, |
| 688 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 678 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 689 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 679 EXPECT_TRUE(recorder.events().empty()); | 690 EXPECT_TRUE(recorder.events().empty()); |
| 680 | 691 |
| 681 // Check that we do dispatch the held MOUSE_DRAGGED event before another type | 692 // Check that we do dispatch the held MOUSE_DRAGGED event before another type |
| 682 // of event. | 693 // of event. |
| 683 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 694 ui::MouseEvent mouse_pressed_event( |
| 684 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 695 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 685 0); | 696 ui::EventTimeForNow(), 0, 0, |
| 697 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 686 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 698 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 687 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 699 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 688 EventTypesToString(recorder.events())); | 700 EventTypesToString(recorder.events())); |
| 689 recorder.Reset(); | 701 recorder.Reset(); |
| 690 | 702 |
| 691 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and | 703 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and |
| 692 // elsewhere in this test) we re-define each event prior to dispatch so that | 704 // elsewhere in this test) we re-define each event prior to dispatch so that |
| 693 // it has the correct state (phase, handled, target, etc.). | 705 // it has the correct state (phase, handled, target, etc.). |
| 694 mouse_dragged_event = | 706 mouse_dragged_event = ui::MouseEvent( |
| 695 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 707 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 696 ui::EventTimeForNow(), 0, 0); | 708 ui::EventTimeForNow(), 0, 0, |
| 697 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 709 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 698 gfx::Point(10, 10), ui::EventTimeForNow(), | 710 ui::MouseEvent mouse_dragged_event2( |
| 699 0, 0); | 711 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 712 ui::EventTimeForNow(), 0, 0, |
| 713 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 700 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 714 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 701 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 715 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 702 EXPECT_TRUE(recorder.events().empty()); | 716 EXPECT_TRUE(recorder.events().empty()); |
| 703 mouse_pressed_event = | 717 mouse_pressed_event = ui::MouseEvent( |
| 704 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), | 718 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 705 ui::EventTimeForNow(), 0, 0); | 719 ui::EventTimeForNow(), 0, 0, |
| 720 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 706 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 721 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 707 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 722 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 708 EventTypesToString(recorder.events())); | 723 EventTypesToString(recorder.events())); |
| 709 recorder.Reset(); | 724 recorder.Reset(); |
| 710 | 725 |
| 711 // Check that on ReleasePointerMoves, held events are not dispatched | 726 // Check that on ReleasePointerMoves, held events are not dispatched |
| 712 // immediately, but posted instead. | 727 // immediately, but posted instead. |
| 713 mouse_dragged_event = | 728 mouse_dragged_event = ui::MouseEvent( |
| 714 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 729 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 715 ui::EventTimeForNow(), 0, 0); | 730 ui::EventTimeForNow(), 0, 0, |
| 731 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 716 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 732 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 717 host()->dispatcher()->ReleasePointerMoves(); | 733 host()->dispatcher()->ReleasePointerMoves(); |
| 718 EXPECT_TRUE(recorder.events().empty()); | 734 EXPECT_TRUE(recorder.events().empty()); |
| 719 RunAllPendingInMessageLoop(); | 735 RunAllPendingInMessageLoop(); |
| 720 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 736 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
| 721 recorder.Reset(); | 737 recorder.Reset(); |
| 722 | 738 |
| 723 // However if another message comes in before the dispatch of the posted | 739 // However if another message comes in before the dispatch of the posted |
| 724 // event, check that the posted event is dispatched before this new event. | 740 // event, check that the posted event is dispatched before this new event. |
| 725 host()->dispatcher()->HoldPointerMoves(); | 741 host()->dispatcher()->HoldPointerMoves(); |
| 726 mouse_dragged_event = | 742 mouse_dragged_event = ui::MouseEvent( |
| 727 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 743 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 728 ui::EventTimeForNow(), 0, 0); | 744 ui::EventTimeForNow(), 0, 0, |
| 745 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 729 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 746 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 730 host()->dispatcher()->ReleasePointerMoves(); | 747 host()->dispatcher()->ReleasePointerMoves(); |
| 731 mouse_pressed_event = | 748 mouse_pressed_event = ui::MouseEvent( |
| 732 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), | 749 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 733 ui::EventTimeForNow(), 0, 0); | 750 ui::EventTimeForNow(), 0, 0, |
| 751 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 734 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 752 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 735 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 753 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 736 EventTypesToString(recorder.events())); | 754 EventTypesToString(recorder.events())); |
| 737 recorder.Reset(); | 755 recorder.Reset(); |
| 738 RunAllPendingInMessageLoop(); | 756 RunAllPendingInMessageLoop(); |
| 739 EXPECT_TRUE(recorder.events().empty()); | 757 EXPECT_TRUE(recorder.events().empty()); |
| 740 | 758 |
| 741 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce | 759 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce |
| 742 // them. | 760 // them. |
| 743 host()->dispatcher()->HoldPointerMoves(); | 761 host()->dispatcher()->HoldPointerMoves(); |
| 744 mouse_dragged_event = | 762 mouse_dragged_event = ui::MouseEvent( |
| 745 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 763 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 746 ui::EventTimeForNow(), 0, 0); | 764 ui::EventTimeForNow(), 0, 0, |
| 765 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 747 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 766 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 748 host()->dispatcher()->ReleasePointerMoves(); | 767 host()->dispatcher()->ReleasePointerMoves(); |
| 749 mouse_dragged_event2 = | 768 mouse_dragged_event2 = ui::MouseEvent( |
| 750 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 769 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 751 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 770 ui::EventTimeForNow(), 0, 0, |
| 771 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 752 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 772 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 753 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 773 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
| 754 recorder.Reset(); | 774 recorder.Reset(); |
| 755 RunAllPendingInMessageLoop(); | 775 RunAllPendingInMessageLoop(); |
| 756 EXPECT_TRUE(recorder.events().empty()); | 776 EXPECT_TRUE(recorder.events().empty()); |
| 757 | 777 |
| 758 // Check that synthetic mouse move event has a right location when issued | 778 // Check that synthetic mouse move event has a right location when issued |
| 759 // while holding pointer moves. | 779 // while holding pointer moves. |
| 760 mouse_dragged_event = | 780 mouse_dragged_event = ui::MouseEvent( |
| 761 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 781 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 762 ui::EventTimeForNow(), 0, 0); | 782 ui::EventTimeForNow(), 0, 0, |
| 763 mouse_dragged_event2 = | 783 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 764 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 784 mouse_dragged_event2 = ui::MouseEvent( |
| 765 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 785 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 766 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), | 786 ui::EventTimeForNow(), 0, 0, |
| 767 gfx::Point(28, 28), ui::EventTimeForNow(), | 787 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 768 0, 0); | 788 ui::MouseEvent mouse_dragged_event3( |
| 789 ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), gfx::Point(28, 28), |
| 790 ui::EventTimeForNow(), 0, 0, |
| 791 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 769 host()->dispatcher()->HoldPointerMoves(); | 792 host()->dispatcher()->HoldPointerMoves(); |
| 770 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 793 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 771 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 794 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 772 window->SetBounds(gfx::Rect(15, 15, 80, 80)); | 795 window->SetBounds(gfx::Rect(15, 15, 80, 80)); |
| 773 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); | 796 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); |
| 774 RunAllPendingInMessageLoop(); | 797 RunAllPendingInMessageLoop(); |
| 775 EXPECT_TRUE(recorder.events().empty()); | 798 EXPECT_TRUE(recorder.events().empty()); |
| 776 host()->dispatcher()->ReleasePointerMoves(); | 799 host()->dispatcher()->ReleasePointerMoves(); |
| 777 RunAllPendingInMessageLoop(); | 800 RunAllPendingInMessageLoop(); |
| 778 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(recorder.events())); | 801 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(recorder.events())); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); | 877 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
| 855 window_first->Show(); | 878 window_first->Show(); |
| 856 window_first->AddPreTargetHandler(&recorder_first); | 879 window_first->AddPreTargetHandler(&recorder_first); |
| 857 | 880 |
| 858 std::unique_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( | 881 std::unique_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( |
| 859 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); | 882 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); |
| 860 window_second->Show(); | 883 window_second->Show(); |
| 861 window_second->AddPreTargetHandler(&recorder_second); | 884 window_second->AddPreTargetHandler(&recorder_second); |
| 862 | 885 |
| 863 const gfx::Point event_location(22, 33); | 886 const gfx::Point event_location(22, 33); |
| 864 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 887 ui::MouseEvent mouse( |
| 865 ui::EventTimeForNow(), 0, 0); | 888 ui::ET_MOUSE_MOVED, event_location, event_location, ui::EventTimeForNow(), |
| 889 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 866 DispatchEventUsingWindowDispatcher(&mouse); | 890 DispatchEventUsingWindowDispatcher(&mouse); |
| 867 | 891 |
| 868 EXPECT_TRUE(recorder_first.events().empty()); | 892 EXPECT_TRUE(recorder_first.events().empty()); |
| 869 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", | 893 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", |
| 870 EventTypesToString(recorder_second.events())); | 894 EventTypesToString(recorder_second.events())); |
| 871 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); | 895 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); |
| 872 EXPECT_EQ(gfx::Point(2, 3).ToString(), | 896 EXPECT_EQ(gfx::Point(2, 3).ToString(), |
| 873 recorder_second.mouse_locations()[0].ToString()); | 897 recorder_second.mouse_locations()[0].ToString()); |
| 874 } | 898 } |
| 875 | 899 |
| 876 // Tests that a mouse exit is dispatched to the last mouse location when | 900 // Tests that a mouse exit is dispatched to the last mouse location when |
| 877 // the window is hiddden. | 901 // the window is hiddden. |
| 878 TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { | 902 TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { |
| 879 EventFilterRecorder recorder; | 903 EventFilterRecorder recorder; |
| 880 | 904 |
| 881 test::TestWindowDelegate delegate; | 905 test::TestWindowDelegate delegate; |
| 882 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 906 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 883 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 907 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 884 window->Show(); | 908 window->Show(); |
| 885 window->AddPreTargetHandler(&recorder); | 909 window->AddPreTargetHandler(&recorder); |
| 886 | 910 |
| 887 // Dispatch a mouse move event into the window. | 911 // Dispatch a mouse move event into the window. |
| 888 const gfx::Point event_location(22, 33); | 912 const gfx::Point event_location(22, 33); |
| 889 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 913 ui::MouseEvent mouse( |
| 890 ui::EventTimeForNow(), 0, 0); | 914 ui::ET_MOUSE_MOVED, event_location, event_location, ui::EventTimeForNow(), |
| 915 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 891 DispatchEventUsingWindowDispatcher(&mouse); | 916 DispatchEventUsingWindowDispatcher(&mouse); |
| 892 EXPECT_FALSE(recorder.events().empty()); | 917 EXPECT_FALSE(recorder.events().empty()); |
| 893 recorder.Reset(); | 918 recorder.Reset(); |
| 894 | 919 |
| 895 // Hide the window and verify a mouse exit event's location. | 920 // Hide the window and verify a mouse exit event's location. |
| 896 window->Hide(); | 921 window->Hide(); |
| 897 EXPECT_FALSE(recorder.events().empty()); | 922 EXPECT_FALSE(recorder.events().empty()); |
| 898 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); | 923 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); |
| 899 ASSERT_EQ(1u, recorder.mouse_locations().size()); | 924 ASSERT_EQ(1u, recorder.mouse_locations().size()); |
| 900 EXPECT_EQ(gfx::Point(12, 23).ToString(), | 925 EXPECT_EQ(gfx::Point(12, 23).ToString(), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 | 1043 |
| 1019 test::TestWindowDelegate delegate; | 1044 test::TestWindowDelegate delegate; |
| 1020 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1045 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1021 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1046 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1022 window->Show(); | 1047 window->Show(); |
| 1023 window->SetCapture(); | 1048 window->SetCapture(); |
| 1024 | 1049 |
| 1025 test::TestCursorClient cursor_client(root_window()); | 1050 test::TestCursorClient cursor_client(root_window()); |
| 1026 | 1051 |
| 1027 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1052 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 1028 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1053 ui::MouseEvent mouse1( |
| 1029 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1054 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1055 ui::EventTimeForNow(), 0, 0, |
| 1056 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1030 DispatchEventUsingWindowDispatcher(&mouse1); | 1057 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1031 EXPECT_FALSE(recorder.events().empty()); | 1058 EXPECT_FALSE(recorder.events().empty()); |
| 1032 recorder.Reset(); | 1059 recorder.Reset(); |
| 1033 | 1060 |
| 1034 // Dispatch a synthetic mouse event when mouse events are enabled. | 1061 // Dispatch a synthetic mouse event when mouse events are enabled. |
| 1035 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1062 ui::MouseEvent mouse2( |
| 1036 gfx::Point(10, 10), ui::EventTimeForNow(), | 1063 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1037 ui::EF_IS_SYNTHESIZED, 0); | 1064 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0, |
| 1065 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1038 DispatchEventUsingWindowDispatcher(&mouse2); | 1066 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1039 EXPECT_FALSE(recorder.events().empty()); | 1067 EXPECT_FALSE(recorder.events().empty()); |
| 1040 recorder.Reset(); | 1068 recorder.Reset(); |
| 1041 | 1069 |
| 1042 // Dispatch a synthetic mouse event when mouse events are disabled. | 1070 // Dispatch a synthetic mouse event when mouse events are disabled. |
| 1043 cursor_client.DisableMouseEvents(); | 1071 cursor_client.DisableMouseEvents(); |
| 1044 DispatchEventUsingWindowDispatcher(&mouse2); | 1072 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1045 EXPECT_TRUE(recorder.events().empty()); | 1073 EXPECT_TRUE(recorder.events().empty()); |
| 1046 root_window()->RemovePreTargetHandler(&recorder); | 1074 root_window()->RemovePreTargetHandler(&recorder); |
| 1047 } | 1075 } |
| 1048 | 1076 |
| 1049 // Tests that a mouse-move event is not synthesized when a mouse-button is down. | 1077 // Tests that a mouse-move event is not synthesized when a mouse-button is down. |
| 1050 TEST_P(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { | 1078 TEST_P(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { |
| 1051 EventFilterRecorder recorder; | 1079 EventFilterRecorder recorder; |
| 1052 test::TestWindowDelegate delegate; | 1080 test::TestWindowDelegate delegate; |
| 1053 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1081 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1054 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1082 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1055 window->Show(); | 1083 window->Show(); |
| 1056 | 1084 |
| 1057 window->AddPreTargetHandler(&recorder); | 1085 window->AddPreTargetHandler(&recorder); |
| 1058 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1086 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 1059 ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1087 ui::MouseEvent mouse1( |
| 1060 gfx::Point(10, 10), ui::EventTimeForNow(), | 1088 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1061 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1089 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 1090 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1062 DispatchEventUsingWindowDispatcher(&mouse1); | 1091 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1063 ASSERT_EQ(1u, recorder.events().size()); | 1092 ASSERT_EQ(1u, recorder.events().size()); |
| 1064 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]); | 1093 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]); |
| 1065 window->RemovePreTargetHandler(&recorder); | 1094 window->RemovePreTargetHandler(&recorder); |
| 1066 recorder.Reset(); | 1095 recorder.Reset(); |
| 1067 | 1096 |
| 1068 // Move |window| away from underneath the cursor. | 1097 // Move |window| away from underneath the cursor. |
| 1069 root_window()->AddPreTargetHandler(&recorder); | 1098 root_window()->AddPreTargetHandler(&recorder); |
| 1070 window->SetBounds(gfx::Rect(30, 30, 100, 100)); | 1099 window->SetBounds(gfx::Rect(30, 30, 100, 100)); |
| 1071 EXPECT_TRUE(recorder.events().empty()); | 1100 EXPECT_TRUE(recorder.events().empty()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1089 test::TestWindowDelegate delegate; | 1118 test::TestWindowDelegate delegate; |
| 1090 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1119 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1091 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1120 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1092 window->Show(); | 1121 window->Show(); |
| 1093 window->SetCapture(); | 1122 window->SetCapture(); |
| 1094 | 1123 |
| 1095 EventFilterRecorder recorder; | 1124 EventFilterRecorder recorder; |
| 1096 window->AddPreTargetHandler(&recorder); | 1125 window->AddPreTargetHandler(&recorder); |
| 1097 | 1126 |
| 1098 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. | 1127 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. |
| 1099 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1128 ui::MouseEvent mouse( |
| 1100 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1129 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1130 ui::EventTimeForNow(), 0, 0, |
| 1131 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1101 DispatchEventUsingWindowDispatcher(&mouse); | 1132 DispatchEventUsingWindowDispatcher(&mouse); |
| 1102 EXPECT_FALSE(recorder.events().empty()); | 1133 EXPECT_FALSE(recorder.events().empty()); |
| 1103 recorder.Reset(); | 1134 recorder.Reset(); |
| 1104 | 1135 |
| 1105 // Update the window bounds so that cursor is now outside the window. | 1136 // Update the window bounds so that cursor is now outside the window. |
| 1106 // This should trigger a synthetic MOVED event. | 1137 // This should trigger a synthetic MOVED event. |
| 1107 gfx::Rect bounds1(20, 20, 100, 100); | 1138 gfx::Rect bounds1(20, 20, 100, 100); |
| 1108 window->SetBounds(bounds1); | 1139 window->SetBounds(bounds1); |
| 1109 RunAllPendingInMessageLoop(); | 1140 RunAllPendingInMessageLoop(); |
| 1110 ASSERT_FALSE(recorder.events().empty()); | 1141 ASSERT_FALSE(recorder.events().empty()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 | 1175 |
| 1145 test::TestWindowDelegate delegate; | 1176 test::TestWindowDelegate delegate; |
| 1146 gfx::Point window_origin(7, 18); | 1177 gfx::Point window_origin(7, 18); |
| 1147 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1178 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1148 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1179 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
| 1149 root_window())); | 1180 root_window())); |
| 1150 window->Show(); | 1181 window->Show(); |
| 1151 | 1182 |
| 1152 // Dispatch a mouse move event into the window. | 1183 // Dispatch a mouse move event into the window. |
| 1153 gfx::Point mouse_location(gfx::Point(15, 25)); | 1184 gfx::Point mouse_location(gfx::Point(15, 25)); |
| 1154 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1185 ui::MouseEvent mouse1( |
| 1155 ui::EventTimeForNow(), 0, 0); | 1186 ui::ET_MOUSE_MOVED, mouse_location, mouse_location, ui::EventTimeForNow(), |
| 1187 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1156 EXPECT_TRUE(recorder.events().empty()); | 1188 EXPECT_TRUE(recorder.events().empty()); |
| 1157 DispatchEventUsingWindowDispatcher(&mouse1); | 1189 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1158 EXPECT_FALSE(recorder.events().empty()); | 1190 EXPECT_FALSE(recorder.events().empty()); |
| 1159 recorder.Reset(); | 1191 recorder.Reset(); |
| 1160 | 1192 |
| 1161 // Hide the cursor and verify a mouse exit was dispatched. | 1193 // Hide the cursor and verify a mouse exit was dispatched. |
| 1162 host()->OnCursorVisibilityChanged(false); | 1194 host()->OnCursorVisibilityChanged(false); |
| 1163 EXPECT_FALSE(recorder.events().empty()); | 1195 EXPECT_FALSE(recorder.events().empty()); |
| 1164 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); | 1196 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); |
| 1165 | 1197 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1181 | 1213 |
| 1182 test::TestWindowDelegate delegate; | 1214 test::TestWindowDelegate delegate; |
| 1183 gfx::Point window_origin(7, 18); | 1215 gfx::Point window_origin(7, 18); |
| 1184 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1216 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1185 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1217 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
| 1186 root_window())); | 1218 root_window())); |
| 1187 window->Show(); | 1219 window->Show(); |
| 1188 | 1220 |
| 1189 // Dispatch a mouse move event into the window. | 1221 // Dispatch a mouse move event into the window. |
| 1190 gfx::Point mouse_location(gfx::Point(15, 25)); | 1222 gfx::Point mouse_location(gfx::Point(15, 25)); |
| 1191 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1223 ui::MouseEvent mouse1( |
| 1192 ui::EventTimeForNow(), 0, 0); | 1224 ui::ET_MOUSE_MOVED, mouse_location, mouse_location, ui::EventTimeForNow(), |
| 1225 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1193 EXPECT_TRUE(recorder.events().empty()); | 1226 EXPECT_TRUE(recorder.events().empty()); |
| 1194 DispatchEventUsingWindowDispatcher(&mouse1); | 1227 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1195 EXPECT_FALSE(recorder.events().empty()); | 1228 EXPECT_FALSE(recorder.events().empty()); |
| 1196 recorder.Reset(); | 1229 recorder.Reset(); |
| 1197 | 1230 |
| 1198 test::TestCursorClient cursor_client(root_window()); | 1231 test::TestCursorClient cursor_client(root_window()); |
| 1199 cursor_client.DisableMouseEvents(); | 1232 cursor_client.DisableMouseEvents(); |
| 1200 | 1233 |
| 1201 gfx::Point mouse_exit_location(gfx::Point(150, 150)); | 1234 gfx::Point mouse_exit_location(gfx::Point(150, 150)); |
| 1202 ui::MouseEvent mouse2(ui::ET_MOUSE_EXITED, gfx::Point(150, 150), | 1235 ui::MouseEvent mouse2( |
| 1203 gfx::Point(150, 150), ui::EventTimeForNow(), | 1236 ui::ET_MOUSE_EXITED, gfx::Point(150, 150), gfx::Point(150, 150), |
| 1204 ui::EF_IS_SYNTHESIZED, 0); | 1237 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0, |
| 1238 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1205 DispatchEventUsingWindowDispatcher(&mouse2); | 1239 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1206 | 1240 |
| 1207 EXPECT_FALSE(recorder.events().empty()); | 1241 EXPECT_FALSE(recorder.events().empty()); |
| 1208 // We get the mouse exited event twice in our filter. Once during the | 1242 // We get the mouse exited event twice in our filter. Once during the |
| 1209 // predispatch phase and during the actual dispatch. | 1243 // predispatch phase and during the actual dispatch. |
| 1210 EXPECT_EQ("MOUSE_EXITED MOUSE_EXITED", EventTypesToString(recorder.events())); | 1244 EXPECT_EQ("MOUSE_EXITED MOUSE_EXITED", EventTypesToString(recorder.events())); |
| 1211 | 1245 |
| 1212 // Verify the mouse exit was dispatched at the correct location | 1246 // Verify the mouse exit was dispatched at the correct location |
| 1213 // (in the correct coordinate space). | 1247 // (in the correct coordinate space). |
| 1214 int translated_x = mouse_exit_location.x() - window_origin.x(); | 1248 int translated_x = mouse_exit_location.x() - window_origin.x(); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 w1->AddPreTargetHandler(&w1_filter); | 1692 w1->AddPreTargetHandler(&w1_filter); |
| 1659 EventFilterRecorder w2_filter; | 1693 EventFilterRecorder w2_filter; |
| 1660 w2->AddPreTargetHandler(&w2_filter); | 1694 w2->AddPreTargetHandler(&w2_filter); |
| 1661 | 1695 |
| 1662 // Move mouse over window 2. This should generate a mouse-exited event for | 1696 // Move mouse over window 2. This should generate a mouse-exited event for |
| 1663 // window 1 resulting in deletion of window tree host and its event | 1697 // window 1 resulting in deletion of window tree host and its event |
| 1664 // dispatcher. The event dispatching should abort since the dispatcher is | 1698 // dispatcher. The event dispatching should abort since the dispatcher is |
| 1665 // destroyed. This test passes if no crash happens. | 1699 // destroyed. This test passes if no crash happens. |
| 1666 // Here we can't use EventGenerator since it expects that the dispatcher is | 1700 // Here we can't use EventGenerator since it expects that the dispatcher is |
| 1667 // not destroyed at the end of the dispatch. | 1701 // not destroyed at the end of the dispatch. |
| 1668 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::Point(20, 20), | 1702 ui::MouseEvent mouse_move( |
| 1669 gfx::Point(20, 20), base::TimeTicks(), 0, 0); | 1703 ui::ET_MOUSE_MOVED, gfx::Point(20, 20), gfx::Point(20, 20), |
| 1704 base::TimeTicks(), 0, 0, |
| 1705 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1670 ui::EventDispatchDetails details = | 1706 ui::EventDispatchDetails details = |
| 1671 host->dispatcher()->DispatchEvent(w2, &mouse_move); | 1707 host->dispatcher()->DispatchEvent(w2, &mouse_move); |
| 1672 EXPECT_TRUE(details.dispatcher_destroyed); | 1708 EXPECT_TRUE(details.dispatcher_destroyed); |
| 1673 | 1709 |
| 1674 // Check events received by the two windows. | 1710 // Check events received by the two windows. |
| 1675 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(w1_filter.events())); | 1711 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(w1_filter.events())); |
| 1676 EXPECT_EQ(std::string(), EventTypesToString(w2_filter.events())); | 1712 EXPECT_EQ(std::string(), EventTypesToString(w2_filter.events())); |
| 1677 } | 1713 } |
| 1678 | 1714 |
| 1679 namespace { | 1715 namespace { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 : root_(root), | 1767 : root_(root), |
| 1732 mouse_event_count_(0) {} | 1768 mouse_event_count_(0) {} |
| 1733 ~DontResetHeldEventWindowDelegate() override {} | 1769 ~DontResetHeldEventWindowDelegate() override {} |
| 1734 | 1770 |
| 1735 int mouse_event_count() const { return mouse_event_count_; } | 1771 int mouse_event_count() const { return mouse_event_count_; } |
| 1736 | 1772 |
| 1737 // TestWindowDelegate: | 1773 // TestWindowDelegate: |
| 1738 void OnMouseEvent(ui::MouseEvent* event) override { | 1774 void OnMouseEvent(ui::MouseEvent* event) override { |
| 1739 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && | 1775 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && |
| 1740 mouse_event_count_++ == 0) { | 1776 mouse_event_count_++ == 0) { |
| 1741 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1777 ui::MouseEvent mouse_event( |
| 1742 gfx::Point(10, 10), ui::EventTimeForNow(), | 1778 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1743 ui::EF_SHIFT_DOWN, 0); | 1779 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, 0, |
| 1780 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1744 root_->GetHost()->dispatcher()->RepostEvent(&mouse_event); | 1781 root_->GetHost()->dispatcher()->RepostEvent(&mouse_event); |
| 1745 } | 1782 } |
| 1746 } | 1783 } |
| 1747 | 1784 |
| 1748 private: | 1785 private: |
| 1749 Window* root_; | 1786 Window* root_; |
| 1750 int mouse_event_count_; | 1787 int mouse_event_count_; |
| 1751 | 1788 |
| 1752 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); | 1789 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); |
| 1753 }; | 1790 }; |
| 1754 | 1791 |
| 1755 } // namespace | 1792 } // namespace |
| 1756 | 1793 |
| 1757 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1794 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
| 1758 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1795 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
| 1759 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1796 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
| 1760 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1797 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
| 1761 // schedule another reposted event. | 1798 // schedule another reposted event. |
| 1762 TEST_P(WindowEventDispatcherTest, DontResetHeldEvent) { | 1799 TEST_P(WindowEventDispatcherTest, DontResetHeldEvent) { |
| 1763 DontResetHeldEventWindowDelegate delegate(root_window()); | 1800 DontResetHeldEventWindowDelegate delegate(root_window()); |
| 1764 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1801 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
| 1765 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1802 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1766 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1803 ui::MouseEvent pressed( |
| 1767 gfx::Point(10, 10), ui::EventTimeForNow(), | 1804 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1768 ui::EF_SHIFT_DOWN, 0); | 1805 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, 0, |
| 1806 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1769 root_window()->GetHost()->dispatcher()->RepostEvent(&pressed); | 1807 root_window()->GetHost()->dispatcher()->RepostEvent(&pressed); |
| 1770 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1808 ui::MouseEvent pressed2( |
| 1771 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1809 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1810 ui::EventTimeForNow(), 0, 0, |
| 1811 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1772 // Dispatch an event to flush event scheduled by way of RepostEvent(). | 1812 // Dispatch an event to flush event scheduled by way of RepostEvent(). |
| 1773 DispatchEventUsingWindowDispatcher(&pressed2); | 1813 DispatchEventUsingWindowDispatcher(&pressed2); |
| 1774 // Delegate should have seen reposted event (identified by way of | 1814 // Delegate should have seen reposted event (identified by way of |
| 1775 // EF_SHIFT_DOWN). Dispatch another event to flush the second | 1815 // EF_SHIFT_DOWN). Dispatch another event to flush the second |
| 1776 // RepostedEvent(). | 1816 // RepostedEvent(). |
| 1777 EXPECT_EQ(1, delegate.mouse_event_count()); | 1817 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 1778 DispatchEventUsingWindowDispatcher(&pressed2); | 1818 DispatchEventUsingWindowDispatcher(&pressed2); |
| 1779 EXPECT_EQ(2, delegate.mouse_event_count()); | 1819 EXPECT_EQ(2, delegate.mouse_event_count()); |
| 1780 } | 1820 } |
| 1781 | 1821 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 // we don't crash. | 1858 // we don't crash. |
| 1819 TEST_P(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { | 1859 TEST_P(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { |
| 1820 // Should be deleted by |delegate|. | 1860 // Should be deleted by |delegate|. |
| 1821 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); | 1861 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); |
| 1822 h2->InitHost(); | 1862 h2->InitHost(); |
| 1823 h2->window()->Show(); | 1863 h2->window()->Show(); |
| 1824 DeleteHostFromHeldMouseEventDelegate delegate(h2); | 1864 DeleteHostFromHeldMouseEventDelegate delegate(h2); |
| 1825 // Owned by |h2|. | 1865 // Owned by |h2|. |
| 1826 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); | 1866 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); |
| 1827 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1867 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1828 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1868 ui::MouseEvent pressed( |
| 1829 gfx::Point(10, 10), ui::EventTimeForNow(), | 1869 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1830 ui::EF_SHIFT_DOWN, 0); | 1870 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, 0, |
| 1871 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 1831 h2->dispatcher()->RepostEvent(&pressed); | 1872 h2->dispatcher()->RepostEvent(&pressed); |
| 1832 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. | 1873 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. |
| 1833 RunAllPendingInMessageLoop(); | 1874 RunAllPendingInMessageLoop(); |
| 1834 EXPECT_TRUE(delegate.got_mouse_event()); | 1875 EXPECT_TRUE(delegate.got_mouse_event()); |
| 1835 EXPECT_TRUE(delegate.got_destroy()); | 1876 EXPECT_TRUE(delegate.got_destroy()); |
| 1836 } | 1877 } |
| 1837 | 1878 |
| 1838 TEST_P(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { | 1879 TEST_P(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { |
| 1839 EventFilterRecorder recorder; | 1880 EventFilterRecorder recorder; |
| 1840 root_window()->AddPreTargetHandler(&recorder); | 1881 root_window()->AddPreTargetHandler(&recorder); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 void RunTest() { | 2071 void RunTest() { |
| 2031 // Reset any event the window may have received when bringing up the window | 2072 // Reset any event the window may have received when bringing up the window |
| 2032 // (e.g. mouse-move events if the mouse cursor is over the window). | 2073 // (e.g. mouse-move events if the mouse cursor is over the window). |
| 2033 handler_.Reset(); | 2074 handler_.Reset(); |
| 2034 | 2075 |
| 2035 // Start a nested message-loop, post an event to be dispatched, and then | 2076 // Start a nested message-loop, post an event to be dispatched, and then |
| 2036 // terminate the message-loop. When the message-loop unwinds and gets back, | 2077 // terminate the message-loop. When the message-loop unwinds and gets back, |
| 2037 // the reposted event should not have fired. | 2078 // the reposted event should not have fired. |
| 2038 std::unique_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( | 2079 std::unique_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
| 2039 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), | 2080 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 2040 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); | 2081 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2082 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 2041 message_loop()->task_runner()->PostTask( | 2083 message_loop()->task_runner()->PostTask( |
| 2042 FROM_HERE, | 2084 FROM_HERE, |
| 2043 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, | 2085 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, |
| 2044 host()->dispatcher(), base::Passed(&mouse))); | 2086 host()->dispatcher(), base::Passed(&mouse))); |
| 2045 message_loop()->task_runner()->PostTask( | 2087 message_loop()->task_runner()->PostTask( |
| 2046 FROM_HERE, message_loop()->QuitWhenIdleClosure()); | 2088 FROM_HERE, message_loop()->QuitWhenIdleClosure()); |
| 2047 | 2089 |
| 2048 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); | 2090 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); |
| 2049 base::RunLoop loop; | 2091 base::RunLoop loop; |
| 2050 loop.Run(); | 2092 loop.Run(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2114 std::unique_ptr<aura::Window> child(test::CreateTestWindowWithDelegate( | 2156 std::unique_ptr<aura::Window> child(test::CreateTestWindowWithDelegate( |
| 2115 &delegate, 1234, gfx::Rect(20, 20, 100, 100), root_window())); | 2157 &delegate, 1234, gfx::Rect(20, 20, 100, 100), root_window())); |
| 2116 child->Show(); | 2158 child->Show(); |
| 2117 | 2159 |
| 2118 ui::test::TestEventHandler handler_child; | 2160 ui::test::TestEventHandler handler_child; |
| 2119 ui::test::TestEventHandler handler_root; | 2161 ui::test::TestEventHandler handler_root; |
| 2120 root_window()->AddPreTargetHandler(&handler_root); | 2162 root_window()->AddPreTargetHandler(&handler_root); |
| 2121 child->AddPreTargetHandler(&handler_child); | 2163 child->AddPreTargetHandler(&handler_child); |
| 2122 | 2164 |
| 2123 { | 2165 { |
| 2124 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(30, 30), | 2166 ui::MouseEvent move( |
| 2125 gfx::Point(30, 30), ui::EventTimeForNow(), ui::EF_NONE, | 2167 ui::ET_MOUSE_MOVED, gfx::Point(30, 30), gfx::Point(30, 30), |
| 2126 ui::EF_NONE); | 2168 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2169 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2127 DispatchEventUsingWindowDispatcher(&move); | 2170 DispatchEventUsingWindowDispatcher(&move); |
| 2128 EXPECT_EQ(0, handler_child.num_mouse_events()); | 2171 EXPECT_EQ(0, handler_child.num_mouse_events()); |
| 2129 EXPECT_EQ(1, handler_root.num_mouse_events()); | 2172 EXPECT_EQ(1, handler_root.num_mouse_events()); |
| 2130 } | 2173 } |
| 2131 | 2174 |
| 2132 { | 2175 { |
| 2133 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), | 2176 ui::MouseEvent move( |
| 2134 gfx::Point(50, 50), ui::EventTimeForNow(), ui::EF_NONE, | 2177 ui::ET_MOUSE_MOVED, gfx::Point(50, 50), gfx::Point(50, 50), |
| 2135 ui::EF_NONE); | 2178 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2179 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2136 DispatchEventUsingWindowDispatcher(&move); | 2180 DispatchEventUsingWindowDispatcher(&move); |
| 2137 // The child receives an ENTER, and a MOVED event. | 2181 // The child receives an ENTER, and a MOVED event. |
| 2138 EXPECT_EQ(2, handler_child.num_mouse_events()); | 2182 EXPECT_EQ(2, handler_child.num_mouse_events()); |
| 2139 // The root receives both the ENTER and the MOVED events dispatched to | 2183 // The root receives both the ENTER and the MOVED events dispatched to |
| 2140 // |child|, as well as an EXIT event. | 2184 // |child|, as well as an EXIT event. |
| 2141 EXPECT_EQ(3, handler_root.num_mouse_events()); | 2185 EXPECT_EQ(3, handler_root.num_mouse_events()); |
| 2142 } | 2186 } |
| 2143 | 2187 |
| 2144 child->RemovePreTargetHandler(&handler_child); | 2188 child->RemovePreTargetHandler(&handler_child); |
| 2145 root_window()->RemovePreTargetHandler(&handler_root); | 2189 root_window()->RemovePreTargetHandler(&handler_root); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2214 | 2258 |
| 2215 // Tests that if dispatching a 'held' event triggers a nested message loop, then | 2259 // Tests that if dispatching a 'held' event triggers a nested message loop, then |
| 2216 // the events that are dispatched from the nested message loop are transformed | 2260 // the events that are dispatched from the nested message loop are transformed |
| 2217 // correctly. | 2261 // correctly. |
| 2218 TEST_P(WindowEventDispatcherTestInHighDPI, | 2262 TEST_P(WindowEventDispatcherTestInHighDPI, |
| 2219 EventsTransformedInRepostedEventTriggeredNestedLoop) { | 2263 EventsTransformedInRepostedEventTriggeredNestedLoop) { |
| 2220 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 2264 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 2221 // Make sure the window is visible. | 2265 // Make sure the window is visible. |
| 2222 RunAllPendingInMessageLoop(); | 2266 RunAllPendingInMessageLoop(); |
| 2223 | 2267 |
| 2224 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::Point(80, 80), | 2268 ui::MouseEvent mouse_move( |
| 2225 gfx::Point(80, 80), ui::EventTimeForNow(), | 2269 ui::ET_MOUSE_MOVED, gfx::Point(80, 80), gfx::Point(80, 80), |
| 2226 ui::EF_NONE, ui::EF_NONE); | 2270 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2271 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2227 const base::Closure callback_on_right_click = base::Bind( | 2272 const base::Closure callback_on_right_click = base::Bind( |
| 2228 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), | 2273 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), |
| 2229 base::Unretained(this), base::Unretained(&mouse_move)); | 2274 base::Unretained(this), base::Unretained(&mouse_move)); |
| 2230 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); | 2275 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); |
| 2231 window->AddPreTargetHandler(&handler); | 2276 window->AddPreTargetHandler(&handler); |
| 2232 | 2277 |
| 2233 std::unique_ptr<ui::MouseEvent> mouse( | 2278 std::unique_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
| 2234 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 2279 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 2235 gfx::Point(10, 10), ui::EventTimeForNow(), | 2280 ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON, |
| 2236 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 2281 ui::EF_RIGHT_MOUSE_BUTTON, |
| 2282 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 2237 host()->dispatcher()->RepostEvent(mouse.get()); | 2283 host()->dispatcher()->RepostEvent(mouse.get()); |
| 2238 EXPECT_EQ(0, handler.num_mouse_events()); | 2284 EXPECT_EQ(0, handler.num_mouse_events()); |
| 2239 | 2285 |
| 2240 base::RunLoop run_loop; | 2286 base::RunLoop run_loop; |
| 2241 run_loop.RunUntilIdle(); | 2287 run_loop.RunUntilIdle(); |
| 2242 // The window should receive the mouse-press and the mouse-move events. | 2288 // The window should receive the mouse-press and the mouse-move events. |
| 2243 EXPECT_EQ(2, handler.num_mouse_events()); | 2289 EXPECT_EQ(2, handler.num_mouse_events()); |
| 2244 // The mouse-move event location should be transformed because of the DSF | 2290 // The mouse-move event location should be transformed because of the DSF |
| 2245 // before it reaches the window. | 2291 // before it reaches the window. |
| 2246 EXPECT_EQ(gfx::Point(40, 40).ToString(), | 2292 EXPECT_EQ(gfx::Point(40, 40).ToString(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2267 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); | 2313 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); |
| 2268 }; | 2314 }; |
| 2269 | 2315 |
| 2270 TEST_P(WindowEventDispatcherTest, SynthesizedLocatedEvent) { | 2316 TEST_P(WindowEventDispatcherTest, SynthesizedLocatedEvent) { |
| 2271 ui::test::EventGenerator generator(root_window()); | 2317 ui::test::EventGenerator generator(root_window()); |
| 2272 generator.MoveMouseTo(10, 10); | 2318 generator.MoveMouseTo(10, 10); |
| 2273 EXPECT_EQ("10,10", | 2319 EXPECT_EQ("10,10", |
| 2274 Env::GetInstance()->last_mouse_location().ToString()); | 2320 Env::GetInstance()->last_mouse_location().ToString()); |
| 2275 | 2321 |
| 2276 // Synthesized event should not update the mouse location. | 2322 // Synthesized event should not update the mouse location. |
| 2277 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 2323 ui::MouseEvent mouseev( |
| 2278 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0); | 2324 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 2325 ui::EF_IS_SYNTHESIZED, 0, |
| 2326 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2279 generator.Dispatch(&mouseev); | 2327 generator.Dispatch(&mouseev); |
| 2280 EXPECT_EQ("10,10", | 2328 EXPECT_EQ("10,10", |
| 2281 Env::GetInstance()->last_mouse_location().ToString()); | 2329 Env::GetInstance()->last_mouse_location().ToString()); |
| 2282 | 2330 |
| 2283 generator.MoveMouseTo(0, 0); | 2331 generator.MoveMouseTo(0, 0); |
| 2284 EXPECT_EQ("0,0", | 2332 EXPECT_EQ("0,0", |
| 2285 Env::GetInstance()->last_mouse_location().ToString()); | 2333 Env::GetInstance()->last_mouse_location().ToString()); |
| 2286 | 2334 |
| 2287 // Make sure the location gets updated when a syntheiszed enter | 2335 // Make sure the location gets updated when a syntheiszed enter |
| 2288 // event destroyed the window. | 2336 // event destroyed the window. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 explicit DispatchEventHandler(Window* target) | 2410 explicit DispatchEventHandler(Window* target) |
| 2363 : target_(target), | 2411 : target_(target), |
| 2364 dispatched_(false) {} | 2412 dispatched_(false) {} |
| 2365 ~DispatchEventHandler() override {} | 2413 ~DispatchEventHandler() override {} |
| 2366 | 2414 |
| 2367 bool dispatched() const { return dispatched_; } | 2415 bool dispatched() const { return dispatched_; } |
| 2368 private: | 2416 private: |
| 2369 // ui::EventHandler: | 2417 // ui::EventHandler: |
| 2370 void OnMouseEvent(ui::MouseEvent* mouse) override { | 2418 void OnMouseEvent(ui::MouseEvent* mouse) override { |
| 2371 if (mouse->type() == ui::ET_MOUSE_MOVED) { | 2419 if (mouse->type() == ui::ET_MOUSE_MOVED) { |
| 2372 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), | 2420 ui::MouseEvent move( |
| 2373 target_->bounds().CenterPoint(), | 2421 ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), |
| 2374 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 2422 target_->bounds().CenterPoint(), ui::EventTimeForNow(), ui::EF_NONE, |
| 2423 ui::EF_NONE, |
| 2424 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2375 ui::EventDispatchDetails details = | 2425 ui::EventDispatchDetails details = |
| 2376 target_->GetHost()->dispatcher()->OnEventFromSource(&move); | 2426 target_->GetHost()->dispatcher()->OnEventFromSource(&move); |
| 2377 ASSERT_FALSE(details.dispatcher_destroyed); | 2427 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2378 EXPECT_FALSE(details.target_destroyed); | 2428 EXPECT_FALSE(details.target_destroyed); |
| 2379 EXPECT_EQ(target_, move.target()); | 2429 EXPECT_EQ(target_, move.target()); |
| 2380 dispatched_ = true; | 2430 dispatched_ = true; |
| 2381 } | 2431 } |
| 2382 ui::EventHandler::OnMouseEvent(mouse); | 2432 ui::EventHandler::OnMouseEvent(mouse); |
| 2383 } | 2433 } |
| 2384 | 2434 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 // when |second| receives an event. | 2487 // when |second| receives an event. |
| 2438 MoveWindowHandler move_window(first.get(), second_root); | 2488 MoveWindowHandler move_window(first.get(), second_root); |
| 2439 second->AddPreTargetHandler(&move_window); | 2489 second->AddPreTargetHandler(&move_window); |
| 2440 | 2490 |
| 2441 // Some sanity checks: |first| is inside |root_window()|'s tree. | 2491 // Some sanity checks: |first| is inside |root_window()|'s tree. |
| 2442 EXPECT_EQ(root_window(), first->GetRootWindow()); | 2492 EXPECT_EQ(root_window(), first->GetRootWindow()); |
| 2443 // The two root windows are different. | 2493 // The two root windows are different. |
| 2444 EXPECT_NE(root_window(), second_root); | 2494 EXPECT_NE(root_window(), second_root); |
| 2445 | 2495 |
| 2446 // Dispatch an event to |first|. | 2496 // Dispatch an event to |first|. |
| 2447 ui::MouseEvent move(ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(), | 2497 ui::MouseEvent move( |
| 2448 first->bounds().CenterPoint(), ui::EventTimeForNow(), | 2498 ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(), |
| 2449 ui::EF_NONE, ui::EF_NONE); | 2499 first->bounds().CenterPoint(), ui::EventTimeForNow(), ui::EF_NONE, |
| 2500 ui::EF_NONE, |
| 2501 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2450 ui::EventDispatchDetails details = | 2502 ui::EventDispatchDetails details = |
| 2451 host()->dispatcher()->OnEventFromSource(&move); | 2503 host()->dispatcher()->OnEventFromSource(&move); |
| 2452 ASSERT_FALSE(details.dispatcher_destroyed); | 2504 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2453 EXPECT_TRUE(details.target_destroyed); | 2505 EXPECT_TRUE(details.target_destroyed); |
| 2454 EXPECT_EQ(first.get(), move.target()); | 2506 EXPECT_EQ(first.get(), move.target()); |
| 2455 EXPECT_TRUE(dispatch_event.dispatched()); | 2507 EXPECT_TRUE(dispatch_event.dispatched()); |
| 2456 EXPECT_EQ(second_root, first->GetRootWindow()); | 2508 EXPECT_EQ(second_root, first->GetRootWindow()); |
| 2457 | 2509 |
| 2458 first->RemovePreTargetHandler(&dispatch_event); | 2510 first->RemovePreTargetHandler(&dispatch_event); |
| 2459 second->RemovePreTargetHandler(&move_window); | 2511 second->RemovePreTargetHandler(&move_window); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2539 EXPECT_EQ(window_second.get(), | 2591 EXPECT_EQ(window_second.get(), |
| 2540 client::GetCaptureWindow(root_window())); | 2592 client::GetCaptureWindow(root_window())); |
| 2541 | 2593 |
| 2542 // Send an event to the first host. Make sure it goes to |window_second| in | 2594 // Send an event to the first host. Make sure it goes to |window_second| in |
| 2543 // |second_host| instead (since it has capture). | 2595 // |second_host| instead (since it has capture). |
| 2544 EventFilterRecorder recorder_first; | 2596 EventFilterRecorder recorder_first; |
| 2545 window_first->AddPreTargetHandler(&recorder_first); | 2597 window_first->AddPreTargetHandler(&recorder_first); |
| 2546 EventFilterRecorder recorder_second; | 2598 EventFilterRecorder recorder_second; |
| 2547 window_second->AddPreTargetHandler(&recorder_second); | 2599 window_second->AddPreTargetHandler(&recorder_second); |
| 2548 const gfx::Point event_location(25, 15); | 2600 const gfx::Point event_location(25, 15); |
| 2549 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, event_location, event_location, | 2601 ui::MouseEvent mouse( |
| 2550 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2602 ui::ET_MOUSE_PRESSED, event_location, event_location, |
| 2551 ui::EF_LEFT_MOUSE_BUTTON); | 2603 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2604 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2552 DispatchEventUsingWindowDispatcher(&mouse); | 2605 DispatchEventUsingWindowDispatcher(&mouse); |
| 2553 EXPECT_TRUE(recorder_first.events().empty()); | 2606 EXPECT_TRUE(recorder_first.events().empty()); |
| 2554 ASSERT_EQ(1u, recorder_second.events().size()); | 2607 ASSERT_EQ(1u, recorder_second.events().size()); |
| 2555 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); | 2608 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); |
| 2556 EXPECT_EQ(event_location.ToString(), | 2609 EXPECT_EQ(event_location.ToString(), |
| 2557 recorder_second.mouse_locations()[0].ToString()); | 2610 recorder_second.mouse_locations()[0].ToString()); |
| 2558 } | 2611 } |
| 2559 | 2612 |
| 2560 class AsyncWindowDelegate : public test::TestWindowDelegate { | 2613 class AsyncWindowDelegate : public test::TestWindowDelegate { |
| 2561 public: | 2614 public: |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2698 | 2751 |
| 2699 // Tests that we correctly report the fraction of time without user input via | 2752 // Tests that we correctly report the fraction of time without user input via |
| 2700 // UMA. | 2753 // UMA. |
| 2701 TEST_P(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { | 2754 TEST_P(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { |
| 2702 const char* kHistogram = "Event.FractionOfTimeWithoutUserInput"; | 2755 const char* kHistogram = "Event.FractionOfTimeWithoutUserInput"; |
| 2703 base::HistogramTester tester; | 2756 base::HistogramTester tester; |
| 2704 | 2757 |
| 2705 std::unique_ptr<aura::Window> window( | 2758 std::unique_ptr<aura::Window> window( |
| 2706 test::CreateTestWindowWithId(1234, root_window())); | 2759 test::CreateTestWindowWithId(1234, root_window())); |
| 2707 | 2760 |
| 2708 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 2761 ui::MouseEvent mouse1( |
| 2709 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(4), 0, | 2762 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 2710 0); | 2763 ui::EventTimeStampFromSeconds(4), 0, 0, |
| 2764 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2711 | 2765 |
| 2712 // To flush the idle fraction reporter, we need to dispatch two events. The | 2766 // To flush the idle fraction reporter, we need to dispatch two events. The |
| 2713 // first event causes us to record the previous active period, and the second | 2767 // first event causes us to record the previous active period, and the second |
| 2714 // flushes the previous active period. | 2768 // flushes the previous active period. |
| 2715 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 2769 ui::MouseEvent mouse2( |
| 2716 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(16), | 2770 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 2717 0, 0); | 2771 ui::EventTimeStampFromSeconds(16), 0, 0, |
| 2772 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2718 | 2773 |
| 2719 ui::MouseEvent mouse3(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 2774 ui::MouseEvent mouse3( |
| 2720 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(30), | 2775 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 2721 0, 0); | 2776 ui::EventTimeStampFromSeconds(30), 0, 0, |
| 2777 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2722 | 2778 |
| 2723 DispatchEventUsingWindowDispatcher(&mouse1); | 2779 DispatchEventUsingWindowDispatcher(&mouse1); |
| 2724 DispatchEventUsingWindowDispatcher(&mouse2); | 2780 DispatchEventUsingWindowDispatcher(&mouse2); |
| 2725 DispatchEventUsingWindowDispatcher(&mouse3); | 2781 DispatchEventUsingWindowDispatcher(&mouse3); |
| 2726 | 2782 |
| 2727 tester.ExpectTotalCount(kHistogram, 1); | 2783 tester.ExpectTotalCount(kHistogram, 1); |
| 2728 } | 2784 } |
| 2729 | 2785 |
| 2730 INSTANTIATE_TEST_CASE_P(/* no prefix */, | 2786 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 2731 WindowEventDispatcherTest, | 2787 WindowEventDispatcherTest, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2774 | 2830 |
| 2775 // Enable fetching mouse location from mouse. | 2831 // Enable fetching mouse location from mouse. |
| 2776 test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); | 2832 test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); |
| 2777 EXPECT_EQ(gfx::Point(0, 0), | 2833 EXPECT_EQ(gfx::Point(0, 0), |
| 2778 window_tree_client_impl()->GetCursorScreenPoint()); | 2834 window_tree_client_impl()->GetCursorScreenPoint()); |
| 2779 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); | 2835 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); |
| 2780 | 2836 |
| 2781 // Dispatch an event to |mouse_location|. While dispatching the event | 2837 // Dispatch an event to |mouse_location|. While dispatching the event |
| 2782 // Env::last_mouse_location() should return |mouse_location|. | 2838 // Env::last_mouse_location() should return |mouse_location|. |
| 2783 const gfx::Point mouse_location(1, 2); | 2839 const gfx::Point mouse_location(1, 2); |
| 2784 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, | 2840 ui::MouseEvent mouse( |
| 2785 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2841 ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, |
| 2786 ui::EF_LEFT_MOUSE_BUTTON); | 2842 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2843 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2787 DispatchEventUsingWindowDispatcher(&mouse); | 2844 DispatchEventUsingWindowDispatcher(&mouse); |
| 2788 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); | 2845 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); |
| 2789 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); | 2846 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); |
| 2790 | 2847 |
| 2791 // After dispatch the location should fallback to that of the | 2848 // After dispatch the location should fallback to that of the |
| 2792 // WindowTreeClient, which defaults to 0,0. | 2849 // WindowTreeClient, which defaults to 0,0. |
| 2793 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); | 2850 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); |
| 2794 } | 2851 } |
| 2795 | 2852 |
| 2796 TEST_F(WindowEventDispatcherMusTest, UseDefaultTargeterToFindTarget) { | 2853 TEST_F(WindowEventDispatcherMusTest, UseDefaultTargeterToFindTarget) { |
| 2797 LastEventLocationDelegate last_event_location_delegate1; | 2854 LastEventLocationDelegate last_event_location_delegate1; |
| 2798 std::unique_ptr<Window> child1( | 2855 std::unique_ptr<Window> child1( |
| 2799 CreateTestWindowWithDelegate(&last_event_location_delegate1, 123, | 2856 CreateTestWindowWithDelegate(&last_event_location_delegate1, 123, |
| 2800 gfx::Rect(10, 10, 100, 100), root_window())); | 2857 gfx::Rect(10, 10, 100, 100), root_window())); |
| 2801 LastEventLocationDelegate last_event_location_delegate2; | 2858 LastEventLocationDelegate last_event_location_delegate2; |
| 2802 std::unique_ptr<Window> child2( | 2859 std::unique_ptr<Window> child2( |
| 2803 CreateTestWindowWithDelegate(&last_event_location_delegate2, 124, | 2860 CreateTestWindowWithDelegate(&last_event_location_delegate2, 124, |
| 2804 gfx::Rect(20, 30, 100, 100), child1.get())); | 2861 gfx::Rect(20, 30, 100, 100), child1.get())); |
| 2805 | 2862 |
| 2806 const gfx::Point mouse_location(30, 40); | 2863 const gfx::Point mouse_location(30, 40); |
| 2807 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, | 2864 ui::MouseEvent mouse( |
| 2808 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2865 ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, |
| 2809 ui::EF_LEFT_MOUSE_BUTTON); | 2866 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2867 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2810 DispatchEventUsingWindowDispatcher(&mouse); | 2868 DispatchEventUsingWindowDispatcher(&mouse); |
| 2811 EXPECT_EQ(0, last_event_location_delegate1.mouse_event_count()); | 2869 EXPECT_EQ(0, last_event_location_delegate1.mouse_event_count()); |
| 2812 EXPECT_EQ(1, last_event_location_delegate2.mouse_event_count()); | 2870 EXPECT_EQ(1, last_event_location_delegate2.mouse_event_count()); |
| 2813 EXPECT_EQ(gfx::Point(), last_event_location_delegate1.last_mouse_location()); | 2871 EXPECT_EQ(gfx::Point(), last_event_location_delegate1.last_mouse_location()); |
| 2814 EXPECT_EQ(mouse_location, | 2872 EXPECT_EQ(mouse_location, |
| 2815 last_event_location_delegate2.last_mouse_location()); | 2873 last_event_location_delegate2.last_mouse_location()); |
| 2816 } | 2874 } |
| 2817 | 2875 |
| 2818 TEST_F(WindowEventDispatcherMusTest, UseDefaultTargeterToFindTarget2) { | 2876 TEST_F(WindowEventDispatcherMusTest, UseDefaultTargeterToFindTarget2) { |
| 2819 LastEventLocationDelegate last_event_location_delegate1; | 2877 LastEventLocationDelegate last_event_location_delegate1; |
| 2820 std::unique_ptr<Window> child1( | 2878 std::unique_ptr<Window> child1( |
| 2821 CreateTestWindowWithDelegate(&last_event_location_delegate1, 123, | 2879 CreateTestWindowWithDelegate(&last_event_location_delegate1, 123, |
| 2822 gfx::Rect(10, 10, 100, 100), root_window())); | 2880 gfx::Rect(10, 10, 100, 100), root_window())); |
| 2823 LastEventLocationDelegate last_event_location_delegate2; | 2881 LastEventLocationDelegate last_event_location_delegate2; |
| 2824 std::unique_ptr<Window> child2( | 2882 std::unique_ptr<Window> child2( |
| 2825 CreateTestWindowWithDelegate(&last_event_location_delegate2, 124, | 2883 CreateTestWindowWithDelegate(&last_event_location_delegate2, 124, |
| 2826 gfx::Rect(20, 30, 100, 100), child1.get())); | 2884 gfx::Rect(20, 30, 100, 100), child1.get())); |
| 2827 | 2885 |
| 2828 const gfx::Point mouse_location(15, 25); | 2886 const gfx::Point mouse_location(15, 25); |
| 2829 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, | 2887 ui::MouseEvent mouse( |
| 2830 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2888 ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, |
| 2831 ui::EF_LEFT_MOUSE_BUTTON); | 2889 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2890 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2832 DispatchEventUsingWindowDispatcher(&mouse); | 2891 DispatchEventUsingWindowDispatcher(&mouse); |
| 2833 EXPECT_EQ(1, last_event_location_delegate1.mouse_event_count()); | 2892 EXPECT_EQ(1, last_event_location_delegate1.mouse_event_count()); |
| 2834 EXPECT_EQ(0, last_event_location_delegate2.mouse_event_count()); | 2893 EXPECT_EQ(0, last_event_location_delegate2.mouse_event_count()); |
| 2835 EXPECT_EQ(mouse_location, | 2894 EXPECT_EQ(mouse_location, |
| 2836 last_event_location_delegate1.last_mouse_location()); | 2895 last_event_location_delegate1.last_mouse_location()); |
| 2837 EXPECT_EQ(gfx::Point(), last_event_location_delegate2.last_mouse_location()); | 2896 EXPECT_EQ(gfx::Point(), last_event_location_delegate2.last_mouse_location()); |
| 2838 } | 2897 } |
| 2839 | 2898 |
| 2840 class NestedLocationDelegate : public test::TestWindowDelegate { | 2899 class NestedLocationDelegate : public test::TestWindowDelegate { |
| 2841 public: | 2900 public: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2901 | 2960 |
| 2902 // Enable fetching mouse location from mouse. | 2961 // Enable fetching mouse location from mouse. |
| 2903 test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); | 2962 test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); |
| 2904 EXPECT_EQ(gfx::Point(0, 0), | 2963 EXPECT_EQ(gfx::Point(0, 0), |
| 2905 window_tree_client_impl()->GetCursorScreenPoint()); | 2964 window_tree_client_impl()->GetCursorScreenPoint()); |
| 2906 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); | 2965 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); |
| 2907 | 2966 |
| 2908 // Dispatch an event to |mouse_location|. While dispatching the event | 2967 // Dispatch an event to |mouse_location|. While dispatching the event |
| 2909 // Env::last_mouse_location() should return |mouse_location|. | 2968 // Env::last_mouse_location() should return |mouse_location|. |
| 2910 const gfx::Point mouse_location(1, 2); | 2969 const gfx::Point mouse_location(1, 2); |
| 2911 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, | 2970 ui::MouseEvent mouse( |
| 2912 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2971 ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, |
| 2913 ui::EF_LEFT_MOUSE_BUTTON); | 2972 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2973 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 2914 DispatchEventUsingWindowDispatcher(&mouse); | 2974 DispatchEventUsingWindowDispatcher(&mouse); |
| 2915 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); | 2975 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); |
| 2916 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); | 2976 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); |
| 2917 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); | 2977 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); |
| 2918 | 2978 |
| 2919 // After dispatch the location should fallback to that of the | 2979 // After dispatch the location should fallback to that of the |
| 2920 // WindowTreeClient, which defaults to 0,0. | 2980 // WindowTreeClient, which defaults to 0,0. |
| 2921 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); | 2981 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); |
| 2922 } | 2982 } |
| 2923 | 2983 |
| 2924 } // namespace aura | 2984 } // namespace aura |
| OLD | NEW |