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/test_server_window_delegate.h" | 9 #include "services/ui/ws/test_server_window_delegate.h" |
10 #include "services/ui/ws/window_finder.h" | 10 #include "services/ui/ws/window_finder.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 child1.SetVisible(true); | 27 child1.SetVisible(true); |
28 child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); | 28 child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); |
29 | 29 |
30 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 30 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
31 root.Add(&child2); | 31 root.Add(&child2); |
32 child2.SetVisible(true); | 32 child2.SetVisible(true); |
33 child2.SetBounds(gfx::Rect(15, 15, 20, 20), base::nullopt); | 33 child2.SetBounds(gfx::Rect(15, 15, 20, 20), base::nullopt); |
34 | 34 |
35 EXPECT_EQ( | 35 EXPECT_EQ( |
36 &child2, | 36 &child2, |
37 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); | 37 FindDeepestVisibleWindowForLocation(&root, gfx::Point(16, 16)).window); |
38 | 38 |
39 EXPECT_EQ( | 39 EXPECT_EQ( |
40 &child1, | 40 &child1, |
41 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); | 41 FindDeepestVisibleWindowForLocation(&root, gfx::Point(13, 14)).window); |
42 | 42 |
43 child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); | 43 child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); |
44 EXPECT_EQ( | 44 EXPECT_EQ( |
45 nullptr, | 45 nullptr, |
46 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); | 46 FindDeepestVisibleWindowForLocation(&root, gfx::Point(13, 14)).window); |
47 | 47 |
48 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); | 48 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); |
49 EXPECT_EQ( | 49 EXPECT_EQ( |
50 &child2, | 50 &child2, |
51 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); | 51 FindDeepestVisibleWindowForLocation(&root, gfx::Point(13, 14)).window); |
52 } | 52 } |
53 | 53 |
54 TEST(WindowFinderTest, FindDeepestVisibleWindowNonClientArea) { | 54 TEST(WindowFinderTest, FindDeepestVisibleWindowNonClientArea) { |
55 TestServerWindowDelegate window_delegate; | 55 TestServerWindowDelegate window_delegate; |
56 ServerWindow root(&window_delegate, WindowId(1, 2)); | 56 ServerWindow root(&window_delegate, WindowId(1, 2)); |
57 window_delegate.set_root_window(&root); | 57 window_delegate.set_root_window(&root); |
58 root.SetVisible(true); | 58 root.SetVisible(true); |
59 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 59 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
60 | 60 |
61 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 61 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
62 root.Add(&child1); | 62 root.Add(&child1); |
63 child1.SetVisible(true); | 63 child1.SetVisible(true); |
64 child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); | 64 child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); |
65 | 65 |
66 DeepestWindow result = | 66 DeepestWindow result = |
67 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)); | 67 FindDeepestVisibleWindowForLocation(&root, gfx::Point(13, 14)); |
68 EXPECT_EQ(&child1, result.window); | 68 EXPECT_EQ(&child1, result.window); |
69 EXPECT_FALSE(result.in_non_client_area); | 69 EXPECT_FALSE(result.in_non_client_area); |
70 | 70 |
71 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); | 71 result = FindDeepestVisibleWindowForLocation(&root, gfx::Point(11, 11)); |
72 EXPECT_EQ(&child1, result.window); | 72 EXPECT_EQ(&child1, result.window); |
73 EXPECT_FALSE(result.in_non_client_area); | 73 EXPECT_FALSE(result.in_non_client_area); |
74 | 74 |
75 // 11, 11 is over the non-client area. | 75 // 11, 11 is over the non-client area. |
76 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); | 76 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
77 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); | 77 result = FindDeepestVisibleWindowForLocation(&root, gfx::Point(11, 11)); |
78 EXPECT_EQ(&child1, result.window); | 78 EXPECT_EQ(&child1, result.window); |
79 EXPECT_TRUE(result.in_non_client_area); | 79 EXPECT_TRUE(result.in_non_client_area); |
80 | 80 |
81 // 15, 15 is over the client area. | 81 // 15, 15 is over the client area. |
82 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); | 82 result = FindDeepestVisibleWindowForLocation(&root, gfx::Point(15, 15)); |
83 EXPECT_EQ(&child1, result.window); | 83 EXPECT_EQ(&child1, result.window); |
84 EXPECT_FALSE(result.in_non_client_area); | 84 EXPECT_FALSE(result.in_non_client_area); |
85 | 85 |
86 // EventTargetingPolicy::NONE should not impact the result for the | 86 // EventTargetingPolicy::NONE should not impact the result for the |
87 // non-client area. | 87 // non-client area. |
88 child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); | 88 child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); |
89 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); | 89 result = FindDeepestVisibleWindowForLocation(&root, gfx::Point(11, 11)); |
90 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); | 90 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
91 EXPECT_EQ(&child1, result.window); | 91 EXPECT_EQ(&child1, result.window); |
92 EXPECT_TRUE(result.in_non_client_area); | 92 EXPECT_TRUE(result.in_non_client_area); |
93 | 93 |
94 // EventTargetingPolicy::NONE means the client area won't be matched though. | 94 // EventTargetingPolicy::NONE means the client area won't be matched though. |
95 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); | 95 result = FindDeepestVisibleWindowForLocation(&root, gfx::Point(15, 15)); |
96 EXPECT_EQ(&root, result.window); | 96 EXPECT_EQ(&root, result.window); |
97 EXPECT_FALSE(result.in_non_client_area); | 97 EXPECT_FALSE(result.in_non_client_area); |
98 } | 98 } |
99 | 99 |
100 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { | 100 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { |
101 TestServerWindowDelegate window_delegate; | 101 TestServerWindowDelegate window_delegate; |
102 ServerWindow root(&window_delegate, WindowId(1, 2)); | 102 ServerWindow root(&window_delegate, WindowId(1, 2)); |
103 window_delegate.set_root_window(&root); | 103 window_delegate.set_root_window(&root); |
104 root.SetVisible(true); | 104 root.SetVisible(true); |
105 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 105 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
106 | 106 |
107 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); | 107 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); |
108 root.Add(&child_with_mask); | 108 root.Add(&child_with_mask); |
109 child_with_mask.SetVisible(true); | 109 child_with_mask.SetVisible(true); |
110 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); | 110 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); |
111 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); | 111 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); |
112 | 112 |
113 // Test a point inside the window but outside the mask. | 113 // Test a point inside the window but outside the mask. |
114 EXPECT_EQ( | 114 EXPECT_EQ( |
115 &root, | 115 &root, |
116 FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)).window); | 116 FindDeepestVisibleWindowForLocation(&root, gfx::Point(11, 11)).window); |
117 | 117 |
118 // Test a point inside the window and inside the mask. | 118 // Test a point inside the window and inside the mask. |
119 EXPECT_EQ( | 119 EXPECT_EQ( |
120 &child_with_mask, | 120 &child_with_mask, |
121 FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)).window); | 121 FindDeepestVisibleWindowForLocation(&root, gfx::Point(15, 15)).window); |
122 } | 122 } |
123 | 123 |
124 TEST(WindowFinderTest, FindDeepestVisibleWindowOverNonTarget) { | 124 TEST(WindowFinderTest, FindDeepestVisibleWindowOverNonTarget) { |
125 TestServerWindowDelegate window_delegate; | 125 TestServerWindowDelegate window_delegate; |
126 ServerWindow root(&window_delegate, WindowId(1, 2)); | 126 ServerWindow root(&window_delegate, WindowId(1, 2)); |
127 window_delegate.set_root_window(&root); | 127 window_delegate.set_root_window(&root); |
128 root.SetVisible(true); | 128 root.SetVisible(true); |
129 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 129 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
130 | 130 |
131 // Create two windows, |child1| and |child2|. The two overlap but |child2| is | 131 // Create two windows, |child1| and |child2|. The two overlap but |child2| is |
132 // not a valid event target. | 132 // not a valid event target. |
133 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 133 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
134 root.Add(&child1); | 134 root.Add(&child1); |
135 child1.SetVisible(true); | 135 child1.SetVisible(true); |
136 child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); | 136 child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); |
137 | 137 |
138 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 138 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
139 root.Add(&child2); | 139 root.Add(&child2); |
140 child2.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); | 140 child2.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE); |
141 child2.SetVisible(true); | 141 child2.SetVisible(true); |
142 child2.SetBounds(gfx::Rect(15, 15, 20, 20), base::nullopt); | 142 child2.SetBounds(gfx::Rect(15, 15, 20, 20), base::nullopt); |
143 | 143 |
144 // 16, 16 is over |child2| and |child1|, but as |child2| isn't a valid event | 144 // 16, 16 is over |child2| and |child1|, but as |child2| isn't a valid event |
145 // target |child1| should be picked. | 145 // target |child1| should be picked. |
146 EXPECT_EQ( | 146 EXPECT_EQ( |
147 &child1, | 147 &child1, |
148 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); | 148 FindDeepestVisibleWindowForLocation(&root, gfx::Point(16, 16)).window); |
149 } | 149 } |
150 | 150 |
151 TEST(WindowFinderTest, NonClientPreferredOverChild) { | 151 TEST(WindowFinderTest, NonClientPreferredOverChild) { |
152 TestServerWindowDelegate window_delegate; | 152 TestServerWindowDelegate window_delegate; |
153 ServerWindow root(&window_delegate, WindowId(1, 2)); | 153 ServerWindow root(&window_delegate, WindowId(1, 2)); |
154 window_delegate.set_root_window(&root); | 154 window_delegate.set_root_window(&root); |
155 root.SetVisible(true); | 155 root.SetVisible(true); |
156 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 156 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
157 | 157 |
158 // Create two windows, |child| and |child_child|; |child| is a child of the | 158 // Create two windows, |child| and |child_child|; |child| is a child of the |
159 // root and |child_child| and child of |child|. All share the same size with | 159 // root and |child_child| and child of |child|. All share the same size with |
160 // |child| having a non-client area. | 160 // |child| having a non-client area. |
161 ServerWindow child(&window_delegate, WindowId(1, 3)); | 161 ServerWindow child(&window_delegate, WindowId(1, 3)); |
162 root.Add(&child); | 162 root.Add(&child); |
163 child.SetVisible(true); | 163 child.SetVisible(true); |
164 child.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 164 child.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
165 child.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); | 165 child.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
166 | 166 |
167 ServerWindow child_child(&window_delegate, WindowId(1, 4)); | 167 ServerWindow child_child(&window_delegate, WindowId(1, 4)); |
168 child.Add(&child_child); | 168 child.Add(&child_child); |
169 child_child.SetVisible(true); | 169 child_child.SetVisible(true); |
170 child_child.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 170 child_child.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
171 | 171 |
172 // |child| was should be returned as the event is over the non-client area. | 172 // |child| was should be returned as the event is over the non-client area. |
173 EXPECT_EQ(&child, | 173 EXPECT_EQ( |
174 FindDeepestVisibleWindowForEvents(&root, gfx::Point(1, 1)).window); | 174 &child, |
| 175 FindDeepestVisibleWindowForLocation(&root, gfx::Point(1, 1)).window); |
175 } | 176 } |
176 | 177 |
177 TEST(WindowFinderTest, FindDeepestVisibleWindowWithTransform) { | 178 TEST(WindowFinderTest, FindDeepestVisibleWindowWithTransform) { |
178 TestServerWindowDelegate window_delegate; | 179 TestServerWindowDelegate window_delegate; |
179 ServerWindow root(&window_delegate, WindowId(1, 2)); | 180 ServerWindow root(&window_delegate, WindowId(1, 2)); |
180 root.set_event_targeting_policy( | 181 root.set_event_targeting_policy( |
181 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 182 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
182 window_delegate.set_root_window(&root); | 183 window_delegate.set_root_window(&root); |
183 root.SetVisible(true); | 184 root.SetVisible(true); |
184 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); | 185 root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt); |
185 ServerWindow child(&window_delegate, WindowId(1, 3)); | 186 ServerWindow child(&window_delegate, WindowId(1, 3)); |
186 root.Add(&child); | 187 root.Add(&child); |
187 child.SetVisible(true); | 188 child.SetVisible(true); |
188 child.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); | 189 child.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt); |
189 gfx::Transform transform; | 190 gfx::Transform transform; |
190 transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2)); | 191 transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2)); |
191 child.SetTransform(transform); | 192 child.SetTransform(transform); |
192 | 193 |
193 EXPECT_EQ( | 194 EXPECT_EQ( |
194 &child, | 195 &child, |
195 FindDeepestVisibleWindowForEvents(&root, gfx::Point(49, 49)).window); | 196 FindDeepestVisibleWindowForLocation(&root, gfx::Point(49, 49)).window); |
196 EXPECT_EQ(nullptr, | 197 EXPECT_EQ( |
197 FindDeepestVisibleWindowForEvents(&root, gfx::Point(9, 9)).window); | 198 nullptr, |
| 199 FindDeepestVisibleWindowForLocation(&root, gfx::Point(9, 9)).window); |
198 | 200 |
199 // Verify extended hit test with transform is picked up. | 201 // Verify extended hit test with transform is picked up. |
200 child.set_extended_hit_test_region(gfx::Insets(2, 2, 2, 2)); | 202 child.set_extended_hit_test_region(gfx::Insets(2, 2, 2, 2)); |
201 EXPECT_EQ(&child, | 203 EXPECT_EQ( |
202 FindDeepestVisibleWindowForEvents(&root, gfx::Point(7, 7)).window); | 204 &child, |
203 EXPECT_EQ(nullptr, | 205 FindDeepestVisibleWindowForLocation(&root, gfx::Point(7, 7)).window); |
204 FindDeepestVisibleWindowForEvents(&root, gfx::Point(4, 4)).window); | 206 EXPECT_EQ( |
| 207 nullptr, |
| 208 FindDeepestVisibleWindowForLocation(&root, gfx::Point(4, 4)).window); |
205 } | 209 } |
206 | 210 |
207 } // namespace ws | 211 } // namespace ws |
208 } // namespace ui | 212 } // namespace ui |
OLD | NEW |