| 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 InputEventBasicTestEventHandler() {} |
| 543 ~InputEventBasicTestEventHandler() override {} |
| 544 |
| 545 bool got_move() const { return got_move_; } |
| 546 const gfx::Point& last_event_location() const { return last_event_location_; } |
| 547 void set_event_id(uint32_t event_id) { event_id_ = event_id; } |
| 548 |
| 549 // ui::test::TestEventHandler overrides. |
| 550 void OnMouseEvent(ui::MouseEvent* event) override { |
| 551 if (event->type() == ui::ET_MOUSE_MOVED) |
| 552 got_move_ = true; |
| 553 last_event_location_ = event->location(); |
| 554 event->SetHandled(); |
| 555 } |
| 556 |
| 557 void reset() { |
| 558 got_move_ = false; |
| 559 last_event_location_ = gfx::Point(); |
| 560 event_id_ = 0; |
| 561 } |
| 562 |
| 563 private: |
| 564 bool got_move_ = false; |
| 565 gfx::Point last_event_location_; |
| 566 uint32_t event_id_ = 0; |
| 567 |
| 568 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler); |
| 569 }; |
| 570 |
| 539 } // namespace | 571 } // namespace |
| 540 | 572 |
| 541 TEST_F(WindowTreeClientClientTest, InputEventBasic) { | 573 TEST_F(WindowTreeClientClientTest, InputEventBasic) { |
| 542 InputEventBasicTestWindowDelegate window_delegate(window_tree()); | 574 InputEventBasicTestWindowDelegate window_delegate(window_tree()); |
| 543 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | 575 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 544 Window* top_level = window_tree_host.window(); | 576 Window* top_level = window_tree_host.window(); |
| 545 const gfx::Rect bounds(0, 0, 100, 100); | 577 const gfx::Rect bounds(0, 0, 100, 100); |
| 546 window_tree_host.SetBoundsInPixels(bounds); | 578 window_tree_host.SetBoundsInPixels(bounds); |
| 547 window_tree_host.InitHost(); | 579 window_tree_host.InitHost(); |
| 548 window_tree_host.Show(); | 580 window_tree_host.Show(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 window_tree()->GetEventResult(event_id)); | 804 window_tree()->GetEventResult(event_id)); |
| 773 EXPECT_FALSE(window_delegate1->got_move()); | 805 EXPECT_FALSE(window_delegate1->got_move()); |
| 774 EXPECT_TRUE(window_delegate2->got_move()); | 806 EXPECT_TRUE(window_delegate2->got_move()); |
| 775 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location()); | 807 EXPECT_EQ(gfx::Point(30, 30), window_delegate2->last_event_location()); |
| 776 child2.reset(); | 808 child2.reset(); |
| 777 child1.reset(); | 809 child1.reset(); |
| 778 window_tree_host.reset(); | 810 window_tree_host.reset(); |
| 779 capture_client.reset(); | 811 capture_client.reset(); |
| 780 } | 812 } |
| 781 | 813 |
| 814 TEST_F(WindowTreeClientClientTest, InputEventRootWindow) { |
| 815 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 816 Window* top_level = window_tree_host.window(); |
| 817 InputEventBasicTestEventHandler root_handler; |
| 818 top_level->AddPreTargetHandler(&root_handler); |
| 819 const gfx::Rect bounds(0, 0, 100, 100); |
| 820 window_tree_host.SetBoundsInPixels(bounds); |
| 821 window_tree_host.InitHost(); |
| 822 window_tree_host.Show(); |
| 823 EXPECT_EQ(bounds, top_level->bounds()); |
| 824 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
| 825 InputEventBasicTestWindowDelegate child_delegate(window_tree()); |
| 826 Window child(&child_delegate); |
| 827 child.Init(ui::LAYER_NOT_DRAWN); |
| 828 top_level->AddChild(&child); |
| 829 child.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 830 child.Show(); |
| 831 |
| 832 EXPECT_FALSE(root_handler.got_move()); |
| 833 EXPECT_FALSE(child_delegate.got_move()); |
| 834 |
| 835 const gfx::Point event_location_in_child(20, 30); |
| 836 const uint32_t event_id = 1; |
| 837 root_handler.set_event_id(event_id); |
| 838 child_delegate.set_event_id(event_id); |
| 839 std::unique_ptr<ui::Event> ui_event( |
| 840 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, |
| 841 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 842 window_tree_client()->OnWindowInputEvent( |
| 843 event_id, server_id(top_level), window_tree_host.display_id(), |
| 844 ui::Event::Clone(*ui_event.get()), 0); |
| 845 |
| 846 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 847 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 848 window_tree()->GetEventResult(event_id)); |
| 849 EXPECT_TRUE(root_handler.got_move()); |
| 850 EXPECT_EQ(gfx::Point(20, 30), root_handler.last_event_location()); |
| 851 EXPECT_FALSE(child_delegate.got_move()); |
| 852 EXPECT_EQ(gfx::Point(), child_delegate.last_event_location()); |
| 853 } |
| 854 |
| 782 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { | 855 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
| 783 public: | 856 public: |
| 784 WindowTreeClientPointerObserverTest() {} | 857 WindowTreeClientPointerObserverTest() {} |
| 785 ~WindowTreeClientPointerObserverTest() override {} | 858 ~WindowTreeClientPointerObserverTest() override {} |
| 786 | 859 |
| 787 void DeleteLastEventObserved() { last_event_observed_.reset(); } | 860 void DeleteLastEventObserved() { last_event_observed_.reset(); } |
| 788 const ui::PointerEvent* last_event_observed() const { | 861 const ui::PointerEvent* last_event_observed() const { |
| 789 return last_event_observed_.get(); | 862 return last_event_observed_.get(); |
| 790 } | 863 } |
| 791 | 864 |
| (...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 window_tree()->GetEventResult(event_id)); | 1984 window_tree()->GetEventResult(event_id)); |
| 1912 EXPECT_TRUE(window_delegate1.got_move()); | 1985 EXPECT_TRUE(window_delegate1.got_move()); |
| 1913 EXPECT_FALSE(window_delegate2.got_move()); | 1986 EXPECT_FALSE(window_delegate2.got_move()); |
| 1914 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, | 1987 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, |
| 1915 event_location_in_dip.y() + 30); | 1988 event_location_in_dip.y() + 30); |
| 1916 EXPECT_EQ(transformed_event_location_in_dip, | 1989 EXPECT_EQ(transformed_event_location_in_dip, |
| 1917 window_delegate1.last_event_location()); | 1990 window_delegate1.last_event_location()); |
| 1918 } | 1991 } |
| 1919 | 1992 |
| 1920 } // namespace aura | 1993 } // namespace aura |
| OLD | NEW |