| 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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 667 |
| 668 // Check that we do dispatch the held MOUSE_DRAGGED event before another type | 668 // Check that we do dispatch the held MOUSE_DRAGGED event before another type |
| 669 // of event. | 669 // of event. |
| 670 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 670 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), |
| 671 gfx::Point(0, 0), 0, 0); | 671 gfx::Point(0, 0), 0, 0); |
| 672 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 672 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 673 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 673 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 674 EventTypesToString(recorder.events())); | 674 EventTypesToString(recorder.events())); |
| 675 recorder.Reset(); | 675 recorder.Reset(); |
| 676 | 676 |
| 677 // Check that we coalesce held MOUSE_DRAGGED events. | 677 // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and |
| 678 // elsewhere in this test) we re-define each event prior to dispatch so that |
| 679 // it has the correct state (phase, handled, target, etc.). |
| 680 mouse_dragged_event = ui::MouseEvent( |
| 681 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 678 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), | 682 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), |
| 679 gfx::Point(10, 10), 0, 0); | 683 gfx::Point(10, 10), 0, 0); |
| 680 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 684 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 681 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 685 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 682 EXPECT_TRUE(recorder.events().empty()); | 686 EXPECT_TRUE(recorder.events().empty()); |
| 687 mouse_pressed_event = ui::MouseEvent( |
| 688 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 683 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 689 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 684 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 690 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 685 EventTypesToString(recorder.events())); | 691 EventTypesToString(recorder.events())); |
| 686 recorder.Reset(); | 692 recorder.Reset(); |
| 687 | 693 |
| 688 // Check that on ReleasePointerMoves, held events are not dispatched | 694 // Check that on ReleasePointerMoves, held events are not dispatched |
| 689 // immediately, but posted instead. | 695 // immediately, but posted instead. |
| 696 mouse_dragged_event = ui::MouseEvent( |
| 697 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 690 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 698 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 691 host()->dispatcher()->ReleasePointerMoves(); | 699 host()->dispatcher()->ReleasePointerMoves(); |
| 692 EXPECT_TRUE(recorder.events().empty()); | 700 EXPECT_TRUE(recorder.events().empty()); |
| 693 RunAllPendingInMessageLoop(); | 701 RunAllPendingInMessageLoop(); |
| 694 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 702 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
| 695 recorder.Reset(); | 703 recorder.Reset(); |
| 696 | 704 |
| 697 // However if another message comes in before the dispatch of the posted | 705 // However if another message comes in before the dispatch of the posted |
| 698 // event, check that the posted event is dispatched before this new event. | 706 // event, check that the posted event is dispatched before this new event. |
| 699 host()->dispatcher()->HoldPointerMoves(); | 707 host()->dispatcher()->HoldPointerMoves(); |
| 708 mouse_dragged_event = ui::MouseEvent( |
| 709 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 700 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 710 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 701 host()->dispatcher()->ReleasePointerMoves(); | 711 host()->dispatcher()->ReleasePointerMoves(); |
| 712 mouse_pressed_event = ui::MouseEvent( |
| 713 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 702 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); | 714 DispatchEventUsingWindowDispatcher(&mouse_pressed_event); |
| 703 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 715 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
| 704 EventTypesToString(recorder.events())); | 716 EventTypesToString(recorder.events())); |
| 705 recorder.Reset(); | 717 recorder.Reset(); |
| 706 RunAllPendingInMessageLoop(); | 718 RunAllPendingInMessageLoop(); |
| 707 EXPECT_TRUE(recorder.events().empty()); | 719 EXPECT_TRUE(recorder.events().empty()); |
| 708 | 720 |
| 709 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce | 721 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce |
| 710 // them. | 722 // them. |
| 711 host()->dispatcher()->HoldPointerMoves(); | 723 host()->dispatcher()->HoldPointerMoves(); |
| 724 mouse_dragged_event = ui::MouseEvent( |
| 725 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 712 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 726 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 713 host()->dispatcher()->ReleasePointerMoves(); | 727 host()->dispatcher()->ReleasePointerMoves(); |
| 728 mouse_dragged_event2 = ui::MouseEvent( |
| 729 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); |
| 714 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 730 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 715 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); | 731 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events())); |
| 716 recorder.Reset(); | 732 recorder.Reset(); |
| 717 RunAllPendingInMessageLoop(); | 733 RunAllPendingInMessageLoop(); |
| 718 EXPECT_TRUE(recorder.events().empty()); | 734 EXPECT_TRUE(recorder.events().empty()); |
| 719 | 735 |
| 720 // Check that synthetic mouse move event has a right location when issued | 736 // Check that synthetic mouse move event has a right location when issued |
| 721 // while holding pointer moves. | 737 // while holding pointer moves. |
| 738 mouse_dragged_event = ui::MouseEvent( |
| 739 ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); |
| 740 mouse_dragged_event2 = ui::MouseEvent( |
| 741 ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); |
| 722 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), | 742 ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28), |
| 723 gfx::Point(28, 28), 0, 0); | 743 gfx::Point(28, 28), 0, 0); |
| 724 host()->dispatcher()->HoldPointerMoves(); | 744 host()->dispatcher()->HoldPointerMoves(); |
| 725 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); | 745 DispatchEventUsingWindowDispatcher(&mouse_dragged_event); |
| 726 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); | 746 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2); |
| 727 window->SetBounds(gfx::Rect(15, 15, 80, 80)); | 747 window->SetBounds(gfx::Rect(15, 15, 80, 80)); |
| 728 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); | 748 DispatchEventUsingWindowDispatcher(&mouse_dragged_event3); |
| 729 RunAllPendingInMessageLoop(); | 749 RunAllPendingInMessageLoop(); |
| 730 EXPECT_TRUE(recorder.events().empty()); | 750 EXPECT_TRUE(recorder.events().empty()); |
| 731 host()->dispatcher()->ReleasePointerMoves(); | 751 host()->dispatcher()->ReleasePointerMoves(); |
| (...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2340 ASSERT_EQ(1u, recorder.touch_locations().size()); | 2360 ASSERT_EQ(1u, recorder.touch_locations().size()); |
| 2341 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), | 2361 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), |
| 2342 recorder.touch_locations()[0].ToString()); | 2362 recorder.touch_locations()[0].ToString()); |
| 2343 | 2363 |
| 2344 ASSERT_EQ(2u, recorder.gesture_locations().size()); | 2364 ASSERT_EQ(2u, recorder.gesture_locations().size()); |
| 2345 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), | 2365 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), |
| 2346 recorder.gesture_locations()[0].ToString()); | 2366 recorder.gesture_locations()[0].ToString()); |
| 2347 } | 2367 } |
| 2348 | 2368 |
| 2349 } // namespace aura | 2369 } // namespace aura |
| OLD | NEW |