| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/common/wm_shell.h" | 5 #include "ash/common/wm_shell.h" |
| 6 #include "ash/public/cpp/shell_window_ids.h" | 6 #include "ash/public/cpp/shell_window_ids.h" |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ash/test/test_activation_delegate.h" | 9 #include "ash/test/test_activation_delegate.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 aura::WindowTreeHost* host = root_window->GetHost(); | 491 aura::WindowTreeHost* host = root_window->GetHost(); |
| 492 ui::EventSink* sink = host->event_sink(); | 492 ui::EventSink* sink = host->event_sink(); |
| 493 | 493 |
| 494 // Cursor starts as a pointer (set during Shell::Init()). | 494 // Cursor starts as a pointer (set during Shell::Init()). |
| 495 EXPECT_EQ(ui::kCursorPointer, host->last_cursor().native_type()); | 495 EXPECT_EQ(ui::kCursorPointer, host->last_cursor().native_type()); |
| 496 | 496 |
| 497 { | 497 { |
| 498 // Resize edges and corners show proper cursors. | 498 // Resize edges and corners show proper cursors. |
| 499 window_delegate.set_hittest_code(HTBOTTOM); | 499 window_delegate.set_hittest_code(HTBOTTOM); |
| 500 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, | 500 ui::MouseEvent move1( |
| 501 ui::EventTimeForNow(), 0, 0); | 501 ui::ET_MOUSE_MOVED, point1, point1, ui::EventTimeForNow(), 0, 0, |
| 502 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 502 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); | 503 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); |
| 503 ASSERT_FALSE(details.dispatcher_destroyed); | 504 ASSERT_FALSE(details.dispatcher_destroyed); |
| 504 EXPECT_EQ(ui::kCursorSouthResize, host->last_cursor().native_type()); | 505 EXPECT_EQ(ui::kCursorSouthResize, host->last_cursor().native_type()); |
| 505 } | 506 } |
| 506 | 507 |
| 507 { | 508 { |
| 508 window_delegate.set_hittest_code(HTBOTTOMLEFT); | 509 window_delegate.set_hittest_code(HTBOTTOMLEFT); |
| 509 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, | 510 ui::MouseEvent move2( |
| 510 ui::EventTimeForNow(), 0, 0); | 511 ui::ET_MOUSE_MOVED, point2, point2, ui::EventTimeForNow(), 0, 0, |
| 512 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 511 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); | 513 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); |
| 512 ASSERT_FALSE(details.dispatcher_destroyed); | 514 ASSERT_FALSE(details.dispatcher_destroyed); |
| 513 EXPECT_EQ(ui::kCursorSouthWestResize, host->last_cursor().native_type()); | 515 EXPECT_EQ(ui::kCursorSouthWestResize, host->last_cursor().native_type()); |
| 514 } | 516 } |
| 515 | 517 |
| 516 { | 518 { |
| 517 window_delegate.set_hittest_code(HTBOTTOMRIGHT); | 519 window_delegate.set_hittest_code(HTBOTTOMRIGHT); |
| 518 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, | 520 ui::MouseEvent move1( |
| 519 ui::EventTimeForNow(), 0, 0); | 521 ui::ET_MOUSE_MOVED, point1, point1, ui::EventTimeForNow(), 0, 0, |
| 522 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 520 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); | 523 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); |
| 521 ASSERT_FALSE(details.dispatcher_destroyed); | 524 ASSERT_FALSE(details.dispatcher_destroyed); |
| 522 EXPECT_EQ(ui::kCursorSouthEastResize, host->last_cursor().native_type()); | 525 EXPECT_EQ(ui::kCursorSouthEastResize, host->last_cursor().native_type()); |
| 523 } | 526 } |
| 524 | 527 |
| 525 { | 528 { |
| 526 window_delegate.set_hittest_code(HTLEFT); | 529 window_delegate.set_hittest_code(HTLEFT); |
| 527 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, | 530 ui::MouseEvent move2( |
| 528 ui::EventTimeForNow(), 0, 0); | 531 ui::ET_MOUSE_MOVED, point2, point2, ui::EventTimeForNow(), 0, 0, |
| 532 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 529 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); | 533 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); |
| 530 ASSERT_FALSE(details.dispatcher_destroyed); | 534 ASSERT_FALSE(details.dispatcher_destroyed); |
| 531 EXPECT_EQ(ui::kCursorWestResize, host->last_cursor().native_type()); | 535 EXPECT_EQ(ui::kCursorWestResize, host->last_cursor().native_type()); |
| 532 } | 536 } |
| 533 | 537 |
| 534 { | 538 { |
| 535 window_delegate.set_hittest_code(HTRIGHT); | 539 window_delegate.set_hittest_code(HTRIGHT); |
| 536 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, | 540 ui::MouseEvent move1( |
| 537 ui::EventTimeForNow(), 0, 0); | 541 ui::ET_MOUSE_MOVED, point1, point1, ui::EventTimeForNow(), 0, 0, |
| 542 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 538 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); | 543 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); |
| 539 ASSERT_FALSE(details.dispatcher_destroyed); | 544 ASSERT_FALSE(details.dispatcher_destroyed); |
| 540 EXPECT_EQ(ui::kCursorEastResize, host->last_cursor().native_type()); | 545 EXPECT_EQ(ui::kCursorEastResize, host->last_cursor().native_type()); |
| 541 } | 546 } |
| 542 | 547 |
| 543 { | 548 { |
| 544 window_delegate.set_hittest_code(HTTOP); | 549 window_delegate.set_hittest_code(HTTOP); |
| 545 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, | 550 ui::MouseEvent move2( |
| 546 ui::EventTimeForNow(), 0, 0); | 551 ui::ET_MOUSE_MOVED, point2, point2, ui::EventTimeForNow(), 0, 0, |
| 552 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 547 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); | 553 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); |
| 548 ASSERT_FALSE(details.dispatcher_destroyed); | 554 ASSERT_FALSE(details.dispatcher_destroyed); |
| 549 EXPECT_EQ(ui::kCursorNorthResize, host->last_cursor().native_type()); | 555 EXPECT_EQ(ui::kCursorNorthResize, host->last_cursor().native_type()); |
| 550 } | 556 } |
| 551 | 557 |
| 552 { | 558 { |
| 553 window_delegate.set_hittest_code(HTTOPLEFT); | 559 window_delegate.set_hittest_code(HTTOPLEFT); |
| 554 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, | 560 ui::MouseEvent move1( |
| 555 ui::EventTimeForNow(), 0, 0); | 561 ui::ET_MOUSE_MOVED, point1, point1, ui::EventTimeForNow(), 0, 0, |
| 562 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 556 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); | 563 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); |
| 557 ASSERT_FALSE(details.dispatcher_destroyed); | 564 ASSERT_FALSE(details.dispatcher_destroyed); |
| 558 EXPECT_EQ(ui::kCursorNorthWestResize, host->last_cursor().native_type()); | 565 EXPECT_EQ(ui::kCursorNorthWestResize, host->last_cursor().native_type()); |
| 559 } | 566 } |
| 560 | 567 |
| 561 { | 568 { |
| 562 window_delegate.set_hittest_code(HTTOPRIGHT); | 569 window_delegate.set_hittest_code(HTTOPRIGHT); |
| 563 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, | 570 ui::MouseEvent move2( |
| 564 ui::EventTimeForNow(), 0, 0); | 571 ui::ET_MOUSE_MOVED, point2, point2, ui::EventTimeForNow(), 0, 0, |
| 572 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 565 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); | 573 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2); |
| 566 ASSERT_FALSE(details.dispatcher_destroyed); | 574 ASSERT_FALSE(details.dispatcher_destroyed); |
| 567 EXPECT_EQ(ui::kCursorNorthEastResize, host->last_cursor().native_type()); | 575 EXPECT_EQ(ui::kCursorNorthEastResize, host->last_cursor().native_type()); |
| 568 } | 576 } |
| 569 | 577 |
| 570 { | 578 { |
| 571 // Client area uses null cursor. | 579 // Client area uses null cursor. |
| 572 window_delegate.set_hittest_code(HTCLIENT); | 580 window_delegate.set_hittest_code(HTCLIENT); |
| 573 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, | 581 ui::MouseEvent move1( |
| 574 ui::EventTimeForNow(), 0, 0); | 582 ui::ET_MOUSE_MOVED, point1, point1, ui::EventTimeForNow(), 0, 0, |
| 583 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 575 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); | 584 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1); |
| 576 ASSERT_FALSE(details.dispatcher_destroyed); | 585 ASSERT_FALSE(details.dispatcher_destroyed); |
| 577 EXPECT_EQ(ui::kCursorNull, host->last_cursor().native_type()); | 586 EXPECT_EQ(ui::kCursorNull, host->last_cursor().native_type()); |
| 578 } | 587 } |
| 579 } | 588 } |
| 580 | 589 |
| 581 TEST_F(WindowManagerTest, TransformActivate) { | 590 TEST_F(WindowManagerTest, TransformActivate) { |
| 582 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 591 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 583 gfx::Size size = root_window->bounds().size(); | 592 gfx::Size size = root_window->bounds().size(); |
| 584 EXPECT_EQ(gfx::Rect(size).ToString(), | 593 EXPECT_EQ(gfx::Rect(size).ToString(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 595 | 604 |
| 596 test::TestActivationDelegate d1; | 605 test::TestActivationDelegate d1; |
| 597 aura::test::TestWindowDelegate wd; | 606 aura::test::TestWindowDelegate wd; |
| 598 std::unique_ptr<aura::Window> w1( | 607 std::unique_ptr<aura::Window> w1( |
| 599 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50))); | 608 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50))); |
| 600 d1.SetWindow(w1.get()); | 609 d1.SetWindow(w1.get()); |
| 601 w1->Show(); | 610 w1->Show(); |
| 602 | 611 |
| 603 gfx::Point miss_point(5, 5); | 612 gfx::Point miss_point(5, 5); |
| 604 transform.TransformPoint(&miss_point); | 613 transform.TransformPoint(&miss_point); |
| 605 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, miss_point, miss_point, | 614 ui::MouseEvent mouseev1( |
| 606 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 615 ui::ET_MOUSE_PRESSED, miss_point, miss_point, ui::EventTimeForNow(), |
| 607 ui::EF_LEFT_MOUSE_BUTTON); | 616 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 617 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 608 ui::EventSink* sink = root_window->GetHost()->event_sink(); | 618 ui::EventSink* sink = root_window->GetHost()->event_sink(); |
| 609 ui::EventDispatchDetails details = sink->OnEventFromSource(&mouseev1); | 619 ui::EventDispatchDetails details = sink->OnEventFromSource(&mouseev1); |
| 610 ASSERT_FALSE(details.dispatcher_destroyed); | 620 ASSERT_FALSE(details.dispatcher_destroyed); |
| 611 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); | 621 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); |
| 612 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, miss_point, miss_point, | 622 ui::MouseEvent mouseup( |
| 613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 623 ui::ET_MOUSE_RELEASED, miss_point, miss_point, ui::EventTimeForNow(), |
| 614 ui::EF_LEFT_MOUSE_BUTTON); | 624 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 625 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 615 details = sink->OnEventFromSource(&mouseup); | 626 details = sink->OnEventFromSource(&mouseup); |
| 616 ASSERT_FALSE(details.dispatcher_destroyed); | 627 ASSERT_FALSE(details.dispatcher_destroyed); |
| 617 | 628 |
| 618 gfx::Point hit_point(5, 15); | 629 gfx::Point hit_point(5, 15); |
| 619 transform.TransformPoint(&hit_point); | 630 transform.TransformPoint(&hit_point); |
| 620 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, hit_point, hit_point, | 631 ui::MouseEvent mouseev2( |
| 621 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 632 ui::ET_MOUSE_PRESSED, hit_point, hit_point, ui::EventTimeForNow(), |
| 622 ui::EF_LEFT_MOUSE_BUTTON); | 633 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 634 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 623 details = sink->OnEventFromSource(&mouseev2); | 635 details = sink->OnEventFromSource(&mouseev2); |
| 624 ASSERT_FALSE(details.dispatcher_destroyed); | 636 ASSERT_FALSE(details.dispatcher_destroyed); |
| 625 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 637 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 626 EXPECT_EQ(w1.get(), | 638 EXPECT_EQ(w1.get(), |
| 627 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); | 639 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); |
| 628 } | 640 } |
| 629 | 641 |
| 630 TEST_F(WindowManagerTest, AdditionalFilters) { | 642 TEST_F(WindowManagerTest, AdditionalFilters) { |
| 631 // The IME event filter interferes with the basic key event propagation we | 643 // The IME event filter interferes with the basic key event propagation we |
| 632 // attempt to do here, so we disable it. | 644 // attempt to do here, so we disable it. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 645 // Adds them to root window event filter. | 657 // Adds them to root window event filter. |
| 646 ::wm::CompoundEventFilter* env_filter = Shell::GetInstance()->env_filter(); | 658 ::wm::CompoundEventFilter* env_filter = Shell::GetInstance()->env_filter(); |
| 647 env_filter->AddHandler(f1.get()); | 659 env_filter->AddHandler(f1.get()); |
| 648 env_filter->AddHandler(f2.get()); | 660 env_filter->AddHandler(f2.get()); |
| 649 | 661 |
| 650 // Dispatches mouse and keyboard events. | 662 // Dispatches mouse and keyboard events. |
| 651 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 663 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 652 ui::EventSink* sink = root_window->GetHost()->event_sink(); | 664 ui::EventSink* sink = root_window->GetHost()->event_sink(); |
| 653 ui::EventDispatchDetails details = sink->OnEventFromSource(&key_event); | 665 ui::EventDispatchDetails details = sink->OnEventFromSource(&key_event); |
| 654 ASSERT_FALSE(details.dispatcher_destroyed); | 666 ASSERT_FALSE(details.dispatcher_destroyed); |
| 655 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 667 ui::MouseEvent mouse_pressed( |
| 656 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); | 668 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 669 ui::EventTimeForNow(), 0, 0, |
| 670 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 657 details = sink->OnEventFromSource(&mouse_pressed); | 671 details = sink->OnEventFromSource(&mouse_pressed); |
| 658 ASSERT_FALSE(details.dispatcher_destroyed); | 672 ASSERT_FALSE(details.dispatcher_destroyed); |
| 659 | 673 |
| 660 // Both filters should get the events. | 674 // Both filters should get the events. |
| 661 EXPECT_EQ(1, f1->num_key_events()); | 675 EXPECT_EQ(1, f1->num_key_events()); |
| 662 EXPECT_EQ(1, f1->num_mouse_events()); | 676 EXPECT_EQ(1, f1->num_mouse_events()); |
| 663 EXPECT_EQ(1, f2->num_key_events()); | 677 EXPECT_EQ(1, f2->num_key_events()); |
| 664 EXPECT_EQ(1, f2->num_mouse_events()); | 678 EXPECT_EQ(1, f2->num_mouse_events()); |
| 665 | 679 |
| 666 f1->Reset(); | 680 f1->Reset(); |
| 667 f2->Reset(); | 681 f2->Reset(); |
| 668 | 682 |
| 669 // Makes f1 consume events. | 683 // Makes f1 consume events. |
| 670 f1->set_key_event_handling_result(ui::ER_CONSUMED); | 684 f1->set_key_event_handling_result(ui::ER_CONSUMED); |
| 671 f1->set_mouse_event_handling_result(ui::ER_CONSUMED); | 685 f1->set_mouse_event_handling_result(ui::ER_CONSUMED); |
| 672 | 686 |
| 673 // Dispatches events. | 687 // Dispatches events. |
| 674 details = sink->OnEventFromSource(&key_event); | 688 details = sink->OnEventFromSource(&key_event); |
| 675 ASSERT_FALSE(details.dispatcher_destroyed); | 689 ASSERT_FALSE(details.dispatcher_destroyed); |
| 676 ui::MouseEvent mouse_released(ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), | 690 ui::MouseEvent mouse_released( |
| 677 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); | 691 ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), |
| 692 ui::EventTimeForNow(), 0, 0, |
| 693 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 678 details = sink->OnEventFromSource(&mouse_released); | 694 details = sink->OnEventFromSource(&mouse_released); |
| 679 ASSERT_FALSE(details.dispatcher_destroyed); | 695 ASSERT_FALSE(details.dispatcher_destroyed); |
| 680 | 696 |
| 681 // f1 should still get the events but f2 no longer gets them. | 697 // f1 should still get the events but f2 no longer gets them. |
| 682 EXPECT_EQ(1, f1->num_key_events()); | 698 EXPECT_EQ(1, f1->num_key_events()); |
| 683 EXPECT_EQ(1, f1->num_mouse_events()); | 699 EXPECT_EQ(1, f1->num_mouse_events()); |
| 684 EXPECT_EQ(0, f2->num_key_events()); | 700 EXPECT_EQ(0, f2->num_key_events()); |
| 685 EXPECT_EQ(0, f2->num_mouse_events()); | 701 EXPECT_EQ(0, f2->num_mouse_events()); |
| 686 | 702 |
| 687 f1->Reset(); | 703 f1->Reset(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 observer_b.reset(); | 872 observer_b.reset(); |
| 857 generator.MoveMouseTo(50, 50); | 873 generator.MoveMouseTo(50, 50); |
| 858 EXPECT_TRUE(observer_a.did_visibility_change()); | 874 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 859 EXPECT_FALSE(observer_b.did_visibility_change()); | 875 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 860 EXPECT_TRUE(observer_a.is_cursor_visible()); | 876 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 861 | 877 |
| 862 cursor_manager->RemoveObserver(&observer_a); | 878 cursor_manager->RemoveObserver(&observer_a); |
| 863 } | 879 } |
| 864 | 880 |
| 865 } // namespace ash | 881 } // namespace ash |
| OLD | NEW |