| 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/window_finder.h" | 5 #include "services/ui/ws/window_finder.h" |
| 6 | 6 |
| 7 #include "services/ui/ws/server_window.h" | 7 #include "services/ui/ws/server_window.h" |
| 8 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 8 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h" | 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h" |
| 10 #include "services/ui/ws/test_server_window_delegate.h" | 10 #include "services/ui/ws/test_server_window_delegate.h" |
| 11 #include "services/ui/ws/window_finder.h" | 11 #include "services/ui/ws/window_finder.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 namespace ws { | 15 namespace ws { |
| 16 | 16 |
| 17 TEST(WindowFinderTest, FindDeepestVisibleWindow) { | 17 TEST(WindowFinderTest, FindDeepestVisibleWindow) { |
| 18 TestServerWindowDelegate window_delegate; | 18 TestServerWindowDelegate window_delegate; |
| 19 ServerWindow root(&window_delegate, WindowId(1, 2)); | 19 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 20 root.set_event_targeting_policy( |
| 21 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
| 20 window_delegate.set_root_window(&root); | 22 window_delegate.set_root_window(&root); |
| 21 root.SetVisible(true); | 23 root.SetVisible(true); |
| 22 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 24 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 23 | 25 |
| 24 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 26 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
| 25 root.Add(&child1); | 27 root.Add(&child1); |
| 26 EnableHitTest(&child1); | |
| 27 child1.SetVisible(true); | 28 child1.SetVisible(true); |
| 28 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 29 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 29 | 30 |
| 30 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 31 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
| 31 root.Add(&child2); | 32 root.Add(&child2); |
| 32 EnableHitTest(&child2); | |
| 33 child2.SetVisible(true); | 33 child2.SetVisible(true); |
| 34 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); | 34 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); |
| 35 | 35 |
| 36 EXPECT_EQ( | 36 EXPECT_EQ( |
| 37 &child2, | 37 &child2, |
| 38 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); | 38 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); |
| 39 | 39 |
| 40 EXPECT_EQ( | 40 EXPECT_EQ( |
| 41 &child1, | 41 &child1, |
| 42 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); | 42 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); |
| 43 | 43 |
| 44 child1.set_can_accept_events(false); | 44 child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); |
| 45 EXPECT_EQ( | 45 EXPECT_EQ( |
| 46 nullptr, | 46 nullptr, |
| 47 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); | 47 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); |
| 48 | 48 |
| 49 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); | 49 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); |
| 50 EXPECT_EQ( | 50 EXPECT_EQ( |
| 51 &child2, | 51 &child2, |
| 52 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); | 52 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST(WindowFinderTest, FindDeepestVisibleWindowNonClientArea) { | 55 TEST(WindowFinderTest, FindDeepestVisibleWindowNonClientArea) { |
| 56 TestServerWindowDelegate window_delegate; | 56 TestServerWindowDelegate window_delegate; |
| 57 ServerWindow root(&window_delegate, WindowId(1, 2)); | 57 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 58 EnableHitTest(&root); | |
| 59 window_delegate.set_root_window(&root); | 58 window_delegate.set_root_window(&root); |
| 60 root.SetVisible(true); | 59 root.SetVisible(true); |
| 61 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 60 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 62 | 61 |
| 63 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 62 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
| 64 root.Add(&child1); | 63 root.Add(&child1); |
| 65 EnableHitTest(&child1); | |
| 66 child1.SetVisible(true); | 64 child1.SetVisible(true); |
| 67 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 65 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 68 | 66 |
| 69 DeepestWindow result = | 67 DeepestWindow result = |
| 70 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)); | 68 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)); |
| 71 EXPECT_EQ(&child1, result.window); | 69 EXPECT_EQ(&child1, result.window); |
| 72 EXPECT_FALSE(result.in_non_client_area); | 70 EXPECT_FALSE(result.in_non_client_area); |
| 73 | 71 |
| 74 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); | 72 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); |
| 75 EXPECT_EQ(&child1, result.window); | 73 EXPECT_EQ(&child1, result.window); |
| 76 EXPECT_FALSE(result.in_non_client_area); | 74 EXPECT_FALSE(result.in_non_client_area); |
| 77 | 75 |
| 78 // 11, 11 is over the non-client area. | 76 // 11, 11 is over the non-client area. |
| 79 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); | 77 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
| 80 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); | 78 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); |
| 81 EXPECT_EQ(&child1, result.window); | 79 EXPECT_EQ(&child1, result.window); |
| 82 EXPECT_TRUE(result.in_non_client_area); | 80 EXPECT_TRUE(result.in_non_client_area); |
| 83 | 81 |
| 84 // 15, 15 is over the client area. | 82 // 15, 15 is over the client area. |
| 85 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); | 83 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); |
| 86 EXPECT_EQ(&child1, result.window); | 84 EXPECT_EQ(&child1, result.window); |
| 87 EXPECT_FALSE(result.in_non_client_area); | 85 EXPECT_FALSE(result.in_non_client_area); |
| 88 | 86 |
| 89 // set_can_accept_events(false) should not impact the result for the | 87 // EventTargetingPolicy::NONE should not impact the result for the |
| 90 // non-client area. | 88 // non-client area. |
| 91 child1.set_can_accept_events(false); | 89 child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); |
| 92 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); | 90 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); |
| 93 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); | 91 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
| 94 EXPECT_EQ(&child1, result.window); | 92 EXPECT_EQ(&child1, result.window); |
| 95 EXPECT_TRUE(result.in_non_client_area); | 93 EXPECT_TRUE(result.in_non_client_area); |
| 96 | 94 |
| 97 // set_can_accept_events(false) means the client area won't be matched though. | 95 // EventTargetingPolicy::NONE means the client area won't be matched though. |
| 98 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); | 96 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); |
| 99 EXPECT_EQ(&root, result.window); | 97 EXPECT_EQ(&root, result.window); |
| 100 EXPECT_FALSE(result.in_non_client_area); | 98 EXPECT_FALSE(result.in_non_client_area); |
| 101 } | 99 } |
| 102 | 100 |
| 103 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { | 101 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { |
| 104 TestServerWindowDelegate window_delegate; | 102 TestServerWindowDelegate window_delegate; |
| 105 ServerWindow root(&window_delegate, WindowId(1, 2)); | 103 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 106 window_delegate.set_root_window(&root); | 104 window_delegate.set_root_window(&root); |
| 107 EnableHitTest(&root); | |
| 108 root.SetVisible(true); | 105 root.SetVisible(true); |
| 109 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 106 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 110 | 107 |
| 111 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); | 108 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); |
| 112 root.Add(&child_with_mask); | 109 root.Add(&child_with_mask); |
| 113 EnableHitTest(&child_with_mask); | |
| 114 child_with_mask.SetVisible(true); | 110 child_with_mask.SetVisible(true); |
| 115 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20)); | 111 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 116 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); | 112 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); |
| 117 | 113 |
| 118 // Test a point inside the window but outside the mask. | 114 // Test a point inside the window but outside the mask. |
| 119 EXPECT_EQ( | 115 EXPECT_EQ( |
| 120 &root, | 116 &root, |
| 121 FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)).window); | 117 FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)).window); |
| 122 | 118 |
| 123 // Test a point inside the window and inside the mask. | 119 // Test a point inside the window and inside the mask. |
| 124 EXPECT_EQ( | 120 EXPECT_EQ( |
| 125 &child_with_mask, | 121 &child_with_mask, |
| 126 FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)).window); | 122 FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)).window); |
| 127 } | 123 } |
| 128 | 124 |
| 129 TEST(WindowFinderTest, FindDeepestVisibleWindowOverNonTarget) { | 125 TEST(WindowFinderTest, FindDeepestVisibleWindowOverNonTarget) { |
| 130 TestServerWindowDelegate window_delegate; | 126 TestServerWindowDelegate window_delegate; |
| 131 ServerWindow root(&window_delegate, WindowId(1, 2)); | 127 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 132 window_delegate.set_root_window(&root); | 128 window_delegate.set_root_window(&root); |
| 133 root.SetVisible(true); | 129 root.SetVisible(true); |
| 134 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 130 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 135 | 131 |
| 136 // Create two windows, |child1| and |child2|. The two overlap but |child2| is | 132 // Create two windows, |child1| and |child2|. The two overlap but |child2| is |
| 137 // not a valid event target. | 133 // not a valid event target. |
| 138 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 134 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
| 139 root.Add(&child1); | 135 root.Add(&child1); |
| 140 EnableHitTest(&child1); | |
| 141 child1.SetVisible(true); | 136 child1.SetVisible(true); |
| 142 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 137 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 143 | 138 |
| 144 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 139 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
| 145 root.Add(&child2); | 140 root.Add(&child2); |
| 141 child2.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); |
| 146 child2.SetVisible(true); | 142 child2.SetVisible(true); |
| 147 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); | 143 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); |
| 148 | 144 |
| 149 // 16, 16 is over |child2| and |child1|, but as |child2| isn't a valid event | 145 // 16, 16 is over |child2| and |child1|, but as |child2| isn't a valid event |
| 150 // target |child1| should be picked. | 146 // target |child1| should be picked. |
| 151 EXPECT_EQ( | 147 EXPECT_EQ( |
| 152 &child1, | 148 &child1, |
| 153 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); | 149 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); |
| 154 } | 150 } |
| 155 | 151 |
| 152 TEST(WindowFinderTest, NonClientPreferredOverChild) { |
| 153 TestServerWindowDelegate window_delegate; |
| 154 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 155 window_delegate.set_root_window(&root); |
| 156 root.SetVisible(true); |
| 157 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 158 |
| 159 // Create two windows, |child| and |child_child|; |child| is a child of the |
| 160 // root and |child_child| and child of |child|. All share the same size with |
| 161 // |child| having a non-client area. |
| 162 ServerWindow child(&window_delegate, WindowId(1, 3)); |
| 163 root.Add(&child); |
| 164 child.SetVisible(true); |
| 165 child.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 166 child.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
| 167 |
| 168 ServerWindow child_child(&window_delegate, WindowId(1, 4)); |
| 169 child.Add(&child_child); |
| 170 child_child.SetVisible(true); |
| 171 child_child.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 172 |
| 173 // |child| was should be returned as the event is over the non-client area. |
| 174 EXPECT_EQ(&child, |
| 175 FindDeepestVisibleWindowForEvents(&root, gfx::Point(1, 1)).window); |
| 176 } |
| 177 |
| 156 } // namespace ws | 178 } // namespace ws |
| 157 } // namespace ui | 179 } // namespace ui |
| OLD | NEW |