OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mus/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 #include "ui/aura/window_targeter.h" | 36 #include "ui/aura/window_targeter.h" |
37 #include "ui/aura/window_tracker.h" | 37 #include "ui/aura/window_tracker.h" |
38 #include "ui/aura/window_tree_host_observer.h" | 38 #include "ui/aura/window_tree_host_observer.h" |
39 #include "ui/base/class_property.h" | 39 #include "ui/base/class_property.h" |
40 #include "ui/compositor/compositor.h" | 40 #include "ui/compositor/compositor.h" |
41 #include "ui/display/display.h" | 41 #include "ui/display/display.h" |
42 #include "ui/display/display_switches.h" | 42 #include "ui/display/display_switches.h" |
43 #include "ui/display/screen.h" | 43 #include "ui/display/screen.h" |
44 #include "ui/events/event.h" | 44 #include "ui/events/event.h" |
45 #include "ui/events/event_utils.h" | 45 #include "ui/events/event_utils.h" |
46 #include "ui/events/test/test_event_handler.h" | |
46 #include "ui/gfx/geometry/dip_util.h" | 47 #include "ui/gfx/geometry/dip_util.h" |
47 #include "ui/gfx/geometry/rect.h" | 48 #include "ui/gfx/geometry/rect.h" |
48 | 49 |
49 namespace aura { | 50 namespace aura { |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); | 54 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); |
54 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); | 55 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); |
55 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey3, false); | 56 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey3, false); |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 private: | 530 private: |
530 TestWindowTree* test_window_tree_; | 531 TestWindowTree* test_window_tree_; |
531 bool was_acked_ = false; | 532 bool was_acked_ = false; |
532 bool got_move_ = false; | 533 bool got_move_ = false; |
533 gfx::Point last_event_location_; | 534 gfx::Point last_event_location_; |
534 uint32_t event_id_ = 0; | 535 uint32_t event_id_ = 0; |
535 | 536 |
536 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); | 537 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); |
537 }; | 538 }; |
538 | 539 |
540 class InputEventBasicTestEventHandler : public ui::test::TestEventHandler { | |
541 public: | |
542 explicit InputEventBasicTestEventHandler(TestWindowTree* test_window_tree) | |
543 : test_window_tree_(test_window_tree) {} | |
544 ~InputEventBasicTestEventHandler() override {} | |
545 | |
546 bool got_move() const { return got_move_; } | |
547 bool was_acked() const { return was_acked_; } | |
548 const gfx::Point& last_event_location() const { return last_event_location_; } | |
549 void set_event_id(uint32_t event_id) { event_id_ = event_id; } | |
550 | |
551 // ui::test::TestEventHandler overrides. | |
552 void OnMouseEvent(ui::MouseEvent* event) override { | |
553 was_acked_ = test_window_tree_->WasEventAcked(event_id_); | |
554 if (event->type() == ui::ET_MOUSE_MOVED) | |
555 got_move_ = true; | |
556 last_event_location_ = event->location(); | |
557 event->SetHandled(); | |
558 } | |
559 | |
560 void reset() { | |
561 was_acked_ = false; | |
562 got_move_ = false; | |
563 last_event_location_ = gfx::Point(); | |
564 event_id_ = 0; | |
565 } | |
566 | |
567 private: | |
568 TestWindowTree* test_window_tree_; | |
569 bool was_acked_ = false; | |
sadrul
2017/03/04 02:44:00
Can you get rid of this?
riajiang
2017/03/04 21:34:20
Done.
| |
570 bool got_move_ = false; | |
571 gfx::Point last_event_location_; | |
572 uint32_t event_id_ = 0; | |
573 | |
574 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler); | |
575 }; | |
576 | |
539 } // namespace | 577 } // namespace |
540 | 578 |
541 TEST_F(WindowTreeClientClientTest, InputEventBasic) { | 579 TEST_F(WindowTreeClientClientTest, InputEventBasic) { |
542 InputEventBasicTestWindowDelegate window_delegate(window_tree()); | 580 InputEventBasicTestWindowDelegate window_delegate(window_tree()); |
543 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | 581 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
544 Window* top_level = window_tree_host.window(); | 582 Window* top_level = window_tree_host.window(); |
545 const gfx::Rect bounds(0, 0, 100, 100); | 583 const gfx::Rect bounds(0, 0, 100, 100); |
546 window_tree_host.SetBoundsInPixels(bounds); | 584 window_tree_host.SetBoundsInPixels(bounds); |
547 window_tree_host.InitHost(); | 585 window_tree_host.InitHost(); |
548 window_tree_host.Show(); | 586 window_tree_host.Show(); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 window_tree()->GetEventResult(event_id)); | 810 window_tree()->GetEventResult(event_id)); |
773 EXPECT_FALSE(window_delegate1->got_move()); | 811 EXPECT_FALSE(window_delegate1->got_move()); |
774 EXPECT_TRUE(window_delegate2->got_move()); | 812 EXPECT_TRUE(window_delegate2->got_move()); |
775 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location()); | 813 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location()); |
776 child2.reset(); | 814 child2.reset(); |
777 child1.reset(); | 815 child1.reset(); |
778 window_tree_host.reset(); | 816 window_tree_host.reset(); |
779 capture_client.reset(); | 817 capture_client.reset(); |
780 } | 818 } |
781 | 819 |
820 TEST_F(WindowTreeClientClientTest, InputEventRootWindow) { | |
821 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | |
822 Window* top_level = window_tree_host.window(); | |
823 InputEventBasicTestEventHandler event_handler(window_tree()); | |
sadrul
2017/03/04 02:44:00
Call this root_handler (or top_level_handler)
riajiang
2017/03/04 21:34:20
Done.
| |
824 top_level->AddPreTargetHandler(&event_handler); | |
825 const gfx::Rect bounds(0, 0, 100, 100); | |
826 window_tree_host.SetBoundsInPixels(bounds); | |
827 window_tree_host.InitHost(); | |
828 window_tree_host.Show(); | |
829 EXPECT_EQ(bounds, top_level->bounds()); | |
830 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); | |
831 InputEventBasicTestWindowDelegate window_delegate(window_tree()); | |
sadrul
2017/03/04 02:44:00
Call this child_delegate
riajiang
2017/03/04 21:34:20
Done.
| |
832 Window child(&window_delegate); | |
833 child.Init(ui::LAYER_NOT_DRAWN); | |
834 top_level->AddChild(&child); | |
835 child.SetBounds(gfx::Rect(10, 10, 100, 100)); | |
836 child.Show(); | |
837 | |
838 EXPECT_FALSE(event_handler.got_move()); | |
839 EXPECT_FALSE(window_delegate.got_move()); | |
840 | |
841 const gfx::Point event_location_in_child(20, 30); | |
842 const uint32_t event_id = 1; | |
843 event_handler.set_event_id(event_id); | |
844 window_delegate.set_event_id(event_id); | |
845 std::unique_ptr<ui::Event> ui_event( | |
846 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, | |
847 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); | |
848 window_tree_client()->OnWindowInputEvent( | |
849 event_id, server_id(top_level), window_tree_host.display_id(), | |
850 ui::Event::Clone(*ui_event.get()), 0); | |
851 | |
852 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); | |
853 EXPECT_EQ(ui::mojom::EventResult::HANDLED, | |
854 window_tree()->GetEventResult(event_id)); | |
855 EXPECT_TRUE(event_handler.got_move()); | |
856 EXPECT_EQ(gfx::Point(20, 30), event_handler.last_event_location()); | |
857 EXPECT_FALSE(window_delegate.got_move()); | |
858 EXPECT_EQ(gfx::Point(), window_delegate.last_event_location()); | |
859 } | |
860 | |
782 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { | 861 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
783 public: | 862 public: |
784 WindowTreeClientPointerObserverTest() {} | 863 WindowTreeClientPointerObserverTest() {} |
785 ~WindowTreeClientPointerObserverTest() override {} | 864 ~WindowTreeClientPointerObserverTest() override {} |
786 | 865 |
787 void DeleteLastEventObserved() { last_event_observed_.reset(); } | 866 void DeleteLastEventObserved() { last_event_observed_.reset(); } |
788 const ui::PointerEvent* last_event_observed() const { | 867 const ui::PointerEvent* last_event_observed() const { |
789 return last_event_observed_.get(); | 868 return last_event_observed_.get(); |
790 } | 869 } |
791 | 870 |
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1911 window_tree()->GetEventResult(event_id)); | 1990 window_tree()->GetEventResult(event_id)); |
1912 EXPECT_TRUE(window_delegate1.got_move()); | 1991 EXPECT_TRUE(window_delegate1.got_move()); |
1913 EXPECT_FALSE(window_delegate2.got_move()); | 1992 EXPECT_FALSE(window_delegate2.got_move()); |
1914 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, | 1993 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, |
1915 event_location_in_dip.y() + 30); | 1994 event_location_in_dip.y() + 30); |
1916 EXPECT_EQ(transformed_event_location_in_dip, | 1995 EXPECT_EQ(transformed_event_location_in_dip, |
1917 window_delegate1.last_event_location()); | 1996 window_delegate1.last_event_location()); |
1918 } | 1997 } |
1919 | 1998 |
1920 } // namespace aura | 1999 } // namespace aura |
OLD | NEW |