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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::Point point(101, 201); |
120 ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point, point, | 120 ui::MouseEvent event1( |
121 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 121 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
122 ui::EF_LEFT_MOUSE_BUTTON); | 122 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 123 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
123 DispatchEventUsingWindowDispatcher(&event1); | 124 DispatchEventUsingWindowDispatcher(&event1); |
124 | 125 |
125 // Event was tested for non-client area for the target window. | 126 // Event was tested for non-client area for the target window. |
126 EXPECT_EQ(1, delegate1->non_client_count()); | 127 EXPECT_EQ(1, delegate1->non_client_count()); |
127 EXPECT_EQ(0, delegate2->non_client_count()); | 128 EXPECT_EQ(0, delegate2->non_client_count()); |
128 // The non-client component test was in local coordinates. | 129 // The non-client component test was in local coordinates. |
129 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); | 130 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
130 // Mouse event was received by target window. | 131 // Mouse event was received by target window. |
131 EXPECT_EQ(1, delegate1->mouse_event_count()); | 132 EXPECT_EQ(1, delegate1->mouse_event_count()); |
132 EXPECT_EQ(0, delegate2->mouse_event_count()); | 133 EXPECT_EQ(0, delegate2->mouse_event_count()); |
133 // Event was in local coordinates. | 134 // Event was in local coordinates. |
134 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); | 135 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); |
135 // Non-client flag was set. | 136 // Non-client flag was set. |
136 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); | 137 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); |
137 } | 138 } |
138 | 139 |
139 TEST_F(WindowEventDispatcherTest, RepostEvent) { | 140 TEST_F(WindowEventDispatcherTest, RepostEvent) { |
140 // Test RepostEvent in RootWindow. It only works for Mouse Press. | 141 // Test RepostEvent in RootWindow. It only works for Mouse Press. |
141 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 142 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
142 gfx::Point point(10, 10); | 143 gfx::Point point(10, 10); |
143 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, point, point, | 144 ui::MouseEvent event( |
144 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 145 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
145 ui::EF_LEFT_MOUSE_BUTTON); | 146 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 147 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
146 host()->dispatcher()->RepostEvent(event); | 148 host()->dispatcher()->RepostEvent(event); |
147 RunAllPendingInMessageLoop(); | 149 RunAllPendingInMessageLoop(); |
148 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 150 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
149 } | 151 } |
150 | 152 |
151 // Check that we correctly track the state of the mouse buttons in response to | 153 // Check that we correctly track the state of the mouse buttons in response to |
152 // button press and release events. | 154 // button press and release events. |
153 TEST_F(WindowEventDispatcherTest, MouseButtonState) { | 155 TEST_F(WindowEventDispatcherTest, MouseButtonState) { |
154 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 156 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
155 | 157 |
156 gfx::Point location; | 158 gfx::Point location; |
157 scoped_ptr<ui::MouseEvent> event; | 159 scoped_ptr<ui::MouseEvent> event; |
158 | 160 |
159 // Press the left button. | 161 // Press the left button. |
160 event.reset(new ui::MouseEvent( | 162 event.reset(new ui::MouseEvent( |
161 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 163 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
162 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 164 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 165 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
163 DispatchEventUsingWindowDispatcher(event.get()); | 166 DispatchEventUsingWindowDispatcher(event.get()); |
164 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 167 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
165 | 168 |
166 // Additionally press the right. | 169 // Additionally press the right. |
167 event.reset(new ui::MouseEvent( | 170 event.reset(new ui::MouseEvent( |
168 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 171 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
169 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, | 172 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
170 ui::EF_RIGHT_MOUSE_BUTTON)); | 173 ui::EF_RIGHT_MOUSE_BUTTON, |
| 174 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
171 DispatchEventUsingWindowDispatcher(event.get()); | 175 DispatchEventUsingWindowDispatcher(event.get()); |
172 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 176 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
173 | 177 |
174 // Release the left button. | 178 // Release the left button. |
175 event.reset(new ui::MouseEvent( | 179 event.reset(new ui::MouseEvent( |
176 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), | 180 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
177 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 181 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 182 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
178 DispatchEventUsingWindowDispatcher(event.get()); | 183 DispatchEventUsingWindowDispatcher(event.get()); |
179 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 184 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
180 | 185 |
181 // Release the right button. We should ignore the Shift-is-down flag. | 186 // Release the right button. We should ignore the Shift-is-down flag. |
182 event.reset(new ui::MouseEvent(ui::ET_MOUSE_RELEASED, location, location, | 187 event.reset(new ui::MouseEvent( |
183 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, | 188 ui::ET_MOUSE_RELEASED, location, location, ui::EventTimeForNow(), |
184 ui::EF_RIGHT_MOUSE_BUTTON)); | 189 ui::EF_SHIFT_DOWN, ui::EF_RIGHT_MOUSE_BUTTON, |
| 190 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
185 DispatchEventUsingWindowDispatcher(event.get()); | 191 DispatchEventUsingWindowDispatcher(event.get()); |
186 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 192 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
187 | 193 |
188 // Press the middle button. | 194 // Press the middle button. |
189 event.reset(new ui::MouseEvent( | 195 event.reset(new ui::MouseEvent( |
190 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 196 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
191 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON)); | 197 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON, |
| 198 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
192 DispatchEventUsingWindowDispatcher(event.get()); | 199 DispatchEventUsingWindowDispatcher(event.get()); |
193 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 200 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
194 } | 201 } |
195 | 202 |
196 TEST_F(WindowEventDispatcherTest, TranslatedEvent) { | 203 TEST_F(WindowEventDispatcherTest, TranslatedEvent) { |
197 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 204 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, |
198 gfx::Rect(50, 50, 100, 100), root_window())); | 205 gfx::Rect(50, 50, 100, 100), root_window())); |
199 | 206 |
200 gfx::Point origin(100, 100); | 207 gfx::Point origin(100, 100); |
201 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, | 208 ui::MouseEvent root( |
202 ui::EventTimeForNow(), 0, 0); | 209 ui::ET_MOUSE_PRESSED, origin, origin, ui::EventTimeForNow(), 0, 0, |
| 210 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
203 | 211 |
204 EXPECT_EQ("100,100", root.location().ToString()); | 212 EXPECT_EQ("100,100", root.location().ToString()); |
205 EXPECT_EQ("100,100", root.root_location().ToString()); | 213 EXPECT_EQ("100,100", root.root_location().ToString()); |
206 | 214 |
207 ui::MouseEvent translated_event( | 215 ui::MouseEvent translated_event( |
208 root, static_cast<Window*>(root_window()), w1.get(), | 216 root, static_cast<Window*>(root_window()), w1.get(), |
209 ui::ET_MOUSE_ENTERED, root.flags()); | 217 ui::ET_MOUSE_ENTERED, root.flags()); |
210 EXPECT_EQ("50,50", translated_event.location().ToString()); | 218 EXPECT_EQ("50,50", translated_event.location().ToString()); |
211 EXPECT_EQ("100,100", translated_event.root_location().ToString()); | 219 EXPECT_EQ("100,100", translated_event.root_location().ToString()); |
212 } | 220 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 // over |window| and verify |window| gets it (|window| gets it because it has | 627 // over |window| and verify |window| gets it (|window| gets it because it has |
620 // capture). | 628 // capture). |
621 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 629 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
622 EventFilterRecorder recorder; | 630 EventFilterRecorder recorder; |
623 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 631 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
624 window->SetBounds(gfx::Rect(20, 20, 40, 30)); | 632 window->SetBounds(gfx::Rect(20, 20, 40, 30)); |
625 window->AddPreTargetHandler(&recorder); | 633 window->AddPreTargetHandler(&recorder); |
626 window->SetCapture(); | 634 window->SetCapture(); |
627 const ui::MouseEvent press_event( | 635 const ui::MouseEvent press_event( |
628 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 636 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
629 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 637 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 638 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
630 host()->dispatcher()->RepostEvent(press_event); | 639 host()->dispatcher()->RepostEvent(press_event); |
631 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). | 640 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). |
632 // Mouse moves/enters may be generated. We only care about a pressed. | 641 // Mouse moves/enters may be generated. We only care about a pressed. |
633 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != | 642 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != |
634 std::string::npos) << EventTypesToString(recorder.events()); | 643 std::string::npos) << EventTypesToString(recorder.events()); |
635 } | 644 } |
636 | 645 |
637 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { | 646 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { |
638 EventFilterRecorder recorder; | 647 EventFilterRecorder recorder; |
639 root_window()->AddPreTargetHandler(&recorder); | 648 root_window()->AddPreTargetHandler(&recorder); |
640 | 649 |
641 test::TestWindowDelegate delegate; | 650 test::TestWindowDelegate delegate; |
642 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 651 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
643 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 652 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
644 | 653 |
645 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 654 ui::MouseEvent mouse_move_event( |
646 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 655 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), |
647 0); | 656 ui::EventTimeForNow(), 0, 0, |
| 657 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
648 DispatchEventUsingWindowDispatcher(&mouse_move_event); | 658 DispatchEventUsingWindowDispatcher(&mouse_move_event); |
649 // Discard MOUSE_ENTER. | 659 // Discard MOUSE_ENTER. |
650 recorder.Reset(); | 660 recorder.Reset(); |
651 | 661 |
652 host()->dispatcher()->HoldPointerMoves(); | 662 host()->dispatcher()->HoldPointerMoves(); |
653 | 663 |
654 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. | 664 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. |
655 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), | 665 ui::MouseEvent mouse_dragged_event( |
656 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 666 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
657 0); | 667 ui::EventTimeForNow(), 0, 0, |
| 668 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
658 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 669 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
659 EXPECT_TRUE(recorder.events().empty()); | 670 EXPECT_TRUE(recorder.events().empty()); |
660 | 671 |
661 // Check that we do dispatch the held MOUSE_DRAGGED event before another type | 672 // Check that we do dispatch the held MOUSE_DRAGGED event before another type |
662 // of event. | 673 // of event. |
663 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 674 ui::MouseEvent mouse_pressed_event( |
664 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 675 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
665 0); | 676 ui::EventTimeForNow(), 0, 0, |
| 677 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
666 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 678 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
667 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 679 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
668 EventTypesToString(recorder.events())); | 680 EventTypesToString(recorder.events())); |
669 recorder.Reset(); | 681 recorder.Reset(); |
670 | 682 |
671 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and | 683 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and |
672 // elsewhere in this test) we re-define each event prior to dispatch so that | 684 // elsewhere in this test) we re-define each event prior to dispatch so that |
673 // it has the correct state (phase, handled, target, etc.). | 685 // it has the correct state (phase, handled, target, etc.). |
674 mouse_dragged_event = | 686 mouse_dragged_event = ui::MouseEvent( |
675 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 687 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
676 ui::EventTimeForNow(), 0, 0); | 688 ui::EventTimeForNow(), 0, 0, |
677 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 689 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
678 gfx::Point(10, 10), ui::EventTimeForNow(), | 690 ui::MouseEvent mouse_dragged_event2( |
679 0, 0); | 691 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 692 ui::EventTimeForNow(), 0, 0, |
| 693 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
680 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 694 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
681 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 695 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
682 EXPECT_TRUE(recorder.events().empty()); | 696 EXPECT_TRUE(recorder.events().empty()); |
683 mouse_pressed_event = | 697 mouse_pressed_event = ui::MouseEvent( |
684 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), | 698 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
685 ui::EventTimeForNow(), 0, 0); | 699 ui::EventTimeForNow(), 0, 0, |
| 700 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
686 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 701 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
687 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 702 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
688 EventTypesToString(recorder.events())); | 703 EventTypesToString(recorder.events())); |
689 recorder.Reset(); | 704 recorder.Reset(); |
690 | 705 |
691 // Check that on ReleasePointerMoves, held events are not dispatched | 706 // Check that on ReleasePointerMoves, held events are not dispatched |
692 // immediately, but posted instead. | 707 // immediately, but posted instead. |
693 mouse_dragged_event = | 708 mouse_dragged_event = ui::MouseEvent( |
694 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 709 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
695 ui::EventTimeForNow(), 0, 0); | 710 ui::EventTimeForNow(), 0, 0, |
| 711 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
696 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 712 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
697 host()->dispatcher()->ReleasePointerMoves(); | 713 host()->dispatcher()->ReleasePointerMoves(); |
698 EXPECT_TRUE(recorder.events().empty()); | 714 EXPECT_TRUE(recorder.events().empty()); |
699 RunAllPendingInMessageLoop(); | 715 RunAllPendingInMessageLoop(); |
700 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 716 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
701 recorder.Reset(); | 717 recorder.Reset(); |
702 | 718 |
703 // However if another message comes in before the dispatch of the posted | 719 // However if another message comes in before the dispatch of the posted |
704 // event, check that the posted event is dispatched before this new event. | 720 // event, check that the posted event is dispatched before this new event. |
705 host()->dispatcher()->HoldPointerMoves(); | 721 host()->dispatcher()->HoldPointerMoves(); |
706 mouse_dragged_event = | 722 mouse_dragged_event = ui::MouseEvent( |
707 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 723 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
708 ui::EventTimeForNow(), 0, 0); | 724 ui::EventTimeForNow(), 0, 0, |
| 725 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
709 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 726 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
710 host()->dispatcher()->ReleasePointerMoves(); | 727 host()->dispatcher()->ReleasePointerMoves(); |
711 mouse_pressed_event = | 728 mouse_pressed_event = ui::MouseEvent( |
712 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), | 729 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
713 ui::EventTimeForNow(), 0, 0); | 730 ui::EventTimeForNow(), 0, 0, |
| 731 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
714 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 732 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
715 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 733 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
716 EventTypesToString(recorder.events())); | 734 EventTypesToString(recorder.events())); |
717 recorder.Reset(); | 735 recorder.Reset(); |
718 RunAllPendingInMessageLoop(); | 736 RunAllPendingInMessageLoop(); |
719 EXPECT_TRUE(recorder.events().empty()); | 737 EXPECT_TRUE(recorder.events().empty()); |
720 | 738 |
721 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce | 739 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce |
722 // them. | 740 // them. |
723 host()->dispatcher()->HoldPointerMoves(); | 741 host()->dispatcher()->HoldPointerMoves(); |
724 mouse_dragged_event = | 742 mouse_dragged_event = ui::MouseEvent( |
725 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), |
726 ui::EventTimeForNow(), 0, 0); | 744 ui::EventTimeForNow(), 0, 0, |
| 745 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
727 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 746 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
728 host()->dispatcher()->ReleasePointerMoves(); | 747 host()->dispatcher()->ReleasePointerMoves(); |
729 mouse_dragged_event2 = | 748 mouse_dragged_event2 = ui::MouseEvent( |
730 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 749 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), |
731 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 750 ui::EventTimeForNow(), 0, 0, |
| 751 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
732 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 752 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
733 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 753 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
734 recorder.Reset(); | 754 recorder.Reset(); |
735 RunAllPendingInMessageLoop(); | 755 RunAllPendingInMessageLoop(); |
736 EXPECT_TRUE(recorder.events().empty()); | 756 EXPECT_TRUE(recorder.events().empty()); |
737 | 757 |
738 // Check that synthetic mouse move event has a right location when issued | 758 // Check that synthetic mouse move event has a right location when issued |
739 // while holding pointer moves. | 759 // while holding pointer moves. |
740 mouse_dragged_event = | 760 mouse_dragged_event = ui::MouseEvent( |
741 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), | 761 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), |
742 ui::EventTimeForNow(), 0, 0); | 762 ui::EventTimeForNow(), 0, 0, |
743 mouse_dragged_event2 = | 763 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
744 ui::MouseEvent(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 764 mouse_dragged_event2 = ui::MouseEvent( |
745 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 765 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), |
746 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), | 766 ui::EventTimeForNow(), 0, 0, |
747 gfx::Point(28, 28), ui::EventTimeForNow(), | 767 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
748 0, 0); | 768 ui::MouseEvent mouse_dragged_event3( |
| 769 ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), gfx::Point(28, 28), |
| 770 ui::EventTimeForNow(), 0, 0, |
| 771 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
749 host()->dispatcher()->HoldPointerMoves(); | 772 host()->dispatcher()->HoldPointerMoves(); |
750 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 773 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
751 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 774 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
752 window->SetBounds(gfx::Rect(15, 15, 80, 80)); | 775 window->SetBounds(gfx::Rect(15, 15, 80, 80)); |
753 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); | 776 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); |
754 RunAllPendingInMessageLoop(); | 777 RunAllPendingInMessageLoop(); |
755 EXPECT_TRUE(recorder.events().empty()); | 778 EXPECT_TRUE(recorder.events().empty()); |
756 host()->dispatcher()->ReleasePointerMoves(); | 779 host()->dispatcher()->ReleasePointerMoves(); |
757 RunAllPendingInMessageLoop(); | 780 RunAllPendingInMessageLoop(); |
758 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(recorder.events())); | 781 EXPECT_EQ("MOUSE_MOVED", EventTypesToString(recorder.events())); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); | 851 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
829 window_first->Show(); | 852 window_first->Show(); |
830 window_first->AddPreTargetHandler(&recorder_first); | 853 window_first->AddPreTargetHandler(&recorder_first); |
831 | 854 |
832 scoped_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( | 855 scoped_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( |
833 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); | 856 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); |
834 window_second->Show(); | 857 window_second->Show(); |
835 window_second->AddPreTargetHandler(&recorder_second); | 858 window_second->AddPreTargetHandler(&recorder_second); |
836 | 859 |
837 const gfx::Point event_location(22, 33); | 860 const gfx::Point event_location(22, 33); |
838 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 861 ui::MouseEvent mouse( |
839 ui::EventTimeForNow(), 0, 0); | 862 ui::ET_MOUSE_MOVED, event_location, event_location, ui::EventTimeForNow(), |
| 863 0, 0, ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
840 DispatchEventUsingWindowDispatcher(&mouse); | 864 DispatchEventUsingWindowDispatcher(&mouse); |
841 | 865 |
842 EXPECT_TRUE(recorder_first.events().empty()); | 866 EXPECT_TRUE(recorder_first.events().empty()); |
843 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", | 867 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", |
844 EventTypesToString(recorder_second.events())); | 868 EventTypesToString(recorder_second.events())); |
845 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); | 869 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); |
846 EXPECT_EQ(gfx::Point(2, 3).ToString(), | 870 EXPECT_EQ(gfx::Point(2, 3).ToString(), |
847 recorder_second.mouse_locations()[0].ToString()); | 871 recorder_second.mouse_locations()[0].ToString()); |
848 } | 872 } |
849 | 873 |
850 // Tests that a mouse exit is dispatched to the last mouse location when | 874 // Tests that a mouse exit is dispatched to the last mouse location when |
851 // the window is hiddden. | 875 // the window is hiddden. |
852 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { | 876 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { |
853 EventFilterRecorder recorder; | 877 EventFilterRecorder recorder; |
854 | 878 |
855 test::TestWindowDelegate delegate; | 879 test::TestWindowDelegate delegate; |
856 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 880 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
857 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 881 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
858 window->Show(); | 882 window->Show(); |
859 window->AddPreTargetHandler(&recorder); | 883 window->AddPreTargetHandler(&recorder); |
860 | 884 |
861 // Dispatch a mouse move event into the window. | 885 // Dispatch a mouse move event into the window. |
862 const gfx::Point event_location(22, 33); | 886 const gfx::Point event_location(22, 33); |
863 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 887 ui::MouseEvent mouse( |
864 ui::EventTimeForNow(), 0, 0); | 888 ui::ET_MOUSE_MOVED, event_location, event_location, ui::EventTimeForNow(), |
| 889 0, 0, ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
865 DispatchEventUsingWindowDispatcher(&mouse); | 890 DispatchEventUsingWindowDispatcher(&mouse); |
866 EXPECT_FALSE(recorder.events().empty()); | 891 EXPECT_FALSE(recorder.events().empty()); |
867 recorder.Reset(); | 892 recorder.Reset(); |
868 | 893 |
869 // Hide the window and verify a mouse exit event's location. | 894 // Hide the window and verify a mouse exit event's location. |
870 window->Hide(); | 895 window->Hide(); |
871 EXPECT_FALSE(recorder.events().empty()); | 896 EXPECT_FALSE(recorder.events().empty()); |
872 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); | 897 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); |
873 ASSERT_EQ(1u, recorder.mouse_locations().size()); | 898 ASSERT_EQ(1u, recorder.mouse_locations().size()); |
874 EXPECT_EQ(gfx::Point(12, 23).ToString(), | 899 EXPECT_EQ(gfx::Point(12, 23).ToString(), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 1015 |
991 test::TestWindowDelegate delegate; | 1016 test::TestWindowDelegate delegate; |
992 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1017 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
993 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1018 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
994 window->Show(); | 1019 window->Show(); |
995 window->SetCapture(); | 1020 window->SetCapture(); |
996 | 1021 |
997 test::TestCursorClient cursor_client(root_window()); | 1022 test::TestCursorClient cursor_client(root_window()); |
998 | 1023 |
999 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1024 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
1000 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1025 ui::MouseEvent mouse1( |
1001 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1026 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1027 ui::EventTimeForNow(), 0, 0, |
| 1028 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1002 DispatchEventUsingWindowDispatcher(&mouse1); | 1029 DispatchEventUsingWindowDispatcher(&mouse1); |
1003 EXPECT_FALSE(recorder.events().empty()); | 1030 EXPECT_FALSE(recorder.events().empty()); |
1004 recorder.Reset(); | 1031 recorder.Reset(); |
1005 | 1032 |
1006 // Dispatch a synthetic mouse event when mouse events are enabled. | 1033 // Dispatch a synthetic mouse event when mouse events are enabled. |
1007 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1034 ui::MouseEvent mouse2( |
1008 gfx::Point(10, 10), ui::EventTimeForNow(), | 1035 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
1009 ui::EF_IS_SYNTHESIZED, 0); | 1036 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0, |
| 1037 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1010 DispatchEventUsingWindowDispatcher(&mouse2); | 1038 DispatchEventUsingWindowDispatcher(&mouse2); |
1011 EXPECT_FALSE(recorder.events().empty()); | 1039 EXPECT_FALSE(recorder.events().empty()); |
1012 recorder.Reset(); | 1040 recorder.Reset(); |
1013 | 1041 |
1014 // Dispatch a synthetic mouse event when mouse events are disabled. | 1042 // Dispatch a synthetic mouse event when mouse events are disabled. |
1015 cursor_client.DisableMouseEvents(); | 1043 cursor_client.DisableMouseEvents(); |
1016 DispatchEventUsingWindowDispatcher(&mouse2); | 1044 DispatchEventUsingWindowDispatcher(&mouse2); |
1017 EXPECT_TRUE(recorder.events().empty()); | 1045 EXPECT_TRUE(recorder.events().empty()); |
1018 root_window()->RemovePreTargetHandler(&recorder); | 1046 root_window()->RemovePreTargetHandler(&recorder); |
1019 } | 1047 } |
1020 | 1048 |
1021 // Tests that a mouse-move event is not synthesized when a mouse-button is down. | 1049 // Tests that a mouse-move event is not synthesized when a mouse-button is down. |
1022 TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { | 1050 TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { |
1023 EventFilterRecorder recorder; | 1051 EventFilterRecorder recorder; |
1024 test::TestWindowDelegate delegate; | 1052 test::TestWindowDelegate delegate; |
1025 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1053 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1026 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1054 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
1027 window->Show(); | 1055 window->Show(); |
1028 | 1056 |
1029 window->AddPreTargetHandler(&recorder); | 1057 window->AddPreTargetHandler(&recorder); |
1030 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1058 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
1031 ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1059 ui::MouseEvent mouse1( |
1032 gfx::Point(10, 10), ui::EventTimeForNow(), | 1060 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
1033 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1061 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 1062 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1034 DispatchEventUsingWindowDispatcher(&mouse1); | 1063 DispatchEventUsingWindowDispatcher(&mouse1); |
1035 ASSERT_EQ(1u, recorder.events().size()); | 1064 ASSERT_EQ(1u, recorder.events().size()); |
1036 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]); | 1065 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder.events()[0]); |
1037 window->RemovePreTargetHandler(&recorder); | 1066 window->RemovePreTargetHandler(&recorder); |
1038 recorder.Reset(); | 1067 recorder.Reset(); |
1039 | 1068 |
1040 // Move |window| away from underneath the cursor. | 1069 // Move |window| away from underneath the cursor. |
1041 root_window()->AddPreTargetHandler(&recorder); | 1070 root_window()->AddPreTargetHandler(&recorder); |
1042 window->SetBounds(gfx::Rect(30, 30, 100, 100)); | 1071 window->SetBounds(gfx::Rect(30, 30, 100, 100)); |
1043 EXPECT_TRUE(recorder.events().empty()); | 1072 EXPECT_TRUE(recorder.events().empty()); |
(...skipping 17 matching lines...) Expand all Loading... |
1061 test::TestWindowDelegate delegate; | 1090 test::TestWindowDelegate delegate; |
1062 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1091 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1063 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1092 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
1064 window->Show(); | 1093 window->Show(); |
1065 window->SetCapture(); | 1094 window->SetCapture(); |
1066 | 1095 |
1067 EventFilterRecorder recorder; | 1096 EventFilterRecorder recorder; |
1068 window->AddPreTargetHandler(&recorder); | 1097 window->AddPreTargetHandler(&recorder); |
1069 | 1098 |
1070 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. | 1099 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. |
1071 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1100 ui::MouseEvent mouse( |
1072 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1101 ui::ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1102 ui::EventTimeForNow(), 0, 0, |
| 1103 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1073 DispatchEventUsingWindowDispatcher(&mouse); | 1104 DispatchEventUsingWindowDispatcher(&mouse); |
1074 EXPECT_FALSE(recorder.events().empty()); | 1105 EXPECT_FALSE(recorder.events().empty()); |
1075 recorder.Reset(); | 1106 recorder.Reset(); |
1076 | 1107 |
1077 // Update the window bounds so that cursor is now outside the window. | 1108 // Update the window bounds so that cursor is now outside the window. |
1078 // This should trigger a synthetic MOVED event. | 1109 // This should trigger a synthetic MOVED event. |
1079 gfx::Rect bounds1(20, 20, 100, 100); | 1110 gfx::Rect bounds1(20, 20, 100, 100); |
1080 window->SetBounds(bounds1); | 1111 window->SetBounds(bounds1); |
1081 RunAllPendingInMessageLoop(); | 1112 RunAllPendingInMessageLoop(); |
1082 ASSERT_FALSE(recorder.events().empty()); | 1113 ASSERT_FALSE(recorder.events().empty()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 | 1147 |
1117 test::TestWindowDelegate delegate; | 1148 test::TestWindowDelegate delegate; |
1118 gfx::Point window_origin(7, 18); | 1149 gfx::Point window_origin(7, 18); |
1119 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1150 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1120 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1151 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
1121 root_window())); | 1152 root_window())); |
1122 window->Show(); | 1153 window->Show(); |
1123 | 1154 |
1124 // Dispatch a mouse move event into the window. | 1155 // Dispatch a mouse move event into the window. |
1125 gfx::Point mouse_location(gfx::Point(15, 25)); | 1156 gfx::Point mouse_location(gfx::Point(15, 25)); |
1126 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1157 ui::MouseEvent mouse1( |
1127 ui::EventTimeForNow(), 0, 0); | 1158 ui::ET_MOUSE_MOVED, mouse_location, mouse_location, ui::EventTimeForNow(), |
| 1159 0, 0, ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1128 EXPECT_TRUE(recorder.events().empty()); | 1160 EXPECT_TRUE(recorder.events().empty()); |
1129 DispatchEventUsingWindowDispatcher(&mouse1); | 1161 DispatchEventUsingWindowDispatcher(&mouse1); |
1130 EXPECT_FALSE(recorder.events().empty()); | 1162 EXPECT_FALSE(recorder.events().empty()); |
1131 recorder.Reset(); | 1163 recorder.Reset(); |
1132 | 1164 |
1133 // Hide the cursor and verify a mouse exit was dispatched. | 1165 // Hide the cursor and verify a mouse exit was dispatched. |
1134 host()->OnCursorVisibilityChanged(false); | 1166 host()->OnCursorVisibilityChanged(false); |
1135 EXPECT_FALSE(recorder.events().empty()); | 1167 EXPECT_FALSE(recorder.events().empty()); |
1136 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); | 1168 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); |
1137 | 1169 |
(...skipping 15 matching lines...) Expand all Loading... |
1153 | 1185 |
1154 test::TestWindowDelegate delegate; | 1186 test::TestWindowDelegate delegate; |
1155 gfx::Point window_origin(7, 18); | 1187 gfx::Point window_origin(7, 18); |
1156 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1188 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1157 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1189 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
1158 root_window())); | 1190 root_window())); |
1159 window->Show(); | 1191 window->Show(); |
1160 | 1192 |
1161 // Dispatch a mouse move event into the window. | 1193 // Dispatch a mouse move event into the window. |
1162 gfx::Point mouse_location(gfx::Point(15, 25)); | 1194 gfx::Point mouse_location(gfx::Point(15, 25)); |
1163 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1195 ui::MouseEvent mouse1( |
1164 ui::EventTimeForNow(), 0, 0); | 1196 ui::ET_MOUSE_MOVED, mouse_location, mouse_location, ui::EventTimeForNow(), |
| 1197 0, 0, ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1165 EXPECT_TRUE(recorder.events().empty()); | 1198 EXPECT_TRUE(recorder.events().empty()); |
1166 DispatchEventUsingWindowDispatcher(&mouse1); | 1199 DispatchEventUsingWindowDispatcher(&mouse1); |
1167 EXPECT_FALSE(recorder.events().empty()); | 1200 EXPECT_FALSE(recorder.events().empty()); |
1168 recorder.Reset(); | 1201 recorder.Reset(); |
1169 | 1202 |
1170 test::TestCursorClient cursor_client(root_window()); | 1203 test::TestCursorClient cursor_client(root_window()); |
1171 cursor_client.DisableMouseEvents(); | 1204 cursor_client.DisableMouseEvents(); |
1172 | 1205 |
1173 gfx::Point mouse_exit_location(gfx::Point(150, 150)); | 1206 gfx::Point mouse_exit_location(gfx::Point(150, 150)); |
1174 ui::MouseEvent mouse2(ui::ET_MOUSE_EXITED, gfx::Point(150, 150), | 1207 ui::MouseEvent mouse2( |
1175 gfx::Point(150, 150), ui::EventTimeForNow(), | 1208 ui::ET_MOUSE_EXITED, gfx::Point(150, 150), gfx::Point(150, 150), |
1176 ui::EF_IS_SYNTHESIZED, 0); | 1209 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0, |
| 1210 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1177 DispatchEventUsingWindowDispatcher(&mouse2); | 1211 DispatchEventUsingWindowDispatcher(&mouse2); |
1178 | 1212 |
1179 EXPECT_FALSE(recorder.events().empty()); | 1213 EXPECT_FALSE(recorder.events().empty()); |
1180 // We get the mouse exited event twice in our filter. Once during the | 1214 // We get the mouse exited event twice in our filter. Once during the |
1181 // predispatch phase and during the actual dispatch. | 1215 // predispatch phase and during the actual dispatch. |
1182 EXPECT_EQ("MOUSE_EXITED MOUSE_EXITED", EventTypesToString(recorder.events())); | 1216 EXPECT_EQ("MOUSE_EXITED MOUSE_EXITED", EventTypesToString(recorder.events())); |
1183 | 1217 |
1184 // Verify the mouse exit was dispatched at the correct location | 1218 // Verify the mouse exit was dispatched at the correct location |
1185 // (in the correct coordinate space). | 1219 // (in the correct coordinate space). |
1186 int translated_x = mouse_exit_location.x() - window_origin.x(); | 1220 int translated_x = mouse_exit_location.x() - window_origin.x(); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 : root_(root), | 1683 : root_(root), |
1650 mouse_event_count_(0) {} | 1684 mouse_event_count_(0) {} |
1651 ~DontResetHeldEventWindowDelegate() override {} | 1685 ~DontResetHeldEventWindowDelegate() override {} |
1652 | 1686 |
1653 int mouse_event_count() const { return mouse_event_count_; } | 1687 int mouse_event_count() const { return mouse_event_count_; } |
1654 | 1688 |
1655 // TestWindowDelegate: | 1689 // TestWindowDelegate: |
1656 void OnMouseEvent(ui::MouseEvent* event) override { | 1690 void OnMouseEvent(ui::MouseEvent* event) override { |
1657 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && | 1691 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && |
1658 mouse_event_count_++ == 0) { | 1692 mouse_event_count_++ == 0) { |
1659 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1693 ui::MouseEvent mouse_event( |
1660 gfx::Point(10, 10), ui::EventTimeForNow(), | 1694 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
1661 ui::EF_SHIFT_DOWN, 0); | 1695 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, 0, |
| 1696 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1662 root_->GetHost()->dispatcher()->RepostEvent(mouse_event); | 1697 root_->GetHost()->dispatcher()->RepostEvent(mouse_event); |
1663 } | 1698 } |
1664 } | 1699 } |
1665 | 1700 |
1666 private: | 1701 private: |
1667 Window* root_; | 1702 Window* root_; |
1668 int mouse_event_count_; | 1703 int mouse_event_count_; |
1669 | 1704 |
1670 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); | 1705 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); |
1671 }; | 1706 }; |
1672 | 1707 |
1673 } // namespace | 1708 } // namespace |
1674 | 1709 |
1675 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1710 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
1676 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1711 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
1677 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1712 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
1678 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1713 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
1679 // schedule another reposted event. | 1714 // schedule another reposted event. |
1680 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { | 1715 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { |
1681 DontResetHeldEventWindowDelegate delegate(root_window()); | 1716 DontResetHeldEventWindowDelegate delegate(root_window()); |
1682 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1717 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
1683 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1718 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
1684 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1719 ui::MouseEvent pressed( |
1685 gfx::Point(10, 10), ui::EventTimeForNow(), | 1720 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
1686 ui::EF_SHIFT_DOWN, 0); | 1721 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, 0, |
| 1722 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1687 root_window()->GetHost()->dispatcher()->RepostEvent(pressed); | 1723 root_window()->GetHost()->dispatcher()->RepostEvent(pressed); |
1688 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1724 ui::MouseEvent pressed2( |
1689 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1725 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1726 ui::EventTimeForNow(), 0, 0, |
| 1727 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1690 // Dispatch an event to flush event scheduled by way of RepostEvent(). | 1728 // Dispatch an event to flush event scheduled by way of RepostEvent(). |
1691 DispatchEventUsingWindowDispatcher(&pressed2); | 1729 DispatchEventUsingWindowDispatcher(&pressed2); |
1692 // Delegate should have seen reposted event (identified by way of | 1730 // Delegate should have seen reposted event (identified by way of |
1693 // EF_SHIFT_DOWN). Dispatch another event to flush the second | 1731 // EF_SHIFT_DOWN). Dispatch another event to flush the second |
1694 // RepostedEvent(). | 1732 // RepostedEvent(). |
1695 EXPECT_EQ(1, delegate.mouse_event_count()); | 1733 EXPECT_EQ(1, delegate.mouse_event_count()); |
1696 DispatchEventUsingWindowDispatcher(&pressed2); | 1734 DispatchEventUsingWindowDispatcher(&pressed2); |
1697 EXPECT_EQ(2, delegate.mouse_event_count()); | 1735 EXPECT_EQ(2, delegate.mouse_event_count()); |
1698 } | 1736 } |
1699 | 1737 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event | 1773 // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event |
1736 // we don't crash. | 1774 // we don't crash. |
1737 TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { | 1775 TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { |
1738 // Should be deleted by |delegate|. | 1776 // Should be deleted by |delegate|. |
1739 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); | 1777 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); |
1740 h2->InitHost(); | 1778 h2->InitHost(); |
1741 DeleteHostFromHeldMouseEventDelegate delegate(h2); | 1779 DeleteHostFromHeldMouseEventDelegate delegate(h2); |
1742 // Owned by |h2|. | 1780 // Owned by |h2|. |
1743 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); | 1781 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); |
1744 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1782 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
1745 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1783 ui::MouseEvent pressed( |
1746 gfx::Point(10, 10), ui::EventTimeForNow(), | 1784 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
1747 ui::EF_SHIFT_DOWN, 0); | 1785 ui::EventTimeForNow(), ui::EF_SHIFT_DOWN, 0, |
| 1786 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
1748 h2->dispatcher()->RepostEvent(pressed); | 1787 h2->dispatcher()->RepostEvent(pressed); |
1749 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. | 1788 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. |
1750 RunAllPendingInMessageLoop(); | 1789 RunAllPendingInMessageLoop(); |
1751 EXPECT_TRUE(delegate.got_mouse_event()); | 1790 EXPECT_TRUE(delegate.got_mouse_event()); |
1752 EXPECT_TRUE(delegate.got_destroy()); | 1791 EXPECT_TRUE(delegate.got_destroy()); |
1753 } | 1792 } |
1754 | 1793 |
1755 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { | 1794 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { |
1756 EventFilterRecorder recorder; | 1795 EventFilterRecorder recorder; |
1757 root_window()->AddPreTargetHandler(&recorder); | 1796 root_window()->AddPreTargetHandler(&recorder); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 void RunTest() { | 1980 void RunTest() { |
1942 // Reset any event the window may have received when bringing up the window | 1981 // Reset any event the window may have received when bringing up the window |
1943 // (e.g. mouse-move events if the mouse cursor is over the window). | 1982 // (e.g. mouse-move events if the mouse cursor is over the window). |
1944 handler_.Reset(); | 1983 handler_.Reset(); |
1945 | 1984 |
1946 // Start a nested message-loop, post an event to be dispatched, and then | 1985 // Start a nested message-loop, post an event to be dispatched, and then |
1947 // terminate the message-loop. When the message-loop unwinds and gets back, | 1986 // terminate the message-loop. When the message-loop unwinds and gets back, |
1948 // the reposted event should not have fired. | 1987 // the reposted event should not have fired. |
1949 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( | 1988 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
1950 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), | 1989 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
1951 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); | 1990 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 1991 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
1952 message_loop()->PostTask( | 1992 message_loop()->PostTask( |
1953 FROM_HERE, | 1993 FROM_HERE, |
1954 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, | 1994 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, |
1955 host()->dispatcher(), | 1995 host()->dispatcher(), |
1956 base::Passed(&mouse))); | 1996 base::Passed(&mouse))); |
1957 message_loop()->PostTask(FROM_HERE, message_loop()->QuitClosure()); | 1997 message_loop()->PostTask(FROM_HERE, message_loop()->QuitClosure()); |
1958 | 1998 |
1959 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); | 1999 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); |
1960 base::RunLoop loop; | 2000 base::RunLoop loop; |
1961 loop.Run(); | 2001 loop.Run(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, | 2066 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, |
2027 1234, gfx::Rect(20, 20, 100, 100), root_window())); | 2067 1234, gfx::Rect(20, 20, 100, 100), root_window())); |
2028 child->Show(); | 2068 child->Show(); |
2029 | 2069 |
2030 ui::test::TestEventHandler handler_child; | 2070 ui::test::TestEventHandler handler_child; |
2031 ui::test::TestEventHandler handler_root; | 2071 ui::test::TestEventHandler handler_root; |
2032 root_window()->AddPreTargetHandler(&handler_root); | 2072 root_window()->AddPreTargetHandler(&handler_root); |
2033 child->AddPreTargetHandler(&handler_child); | 2073 child->AddPreTargetHandler(&handler_child); |
2034 | 2074 |
2035 { | 2075 { |
2036 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(30, 30), | 2076 ui::MouseEvent move( |
2037 gfx::Point(30, 30), ui::EventTimeForNow(), ui::EF_NONE, | 2077 ui::ET_MOUSE_MOVED, gfx::Point(30, 30), gfx::Point(30, 30), |
2038 ui::EF_NONE); | 2078 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2079 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2039 DispatchEventUsingWindowDispatcher(&move); | 2080 DispatchEventUsingWindowDispatcher(&move); |
2040 EXPECT_EQ(0, handler_child.num_mouse_events()); | 2081 EXPECT_EQ(0, handler_child.num_mouse_events()); |
2041 EXPECT_EQ(1, handler_root.num_mouse_events()); | 2082 EXPECT_EQ(1, handler_root.num_mouse_events()); |
2042 } | 2083 } |
2043 | 2084 |
2044 { | 2085 { |
2045 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(50, 50), | 2086 ui::MouseEvent move( |
2046 gfx::Point(50, 50), ui::EventTimeForNow(), ui::EF_NONE, | 2087 ui::ET_MOUSE_MOVED, gfx::Point(50, 50), gfx::Point(50, 50), |
2047 ui::EF_NONE); | 2088 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2089 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2048 DispatchEventUsingWindowDispatcher(&move); | 2090 DispatchEventUsingWindowDispatcher(&move); |
2049 // The child receives an ENTER, and a MOVED event. | 2091 // The child receives an ENTER, and a MOVED event. |
2050 EXPECT_EQ(2, handler_child.num_mouse_events()); | 2092 EXPECT_EQ(2, handler_child.num_mouse_events()); |
2051 // The root receives both the ENTER and the MOVED events dispatched to | 2093 // The root receives both the ENTER and the MOVED events dispatched to |
2052 // |child|, as well as an EXIT event. | 2094 // |child|, as well as an EXIT event. |
2053 EXPECT_EQ(3, handler_root.num_mouse_events()); | 2095 EXPECT_EQ(3, handler_root.num_mouse_events()); |
2054 } | 2096 } |
2055 | 2097 |
2056 child->RemovePreTargetHandler(&handler_child); | 2098 child->RemovePreTargetHandler(&handler_child); |
2057 root_window()->RemovePreTargetHandler(&handler_root); | 2099 root_window()->RemovePreTargetHandler(&handler_root); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 | 2167 |
2126 // Tests that if dispatching a 'held' event triggers a nested message loop, then | 2168 // Tests that if dispatching a 'held' event triggers a nested message loop, then |
2127 // the events that are dispatched from the nested message loop are transformed | 2169 // the events that are dispatched from the nested message loop are transformed |
2128 // correctly. | 2170 // correctly. |
2129 TEST_F(WindowEventDispatcherTestInHighDPI, | 2171 TEST_F(WindowEventDispatcherTestInHighDPI, |
2130 EventsTransformedInRepostedEventTriggeredNestedLoop) { | 2172 EventsTransformedInRepostedEventTriggeredNestedLoop) { |
2131 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 2173 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
2132 // Make sure the window is visible. | 2174 // Make sure the window is visible. |
2133 RunAllPendingInMessageLoop(); | 2175 RunAllPendingInMessageLoop(); |
2134 | 2176 |
2135 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::Point(80, 80), | 2177 ui::MouseEvent mouse_move( |
2136 gfx::Point(80, 80), ui::EventTimeForNow(), | 2178 ui::ET_MOUSE_MOVED, gfx::Point(80, 80), gfx::Point(80, 80), |
2137 ui::EF_NONE, ui::EF_NONE); | 2179 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 2180 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2138 const base::Closure callback_on_right_click = base::Bind( | 2181 const base::Closure callback_on_right_click = base::Bind( |
2139 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), | 2182 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), |
2140 base::Unretained(this), base::Unretained(&mouse_move)); | 2183 base::Unretained(this), base::Unretained(&mouse_move)); |
2141 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); | 2184 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); |
2142 window->AddPreTargetHandler(&handler); | 2185 window->AddPreTargetHandler(&handler); |
2143 | 2186 |
2144 scoped_ptr<ui::MouseEvent> mouse( | 2187 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
2145 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 2188 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
2146 gfx::Point(10, 10), ui::EventTimeForNow(), | 2189 ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON, |
2147 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 2190 ui::EF_RIGHT_MOUSE_BUTTON, |
| 2191 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
2148 host()->dispatcher()->RepostEvent(*mouse); | 2192 host()->dispatcher()->RepostEvent(*mouse); |
2149 EXPECT_EQ(0, handler.num_mouse_events()); | 2193 EXPECT_EQ(0, handler.num_mouse_events()); |
2150 | 2194 |
2151 base::RunLoop run_loop; | 2195 base::RunLoop run_loop; |
2152 run_loop.RunUntilIdle(); | 2196 run_loop.RunUntilIdle(); |
2153 // The window should receive the mouse-press and the mouse-move events. | 2197 // The window should receive the mouse-press and the mouse-move events. |
2154 EXPECT_EQ(2, handler.num_mouse_events()); | 2198 EXPECT_EQ(2, handler.num_mouse_events()); |
2155 // The mouse-move event location should be transformed because of the DSF | 2199 // The mouse-move event location should be transformed because of the DSF |
2156 // before it reaches the window. | 2200 // before it reaches the window. |
2157 EXPECT_EQ(gfx::Point(40, 40).ToString(), | 2201 EXPECT_EQ(gfx::Point(40, 40).ToString(), |
(...skipping 20 matching lines...) Expand all Loading... |
2178 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); | 2222 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); |
2179 }; | 2223 }; |
2180 | 2224 |
2181 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { | 2225 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { |
2182 ui::test::EventGenerator generator(root_window()); | 2226 ui::test::EventGenerator generator(root_window()); |
2183 generator.MoveMouseTo(10, 10); | 2227 generator.MoveMouseTo(10, 10); |
2184 EXPECT_EQ("10,10", | 2228 EXPECT_EQ("10,10", |
2185 Env::GetInstance()->last_mouse_location().ToString()); | 2229 Env::GetInstance()->last_mouse_location().ToString()); |
2186 | 2230 |
2187 // Synthesized event should not update the mouse location. | 2231 // Synthesized event should not update the mouse location. |
2188 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 2232 ui::MouseEvent mouseev( |
2189 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0); | 2233 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 2234 ui::EF_IS_SYNTHESIZED, 0, |
| 2235 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2190 generator.Dispatch(&mouseev); | 2236 generator.Dispatch(&mouseev); |
2191 EXPECT_EQ("10,10", | 2237 EXPECT_EQ("10,10", |
2192 Env::GetInstance()->last_mouse_location().ToString()); | 2238 Env::GetInstance()->last_mouse_location().ToString()); |
2193 | 2239 |
2194 generator.MoveMouseTo(0, 0); | 2240 generator.MoveMouseTo(0, 0); |
2195 EXPECT_EQ("0,0", | 2241 EXPECT_EQ("0,0", |
2196 Env::GetInstance()->last_mouse_location().ToString()); | 2242 Env::GetInstance()->last_mouse_location().ToString()); |
2197 | 2243 |
2198 // Make sure the location gets updated when a syntheiszed enter | 2244 // Make sure the location gets updated when a syntheiszed enter |
2199 // event destroyed the window. | 2245 // event destroyed the window. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 explicit DispatchEventHandler(Window* target) | 2319 explicit DispatchEventHandler(Window* target) |
2274 : target_(target), | 2320 : target_(target), |
2275 dispatched_(false) {} | 2321 dispatched_(false) {} |
2276 ~DispatchEventHandler() override {} | 2322 ~DispatchEventHandler() override {} |
2277 | 2323 |
2278 bool dispatched() const { return dispatched_; } | 2324 bool dispatched() const { return dispatched_; } |
2279 private: | 2325 private: |
2280 // ui::EventHandler: | 2326 // ui::EventHandler: |
2281 void OnMouseEvent(ui::MouseEvent* mouse) override { | 2327 void OnMouseEvent(ui::MouseEvent* mouse) override { |
2282 if (mouse->type() == ui::ET_MOUSE_MOVED) { | 2328 if (mouse->type() == ui::ET_MOUSE_MOVED) { |
2283 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), | 2329 ui::MouseEvent move( |
2284 target_->bounds().CenterPoint(), | 2330 ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), |
2285 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 2331 target_->bounds().CenterPoint(), ui::EventTimeForNow(), ui::EF_NONE, |
| 2332 ui::EF_NONE, |
| 2333 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2286 ui::EventDispatchDetails details = | 2334 ui::EventDispatchDetails details = |
2287 target_->GetHost()->dispatcher()->OnEventFromSource(&move); | 2335 target_->GetHost()->dispatcher()->OnEventFromSource(&move); |
2288 ASSERT_FALSE(details.dispatcher_destroyed); | 2336 ASSERT_FALSE(details.dispatcher_destroyed); |
2289 EXPECT_FALSE(details.target_destroyed); | 2337 EXPECT_FALSE(details.target_destroyed); |
2290 EXPECT_EQ(target_, move.target()); | 2338 EXPECT_EQ(target_, move.target()); |
2291 dispatched_ = true; | 2339 dispatched_ = true; |
2292 } | 2340 } |
2293 ui::EventHandler::OnMouseEvent(mouse); | 2341 ui::EventHandler::OnMouseEvent(mouse); |
2294 } | 2342 } |
2295 | 2343 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2347 // when |second| receives an event. | 2395 // when |second| receives an event. |
2348 MoveWindowHandler move_window(first.get(), second_root); | 2396 MoveWindowHandler move_window(first.get(), second_root); |
2349 second->AddPreTargetHandler(&move_window); | 2397 second->AddPreTargetHandler(&move_window); |
2350 | 2398 |
2351 // Some sanity checks: |first| is inside |root_window()|'s tree. | 2399 // Some sanity checks: |first| is inside |root_window()|'s tree. |
2352 EXPECT_EQ(root_window(), first->GetRootWindow()); | 2400 EXPECT_EQ(root_window(), first->GetRootWindow()); |
2353 // The two root windows are different. | 2401 // The two root windows are different. |
2354 EXPECT_NE(root_window(), second_root); | 2402 EXPECT_NE(root_window(), second_root); |
2355 | 2403 |
2356 // Dispatch an event to |first|. | 2404 // Dispatch an event to |first|. |
2357 ui::MouseEvent move(ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(), | 2405 ui::MouseEvent move( |
2358 first->bounds().CenterPoint(), ui::EventTimeForNow(), | 2406 ui::ET_MOUSE_MOVED, first->bounds().CenterPoint(), |
2359 ui::EF_NONE, ui::EF_NONE); | 2407 first->bounds().CenterPoint(), ui::EventTimeForNow(), ui::EF_NONE, |
| 2408 ui::EF_NONE, |
| 2409 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2360 ui::EventDispatchDetails details = | 2410 ui::EventDispatchDetails details = |
2361 host()->dispatcher()->OnEventFromSource(&move); | 2411 host()->dispatcher()->OnEventFromSource(&move); |
2362 ASSERT_FALSE(details.dispatcher_destroyed); | 2412 ASSERT_FALSE(details.dispatcher_destroyed); |
2363 EXPECT_TRUE(details.target_destroyed); | 2413 EXPECT_TRUE(details.target_destroyed); |
2364 EXPECT_EQ(first.get(), move.target()); | 2414 EXPECT_EQ(first.get(), move.target()); |
2365 EXPECT_TRUE(dispatch_event.dispatched()); | 2415 EXPECT_TRUE(dispatch_event.dispatched()); |
2366 EXPECT_EQ(second_root, first->GetRootWindow()); | 2416 EXPECT_EQ(second_root, first->GetRootWindow()); |
2367 | 2417 |
2368 first->RemovePreTargetHandler(&dispatch_event); | 2418 first->RemovePreTargetHandler(&dispatch_event); |
2369 second->RemovePreTargetHandler(&move_window); | 2419 second->RemovePreTargetHandler(&move_window); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2446 EXPECT_EQ(window_second.get(), | 2496 EXPECT_EQ(window_second.get(), |
2447 client::GetCaptureWindow(root_window())); | 2497 client::GetCaptureWindow(root_window())); |
2448 | 2498 |
2449 // Send an event to the first host. Make sure it goes to |window_second| in | 2499 // Send an event to the first host. Make sure it goes to |window_second| in |
2450 // |second_host| instead (since it has capture). | 2500 // |second_host| instead (since it has capture). |
2451 EventFilterRecorder recorder_first; | 2501 EventFilterRecorder recorder_first; |
2452 window_first->AddPreTargetHandler(&recorder_first); | 2502 window_first->AddPreTargetHandler(&recorder_first); |
2453 EventFilterRecorder recorder_second; | 2503 EventFilterRecorder recorder_second; |
2454 window_second->AddPreTargetHandler(&recorder_second); | 2504 window_second->AddPreTargetHandler(&recorder_second); |
2455 const gfx::Point event_location(25, 15); | 2505 const gfx::Point event_location(25, 15); |
2456 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, event_location, event_location, | 2506 ui::MouseEvent mouse( |
2457 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2507 ui::ET_MOUSE_PRESSED, event_location, event_location, |
2458 ui::EF_LEFT_MOUSE_BUTTON); | 2508 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 2509 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
2459 DispatchEventUsingWindowDispatcher(&mouse); | 2510 DispatchEventUsingWindowDispatcher(&mouse); |
2460 EXPECT_TRUE(recorder_first.events().empty()); | 2511 EXPECT_TRUE(recorder_first.events().empty()); |
2461 ASSERT_EQ(1u, recorder_second.events().size()); | 2512 ASSERT_EQ(1u, recorder_second.events().size()); |
2462 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); | 2513 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); |
2463 EXPECT_EQ(event_location.ToString(), | 2514 EXPECT_EQ(event_location.ToString(), |
2464 recorder_second.mouse_locations()[0].ToString()); | 2515 recorder_second.mouse_locations()[0].ToString()); |
2465 } | 2516 } |
2466 | 2517 |
2467 class AsyncWindowDelegate : public test::TestWindowDelegate { | 2518 class AsyncWindowDelegate : public test::TestWindowDelegate { |
2468 public: | 2519 public: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2595 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. | 2646 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. |
2596 test_screen()->SetDeviceScaleFactor(2.f); | 2647 test_screen()->SetDeviceScaleFactor(2.f); |
2597 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); | 2648 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); |
2598 RunAllPendingInMessageLoop(); | 2649 RunAllPendingInMessageLoop(); |
2599 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); | 2650 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); |
2600 | 2651 |
2601 w->RemovePreTargetHandler(&recorder); | 2652 w->RemovePreTargetHandler(&recorder); |
2602 } | 2653 } |
2603 | 2654 |
2604 } // namespace aura | 2655 } // namespace aura |
OLD | NEW |