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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "mojo/public/cpp/bindings/map.h" | 14 #include "mojo/public/cpp/bindings/map.h" |
15 #include "services/ui/public/cpp/property_type_converters.h" | 15 #include "services/ui/public/cpp/property_type_converters.h" |
16 #include "services/ui/public/interfaces/window_manager.mojom.h" | 16 #include "services/ui/public/interfaces/window_manager.mojom.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/client/capture_client.h" | 19 #include "ui/aura/client/capture_client.h" |
20 #include "ui/aura/client/capture_client_observer.h" | 20 #include "ui/aura/client/capture_client_observer.h" |
21 #include "ui/aura/client/default_capture_client.h" | 21 #include "ui/aura/client/default_capture_client.h" |
22 #include "ui/aura/client/focus_client.h" | 22 #include "ui/aura/client/focus_client.h" |
23 #include "ui/aura/client/transient_window_client.h" | 23 #include "ui/aura/client/transient_window_client.h" |
24 #include "ui/aura/mus/capture_synchronizer.h" | 24 #include "ui/aura/mus/capture_synchronizer.h" |
| 25 #include "ui/aura/mus/mus_types.h" |
25 #include "ui/aura/mus/property_converter.h" | 26 #include "ui/aura/mus/property_converter.h" |
26 #include "ui/aura/mus/window_mus.h" | 27 #include "ui/aura/mus/window_mus.h" |
27 #include "ui/aura/mus/window_tree_client_delegate.h" | 28 #include "ui/aura/mus/window_tree_client_delegate.h" |
28 #include "ui/aura/mus/window_tree_client_observer.h" | 29 #include "ui/aura/mus/window_tree_client_observer.h" |
29 #include "ui/aura/mus/window_tree_host_mus.h" | 30 #include "ui/aura/mus/window_tree_host_mus.h" |
30 #include "ui/aura/test/aura_mus_test_base.h" | 31 #include "ui/aura/test/aura_mus_test_base.h" |
31 #include "ui/aura/test/mus/test_window_tree.h" | 32 #include "ui/aura/test/mus/test_window_tree.h" |
32 #include "ui/aura/test/mus/window_tree_client_private.h" | 33 #include "ui/aura/test/mus/window_tree_client_private.h" |
33 #include "ui/aura/test/test_window_delegate.h" | 34 #include "ui/aura/test/test_window_delegate.h" |
34 #include "ui/aura/test/test_window_targeter.h" | 35 #include "ui/aura/test/test_window_targeter.h" |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 bool was_acked_ = false; | 535 bool was_acked_ = false; |
535 bool got_move_ = false; | 536 bool got_move_ = false; |
536 gfx::Point last_event_location_; | 537 gfx::Point last_event_location_; |
537 uint32_t event_id_ = 0; | 538 uint32_t event_id_ = 0; |
538 | 539 |
539 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); | 540 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); |
540 }; | 541 }; |
541 | 542 |
542 class InputEventBasicTestEventHandler : public ui::test::TestEventHandler { | 543 class InputEventBasicTestEventHandler : public ui::test::TestEventHandler { |
543 public: | 544 public: |
544 InputEventBasicTestEventHandler() {} | 545 explicit InputEventBasicTestEventHandler(Window* target_window) |
| 546 : target_window_(target_window) {} |
545 ~InputEventBasicTestEventHandler() override {} | 547 ~InputEventBasicTestEventHandler() override {} |
546 | 548 |
547 bool got_move() const { return got_move_; } | 549 bool got_move() const { return got_move_; } |
548 const gfx::Point& last_event_location() const { return last_event_location_; } | 550 const gfx::Point& last_event_location() const { return last_event_location_; } |
549 void set_event_id(uint32_t event_id) { event_id_ = event_id; } | 551 void set_event_id(uint32_t event_id) { event_id_ = event_id; } |
550 | 552 |
551 // ui::test::TestEventHandler overrides. | 553 // ui::test::TestEventHandler overrides. |
552 void OnMouseEvent(ui::MouseEvent* event) override { | 554 void OnMouseEvent(ui::MouseEvent* event) override { |
553 if (event->type() == ui::ET_MOUSE_MOVED) | 555 if (event->target() == target_window_) { |
554 got_move_ = true; | 556 if (event->type() == ui::ET_MOUSE_MOVED) |
555 last_event_location_ = event->location(); | 557 got_move_ = true; |
556 event->SetHandled(); | 558 last_event_location_ = event->location(); |
| 559 event->SetHandled(); |
| 560 } |
557 } | 561 } |
558 | 562 |
559 void reset() { | 563 void reset() { |
560 got_move_ = false; | 564 got_move_ = false; |
561 last_event_location_ = gfx::Point(); | 565 last_event_location_ = gfx::Point(); |
562 event_id_ = 0; | 566 event_id_ = 0; |
563 } | 567 } |
564 | 568 |
565 private: | 569 private: |
| 570 Window* target_window_ = nullptr; |
566 bool got_move_ = false; | 571 bool got_move_ = false; |
567 gfx::Point last_event_location_; | 572 gfx::Point last_event_location_; |
568 uint32_t event_id_ = 0; | 573 uint32_t event_id_ = 0; |
569 | 574 |
570 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler); | 575 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler); |
571 }; | 576 }; |
572 | 577 |
573 } // namespace | 578 } // namespace |
574 | 579 |
575 TEST_F(WindowTreeClientClientTest, InputEventBasic) { | 580 TEST_F(WindowTreeClientClientTest, InputEventBasic) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location()); | 814 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location()); |
810 child2.reset(); | 815 child2.reset(); |
811 child1.reset(); | 816 child1.reset(); |
812 window_tree_host.reset(); | 817 window_tree_host.reset(); |
813 capture_client.reset(); | 818 capture_client.reset(); |
814 } | 819 } |
815 | 820 |
816 TEST_F(WindowTreeClientClientTest, InputEventRootWindow) { | 821 TEST_F(WindowTreeClientClientTest, InputEventRootWindow) { |
817 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | 822 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
818 Window* top_level = window_tree_host.window(); | 823 Window* top_level = window_tree_host.window(); |
819 InputEventBasicTestEventHandler root_handler; | 824 InputEventBasicTestEventHandler root_handler(top_level); |
820 top_level->AddPreTargetHandler(&root_handler); | 825 top_level->AddPreTargetHandler(&root_handler); |
821 const gfx::Rect bounds(0, 0, 100, 100); | 826 const gfx::Rect bounds(0, 0, 100, 100); |
822 window_tree_host.SetBoundsInPixels(bounds); | 827 window_tree_host.SetBoundsInPixels(bounds); |
823 window_tree_host.InitHost(); | 828 window_tree_host.InitHost(); |
824 window_tree_host.Show(); | 829 window_tree_host.Show(); |
825 EXPECT_EQ(bounds, top_level->bounds()); | 830 EXPECT_EQ(bounds, top_level->bounds()); |
826 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); | 831 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
827 InputEventBasicTestWindowDelegate child_delegate(window_tree()); | 832 InputEventBasicTestWindowDelegate child_delegate(window_tree()); |
828 Window child(&child_delegate); | 833 Window child(&child_delegate); |
829 child.Init(ui::LAYER_NOT_DRAWN); | 834 child.Init(ui::LAYER_NOT_DRAWN); |
(...skipping 17 matching lines...) Expand all Loading... |
847 | 852 |
848 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); | 853 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
849 EXPECT_EQ(ui::mojom::EventResult::HANDLED, | 854 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
850 window_tree()->GetEventResult(event_id)); | 855 window_tree()->GetEventResult(event_id)); |
851 EXPECT_TRUE(root_handler.got_move()); | 856 EXPECT_TRUE(root_handler.got_move()); |
852 EXPECT_EQ(gfx::Point(20, 30), root_handler.last_event_location()); | 857 EXPECT_EQ(gfx::Point(20, 30), root_handler.last_event_location()); |
853 EXPECT_FALSE(child_delegate.got_move()); | 858 EXPECT_FALSE(child_delegate.got_move()); |
854 EXPECT_EQ(gfx::Point(), child_delegate.last_event_location()); | 859 EXPECT_EQ(gfx::Point(), child_delegate.last_event_location()); |
855 } | 860 } |
856 | 861 |
| 862 TEST_F(WindowTreeClientClientTest, InputEventNoWindow) { |
| 863 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 864 Window* top_level = window_tree_host.window(); |
| 865 InputEventBasicTestEventHandler root_handler(top_level); |
| 866 top_level->AddPreTargetHandler(&root_handler); |
| 867 const gfx::Rect bounds(0, 0, 100, 100); |
| 868 window_tree_host.SetBoundsInPixels(bounds); |
| 869 window_tree_host.InitHost(); |
| 870 window_tree_host.Show(); |
| 871 EXPECT_EQ(bounds, top_level->bounds()); |
| 872 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
| 873 InputEventBasicTestWindowDelegate child_delegate1(window_tree()); |
| 874 Window child1(&child_delegate1); |
| 875 child1.Init(ui::LAYER_NOT_DRAWN); |
| 876 top_level->AddChild(&child1); |
| 877 child1.SetBounds(gfx::Rect(25, 25, 100, 100)); |
| 878 child1.Show(); |
| 879 InputEventBasicTestWindowDelegate child_delegate2(window_tree()); |
| 880 Window child2(&child_delegate2); |
| 881 child2.Init(ui::LAYER_NOT_DRAWN); |
| 882 top_level->AddChild(&child2); |
| 883 child2.SetBounds(gfx::Rect(40, 40, 100, 100)); |
| 884 child2.Show(); |
| 885 EXPECT_FALSE(root_handler.got_move()); |
| 886 EXPECT_FALSE(child_delegate1.got_move()); |
| 887 EXPECT_FALSE(child_delegate2.got_move()); |
| 888 |
| 889 const gfx::Point event_location(40, 50); |
| 890 const gfx::Point event_root_location(10, 10); |
| 891 uint32_t event_id = 1; |
| 892 root_handler.set_event_id(event_id); |
| 893 child_delegate1.set_event_id(event_id); |
| 894 child_delegate2.set_event_id(event_id); |
| 895 std::unique_ptr<ui::Event> ui_event(new ui::MouseEvent( |
| 896 ui::ET_MOUSE_MOVED, event_location, event_root_location, |
| 897 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 898 window_tree_client()->OnWindowInputEvent( |
| 899 event_id, kInvalidServerId, window_tree_host.display_id(), |
| 900 ui::Event::Clone(*ui_event.get()), 0); |
| 901 // WindowTreeClient::OnWindowInputEvent cannot find a target window with |
| 902 // kInvalidServerId but should use the display_id to find the window_tree_host |
| 903 // for event dispatching and dispatch the event to |top_level| since it's in |
| 904 // the space for |top_level|. |
| 905 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 906 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 907 window_tree()->GetEventResult(event_id)); |
| 908 EXPECT_TRUE(root_handler.got_move()); |
| 909 EXPECT_EQ(event_root_location, root_handler.last_event_location()); |
| 910 EXPECT_FALSE(child_delegate1.got_move()); |
| 911 EXPECT_FALSE(child_delegate2.got_move()); |
| 912 root_handler.reset(); |
| 913 child_delegate1.reset(); |
| 914 child_delegate2.reset(); |
| 915 |
| 916 const gfx::Point event_root_location1(30, 30); |
| 917 event_id = 2; |
| 918 root_handler.set_event_id(event_id); |
| 919 child_delegate1.set_event_id(event_id); |
| 920 child_delegate2.set_event_id(event_id); |
| 921 std::unique_ptr<ui::Event> ui_event1(new ui::MouseEvent( |
| 922 ui::ET_MOUSE_MOVED, event_location, event_root_location1, |
| 923 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 924 window_tree_client()->OnWindowInputEvent( |
| 925 event_id, kInvalidServerId, window_tree_host.display_id(), |
| 926 ui::Event::Clone(*ui_event1.get()), 0); |
| 927 // |child1| should get the event since it's in the space for |child1|. |
| 928 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 929 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 930 window_tree()->GetEventResult(event_id)); |
| 931 EXPECT_FALSE(root_handler.got_move()); |
| 932 EXPECT_TRUE(child_delegate1.got_move()); |
| 933 EXPECT_EQ(gfx::Point(5, 5), child_delegate1.last_event_location()); |
| 934 EXPECT_FALSE(child_delegate2.got_move()); |
| 935 root_handler.reset(); |
| 936 child_delegate1.reset(); |
| 937 child_delegate2.reset(); |
| 938 |
| 939 const gfx::Point event_root_location2(60, 60); |
| 940 event_id = 3; |
| 941 root_handler.set_event_id(event_id); |
| 942 child_delegate1.set_event_id(event_id); |
| 943 child_delegate2.set_event_id(event_id); |
| 944 std::unique_ptr<ui::Event> ui_event2(new ui::MouseEvent( |
| 945 ui::ET_MOUSE_MOVED, event_location, event_root_location2, |
| 946 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 947 window_tree_client()->OnWindowInputEvent( |
| 948 event_id, kInvalidServerId, window_tree_host.display_id(), |
| 949 ui::Event::Clone(*ui_event2.get()), 0); |
| 950 // |child2| should get the event since it's in the space for |child2|. |
| 951 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 952 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 953 window_tree()->GetEventResult(event_id)); |
| 954 EXPECT_FALSE(root_handler.got_move()); |
| 955 EXPECT_FALSE(child_delegate1.got_move()); |
| 956 EXPECT_TRUE(child_delegate2.got_move()); |
| 957 EXPECT_EQ(gfx::Point(20, 20), child_delegate2.last_event_location()); |
| 958 } |
| 959 |
857 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { | 960 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
858 public: | 961 public: |
859 WindowTreeClientPointerObserverTest() {} | 962 WindowTreeClientPointerObserverTest() {} |
860 ~WindowTreeClientPointerObserverTest() override {} | 963 ~WindowTreeClientPointerObserverTest() override {} |
861 | 964 |
862 void DeleteLastEventObserved() { last_event_observed_.reset(); } | 965 void DeleteLastEventObserved() { last_event_observed_.reset(); } |
863 const ui::PointerEvent* last_event_observed() const { | 966 const ui::PointerEvent* last_event_observed() const { |
864 return last_event_observed_.get(); | 967 return last_event_observed_.get(); |
865 } | 968 } |
866 | 969 |
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 window_tree()->GetEventResult(event_id)); | 2122 window_tree()->GetEventResult(event_id)); |
2020 EXPECT_TRUE(window_delegate1.got_move()); | 2123 EXPECT_TRUE(window_delegate1.got_move()); |
2021 EXPECT_FALSE(window_delegate2.got_move()); | 2124 EXPECT_FALSE(window_delegate2.got_move()); |
2022 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, | 2125 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, |
2023 event_location_in_dip.y() + 30); | 2126 event_location_in_dip.y() + 30); |
2024 EXPECT_EQ(transformed_event_location_in_dip, | 2127 EXPECT_EQ(transformed_event_location_in_dip, |
2025 window_delegate1.last_event_location()); | 2128 window_delegate1.last_event_location()); |
2026 } | 2129 } |
2027 | 2130 |
2028 } // namespace aura | 2131 } // namespace aura |
OLD | NEW |