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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/aura/mus/capture_synchronizer.h" | 24 #include "ui/aura/mus/capture_synchronizer.h" |
25 #include "ui/aura/mus/property_converter.h" | 25 #include "ui/aura/mus/property_converter.h" |
26 #include "ui/aura/mus/window_mus.h" | 26 #include "ui/aura/mus/window_mus.h" |
27 #include "ui/aura/mus/window_tree_client_delegate.h" | 27 #include "ui/aura/mus/window_tree_client_delegate.h" |
28 #include "ui/aura/mus/window_tree_client_observer.h" | 28 #include "ui/aura/mus/window_tree_client_observer.h" |
29 #include "ui/aura/mus/window_tree_host_mus.h" | 29 #include "ui/aura/mus/window_tree_host_mus.h" |
30 #include "ui/aura/test/aura_mus_test_base.h" | 30 #include "ui/aura/test/aura_mus_test_base.h" |
31 #include "ui/aura/test/mus/test_window_tree.h" | 31 #include "ui/aura/test/mus/test_window_tree.h" |
32 #include "ui/aura/test/mus/window_tree_client_private.h" | 32 #include "ui/aura/test/mus/window_tree_client_private.h" |
33 #include "ui/aura/test/test_window_delegate.h" | 33 #include "ui/aura/test/test_window_delegate.h" |
| 34 #include "ui/aura/test/test_window_targeter.h" |
34 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
| 36 #include "ui/aura/window_targeter.h" |
35 #include "ui/aura/window_tracker.h" | 37 #include "ui/aura/window_tracker.h" |
36 #include "ui/aura/window_tree_host_observer.h" | 38 #include "ui/aura/window_tree_host_observer.h" |
37 #include "ui/base/class_property.h" | 39 #include "ui/base/class_property.h" |
38 #include "ui/compositor/compositor.h" | 40 #include "ui/compositor/compositor.h" |
39 #include "ui/display/display.h" | 41 #include "ui/display/display.h" |
40 #include "ui/display/display_switches.h" | 42 #include "ui/display/display_switches.h" |
41 #include "ui/display/screen.h" | 43 #include "ui/display/screen.h" |
42 #include "ui/events/event.h" | 44 #include "ui/events/event.h" |
43 #include "ui/events/event_utils.h" | 45 #include "ui/events/event_utils.h" |
44 #include "ui/gfx/geometry/dip_util.h" | 46 #include "ui/gfx/geometry/dip_util.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // Simulate server changing back to original visible. Should take immediately. | 488 // Simulate server changing back to original visible. Should take immediately. |
487 window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()), | 489 window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()), |
488 original_visible); | 490 original_visible); |
489 EXPECT_EQ(original_visible, root_window()->TargetVisibility()); | 491 EXPECT_EQ(original_visible, root_window()->TargetVisibility()); |
490 } | 492 } |
491 | 493 |
492 namespace { | 494 namespace { |
493 | 495 |
494 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { | 496 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { |
495 public: | 497 public: |
496 static uint32_t constexpr kEventId = 1; | |
497 | |
498 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) | 498 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) |
499 : test_window_tree_(test_window_tree) {} | 499 : test_window_tree_(test_window_tree) {} |
500 ~InputEventBasicTestWindowDelegate() override {} | 500 ~InputEventBasicTestWindowDelegate() override {} |
501 | 501 |
502 bool got_move() const { return got_move_; } | 502 bool got_move() const { return got_move_; } |
503 bool was_acked() const { return was_acked_; } | 503 bool was_acked() const { return was_acked_; } |
504 const gfx::Point& last_event_location() const { return last_event_location_; } | 504 const gfx::Point& last_event_location() const { return last_event_location_; } |
| 505 void set_event_id(uint32_t event_id) { event_id_ = event_id; } |
505 | 506 |
506 // TestWindowDelegate:: | 507 // TestWindowDelegate:: |
507 void OnMouseEvent(ui::MouseEvent* event) override { | 508 void OnMouseEvent(ui::MouseEvent* event) override { |
508 was_acked_ = test_window_tree_->WasEventAcked(kEventId); | 509 was_acked_ = test_window_tree_->WasEventAcked(event_id_); |
509 if (event->type() == ui::ET_MOUSE_MOVED) | 510 if (event->type() == ui::ET_MOUSE_MOVED) |
510 got_move_ = true; | 511 got_move_ = true; |
511 last_event_location_ = event->location(); | 512 last_event_location_ = event->location(); |
512 event->SetHandled(); | 513 event->SetHandled(); |
513 } | 514 } |
514 | 515 |
| 516 void reset() { |
| 517 was_acked_ = false; |
| 518 got_move_ = false; |
| 519 last_event_location_ = gfx::Point(); |
| 520 event_id_ = 0; |
| 521 } |
| 522 |
515 private: | 523 private: |
516 TestWindowTree* test_window_tree_; | 524 TestWindowTree* test_window_tree_; |
517 bool was_acked_ = false; | 525 bool was_acked_ = false; |
518 bool got_move_ = false; | 526 bool got_move_ = false; |
519 gfx::Point last_event_location_; | 527 gfx::Point last_event_location_; |
| 528 uint32_t event_id_ = 0; |
520 | 529 |
521 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); | 530 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); |
522 }; | 531 }; |
523 | 532 |
524 } // namespace | 533 } // namespace |
525 | 534 |
526 TEST_F(WindowTreeClientClientTest, InputEventBasic) { | 535 TEST_F(WindowTreeClientClientTest, InputEventBasic) { |
527 InputEventBasicTestWindowDelegate window_delegate(window_tree()); | 536 InputEventBasicTestWindowDelegate window_delegate(window_tree()); |
528 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | 537 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
529 Window* top_level = window_tree_host.window(); | 538 Window* top_level = window_tree_host.window(); |
530 const gfx::Rect bounds(0, 0, 100, 100); | 539 const gfx::Rect bounds(0, 0, 100, 100); |
531 window_tree_host.SetBoundsInPixels(bounds); | 540 window_tree_host.SetBoundsInPixels(bounds); |
532 window_tree_host.InitHost(); | 541 window_tree_host.InitHost(); |
533 window_tree_host.Show(); | 542 window_tree_host.Show(); |
534 EXPECT_EQ(bounds, top_level->bounds()); | 543 EXPECT_EQ(bounds, top_level->bounds()); |
535 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); | 544 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
536 Window child(&window_delegate); | 545 Window child(&window_delegate); |
537 child.Init(ui::LAYER_NOT_DRAWN); | 546 child.Init(ui::LAYER_NOT_DRAWN); |
538 top_level->AddChild(&child); | 547 top_level->AddChild(&child); |
539 child.SetBounds(gfx::Rect(10, 10, 100, 100)); | 548 child.SetBounds(gfx::Rect(10, 10, 100, 100)); |
540 child.Show(); | 549 child.Show(); |
541 EXPECT_FALSE(window_delegate.got_move()); | 550 EXPECT_FALSE(window_delegate.got_move()); |
542 EXPECT_FALSE(window_delegate.was_acked()); | 551 EXPECT_FALSE(window_delegate.was_acked()); |
543 const gfx::Point event_location_in_child(2, 3); | 552 const gfx::Point event_location_in_child(2, 3); |
| 553 const uint32_t event_id = 1; |
| 554 window_delegate.set_event_id(event_id); |
544 std::unique_ptr<ui::Event> ui_event( | 555 std::unique_ptr<ui::Event> ui_event( |
545 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, | 556 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, |
546 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); | 557 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); |
547 window_tree_client()->OnWindowInputEvent( | 558 window_tree_client()->OnWindowInputEvent( |
548 InputEventBasicTestWindowDelegate::kEventId, server_id(&child), | 559 event_id, server_id(&child), window_tree_host.display_id(), |
549 window_tree_host.display_id(), ui::Event::Clone(*ui_event.get()), 0); | 560 ui::Event::Clone(*ui_event.get()), 0); |
550 EXPECT_TRUE(window_tree()->WasEventAcked( | 561 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
551 InputEventBasicTestWindowDelegate::kEventId)); | |
552 EXPECT_EQ(ui::mojom::EventResult::HANDLED, | 562 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
553 window_tree()->GetEventResult( | 563 window_tree()->GetEventResult(event_id)); |
554 InputEventBasicTestWindowDelegate::kEventId)); | |
555 EXPECT_TRUE(window_delegate.got_move()); | 564 EXPECT_TRUE(window_delegate.got_move()); |
556 EXPECT_FALSE(window_delegate.was_acked()); | 565 EXPECT_FALSE(window_delegate.was_acked()); |
557 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); | 566 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); |
558 } | 567 } |
559 | 568 |
| 569 TEST_F(WindowTreeClientClientTest, InputEventFindTargetAndConversion) { |
| 570 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 571 Window* top_level = window_tree_host.window(); |
| 572 const gfx::Rect bounds(0, 0, 100, 100); |
| 573 window_tree_host.SetBoundsInPixels(bounds); |
| 574 window_tree_host.InitHost(); |
| 575 window_tree_host.Show(); |
| 576 EXPECT_EQ(bounds, top_level->bounds()); |
| 577 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
| 578 InputEventBasicTestWindowDelegate window_delegate1(window_tree()); |
| 579 Window child1(&window_delegate1); |
| 580 child1.Init(ui::LAYER_NOT_DRAWN); |
| 581 child1.SetEventTargeter(base::MakeUnique<WindowTargeter>()); |
| 582 top_level->AddChild(&child1); |
| 583 child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 584 child1.Show(); |
| 585 InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| 586 Window child2(&window_delegate2); |
| 587 child2.Init(ui::LAYER_NOT_DRAWN); |
| 588 child1.AddChild(&child2); |
| 589 child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| 590 child2.Show(); |
| 591 |
| 592 EXPECT_FALSE(window_delegate1.got_move()); |
| 593 EXPECT_FALSE(window_delegate2.got_move()); |
| 594 |
| 595 // child1 has a targeter set and event_location is (50, 60), child2 |
| 596 // should get the event even though mus-ws wants to send to child1. |
| 597 const gfx::Point event_location(50, 60); |
| 598 uint32_t event_id = 1; |
| 599 window_delegate1.set_event_id(event_id); |
| 600 window_delegate2.set_event_id(event_id); |
| 601 std::unique_ptr<ui::Event> ui_event( |
| 602 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| 603 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 604 window_tree_client()->OnWindowInputEvent( |
| 605 event_id, server_id(&child1), window_tree_host.display_id(), |
| 606 ui::Event::Clone(*ui_event.get()), 0); |
| 607 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 608 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 609 window_tree()->GetEventResult(event_id)); |
| 610 EXPECT_FALSE(window_delegate1.got_move()); |
| 611 EXPECT_TRUE(window_delegate2.got_move()); |
| 612 EXPECT_EQ(gfx::Point(30, 30), window_delegate2.last_event_location()); |
| 613 window_delegate1.reset(); |
| 614 window_delegate2.reset(); |
| 615 |
| 616 // Remove the targeter for child1 and specify the event to go to child1. This |
| 617 // time child1 should receive the event not child2. |
| 618 child1.SetEventTargeter(nullptr); |
| 619 event_id = 2; |
| 620 window_delegate1.set_event_id(event_id); |
| 621 window_delegate2.set_event_id(event_id); |
| 622 std::unique_ptr<ui::Event> ui_event1( |
| 623 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| 624 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 625 window_tree_client()->OnWindowInputEvent( |
| 626 event_id, server_id(&child1), window_tree_host.display_id(), |
| 627 ui::Event::Clone(*ui_event1.get()), 0); |
| 628 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 629 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 630 window_tree()->GetEventResult(event_id)); |
| 631 EXPECT_TRUE(window_delegate1.got_move()); |
| 632 EXPECT_FALSE(window_delegate2.got_move()); |
| 633 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location()); |
| 634 } |
| 635 |
| 636 TEST_F(WindowTreeClientClientTest, InputEventCustomWindowTargeter) { |
| 637 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 638 Window* top_level = window_tree_host.window(); |
| 639 const gfx::Rect bounds(0, 0, 100, 100); |
| 640 window_tree_host.SetBoundsInPixels(bounds); |
| 641 window_tree_host.InitHost(); |
| 642 window_tree_host.Show(); |
| 643 EXPECT_EQ(bounds, top_level->bounds()); |
| 644 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
| 645 InputEventBasicTestWindowDelegate window_delegate1(window_tree()); |
| 646 Window child1(&window_delegate1); |
| 647 child1.Init(ui::LAYER_NOT_DRAWN); |
| 648 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>()); |
| 649 top_level->AddChild(&child1); |
| 650 child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 651 child1.Show(); |
| 652 InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| 653 Window child2(&window_delegate2); |
| 654 child2.Init(ui::LAYER_NOT_DRAWN); |
| 655 child1.AddChild(&child2); |
| 656 child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| 657 child2.Show(); |
| 658 |
| 659 EXPECT_FALSE(window_delegate1.got_move()); |
| 660 EXPECT_FALSE(window_delegate2.got_move()); |
| 661 |
| 662 // child1 has a custom targeter set which would always return itself as the |
| 663 // target window therefore event should go to child1 unlike |
| 664 // WindowTreeClientClientTest.InputEventFindTargetAndConversion. |
| 665 const gfx::Point event_location(50, 60); |
| 666 uint32_t event_id = 1; |
| 667 window_delegate1.set_event_id(event_id); |
| 668 window_delegate2.set_event_id(event_id); |
| 669 std::unique_ptr<ui::Event> ui_event( |
| 670 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| 671 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 672 window_tree_client()->OnWindowInputEvent( |
| 673 event_id, server_id(&child1), window_tree_host.display_id(), |
| 674 ui::Event::Clone(*ui_event.get()), 0); |
| 675 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 676 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 677 window_tree()->GetEventResult(event_id)); |
| 678 EXPECT_TRUE(window_delegate1.got_move()); |
| 679 EXPECT_FALSE(window_delegate2.got_move()); |
| 680 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location()); |
| 681 window_delegate1.reset(); |
| 682 window_delegate2.reset(); |
| 683 |
| 684 // child1 should get the event even though mus-ws specifies child2 and it's |
| 685 // actually in child2's space. Event location will be transformed. |
| 686 event_id = 2; |
| 687 window_delegate1.set_event_id(event_id); |
| 688 window_delegate2.set_event_id(event_id); |
| 689 window_tree_client()->OnWindowInputEvent( |
| 690 event_id, server_id(&child2), window_tree_host.display_id(), |
| 691 ui::Event::Clone(*ui_event.get()), 0); |
| 692 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 693 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 694 window_tree()->GetEventResult(event_id)); |
| 695 EXPECT_TRUE(window_delegate1.got_move()); |
| 696 EXPECT_FALSE(window_delegate2.got_move()); |
| 697 EXPECT_EQ(gfx::Point(70, 90), window_delegate1.last_event_location()); |
| 698 } |
| 699 |
560 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { | 700 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
561 public: | 701 public: |
562 WindowTreeClientPointerObserverTest() {} | 702 WindowTreeClientPointerObserverTest() {} |
563 ~WindowTreeClientPointerObserverTest() override {} | 703 ~WindowTreeClientPointerObserverTest() override {} |
564 | 704 |
565 void DeleteLastEventObserved() { last_event_observed_.reset(); } | 705 void DeleteLastEventObserved() { last_event_observed_.reset(); } |
566 const ui::PointerEvent* last_event_observed() const { | 706 const ui::PointerEvent* last_event_observed() const { |
567 return last_event_observed_.get(); | 707 return last_event_observed_.get(); |
568 } | 708 } |
569 | 709 |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); | 1721 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); |
1582 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 1722 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
1583 display_id, true); | 1723 display_id, true); |
1584 | 1724 |
1585 // aura::Window should operate in DIP and aura::WindowTreeHost should operate | 1725 // aura::Window should operate in DIP and aura::WindowTreeHost should operate |
1586 // in pixels. | 1726 // in pixels. |
1587 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); | 1727 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); |
1588 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); | 1728 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); |
1589 } | 1729 } |
1590 | 1730 |
1591 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDips) { | 1731 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDip) { |
1592 display::Screen* screen = display::Screen::GetScreen(); | 1732 display::Screen* screen = display::Screen::GetScreen(); |
1593 const display::Display primary_display = screen->GetPrimaryDisplay(); | 1733 const display::Display primary_display = screen->GetPrimaryDisplay(); |
1594 ASSERT_EQ(2.0f, primary_display.device_scale_factor()); | 1734 ASSERT_EQ(2.0f, primary_display.device_scale_factor()); |
1595 | 1735 |
1596 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); | 1736 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); |
1597 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 1737 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
1598 top_level->Init(ui::LAYER_NOT_DRAWN); | 1738 top_level->Init(ui::LAYER_NOT_DRAWN); |
1599 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1739 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1600 top_level->Show(); | 1740 top_level->Show(); |
1601 | 1741 |
(...skipping 13 matching lines...) Expand all Loading... |
1615 | 1755 |
1616 // Delegate received the event in Dips. | 1756 // Delegate received the event in Dips. |
1617 const ui::PointerEvent* last_event = last_event_observed(); | 1757 const ui::PointerEvent* last_event = last_event_observed(); |
1618 ASSERT_TRUE(last_event); | 1758 ASSERT_TRUE(last_event); |
1619 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), | 1759 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), |
1620 last_event->location()); | 1760 last_event->location()); |
1621 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), | 1761 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), |
1622 last_event->root_location()); | 1762 last_event->root_location()); |
1623 } | 1763 } |
1624 | 1764 |
| 1765 TEST_F(WindowTreeClientClientTestHighDPI, InputEventsInDip) { |
| 1766 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 1767 display::Screen* screen = display::Screen::GetScreen(); |
| 1768 display::Display display; |
| 1769 ASSERT_TRUE( |
| 1770 screen->GetDisplayWithDisplayId(window_tree_host.display_id(), &display)); |
| 1771 ASSERT_EQ(2.0f, display.device_scale_factor()); |
| 1772 |
| 1773 Window* top_level = window_tree_host.window(); |
| 1774 const gfx::Rect bounds_in_pixels(0, 0, 100, 100); |
| 1775 window_tree_host.SetBoundsInPixels(bounds_in_pixels); |
| 1776 window_tree_host.InitHost(); |
| 1777 window_tree_host.Show(); |
| 1778 EXPECT_EQ(gfx::ConvertRectToDIP(2.0f, bounds_in_pixels), top_level->bounds()); |
| 1779 EXPECT_EQ(bounds_in_pixels, window_tree_host.GetBoundsInPixels()); |
| 1780 |
| 1781 InputEventBasicTestWindowDelegate window_delegate1(window_tree()); |
| 1782 Window child1(&window_delegate1); |
| 1783 child1.Init(ui::LAYER_NOT_DRAWN); |
| 1784 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>()); |
| 1785 top_level->AddChild(&child1); |
| 1786 child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 1787 child1.Show(); |
| 1788 InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| 1789 Window child2(&window_delegate2); |
| 1790 child2.Init(ui::LAYER_NOT_DRAWN); |
| 1791 child1.AddChild(&child2); |
| 1792 child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| 1793 child2.Show(); |
| 1794 |
| 1795 EXPECT_FALSE(window_delegate1.got_move()); |
| 1796 EXPECT_FALSE(window_delegate2.got_move()); |
| 1797 |
| 1798 // child1 has a custom targeter set which would always return itself as the |
| 1799 // target window therefore event should go to child1 and should be in dip. |
| 1800 const gfx::Point event_location_in_pixels(50, 60); |
| 1801 uint32_t event_id = 1; |
| 1802 window_delegate1.set_event_id(event_id); |
| 1803 window_delegate2.set_event_id(event_id); |
| 1804 std::unique_ptr<ui::Event> ui_event( |
| 1805 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_pixels, |
| 1806 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 1807 window_tree_client()->OnWindowInputEvent( |
| 1808 event_id, server_id(&child1), window_tree_host.display_id(), |
| 1809 ui::Event::Clone(*ui_event.get()), 0); |
| 1810 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 1811 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 1812 window_tree()->GetEventResult(event_id)); |
| 1813 EXPECT_TRUE(window_delegate1.got_move()); |
| 1814 EXPECT_FALSE(window_delegate2.got_move()); |
| 1815 const gfx::Point event_location_in_dip(25, 30); |
| 1816 EXPECT_EQ(event_location_in_dip, window_delegate1.last_event_location()); |
| 1817 window_delegate1.reset(); |
| 1818 window_delegate2.reset(); |
| 1819 |
| 1820 // Event location will be transformed and should be in dip. |
| 1821 event_id = 2; |
| 1822 window_delegate1.set_event_id(event_id); |
| 1823 window_delegate2.set_event_id(event_id); |
| 1824 window_tree_client()->OnWindowInputEvent( |
| 1825 event_id, server_id(&child2), window_tree_host.display_id(), |
| 1826 ui::Event::Clone(*ui_event.get()), 0); |
| 1827 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 1828 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 1829 window_tree()->GetEventResult(event_id)); |
| 1830 EXPECT_TRUE(window_delegate1.got_move()); |
| 1831 EXPECT_FALSE(window_delegate2.got_move()); |
| 1832 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, |
| 1833 event_location_in_dip.y() + 30); |
| 1834 EXPECT_EQ(transformed_event_location_in_dip, |
| 1835 window_delegate1.last_event_location()); |
| 1836 } |
| 1837 |
1625 } // namespace aura | 1838 } // namespace aura |
OLD | NEW |