| 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/root_window.h" | 5 #include "ui/aura/root_window.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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 107 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
| 108 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 108 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
| 109 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 109 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
| 110 delegate1.get(), -1234, bounds1, root_window())); | 110 delegate1.get(), -1234, bounds1, root_window())); |
| 111 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 111 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
| 112 delegate2.get(), -5678, bounds2, root_window())); | 112 delegate2.get(), -5678, bounds2, root_window())); |
| 113 | 113 |
| 114 // Send a mouse event to window1. | 114 // Send a mouse event to window1. |
| 115 gfx::Point point(101, 201); | 115 gfx::Point point(101, 201); |
| 116 ui::MouseEvent event1( | 116 ui::MouseEvent event1( |
| 117 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); | 117 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON, |
| 118 ui::EF_LEFT_MOUSE_BUTTON); |
| 118 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); | 119 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); |
| 119 | 120 |
| 120 // Event was tested for non-client area for the target window. | 121 // Event was tested for non-client area for the target window. |
| 121 EXPECT_EQ(1, delegate1->non_client_count()); | 122 EXPECT_EQ(1, delegate1->non_client_count()); |
| 122 EXPECT_EQ(0, delegate2->non_client_count()); | 123 EXPECT_EQ(0, delegate2->non_client_count()); |
| 123 // The non-client component test was in local coordinates. | 124 // The non-client component test was in local coordinates. |
| 124 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); | 125 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
| 125 // Mouse event was received by target window. | 126 // Mouse event was received by target window. |
| 126 EXPECT_EQ(1, delegate1->mouse_event_count()); | 127 EXPECT_EQ(1, delegate1->mouse_event_count()); |
| 127 EXPECT_EQ(0, delegate2->mouse_event_count()); | 128 EXPECT_EQ(0, delegate2->mouse_event_count()); |
| 128 // Event was in local coordinates. | 129 // Event was in local coordinates. |
| 129 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); | 130 EXPECT_EQ(gfx::Point(1, 1), delegate1->mouse_event_location()); |
| 130 // Non-client flag was set. | 131 // Non-client flag was set. |
| 131 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); | 132 EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); |
| 132 } | 133 } |
| 133 | 134 |
| 134 TEST_F(RootWindowTest, RepostEvent) { | 135 TEST_F(RootWindowTest, RepostEvent) { |
| 135 // Test RepostEvent in RootWindow. It only works for Mouse Press. | 136 // Test RepostEvent in RootWindow. It only works for Mouse Press. |
| 136 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 137 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 137 gfx::Point point(10, 10); | 138 gfx::Point point(10, 10); |
| 138 ui::MouseEvent event( | 139 ui::MouseEvent event( |
| 139 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); | 140 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON, |
| 141 ui::EF_LEFT_MOUSE_BUTTON); |
| 140 dispatcher()->RepostEvent(event); | 142 dispatcher()->RepostEvent(event); |
| 141 RunAllPendingInMessageLoop(); | 143 RunAllPendingInMessageLoop(); |
| 142 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 144 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 143 } | 145 } |
| 144 | 146 |
| 145 // Check that we correctly track the state of the mouse buttons in response to | 147 // Check that we correctly track the state of the mouse buttons in response to |
| 146 // button press and release events. | 148 // button press and release events. |
| 147 TEST_F(RootWindowTest, MouseButtonState) { | 149 TEST_F(RootWindowTest, MouseButtonState) { |
| 148 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 150 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 149 | 151 |
| 150 gfx::Point location; | 152 gfx::Point location; |
| 151 scoped_ptr<ui::MouseEvent> event; | 153 scoped_ptr<ui::MouseEvent> event; |
| 152 | 154 |
| 153 // Press the left button. | 155 // Press the left button. |
| 154 event.reset(new ui::MouseEvent( | 156 event.reset(new ui::MouseEvent( |
| 155 ui::ET_MOUSE_PRESSED, | 157 ui::ET_MOUSE_PRESSED, |
| 156 location, | 158 location, |
| 157 location, | 159 location, |
| 160 ui::EF_LEFT_MOUSE_BUTTON, |
| 158 ui::EF_LEFT_MOUSE_BUTTON)); | 161 ui::EF_LEFT_MOUSE_BUTTON)); |
| 159 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 162 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
| 160 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 163 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 161 | 164 |
| 162 // Additionally press the right. | 165 // Additionally press the right. |
| 163 event.reset(new ui::MouseEvent( | 166 event.reset(new ui::MouseEvent( |
| 164 ui::ET_MOUSE_PRESSED, | 167 ui::ET_MOUSE_PRESSED, |
| 165 location, | 168 location, |
| 166 location, | 169 location, |
| 167 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); | 170 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
| 171 ui::EF_RIGHT_MOUSE_BUTTON)); |
| 168 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 172 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
| 169 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 173 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 170 | 174 |
| 171 // Release the left button. | 175 // Release the left button. |
| 172 event.reset(new ui::MouseEvent( | 176 event.reset(new ui::MouseEvent( |
| 173 ui::ET_MOUSE_RELEASED, | 177 ui::ET_MOUSE_RELEASED, |
| 174 location, | 178 location, |
| 175 location, | 179 location, |
| 176 ui::EF_RIGHT_MOUSE_BUTTON)); | 180 ui::EF_RIGHT_MOUSE_BUTTON, |
| 181 ui::EF_LEFT_MOUSE_BUTTON)); |
| 177 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 182 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
| 178 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 183 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 179 | 184 |
| 180 // Release the right button. We should ignore the Shift-is-down flag. | 185 // Release the right button. We should ignore the Shift-is-down flag. |
| 181 event.reset(new ui::MouseEvent( | 186 event.reset(new ui::MouseEvent( |
| 182 ui::ET_MOUSE_RELEASED, | 187 ui::ET_MOUSE_RELEASED, |
| 183 location, | 188 location, |
| 184 location, | 189 location, |
| 185 ui::EF_SHIFT_DOWN)); | 190 ui::EF_SHIFT_DOWN, |
| 191 ui::EF_RIGHT_MOUSE_BUTTON)); |
| 186 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 192 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
| 187 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 193 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 188 | 194 |
| 189 // Press the middle button. | 195 // Press the middle button. |
| 190 event.reset(new ui::MouseEvent( | 196 event.reset(new ui::MouseEvent( |
| 191 ui::ET_MOUSE_PRESSED, | 197 ui::ET_MOUSE_PRESSED, |
| 192 location, | 198 location, |
| 193 location, | 199 location, |
| 200 ui::EF_MIDDLE_MOUSE_BUTTON, |
| 194 ui::EF_MIDDLE_MOUSE_BUTTON)); | 201 ui::EF_MIDDLE_MOUSE_BUTTON)); |
| 195 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 202 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); |
| 196 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 203 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 197 } | 204 } |
| 198 | 205 |
| 199 TEST_F(RootWindowTest, TranslatedEvent) { | 206 TEST_F(RootWindowTest, TranslatedEvent) { |
| 200 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 207 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, |
| 201 gfx::Rect(50, 50, 100, 100), root_window())); | 208 gfx::Rect(50, 50, 100, 100), root_window())); |
| 202 | 209 |
| 203 gfx::Point origin(100, 100); | 210 gfx::Point origin(100, 100); |
| 204 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); | 211 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0, 0); |
| 205 | 212 |
| 206 EXPECT_EQ("100,100", root.location().ToString()); | 213 EXPECT_EQ("100,100", root.location().ToString()); |
| 207 EXPECT_EQ("100,100", root.root_location().ToString()); | 214 EXPECT_EQ("100,100", root.root_location().ToString()); |
| 208 | 215 |
| 209 ui::MouseEvent translated_event( | 216 ui::MouseEvent translated_event( |
| 210 root, static_cast<Window*>(root_window()), w1.get(), | 217 root, static_cast<Window*>(root_window()), w1.get(), |
| 211 ui::ET_MOUSE_ENTERED, root.flags()); | 218 ui::ET_MOUSE_ENTERED, root.flags()); |
| 212 EXPECT_EQ("50,50", translated_event.location().ToString()); | 219 EXPECT_EQ("50,50", translated_event.location().ToString()); |
| 213 EXPECT_EQ("100,100", translated_event.root_location().ToString()); | 220 EXPECT_EQ("100,100", translated_event.root_location().ToString()); |
| 214 } | 221 } |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // over |window| and verify |window| gets it (|window| gets it because it has | 567 // over |window| and verify |window| gets it (|window| gets it because it has |
| 561 // capture). | 568 // capture). |
| 562 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 569 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 563 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 570 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 564 window->SetBounds(gfx::Rect(20, 20, 40, 30)); | 571 window->SetBounds(gfx::Rect(20, 20, 40, 30)); |
| 565 EventFilterRecorder* recorder = new EventFilterRecorder; | 572 EventFilterRecorder* recorder = new EventFilterRecorder; |
| 566 window->SetEventFilter(recorder); // Takes ownership. | 573 window->SetEventFilter(recorder); // Takes ownership. |
| 567 window->SetCapture(); | 574 window->SetCapture(); |
| 568 const ui::MouseEvent press_event( | 575 const ui::MouseEvent press_event( |
| 569 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 576 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 570 ui::EF_LEFT_MOUSE_BUTTON); | 577 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 571 dispatcher()->RepostEvent(press_event); | 578 dispatcher()->RepostEvent(press_event); |
| 572 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). | 579 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). |
| 573 // Mouse moves/enters may be generated. We only care about a pressed. | 580 // Mouse moves/enters may be generated. We only care about a pressed. |
| 574 EXPECT_TRUE(EventTypesToString(recorder->events()).find("MOUSE_PRESSED") != | 581 EXPECT_TRUE(EventTypesToString(recorder->events()).find("MOUSE_PRESSED") != |
| 575 std::string::npos) << EventTypesToString(recorder->events()); | 582 std::string::npos) << EventTypesToString(recorder->events()); |
| 576 } | 583 } |
| 577 | 584 |
| 578 TEST_F(RootWindowTest, MouseMovesHeld) { | 585 TEST_F(RootWindowTest, MouseMovesHeld) { |
| 579 EventFilterRecorder* filter = new EventFilterRecorder; | 586 EventFilterRecorder* filter = new EventFilterRecorder; |
| 580 root_window()->SetEventFilter(filter); // passes ownership | 587 root_window()->SetEventFilter(filter); // passes ownership |
| 581 | 588 |
| 582 test::TestWindowDelegate delegate; | 589 test::TestWindowDelegate delegate; |
| 583 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 590 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 584 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 591 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 585 | 592 |
| 586 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 593 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), |
| 587 gfx::Point(0, 0), 0); | 594 gfx::Point(0, 0), 0, 0); |
| 588 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 595 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 589 &mouse_move_event); | 596 &mouse_move_event); |
| 590 // Discard MOUSE_ENTER. | 597 // Discard MOUSE_ENTER. |
| 591 filter->events().clear(); | 598 filter->events().clear(); |
| 592 | 599 |
| 593 dispatcher()->HoldPointerMoves(); | 600 dispatcher()->HoldPointerMoves(); |
| 594 | 601 |
| 595 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. | 602 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. |
| 596 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), | 603 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), |
| 597 gfx::Point(0, 0), 0); | 604 gfx::Point(0, 0), 0, 0); |
| 598 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 605 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 599 &mouse_dragged_event); | 606 &mouse_dragged_event); |
| 600 EXPECT_TRUE(filter->events().empty()); | 607 EXPECT_TRUE(filter->events().empty()); |
| 601 | 608 |
| 602 // Check that we do dispatch the held MOUSE_DRAGGED event before another type | 609 // Check that we do dispatch the held MOUSE_DRAGGED event before another type |
| 603 // of event. | 610 // of event. |
| 604 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 611 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), |
| 605 gfx::Point(0, 0), 0); | 612 gfx::Point(0, 0), 0, 0); |
| 606 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 613 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 607 &mouse_pressed_event); | 614 &mouse_pressed_event); |
| 608 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 615 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 609 EventTypesToString(filter->events())); | 616 EventTypesToString(filter->events())); |
| 610 filter->events().clear(); | 617 filter->events().clear(); |
| 611 | 618 |
| 612 // Check that we coalesce held MOUSE_DRAGGED events. | 619 // Check that we coalesce held MOUSE_DRAGGED events. |
| 613 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), | 620 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), |
| 614 gfx::Point(1, 1), 0); | 621 gfx::Point(1, 1), 0, 0); |
| 615 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 622 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 616 &mouse_dragged_event); | 623 &mouse_dragged_event); |
| 617 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 624 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 618 &mouse_dragged_event2); | 625 &mouse_dragged_event2); |
| 619 EXPECT_TRUE(filter->events().empty()); | 626 EXPECT_TRUE(filter->events().empty()); |
| 620 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 627 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
| 621 &mouse_pressed_event); | 628 &mouse_pressed_event); |
| 622 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 629 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 623 EventTypesToString(filter->events())); | 630 EventTypesToString(filter->events())); |
| 624 filter->events().clear(); | 631 filter->events().clear(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 test::TestWindowDelegate delegate; | 732 test::TestWindowDelegate delegate; |
| 726 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 733 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 727 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 734 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 728 window->Show(); | 735 window->Show(); |
| 729 window->SetCapture(); | 736 window->SetCapture(); |
| 730 | 737 |
| 731 test::TestCursorClient cursor_client(root_window()); | 738 test::TestCursorClient cursor_client(root_window()); |
| 732 | 739 |
| 733 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 740 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 734 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 741 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 735 gfx::Point(10, 10), 0); | 742 gfx::Point(10, 10), 0, 0); |
| 736 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); | 743 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); |
| 737 EXPECT_FALSE(filter->events().empty()); | 744 EXPECT_FALSE(filter->events().empty()); |
| 738 filter->events().clear(); | 745 filter->events().clear(); |
| 739 | 746 |
| 740 // Dispatch a synthetic mouse event when mouse events are enabled. | 747 // Dispatch a synthetic mouse event when mouse events are enabled. |
| 741 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 748 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 742 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED); | 749 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0); |
| 743 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); | 750 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); |
| 744 EXPECT_FALSE(filter->events().empty()); | 751 EXPECT_FALSE(filter->events().empty()); |
| 745 filter->events().clear(); | 752 filter->events().clear(); |
| 746 | 753 |
| 747 // Dispatch a synthetic mouse event when mouse events are disabled. | 754 // Dispatch a synthetic mouse event when mouse events are disabled. |
| 748 cursor_client.DisableMouseEvents(); | 755 cursor_client.DisableMouseEvents(); |
| 749 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); | 756 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); |
| 750 EXPECT_TRUE(filter->events().empty()); | 757 EXPECT_TRUE(filter->events().empty()); |
| 751 } | 758 } |
| 752 | 759 |
| 753 // Tests that a mouse exit is dispatched to the last known cursor location | 760 // Tests that a mouse exit is dispatched to the last known cursor location |
| 754 // when the cursor becomes invisible. | 761 // when the cursor becomes invisible. |
| 755 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { | 762 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { |
| 756 EventFilterRecorder* filter = new EventFilterRecorder; | 763 EventFilterRecorder* filter = new EventFilterRecorder; |
| 757 root_window()->SetEventFilter(filter); // passes ownership | 764 root_window()->SetEventFilter(filter); // passes ownership |
| 758 | 765 |
| 759 test::TestWindowDelegate delegate; | 766 test::TestWindowDelegate delegate; |
| 760 gfx::Point window_origin(7, 18); | 767 gfx::Point window_origin(7, 18); |
| 761 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 768 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 762 &delegate, 1234, gfx::Rect(window_origin, | 769 &delegate, 1234, gfx::Rect(window_origin, |
| 763 gfx::Size(100, 100)), root_window())); | 770 gfx::Size(100, 100)), root_window())); |
| 764 window->Show(); | 771 window->Show(); |
| 765 | 772 |
| 766 // Dispatch a mouse move event into the window. | 773 // Dispatch a mouse move event into the window. |
| 767 gfx::Point mouse_location(gfx::Point(15, 25)); | 774 gfx::Point mouse_location(gfx::Point(15, 25)); |
| 768 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, | 775 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, |
| 769 mouse_location, 0); | 776 mouse_location, 0, 0); |
| 770 EXPECT_TRUE(filter->events().empty()); | 777 EXPECT_TRUE(filter->events().empty()); |
| 771 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); | 778 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); |
| 772 EXPECT_FALSE(filter->events().empty()); | 779 EXPECT_FALSE(filter->events().empty()); |
| 773 filter->events().clear(); | 780 filter->events().clear(); |
| 774 | 781 |
| 775 // Hide the cursor and verify a mouse exit was dispatched. | 782 // Hide the cursor and verify a mouse exit was dispatched. |
| 776 dispatcher()->OnCursorVisibilityChanged(false); | 783 dispatcher()->OnCursorVisibilityChanged(false); |
| 777 EXPECT_FALSE(filter->events().empty()); | 784 EXPECT_FALSE(filter->events().empty()); |
| 778 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); | 785 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); |
| 779 | 786 |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 virtual ~DontResetHeldEventWindowDelegate() {} | 1261 virtual ~DontResetHeldEventWindowDelegate() {} |
| 1255 | 1262 |
| 1256 int mouse_event_count() const { return mouse_event_count_; } | 1263 int mouse_event_count() const { return mouse_event_count_; } |
| 1257 | 1264 |
| 1258 // TestWindowDelegate: | 1265 // TestWindowDelegate: |
| 1259 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 1266 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 1260 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && | 1267 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && |
| 1261 mouse_event_count_++ == 0) { | 1268 mouse_event_count_++ == 0) { |
| 1262 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, | 1269 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, |
| 1263 gfx::Point(10, 10), gfx::Point(10, 10), | 1270 gfx::Point(10, 10), gfx::Point(10, 10), |
| 1264 ui::EF_SHIFT_DOWN); | 1271 ui::EF_SHIFT_DOWN, 0); |
| 1265 root_->GetDispatcher()->RepostEvent(mouse_event); | 1272 root_->GetDispatcher()->RepostEvent(mouse_event); |
| 1266 } | 1273 } |
| 1267 } | 1274 } |
| 1268 | 1275 |
| 1269 private: | 1276 private: |
| 1270 Window* root_; | 1277 Window* root_; |
| 1271 int mouse_event_count_; | 1278 int mouse_event_count_; |
| 1272 | 1279 |
| 1273 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); | 1280 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); |
| 1274 }; | 1281 }; |
| 1275 | 1282 |
| 1276 } // namespace | 1283 } // namespace |
| 1277 | 1284 |
| 1278 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1285 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
| 1279 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1286 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
| 1280 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1287 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
| 1281 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1288 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
| 1282 // schedule another reposted event. | 1289 // schedule another reposted event. |
| 1283 TEST_F(RootWindowTest, DontResetHeldEvent) { | 1290 TEST_F(RootWindowTest, DontResetHeldEvent) { |
| 1284 DontResetHeldEventWindowDelegate delegate(root_window()); | 1291 DontResetHeldEventWindowDelegate delegate(root_window()); |
| 1285 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1292 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
| 1286 RootWindowHostDelegate* root_window_delegate = | 1293 RootWindowHostDelegate* root_window_delegate = |
| 1287 static_cast<RootWindowHostDelegate*>(root_window()->GetDispatcher()); | 1294 static_cast<RootWindowHostDelegate*>(root_window()->GetDispatcher()); |
| 1288 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1295 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1289 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, | 1296 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, |
| 1290 gfx::Point(10, 10), gfx::Point(10, 10), | 1297 gfx::Point(10, 10), gfx::Point(10, 10), |
| 1291 ui::EF_SHIFT_DOWN); | 1298 ui::EF_SHIFT_DOWN, 0); |
| 1292 root_window()->GetDispatcher()->RepostEvent(pressed); | 1299 root_window()->GetDispatcher()->RepostEvent(pressed); |
| 1293 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, | 1300 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, |
| 1294 gfx::Point(10, 10), gfx::Point(10, 10), 0); | 1301 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); |
| 1295 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). | 1302 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). |
| 1296 root_window_delegate->OnHostMouseEvent(&pressed2); | 1303 root_window_delegate->OnHostMouseEvent(&pressed2); |
| 1297 // Delegate should have seen reposted event (identified by way of | 1304 // Delegate should have seen reposted event (identified by way of |
| 1298 // EF_SHIFT_DOWN). Invoke OnHostMouseEvent() to flush the second | 1305 // EF_SHIFT_DOWN). Invoke OnHostMouseEvent() to flush the second |
| 1299 // RepostedEvent(). | 1306 // RepostedEvent(). |
| 1300 EXPECT_EQ(1, delegate.mouse_event_count()); | 1307 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 1301 root_window_delegate->OnHostMouseEvent(&pressed2); | 1308 root_window_delegate->OnHostMouseEvent(&pressed2); |
| 1302 EXPECT_EQ(2, delegate.mouse_event_count()); | 1309 EXPECT_EQ(2, delegate.mouse_event_count()); |
| 1303 } | 1310 } |
| 1304 | 1311 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 // Should be deleted by |delegate|. | 1358 // Should be deleted by |delegate|. |
| 1352 RootWindow* r2 = | 1359 RootWindow* r2 = |
| 1353 new RootWindow(RootWindow::CreateParams(gfx::Rect(0, 0, 100, 100))); | 1360 new RootWindow(RootWindow::CreateParams(gfx::Rect(0, 0, 100, 100))); |
| 1354 r2->Init(); | 1361 r2->Init(); |
| 1355 DeleteRootFromHeldMouseEventDelegate delegate(r2); | 1362 DeleteRootFromHeldMouseEventDelegate delegate(r2); |
| 1356 // Owned by |r2|. | 1363 // Owned by |r2|. |
| 1357 Window* w1 = CreateNormalWindow(1, r2->window(), &delegate); | 1364 Window* w1 = CreateNormalWindow(1, r2->window(), &delegate); |
| 1358 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1365 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1359 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, | 1366 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, |
| 1360 gfx::Point(10, 10), gfx::Point(10, 10), | 1367 gfx::Point(10, 10), gfx::Point(10, 10), |
| 1361 ui::EF_SHIFT_DOWN); | 1368 ui::EF_SHIFT_DOWN, 0); |
| 1362 r2->RepostEvent(pressed); | 1369 r2->RepostEvent(pressed); |
| 1363 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. | 1370 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. |
| 1364 RunAllPendingInMessageLoop(); | 1371 RunAllPendingInMessageLoop(); |
| 1365 EXPECT_TRUE(delegate.got_mouse_event()); | 1372 EXPECT_TRUE(delegate.got_mouse_event()); |
| 1366 EXPECT_TRUE(delegate.got_destroy()); | 1373 EXPECT_TRUE(delegate.got_destroy()); |
| 1367 } | 1374 } |
| 1368 | 1375 |
| 1369 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) { | 1376 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) { |
| 1370 EventFilterRecorder* filter = new EventFilterRecorder; | 1377 EventFilterRecorder* filter = new EventFilterRecorder; |
| 1371 root_window()->SetEventFilter(filter); // passes ownership | 1378 root_window()->SetEventFilter(filter); // passes ownership |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 class RootWindowTestWithMessageLoop : public RootWindowTest { | 1477 class RootWindowTestWithMessageLoop : public RootWindowTest { |
| 1471 public: | 1478 public: |
| 1472 RootWindowTestWithMessageLoop() {} | 1479 RootWindowTestWithMessageLoop() {} |
| 1473 virtual ~RootWindowTestWithMessageLoop() {} | 1480 virtual ~RootWindowTestWithMessageLoop() {} |
| 1474 | 1481 |
| 1475 void RunTest() { | 1482 void RunTest() { |
| 1476 // Start a nested message-loop, post an event to be dispatched, and then | 1483 // Start a nested message-loop, post an event to be dispatched, and then |
| 1477 // terminate the message-loop. When the message-loop unwinds and gets back, | 1484 // terminate the message-loop. When the message-loop unwinds and gets back, |
| 1478 // the reposted event should not have fired. | 1485 // the reposted event should not have fired. |
| 1479 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1486 ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), |
| 1480 gfx::Point(10, 10), ui::EF_NONE); | 1487 gfx::Point(10, 10), ui::EF_NONE, ui::EF_NONE); |
| 1481 message_loop()->PostTask(FROM_HERE, | 1488 message_loop()->PostTask(FROM_HERE, |
| 1482 base::Bind(&RootWindow::RepostEvent, | 1489 base::Bind(&RootWindow::RepostEvent, |
| 1483 base::Unretained(dispatcher()), | 1490 base::Unretained(dispatcher()), |
| 1484 mouse)); | 1491 mouse)); |
| 1485 message_loop()->PostTask(FROM_HERE, | 1492 message_loop()->PostTask(FROM_HERE, |
| 1486 message_loop()->QuitClosure()); | 1493 message_loop()->QuitClosure()); |
| 1487 | 1494 |
| 1488 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); | 1495 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); |
| 1489 base::RunLoop loop; | 1496 base::RunLoop loop; |
| 1490 loop.Run(); | 1497 loop.Run(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1521 CHECK(!message_loop()->is_running()); | 1528 CHECK(!message_loop()->is_running()); |
| 1522 // Perform the test in a callback, so that it runs after the message-loop | 1529 // Perform the test in a callback, so that it runs after the message-loop |
| 1523 // starts. | 1530 // starts. |
| 1524 message_loop()->PostTask(FROM_HERE, | 1531 message_loop()->PostTask(FROM_HERE, |
| 1525 base::Bind(&RootWindowTestWithMessageLoop::RunTest, | 1532 base::Bind(&RootWindowTestWithMessageLoop::RunTest, |
| 1526 base::Unretained(this))); | 1533 base::Unretained(this))); |
| 1527 message_loop()->Run(); | 1534 message_loop()->Run(); |
| 1528 } | 1535 } |
| 1529 | 1536 |
| 1530 } // namespace aura | 1537 } // namespace aura |
| OLD | NEW |