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 "components/mus/ws/event_dispatcher.h" | 5 #include "components/mus/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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } | 190 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } |
191 | 191 |
192 bool AreAnyPointersDown() const; | 192 bool AreAnyPointersDown() const; |
193 // Deletes everything created during SetUp() | 193 // Deletes everything created during SetUp() |
194 void ClearSetup(); | 194 void ClearSetup(); |
195 scoped_ptr<ServerWindow> CreateChildWindowWithParent(const WindowId& id, | 195 scoped_ptr<ServerWindow> CreateChildWindowWithParent(const WindowId& id, |
196 ServerWindow* parent); | 196 ServerWindow* parent); |
197 // Creates a window which is a child of |root_window_|. | 197 // Creates a window which is a child of |root_window_|. |
198 scoped_ptr<ServerWindow> CreateChildWindow(const WindowId& id); | 198 scoped_ptr<ServerWindow> CreateChildWindow(const WindowId& id); |
199 bool IsMouseButtonDown() const; | 199 bool IsMouseButtonDown() const; |
200 bool IsWindowPointerTarget(ServerWindow* window) const; | 200 bool IsWindowPointerTarget(const ServerWindow* window) const; |
201 int NumberPointerTargetsForWindow(ServerWindow* window) const; | 201 int NumberPointerTargetsForWindow(ServerWindow* window) const; |
202 | 202 |
203 protected: | 203 protected: |
204 // testing::Test: | 204 // testing::Test: |
205 void SetUp() override; | 205 void SetUp() override; |
206 | 206 |
207 private: | 207 private: |
208 scoped_ptr<TestServerWindowDelegate> window_delegate_; | 208 scoped_ptr<TestServerWindowDelegate> window_delegate_; |
209 scoped_ptr<ServerWindow> root_window_; | 209 scoped_ptr<ServerWindow> root_window_; |
210 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; | 210 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; |
(...skipping 25 matching lines...) Expand all Loading... |
236 | 236 |
237 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( | 237 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( |
238 const WindowId& id) { | 238 const WindowId& id) { |
239 return CreateChildWindowWithParent(id, root_window_.get()); | 239 return CreateChildWindowWithParent(id, root_window_.get()); |
240 } | 240 } |
241 | 241 |
242 bool EventDispatcherTest::IsMouseButtonDown() const { | 242 bool EventDispatcherTest::IsMouseButtonDown() const { |
243 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); | 243 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); |
244 } | 244 } |
245 | 245 |
246 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { | 246 bool EventDispatcherTest::IsWindowPointerTarget( |
| 247 const ServerWindow* window) const { |
247 return EventDispatcherTestApi(event_dispatcher_.get()) | 248 return EventDispatcherTestApi(event_dispatcher_.get()) |
248 .IsObservingWindow(window); | 249 .IsWindowPointerTarget(window); |
249 } | 250 } |
250 | 251 |
251 int EventDispatcherTest::NumberPointerTargetsForWindow( | 252 int EventDispatcherTest::NumberPointerTargetsForWindow( |
252 ServerWindow* window) const { | 253 ServerWindow* window) const { |
253 return EventDispatcherTestApi(event_dispatcher_.get()) | 254 return EventDispatcherTestApi(event_dispatcher_.get()) |
254 .NumberPointerTargetsForWindow(window); | 255 .NumberPointerTargetsForWindow(window); |
255 } | 256 } |
256 | 257 |
257 void EventDispatcherTest::SetUp() { | 258 void EventDispatcherTest::SetUp() { |
258 testing::Test::SetUp(); | 259 testing::Test::SetUp(); |
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 EXPECT_TRUE(details->in_nonclient_area); | 1294 EXPECT_TRUE(details->in_nonclient_area); |
1294 | 1295 |
1295 ASSERT_TRUE(details->event); | 1296 ASSERT_TRUE(details->event); |
1296 ASSERT_TRUE(details->event->IsPointerEvent()); | 1297 ASSERT_TRUE(details->event->IsPointerEvent()); |
1297 | 1298 |
1298 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1299 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1299 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); | 1300 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); |
1300 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); | 1301 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); |
1301 } | 1302 } |
1302 | 1303 |
| 1304 // Tests that events on a system modal window target the modal window itself. |
| 1305 TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) { |
| 1306 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1307 |
| 1308 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1309 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1310 w1->SetModal(); |
| 1311 |
| 1312 // Send event that is over |w1|. |
| 1313 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1314 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
| 1315 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1316 event_dispatcher()->ProcessEvent(mouse_pressed); |
| 1317 |
| 1318 scoped_ptr<DispatchedEventDetails> details = |
| 1319 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1320 ASSERT_TRUE(details); |
| 1321 EXPECT_EQ(w1.get(), details->window); |
| 1322 EXPECT_FALSE(details->in_nonclient_area); |
| 1323 |
| 1324 ASSERT_TRUE(details->event); |
| 1325 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1326 |
| 1327 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1328 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); |
| 1329 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); |
| 1330 } |
| 1331 |
| 1332 // Tests that events outside of system modal window target the modal window. |
| 1333 TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) { |
| 1334 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1335 |
| 1336 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1337 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1338 w1->SetModal(); |
| 1339 event_dispatcher()->SetSystemModalWindow(w1.get()); |
| 1340 |
| 1341 // Send event that is over |w1|. |
| 1342 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1343 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15), |
| 1344 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1345 event_dispatcher()->ProcessEvent(mouse_pressed); |
| 1346 |
| 1347 scoped_ptr<DispatchedEventDetails> details = |
| 1348 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1349 ASSERT_TRUE(details); |
| 1350 EXPECT_EQ(w1.get(), details->window); |
| 1351 EXPECT_TRUE(details->in_nonclient_area); |
| 1352 |
| 1353 ASSERT_TRUE(details->event); |
| 1354 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1355 |
| 1356 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1357 EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location()); |
| 1358 EXPECT_EQ(gfx::Point(35, 5), dispatched_event->location()); |
| 1359 } |
1303 | 1360 |
1304 // Tests that setting capture to a descendant of a modal parent fails. | 1361 // Tests that setting capture to a descendant of a modal parent fails. |
1305 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { | 1362 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { |
1306 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1363 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1307 scoped_ptr<ServerWindow> w11 = | 1364 scoped_ptr<ServerWindow> w11 = |
1308 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); | 1365 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
1309 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1366 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1310 | 1367 |
1311 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1368 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1312 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1369 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
(...skipping 18 matching lines...) Expand all Loading... |
1331 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1388 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1332 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); | 1389 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
1333 | 1390 |
1334 w1->AddTransientWindow(w2.get()); | 1391 w1->AddTransientWindow(w2.get()); |
1335 w2->SetModal(); | 1392 w2->SetModal(); |
1336 | 1393 |
1337 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); | 1394 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); |
1338 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); | 1395 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); |
1339 } | 1396 } |
1340 | 1397 |
| 1398 // Tests that setting capture fails when there is a system modal window. |
| 1399 TEST_F(EventDispatcherTest, ModalWindowSystemSetCapture) { |
| 1400 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1401 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); |
| 1402 |
| 1403 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1404 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1405 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1406 |
| 1407 w2->SetModal(); |
| 1408 event_dispatcher()->SetSystemModalWindow(w2.get()); |
| 1409 |
| 1410 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), false)); |
| 1411 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
| 1412 } |
| 1413 |
1341 } // namespace test | 1414 } // namespace test |
1342 } // namespace ws | 1415 } // namespace ws |
1343 } // namespace mus | 1416 } // namespace mus |
OLD | NEW |