| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 176 |
| 177 ServerWindow* root_window() { return root_window_.get(); } | 177 ServerWindow* root_window() { return root_window_.get(); } |
| 178 TestEventDispatcherDelegate* test_event_dispatcher_delegate() { | 178 TestEventDispatcherDelegate* test_event_dispatcher_delegate() { |
| 179 return test_event_dispatcher_delegate_.get(); | 179 return test_event_dispatcher_delegate_.get(); |
| 180 } | 180 } |
| 181 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } | 181 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } |
| 182 | 182 |
| 183 bool AreAnyPointersDown() const; | 183 bool AreAnyPointersDown() const; |
| 184 // Deletes everything created during SetUp() | 184 // Deletes everything created during SetUp() |
| 185 void ClearSetup(); | 185 void ClearSetup(); |
| 186 // Creates a window which is a child of |root_window_|. It is not owned by | 186 scoped_ptr<ServerWindow> CreateChildWindowWithParent(const WindowId& id, |
| 187 // EventDispatcherTest. | 187 ServerWindow* parent); |
| 188 ServerWindow* CreateChildWindow(const WindowId& id); | 188 // Creates a window which is a child of |root_window_|. |
| 189 scoped_ptr<ServerWindow> CreateChildWindow(const WindowId& id); |
| 189 bool IsMouseButtonDown() const; | 190 bool IsMouseButtonDown() const; |
| 190 bool IsWindowPointerTarget(ServerWindow* window) const; | 191 bool IsWindowPointerTarget(ServerWindow* window) const; |
| 191 int NumberPointerTargetsForWindow(ServerWindow* window) const; | 192 int NumberPointerTargetsForWindow(ServerWindow* window) const; |
| 192 | 193 |
| 193 protected: | 194 protected: |
| 194 // testing::Test: | 195 // testing::Test: |
| 195 void SetUp() override; | 196 void SetUp() override; |
| 196 | 197 |
| 197 private: | 198 private: |
| 198 scoped_ptr<TestServerWindowDelegate> window_delegate_; | 199 scoped_ptr<TestServerWindowDelegate> window_delegate_; |
| 199 scoped_ptr<ServerWindow> root_window_; | 200 scoped_ptr<ServerWindow> root_window_; |
| 200 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; | 201 scoped_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; |
| 201 scoped_ptr<EventDispatcher> event_dispatcher_; | 202 scoped_ptr<EventDispatcher> event_dispatcher_; |
| 202 | 203 |
| 203 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); | 204 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); |
| 204 }; | 205 }; |
| 205 | 206 |
| 206 bool EventDispatcherTest::AreAnyPointersDown() const { | 207 bool EventDispatcherTest::AreAnyPointersDown() const { |
| 207 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown(); | 208 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void EventDispatcherTest::ClearSetup() { | 211 void EventDispatcherTest::ClearSetup() { |
| 211 window_delegate_.reset(); | 212 window_delegate_.reset(); |
| 212 root_window_.reset(); | 213 root_window_.reset(); |
| 213 test_event_dispatcher_delegate_.reset(); | 214 test_event_dispatcher_delegate_.reset(); |
| 214 event_dispatcher_.reset(); | 215 event_dispatcher_.reset(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 ServerWindow* EventDispatcherTest::CreateChildWindow(const WindowId& id) { | 218 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindowWithParent( |
| 218 ServerWindow* child = new ServerWindow(window_delegate_.get(), id); | 219 const WindowId& id, |
| 219 root_window_->Add(child); | 220 ServerWindow* parent) { |
| 221 scoped_ptr<ServerWindow> child(new ServerWindow(window_delegate_.get(), id)); |
| 222 parent->Add(child.get()); |
| 220 child->SetVisible(true); | 223 child->SetVisible(true); |
| 221 EnableHitTest(child); | 224 EnableHitTest(child.get()); |
| 222 return child; | 225 return child; |
| 223 } | 226 } |
| 224 | 227 |
| 228 scoped_ptr<ServerWindow> EventDispatcherTest::CreateChildWindow( |
| 229 const WindowId& id) { |
| 230 return CreateChildWindowWithParent(id, root_window_.get()); |
| 231 } |
| 232 |
| 225 bool EventDispatcherTest::IsMouseButtonDown() const { | 233 bool EventDispatcherTest::IsMouseButtonDown() const { |
| 226 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); | 234 return EventDispatcherTestApi(event_dispatcher_.get()).is_mouse_button_down(); |
| 227 } | 235 } |
| 228 | 236 |
| 229 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { | 237 bool EventDispatcherTest::IsWindowPointerTarget(ServerWindow* window) const { |
| 230 return EventDispatcherTestApi(event_dispatcher_.get()) | 238 return EventDispatcherTestApi(event_dispatcher_.get()) |
| 231 .IsObservingWindow(window); | 239 .IsObservingWindow(window); |
| 232 } | 240 } |
| 233 | 241 |
| 234 int EventDispatcherTest::NumberPointerTargetsForWindow( | 242 int EventDispatcherTest::NumberPointerTargetsForWindow( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 246 root_window_->SetVisible(true); | 254 root_window_->SetVisible(true); |
| 247 | 255 |
| 248 test_event_dispatcher_delegate_.reset( | 256 test_event_dispatcher_delegate_.reset( |
| 249 new TestEventDispatcherDelegate(root_window_.get())); | 257 new TestEventDispatcherDelegate(root_window_.get())); |
| 250 event_dispatcher_.reset( | 258 event_dispatcher_.reset( |
| 251 new EventDispatcher(test_event_dispatcher_delegate_.get())); | 259 new EventDispatcher(test_event_dispatcher_delegate_.get())); |
| 252 event_dispatcher_->set_root(root_window_.get()); | 260 event_dispatcher_->set_root(root_window_.get()); |
| 253 } | 261 } |
| 254 | 262 |
| 255 TEST_F(EventDispatcherTest, ProcessEvent) { | 263 TEST_F(EventDispatcherTest, ProcessEvent) { |
| 256 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 264 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 257 | 265 |
| 258 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 266 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 259 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 267 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 260 | 268 |
| 261 // Send event that is over child. | 269 // Send event that is over child. |
| 262 const ui::PointerEvent ui_event(ui::MouseEvent( | 270 const ui::PointerEvent ui_event(ui::MouseEvent( |
| 263 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), | 271 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
| 264 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 272 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 265 event_dispatcher()->ProcessEvent(ui_event); | 273 event_dispatcher()->ProcessEvent(ui_event); |
| 266 | 274 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 378 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 371 dispatcher->ProcessEvent(key); | 379 dispatcher->ProcessEvent(key); |
| 372 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 380 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| 373 | 381 |
| 374 // TODO(jonross): Update this test to include actual invokation of PostTarget | 382 // TODO(jonross): Update this test to include actual invokation of PostTarget |
| 375 // acceleratos once events acking includes consuming. | 383 // acceleratos once events acking includes consuming. |
| 376 } | 384 } |
| 377 | 385 |
| 378 TEST_F(EventDispatcherTest, Capture) { | 386 TEST_F(EventDispatcherTest, Capture) { |
| 379 ServerWindow* root = root_window(); | 387 ServerWindow* root = root_window(); |
| 380 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 388 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 381 | 389 |
| 382 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 390 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 383 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 391 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 384 | 392 |
| 385 MouseEventTest tests[] = { | 393 MouseEventTest tests[] = { |
| 386 // Send a mouse down event over child. | 394 // Send a mouse down event over child. |
| 387 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), | 395 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
| 388 gfx::Point(20, 25), base::TimeDelta(), | 396 gfx::Point(20, 25), base::TimeDelta(), |
| 389 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 397 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 390 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, | 398 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 412 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 420 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 413 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root, | 421 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root, |
| 414 gfx::Point(50, 50), gfx::Point(50, 50)}, | 422 gfx::Point(50, 50), gfx::Point(50, 50)}, |
| 415 | 423 |
| 416 }; | 424 }; |
| 417 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 425 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
| 418 tests, arraysize(tests)); | 426 tests, arraysize(tests)); |
| 419 } | 427 } |
| 420 | 428 |
| 421 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) { | 429 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) { |
| 422 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 430 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 423 | 431 |
| 424 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 432 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 425 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 433 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 426 | 434 |
| 427 MouseEventTest tests[] = { | 435 MouseEventTest tests[] = { |
| 428 // Send a mouse down event over child with a left mouse button | 436 // Send a mouse down event over child with a left mouse button |
| 429 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), | 437 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
| 430 gfx::Point(20, 25), base::TimeDelta(), | 438 gfx::Point(20, 25), base::TimeDelta(), |
| 431 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 439 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 432 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, | 440 child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 455 ui::EF_LEFT_MOUSE_BUTTON, 0), | 463 ui::EF_LEFT_MOUSE_BUTTON, 0), |
| 456 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr, | 464 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr, |
| 457 gfx::Point(), gfx::Point()}, | 465 gfx::Point(), gfx::Point()}, |
| 458 | 466 |
| 459 }; | 467 }; |
| 460 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 468 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
| 461 tests, arraysize(tests)); | 469 tests, arraysize(tests)); |
| 462 } | 470 } |
| 463 | 471 |
| 464 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) { | 472 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) { |
| 465 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 473 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 466 | 474 |
| 467 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 475 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 468 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 476 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 469 | 477 |
| 470 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); | 478 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); |
| 471 | 479 |
| 472 TestEventDispatcherDelegate* event_dispatcher_delegate = | 480 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 473 test_event_dispatcher_delegate(); | 481 test_event_dispatcher_delegate(); |
| 474 EventDispatcher* dispatcher = event_dispatcher(); | 482 EventDispatcher* dispatcher = event_dispatcher(); |
| 475 | 483 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); | 532 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); |
| 525 | 533 |
| 526 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 534 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 527 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 535 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
| 528 ASSERT_EQ(child.get(), details->window); | 536 ASSERT_EQ(child.get(), details->window); |
| 529 EXPECT_FALSE(details->in_nonclient_area); | 537 EXPECT_FALSE(details->in_nonclient_area); |
| 530 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); | 538 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); |
| 531 } | 539 } |
| 532 | 540 |
| 533 TEST_F(EventDispatcherTest, AdditionalClientArea) { | 541 TEST_F(EventDispatcherTest, AdditionalClientArea) { |
| 534 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 542 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 535 | 543 |
| 536 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 544 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 537 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 545 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 538 | 546 |
| 539 std::vector<gfx::Rect> additional_client_areas; | 547 std::vector<gfx::Rect> additional_client_areas; |
| 540 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); | 548 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); |
| 541 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); | 549 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); |
| 542 | 550 |
| 543 TestEventDispatcherDelegate* event_dispatcher_delegate = | 551 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 544 test_event_dispatcher_delegate(); | 552 test_event_dispatcher_delegate(); |
| 545 // Press in the additional client area, it should go to the child. | 553 // Press in the additional client area, it should go to the child. |
| 546 const ui::PointerEvent press_event(ui::MouseEvent( | 554 const ui::PointerEvent press_event(ui::MouseEvent( |
| 547 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), | 555 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), |
| 548 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 556 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 549 event_dispatcher()->ProcessEvent(press_event); | 557 event_dispatcher()->ProcessEvent(press_event); |
| 550 | 558 |
| 551 // Events should target child and be in the client area. | 559 // Events should target child and be in the client area. |
| 552 scoped_ptr<DispatchedEventDetails> details = | 560 scoped_ptr<DispatchedEventDetails> details = |
| 553 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 561 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 554 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 562 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
| 555 ASSERT_EQ(child.get(), details->window); | 563 ASSERT_EQ(child.get(), details->window); |
| 556 EXPECT_FALSE(details->in_nonclient_area); | 564 EXPECT_FALSE(details->in_nonclient_area); |
| 557 } | 565 } |
| 558 | 566 |
| 559 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) { | 567 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) { |
| 560 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); | 568 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
| 561 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); | 569 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
| 562 | 570 |
| 563 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 571 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 564 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 572 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 565 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 573 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
| 566 | 574 |
| 567 TestEventDispatcherDelegate* event_dispatcher_delegate = | 575 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 568 test_event_dispatcher_delegate(); | 576 test_event_dispatcher_delegate(); |
| 569 EventDispatcher* dispatcher = event_dispatcher(); | 577 EventDispatcher* dispatcher = event_dispatcher(); |
| 570 | 578 |
| 571 // Press on child1. First press event should change focus. | 579 // Press on child1. First press event should change focus. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 585 const ui::PointerEvent touch_event(ui::TouchEvent( | 593 const ui::PointerEvent touch_event(ui::TouchEvent( |
| 586 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeDelta())); | 594 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), 2, base::TimeDelta())); |
| 587 dispatcher->ProcessEvent(touch_event); | 595 dispatcher->ProcessEvent(touch_event); |
| 588 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 596 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 589 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 597 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
| 590 EXPECT_EQ(child2.get(), details->window); | 598 EXPECT_EQ(child2.get(), details->window); |
| 591 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); | 599 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); |
| 592 } | 600 } |
| 593 | 601 |
| 594 TEST_F(EventDispatcherTest, TwoPointersActive) { | 602 TEST_F(EventDispatcherTest, TwoPointersActive) { |
| 595 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); | 603 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
| 596 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); | 604 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
| 597 | 605 |
| 598 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 606 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 599 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 607 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 600 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 608 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
| 601 | 609 |
| 602 TestEventDispatcherDelegate* event_dispatcher_delegate = | 610 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 603 test_event_dispatcher_delegate(); | 611 test_event_dispatcher_delegate(); |
| 604 EventDispatcher* dispatcher = event_dispatcher(); | 612 EventDispatcher* dispatcher = event_dispatcher(); |
| 605 | 613 |
| 606 // Press on child1. | 614 // Press on child1. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 652 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 645 EXPECT_EQ(child1.get(), details->window); | 653 EXPECT_EQ(child1.get(), details->window); |
| 646 const ui::PointerEvent touch_event3(ui::TouchEvent( | 654 const ui::PointerEvent touch_event3(ui::TouchEvent( |
| 647 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeDelta())); | 655 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), 2, base::TimeDelta())); |
| 648 dispatcher->ProcessEvent(touch_event3); | 656 dispatcher->ProcessEvent(touch_event3); |
| 649 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 657 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 650 EXPECT_EQ(child2.get(), details->window); | 658 EXPECT_EQ(child2.get(), details->window); |
| 651 } | 659 } |
| 652 | 660 |
| 653 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) { | 661 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) { |
| 654 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 662 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 655 | 663 |
| 656 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 664 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 657 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 665 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 658 | 666 |
| 659 TestEventDispatcherDelegate* event_dispatcher_delegate = | 667 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 660 test_event_dispatcher_delegate(); | 668 test_event_dispatcher_delegate(); |
| 661 EventDispatcher* dispatcher = event_dispatcher(); | 669 EventDispatcher* dispatcher = event_dispatcher(); |
| 662 | 670 |
| 663 // Press on child. | 671 // Press on child. |
| 664 const ui::PointerEvent touch_event1(ui::TouchEvent( | 672 const ui::PointerEvent touch_event1(ui::TouchEvent( |
| 665 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); | 673 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), 1, base::TimeDelta())); |
| 666 dispatcher->ProcessEvent(touch_event1); | 674 dispatcher->ProcessEvent(touch_event1); |
| 667 scoped_ptr<DispatchedEventDetails> details = | 675 scoped_ptr<DispatchedEventDetails> details = |
| 668 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 676 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 669 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 677 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
| 670 EXPECT_EQ(child.get(), details->window); | 678 EXPECT_EQ(child.get(), details->window); |
| 671 | 679 |
| 672 // Delete child, and continue the drag. Event should not be dispatched. | 680 // Delete child, and continue the drag. Event should not be dispatched. |
| 673 child.reset(); | 681 child.reset(); |
| 674 | 682 |
| 675 const ui::PointerEvent drag_event1(ui::TouchEvent( | 683 const ui::PointerEvent drag_event1(ui::TouchEvent( |
| 676 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta())); | 684 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), 1, base::TimeDelta())); |
| 677 dispatcher->ProcessEvent(drag_event1); | 685 dispatcher->ProcessEvent(drag_event1); |
| 678 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 686 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 679 EXPECT_EQ(nullptr, details.get()); | 687 EXPECT_EQ(nullptr, details.get()); |
| 680 } | 688 } |
| 681 | 689 |
| 682 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) { | 690 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) { |
| 683 ServerWindow* root = root_window(); | 691 ServerWindow* root = root_window(); |
| 684 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 692 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 685 | 693 |
| 686 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 694 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 687 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 695 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 688 | 696 |
| 689 TestEventDispatcherDelegate* event_dispatcher_delegate = | 697 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 690 test_event_dispatcher_delegate(); | 698 test_event_dispatcher_delegate(); |
| 691 EventDispatcher* dispatcher = event_dispatcher(); | 699 EventDispatcher* dispatcher = event_dispatcher(); |
| 692 | 700 |
| 693 // Send event that is not over child. | 701 // Send event that is not over child. |
| 694 const ui::PointerEvent ui_event(ui::MouseEvent( | 702 const ui::PointerEvent ui_event(ui::MouseEvent( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 724 ASSERT_EQ(child.get(), details->window); | 732 ASSERT_EQ(child.get(), details->window); |
| 725 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); | 733 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); |
| 726 ASSERT_TRUE(details->event.get()); | 734 ASSERT_TRUE(details->event.get()); |
| 727 ASSERT_TRUE(details->event->IsPointerEvent()); | 735 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 728 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location()); | 736 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location()); |
| 729 } | 737 } |
| 730 | 738 |
| 731 // TODO(moshayedi): crbug.com/590226. Enable this after we support wheel events | 739 // TODO(moshayedi): crbug.com/590226. Enable this after we support wheel events |
| 732 // in mus event dispatcher. | 740 // in mus event dispatcher. |
| 733 TEST_F(EventDispatcherTest, DISABLED_WheelWhileDown) { | 741 TEST_F(EventDispatcherTest, DISABLED_WheelWhileDown) { |
| 734 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); | 742 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
| 735 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); | 743 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
| 736 | 744 |
| 737 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 745 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 738 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 746 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 739 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 747 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
| 740 | 748 |
| 741 MouseEventTest tests[] = { | 749 MouseEventTest tests[] = { |
| 742 // Send a mouse down event over child1. | 750 // Send a mouse down event over child1. |
| 743 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), | 751 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), |
| 744 gfx::Point(15, 15), base::TimeDelta(), | 752 gfx::Point(15, 15), base::TimeDelta(), |
| 745 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 753 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
| 746 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr, | 754 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr, |
| 747 gfx::Point(), gfx::Point()}, | 755 gfx::Point(), gfx::Point()}, |
| 748 // Send mouse wheel over child2, should go to child1 as it has capture. | 756 // Send mouse wheel over child2, should go to child1 as it has capture. |
| 749 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54), | 757 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54), |
| 750 gfx::Point(53, 54), base::TimeDelta(), ui::EF_NONE, | 758 gfx::Point(53, 54), base::TimeDelta(), ui::EF_NONE, |
| 751 ui::EF_NONE), | 759 ui::EF_NONE), |
| 752 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr, | 760 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr, |
| 753 gfx::Point(), gfx::Point()}, | 761 gfx::Point(), gfx::Point()}, |
| 754 }; | 762 }; |
| 755 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 763 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
| 756 tests, arraysize(tests)); | 764 tests, arraysize(tests)); |
| 757 } | 765 } |
| 758 | 766 |
| 759 // Tests that when explicit capture has been set that all events go to the | 767 // Tests that when explicit capture has been set that all events go to the |
| 760 // designated window, and that when capture is cleared, events find the | 768 // designated window, and that when capture is cleared, events find the |
| 761 // appropriate target window. | 769 // appropriate target window. |
| 762 TEST_F(EventDispatcherTest, SetExplicitCapture) { | 770 TEST_F(EventDispatcherTest, SetExplicitCapture) { |
| 763 ServerWindow* root = root_window(); | 771 ServerWindow* root = root_window(); |
| 764 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 772 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 765 | 773 |
| 766 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 774 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 767 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 775 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 768 | 776 |
| 769 TestEventDispatcherDelegate* event_dispatcher_delegate = | 777 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 770 test_event_dispatcher_delegate(); | 778 test_event_dispatcher_delegate(); |
| 771 EventDispatcher* dispatcher = event_dispatcher(); | 779 EventDispatcher* dispatcher = event_dispatcher(); |
| 772 | 780 |
| 773 { | 781 { |
| 774 // Send all pointer events to the child. | 782 // Send all pointer events to the child. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 856 |
| 849 ASSERT_TRUE(details); | 857 ASSERT_TRUE(details); |
| 850 ASSERT_EQ(root, details->window); | 858 ASSERT_EQ(root, details->window); |
| 851 } | 859 } |
| 852 } | 860 } |
| 853 | 861 |
| 854 // This test verifies that explicit capture overrides and resets implicit | 862 // This test verifies that explicit capture overrides and resets implicit |
| 855 // capture. | 863 // capture. |
| 856 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) { | 864 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) { |
| 857 ServerWindow* root = root_window(); | 865 ServerWindow* root = root_window(); |
| 858 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 866 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 859 | 867 |
| 860 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 868 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 861 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 869 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 862 | 870 |
| 863 TestEventDispatcherDelegate* event_dispatcher_delegate = | 871 TestEventDispatcherDelegate* event_dispatcher_delegate = |
| 864 test_event_dispatcher_delegate(); | 872 test_event_dispatcher_delegate(); |
| 865 EventDispatcher* dispatcher = event_dispatcher(); | 873 EventDispatcher* dispatcher = event_dispatcher(); |
| 866 | 874 |
| 867 // Run some implicit capture tests. | 875 // Run some implicit capture tests. |
| 868 MouseEventTest tests[] = { | 876 MouseEventTest tests[] = { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 // Setting the capture should clear the implicit pointers for the specified | 978 // Setting the capture should clear the implicit pointers for the specified |
| 971 // window. | 979 // window. |
| 972 dispatcher->SetCaptureWindow(root, true); | 980 dispatcher->SetCaptureWindow(root, true); |
| 973 EXPECT_FALSE(AreAnyPointersDown()); | 981 EXPECT_FALSE(AreAnyPointersDown()); |
| 974 EXPECT_FALSE(IsWindowPointerTarget(root)); | 982 EXPECT_FALSE(IsWindowPointerTarget(root)); |
| 975 } | 983 } |
| 976 | 984 |
| 977 // Tests that when explicit capture is changed, that the previous window with | 985 // Tests that when explicit capture is changed, that the previous window with |
| 978 // capture is no longer being observed. | 986 // capture is no longer being observed. |
| 979 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) { | 987 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) { |
| 980 scoped_ptr<ServerWindow> child1(CreateChildWindow(WindowId(1, 3))); | 988 scoped_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
| 981 scoped_ptr<ServerWindow> child2(CreateChildWindow(WindowId(1, 4))); | 989 scoped_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
| 982 | 990 |
| 983 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 991 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 984 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 992 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 985 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 993 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
| 986 | 994 |
| 987 EventDispatcher* dispatcher = event_dispatcher(); | 995 EventDispatcher* dispatcher = event_dispatcher(); |
| 988 ASSERT_FALSE(AreAnyPointersDown()); | 996 ASSERT_FALSE(AreAnyPointersDown()); |
| 989 ASSERT_FALSE(IsWindowPointerTarget(child1.get())); | 997 ASSERT_FALSE(IsWindowPointerTarget(child1.get())); |
| 990 ASSERT_FALSE(IsWindowPointerTarget(child2.get())); | 998 ASSERT_FALSE(IsWindowPointerTarget(child2.get())); |
| 991 dispatcher->SetCaptureWindow(child1.get(), false); | 999 dispatcher->SetCaptureWindow(child1.get(), false); |
| 992 dispatcher->SetCaptureWindow(child2.get(), false); | 1000 dispatcher->SetCaptureWindow(child2.get(), false); |
| 993 EXPECT_EQ(child1.get(), | 1001 EXPECT_EQ(child1.get(), |
| 994 test_event_dispatcher_delegate()->lost_capture_window()); | 1002 test_event_dispatcher_delegate()->lost_capture_window()); |
| 995 | 1003 |
| 996 // If observing does not stop during the capture update this crashes. | 1004 // If observing does not stop during the capture update this crashes. |
| 997 child1->AddObserver(dispatcher); | 1005 child1->AddObserver(dispatcher); |
| 998 } | 1006 } |
| 999 | 1007 |
| 1000 // Tests that destroying a window with explicit capture clears the capture | 1008 // Tests that destroying a window with explicit capture clears the capture |
| 1001 // state. | 1009 // state. |
| 1002 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) { | 1010 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) { |
| 1003 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 1011 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 1004 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1012 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1005 | 1013 |
| 1006 EventDispatcher* dispatcher = event_dispatcher(); | 1014 EventDispatcher* dispatcher = event_dispatcher(); |
| 1007 dispatcher->SetCaptureWindow(child.get(), false); | 1015 dispatcher->SetCaptureWindow(child.get(), false); |
| 1008 EXPECT_EQ(child.get(), dispatcher->capture_window()); | 1016 EXPECT_EQ(child.get(), dispatcher->capture_window()); |
| 1009 | 1017 |
| 1010 ServerWindow* lost_capture_window = child.get(); | 1018 ServerWindow* lost_capture_window = child.get(); |
| 1011 child.reset(); | 1019 child.reset(); |
| 1012 EXPECT_EQ(nullptr, dispatcher->capture_window()); | 1020 EXPECT_EQ(nullptr, dispatcher->capture_window()); |
| 1013 EXPECT_EQ(lost_capture_window, | 1021 EXPECT_EQ(lost_capture_window, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1035 | 1043 |
| 1036 // Events should target child and be in the client area. | 1044 // Events should target child and be in the client area. |
| 1037 scoped_ptr<DispatchedEventDetails> details = | 1045 scoped_ptr<DispatchedEventDetails> details = |
| 1038 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1046 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 1039 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 1047 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
| 1040 ASSERT_EQ(root, details->window); | 1048 ASSERT_EQ(root, details->window); |
| 1041 EXPECT_TRUE(details->in_nonclient_area); | 1049 EXPECT_TRUE(details->in_nonclient_area); |
| 1042 } | 1050 } |
| 1043 | 1051 |
| 1044 TEST_F(EventDispatcherTest, ProcessPointerEvents) { | 1052 TEST_F(EventDispatcherTest, ProcessPointerEvents) { |
| 1045 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 1053 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 1046 | 1054 |
| 1047 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1055 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1048 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1056 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1049 | 1057 |
| 1050 { | 1058 { |
| 1051 const ui::PointerEvent pointer_event(ui::MouseEvent( | 1059 const ui::PointerEvent pointer_event(ui::MouseEvent( |
| 1052 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), | 1060 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
| 1053 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1061 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1054 event_dispatcher()->ProcessEvent(pointer_event); | 1062 event_dispatcher()->ProcessEvent(pointer_event); |
| 1055 | 1063 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1082 ASSERT_TRUE(details->event->IsPointerEvent()); | 1090 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1083 | 1091 |
| 1084 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1092 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1085 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); | 1093 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); |
| 1086 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); | 1094 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); |
| 1087 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); | 1095 EXPECT_EQ(touch_id, dispatched_event->pointer_id()); |
| 1088 } | 1096 } |
| 1089 } | 1097 } |
| 1090 | 1098 |
| 1091 TEST_F(EventDispatcherTest, ResetClearsPointerDown) { | 1099 TEST_F(EventDispatcherTest, ResetClearsPointerDown) { |
| 1092 scoped_ptr<ServerWindow> child(CreateChildWindow(WindowId(1, 3))); | 1100 scoped_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
| 1093 | 1101 |
| 1094 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1102 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1095 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1103 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 1096 | 1104 |
| 1097 // Send event that is over child. | 1105 // Send event that is over child. |
| 1098 const ui::PointerEvent ui_event(ui::MouseEvent( | 1106 const ui::PointerEvent ui_event(ui::MouseEvent( |
| 1099 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), | 1107 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
| 1100 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1108 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1101 event_dispatcher()->ProcessEvent(ui_event); | 1109 event_dispatcher()->ProcessEvent(ui_event); |
| 1102 | 1110 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1118 | 1126 |
| 1119 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); | 1127 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); |
| 1120 EventDispatcher* dispatcher = event_dispatcher(); | 1128 EventDispatcher* dispatcher = event_dispatcher(); |
| 1121 dispatcher->SetCaptureWindow(root, true); | 1129 dispatcher->SetCaptureWindow(root, true); |
| 1122 | 1130 |
| 1123 event_dispatcher()->Reset(); | 1131 event_dispatcher()->Reset(); |
| 1124 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); | 1132 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
| 1125 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); | 1133 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
| 1126 } | 1134 } |
| 1127 | 1135 |
| 1136 // Tests that events on a modal parent target the modal child. |
| 1137 TEST_F(EventDispatcherTest, ModalWindowEventOnModalParent) { |
| 1138 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1139 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1140 |
| 1141 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1142 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1143 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1144 |
| 1145 w1->AddTransientWindow(w2.get()); |
| 1146 w2->SetModal(); |
| 1147 |
| 1148 // Send event that is over |w1|. |
| 1149 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1150 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
| 1151 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1152 event_dispatcher()->ProcessEvent(mouse_pressed); |
| 1153 |
| 1154 scoped_ptr<DispatchedEventDetails> details = |
| 1155 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1156 ASSERT_TRUE(details); |
| 1157 EXPECT_EQ(w2.get(), details->window); |
| 1158 EXPECT_TRUE(details->in_nonclient_area); |
| 1159 |
| 1160 ASSERT_TRUE(details->event); |
| 1161 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1162 |
| 1163 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1164 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); |
| 1165 EXPECT_EQ(gfx::Point(-35, 5), dispatched_event->location()); |
| 1166 } |
| 1167 |
| 1168 // Tests that events on a modal child target the modal child itself. |
| 1169 TEST_F(EventDispatcherTest, ModalWindowEventOnModalChild) { |
| 1170 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1171 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1172 |
| 1173 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1174 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1175 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1176 |
| 1177 w1->AddTransientWindow(w2.get()); |
| 1178 w2->SetModal(); |
| 1179 |
| 1180 // Send event that is over |w2|. |
| 1181 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1182 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15), |
| 1183 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1184 event_dispatcher()->ProcessEvent(mouse_pressed); |
| 1185 |
| 1186 scoped_ptr<DispatchedEventDetails> details = |
| 1187 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1188 ASSERT_TRUE(details); |
| 1189 EXPECT_EQ(w2.get(), details->window); |
| 1190 EXPECT_FALSE(details->in_nonclient_area); |
| 1191 |
| 1192 ASSERT_TRUE(details->event); |
| 1193 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1194 |
| 1195 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1196 EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location()); |
| 1197 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); |
| 1198 } |
| 1199 |
| 1200 // Tests that events on an unrelated window are not affected by the modal |
| 1201 // window. |
| 1202 TEST_F(EventDispatcherTest, ModalWindowEventOnUnrelatedWindow) { |
| 1203 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1204 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1205 scoped_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); |
| 1206 |
| 1207 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1208 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1209 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1210 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 1211 |
| 1212 w1->AddTransientWindow(w2.get()); |
| 1213 w2->SetModal(); |
| 1214 |
| 1215 // Send event that is over |w3|. |
| 1216 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1217 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15), |
| 1218 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1219 event_dispatcher()->ProcessEvent(mouse_pressed); |
| 1220 |
| 1221 scoped_ptr<DispatchedEventDetails> details = |
| 1222 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1223 ASSERT_TRUE(details); |
| 1224 EXPECT_EQ(w3.get(), details->window); |
| 1225 EXPECT_FALSE(details->in_nonclient_area); |
| 1226 |
| 1227 ASSERT_TRUE(details->event); |
| 1228 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1229 |
| 1230 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1231 EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location()); |
| 1232 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); |
| 1233 } |
| 1234 |
| 1235 // Tests that events events on a descendant of a modal parent target the modal |
| 1236 // child. |
| 1237 TEST_F(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) { |
| 1238 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1239 scoped_ptr<ServerWindow> w11 = |
| 1240 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
| 1241 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1242 |
| 1243 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1244 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1245 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 1246 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1247 |
| 1248 w1->AddTransientWindow(w2.get()); |
| 1249 w2->SetModal(); |
| 1250 |
| 1251 // Send event that is over |w11|. |
| 1252 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
| 1253 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25), |
| 1254 base::TimeDelta(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 1255 event_dispatcher()->ProcessEvent(mouse_pressed); |
| 1256 |
| 1257 scoped_ptr<DispatchedEventDetails> details = |
| 1258 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
| 1259 ASSERT_TRUE(details); |
| 1260 EXPECT_EQ(w2.get(), details->window); |
| 1261 EXPECT_TRUE(details->in_nonclient_area); |
| 1262 |
| 1263 ASSERT_TRUE(details->event); |
| 1264 ASSERT_TRUE(details->event->IsPointerEvent()); |
| 1265 |
| 1266 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
| 1267 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); |
| 1268 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); |
| 1269 } |
| 1270 |
| 1271 |
| 1272 // Tests that setting capture to a descendant of a modal parent fails. |
| 1273 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { |
| 1274 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1275 scoped_ptr<ServerWindow> w11 = |
| 1276 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
| 1277 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1278 |
| 1279 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1280 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1281 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
| 1282 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1283 |
| 1284 w1->AddTransientWindow(w2.get()); |
| 1285 w2->SetModal(); |
| 1286 |
| 1287 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), false)); |
| 1288 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
| 1289 } |
| 1290 |
| 1291 // Tests that setting capture to a window unrelated to a modal parent works. |
| 1292 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { |
| 1293 scoped_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
| 1294 scoped_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
| 1295 scoped_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); |
| 1296 |
| 1297 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1298 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 1299 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
| 1300 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
| 1301 |
| 1302 w1->AddTransientWindow(w2.get()); |
| 1303 w2->SetModal(); |
| 1304 |
| 1305 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), false)); |
| 1306 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); |
| 1307 } |
| 1308 |
| 1128 } // namespace test | 1309 } // namespace test |
| 1129 } // namespace ws | 1310 } // namespace ws |
| 1130 } // namespace mus | 1311 } // namespace mus |
| OLD | NEW |