Chromium Code Reviews| 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 "services/ui/ws/event_dispatcher.h" | 5 #include "services/ui/ws/event_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 event_dispatcher_.reset(); | 279 event_dispatcher_.reset(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent( | 282 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent( |
| 283 const WindowId& id, | 283 const WindowId& id, |
| 284 ServerWindow* parent) { | 284 ServerWindow* parent) { |
| 285 std::unique_ptr<ServerWindow> child( | 285 std::unique_ptr<ServerWindow> child( |
| 286 new ServerWindow(window_delegate_.get(), id)); | 286 new ServerWindow(window_delegate_.get(), id)); |
| 287 parent->Add(child.get()); | 287 parent->Add(child.get()); |
| 288 child->SetVisible(true); | 288 child->SetVisible(true); |
| 289 EnableHitTest(child.get()); | |
| 290 return child; | 289 return child; |
| 291 } | 290 } |
| 292 | 291 |
| 293 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( | 292 std::unique_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( |
| 294 const WindowId& id) { | 293 const WindowId& id) { |
| 295 return CreateChildWindowWithParent(id, root_window_.get()); | 294 return CreateChildWindowWithParent(id, root_window_.get()); |
| 296 } | 295 } |
| 297 | 296 |
| 298 bool EventDispatcherTest::IsMouseButtonDown() const { | 297 bool EventDispatcherTest::IsMouseButtonDown() const { |
| 299 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); | 298 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 316 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller(); | 315 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller(); |
| 317 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow(); | 316 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow(); |
| 318 } | 317 } |
| 319 | 318 |
| 320 void EventDispatcherTest::SetUp() { | 319 void EventDispatcherTest::SetUp() { |
| 321 testing::Test::SetUp(); | 320 testing::Test::SetUp(); |
| 322 | 321 |
| 323 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>(); | 322 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>(); |
| 324 root_window_ = | 323 root_window_ = |
| 325 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2)); | 324 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2)); |
| 326 EnableHitTest(root_window_.get()); | 325 root_window_->set_event_targeting_policy( |
| 326 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); | |
|
sadrul
2017/02/01 20:42:00
Probably not needed since the default?
sky
2017/02/01 21:13:50
Done.
| |
| 327 window_delegate_->set_root_window(root_window_.get()); | 327 window_delegate_->set_root_window(root_window_.get()); |
| 328 root_window_->SetVisible(true); | 328 root_window_->SetVisible(true); |
| 329 | 329 |
| 330 test_event_dispatcher_delegate_ = | 330 test_event_dispatcher_delegate_ = |
| 331 base::MakeUnique<TestEventDispatcherDelegate>(this); | 331 base::MakeUnique<TestEventDispatcherDelegate>(this); |
| 332 event_dispatcher_ = | 332 event_dispatcher_ = |
| 333 base::MakeUnique<EventDispatcher>(test_event_dispatcher_delegate_.get()); | 333 base::MakeUnique<EventDispatcher>(test_event_dispatcher_delegate_.get()); |
| 334 test_event_dispatcher_delegate_->set_root(root_window_.get()); | 334 test_event_dispatcher_delegate_->set_root(root_window_.get()); |
| 335 } | 335 } |
| 336 | 336 |
| (...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); | 1656 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); |
| 1657 | 1657 |
| 1658 // Remove the last remaining system modal window. There should be no active | 1658 // Remove the last remaining system modal window. There should be no active |
| 1659 // one anymore. | 1659 // one anymore. |
| 1660 w3.reset(); | 1660 w3.reset(); |
| 1661 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); | 1661 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); |
| 1662 } | 1662 } |
| 1663 | 1663 |
| 1664 TEST_F(EventDispatcherTest, CaptureNotResetOnParentChange) { | 1664 TEST_F(EventDispatcherTest, CaptureNotResetOnParentChange) { |
| 1665 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1665 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1666 DisableHitTest(w1.get()); | 1666 w1->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
| 1667 std::unique_ptr<ServerWindow> w11 = | 1667 std::unique_ptr<ServerWindow> w11 = |
| 1668 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); | 1668 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
| 1669 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1669 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1670 DisableHitTest(w2.get()); | 1670 w2->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
| 1671 | 1671 |
| 1672 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1672 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1673 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1673 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1674 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); | 1674 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 1675 w2->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1675 w2->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1676 | 1676 |
| 1677 // Send event that is over |w11|. | 1677 // Send event that is over |w11|. |
| 1678 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1678 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1679 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), | 1679 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
| 1680 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1680 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1706 // Changing capture from client to non-client should notify the delegate. | 1706 // Changing capture from client to non-client should notify the delegate. |
| 1707 // The delegate can decide if it really wants to forward the event or not. | 1707 // The delegate can decide if it really wants to forward the event or not. |
| 1708 EXPECT_EQ(child.get(), | 1708 EXPECT_EQ(child.get(), |
| 1709 test_event_dispatcher_delegate()->lost_capture_window()); | 1709 test_event_dispatcher_delegate()->lost_capture_window()); |
| 1710 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); | 1710 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); |
| 1711 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); | 1711 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); |
| 1712 } | 1712 } |
| 1713 | 1713 |
| 1714 TEST_F(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) { | 1714 TEST_F(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) { |
| 1715 ServerWindow* root = root_window(); | 1715 ServerWindow* root = root_window(); |
| 1716 DisableHitTest(root); | 1716 root->set_event_targeting_policy( |
| 1717 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | |
| 1717 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1718 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 1718 | 1719 |
| 1719 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1720 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1720 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1721 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1721 | 1722 |
| 1722 MouseEventTest tests[] = { | 1723 MouseEventTest tests[] = { |
| 1723 // Send a mouse down over the root, but not the child. No event should | 1724 // Send a mouse down over the root, but not the child. No event should |
| 1724 // be generated. | 1725 // be generated. |
| 1725 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), | 1726 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), |
| 1726 base::TimeTicks(), 0, 0), | 1727 base::TimeTicks(), 0, 0), |
| 1727 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), | 1728 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), |
| 1728 gfx::Point()}, | 1729 gfx::Point()}, |
| 1729 | 1730 |
| 1730 // Move into child. | 1731 // Move into child. |
| 1731 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), | 1732 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), |
| 1732 gfx::Point(12, 12), base::TimeTicks(), 0, 0), | 1733 gfx::Point(12, 12), base::TimeTicks(), 0, 0), |
| 1733 child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(), | 1734 child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(), |
| 1734 gfx::Point()}}; | 1735 gfx::Point()}}; |
| 1735 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 1736 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
| 1736 tests, arraysize(tests)); | 1737 tests, arraysize(tests)); |
| 1737 } | 1738 } |
| 1738 | 1739 |
| 1739 TEST_F(EventDispatcherTest, NoTargetToTargetWithMouseDown) { | 1740 TEST_F(EventDispatcherTest, NoTargetToTargetWithMouseDown) { |
| 1740 ServerWindow* root = root_window(); | 1741 ServerWindow* root = root_window(); |
| 1741 DisableHitTest(root); | 1742 root->set_event_targeting_policy( |
| 1743 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | |
| 1742 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1744 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 1743 | 1745 |
| 1744 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1746 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1745 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1747 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1746 | 1748 |
| 1747 MouseEventTest tests[] = { | 1749 MouseEventTest tests[] = { |
| 1748 // Mouse over the root, but not the child. No event should be generated. | 1750 // Mouse over the root, but not the child. No event should be generated. |
| 1749 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), | 1751 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), |
| 1750 base::TimeTicks(), 0, 0), | 1752 base::TimeTicks(), 0, 0), |
| 1751 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), | 1753 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1763 gfx::Point(12, 12), base::TimeTicks(), | 1765 gfx::Point(12, 12), base::TimeTicks(), |
| 1764 ui::EF_LEFT_MOUSE_BUTTON, 0), | 1766 ui::EF_LEFT_MOUSE_BUTTON, 0), |
| 1765 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), | 1767 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), |
| 1766 gfx::Point()}}; | 1768 gfx::Point()}}; |
| 1767 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 1769 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
| 1768 tests, arraysize(tests)); | 1770 tests, arraysize(tests)); |
| 1769 } | 1771 } |
| 1770 | 1772 |
| 1771 TEST_F(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) { | 1773 TEST_F(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) { |
| 1772 ServerWindow* root = root_window(); | 1774 ServerWindow* root = root_window(); |
| 1773 DisableHitTest(root); | 1775 root->set_event_targeting_policy( |
| 1776 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | |
| 1774 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); | 1777 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); |
| 1775 std::unique_ptr<ServerWindow> c2 = CreateChildWindow(WindowId(1, 4)); | 1778 std::unique_ptr<ServerWindow> c2 = CreateChildWindow(WindowId(1, 4)); |
| 1776 | 1779 |
| 1777 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1780 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1778 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1781 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1779 c2->SetBounds(gfx::Rect(15, 15, 20, 20)); | 1782 c2->SetBounds(gfx::Rect(15, 15, 20, 20)); |
| 1780 | 1783 |
| 1781 MouseEventTest tests[] = { | 1784 MouseEventTest tests[] = { |
| 1782 // Mouse over |c2|. | 1785 // Mouse over |c2|. |
| 1783 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(16, 16), | 1786 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(16, 16), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1796 | 1799 |
| 1797 // Set capture on |c1|. No events should be sent as |c1| is in the same | 1800 // Set capture on |c1|. No events should be sent as |c1| is in the same |
| 1798 // client. | 1801 // client. |
| 1799 event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId); | 1802 event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId); |
| 1800 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); | 1803 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
| 1801 } | 1804 } |
| 1802 | 1805 |
| 1803 } // namespace test | 1806 } // namespace test |
| 1804 } // namespace ws | 1807 } // namespace ws |
| 1805 } // namespace ui | 1808 } // namespace ui |
| OLD | NEW |