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_delegate1.was_acked()); |
| 594 EXPECT_FALSE(window_delegate2.got_move()); |
| 595 EXPECT_FALSE(window_delegate2.was_acked()); |
| 596 |
| 597 // child1 has a targeter set and event_location is (50, 60), child2 |
| 598 // should get the event even though mus-ws wants to send to child1. |
| 599 const gfx::Point event_location(50, 60); |
| 600 uint32_t event_id = 1; |
| 601 window_delegate1.set_event_id(event_id); |
| 602 window_delegate2.set_event_id(event_id); |
| 603 std::unique_ptr<ui::Event> ui_event( |
| 604 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| 605 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 606 window_tree_client()->OnWindowInputEvent( |
| 607 event_id, server_id(&child1), window_tree_host.display_id(), |
| 608 ui::Event::Clone(*ui_event.get()), 0); |
| 609 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 610 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 611 window_tree()->GetEventResult(event_id)); |
| 612 EXPECT_FALSE(window_delegate1.got_move()); |
| 613 EXPECT_FALSE(window_delegate1.was_acked()); |
| 614 EXPECT_TRUE(window_delegate2.got_move()); |
| 615 EXPECT_FALSE(window_delegate2.was_acked()); |
| 616 EXPECT_EQ(gfx::Point(30, 30), window_delegate2.last_event_location()); |
| 617 window_delegate1.reset(); |
| 618 window_delegate2.reset(); |
| 619 |
| 620 // Remove the targeter for child1 and specify the event to go to child1. This |
| 621 // time child1 should receive the event not child2. |
| 622 child1.SetEventTargeter(nullptr); |
| 623 event_id = 2; |
| 624 window_delegate1.set_event_id(event_id); |
| 625 window_delegate2.set_event_id(event_id); |
| 626 std::unique_ptr<ui::Event> ui_event1( |
| 627 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| 628 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 629 window_tree_client()->OnWindowInputEvent( |
| 630 event_id, server_id(&child1), window_tree_host.display_id(), |
| 631 ui::Event::Clone(*ui_event1.get()), 0); |
| 632 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 633 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 634 window_tree()->GetEventResult(event_id)); |
| 635 EXPECT_TRUE(window_delegate1.got_move()); |
| 636 EXPECT_FALSE(window_delegate1.was_acked()); |
| 637 EXPECT_FALSE(window_delegate2.got_move()); |
| 638 EXPECT_FALSE(window_delegate2.was_acked()); |
| 639 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location()); |
| 640 } |
| 641 |
| 642 TEST_F(WindowTreeClientClientTest, InputEventCustomWindowTargeter) { |
| 643 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 644 Window* top_level = window_tree_host.window(); |
| 645 const gfx::Rect bounds(0, 0, 100, 100); |
| 646 window_tree_host.SetBoundsInPixels(bounds); |
| 647 window_tree_host.InitHost(); |
| 648 window_tree_host.Show(); |
| 649 EXPECT_EQ(bounds, top_level->bounds()); |
| 650 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); |
| 651 InputEventBasicTestWindowDelegate window_delegate1(window_tree()); |
| 652 Window child1(&window_delegate1); |
| 653 child1.Init(ui::LAYER_NOT_DRAWN); |
| 654 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>()); |
| 655 top_level->AddChild(&child1); |
| 656 child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 657 child1.Show(); |
| 658 InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| 659 Window child2(&window_delegate2); |
| 660 child2.Init(ui::LAYER_NOT_DRAWN); |
| 661 child1.AddChild(&child2); |
| 662 child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| 663 child2.Show(); |
| 664 |
| 665 EXPECT_FALSE(window_delegate1.got_move()); |
| 666 EXPECT_FALSE(window_delegate1.was_acked()); |
| 667 EXPECT_FALSE(window_delegate2.got_move()); |
| 668 EXPECT_FALSE(window_delegate2.was_acked()); |
| 669 |
| 670 // child1 has a custom targeter set which would always return itself as the |
| 671 // target window therefore event should go to child1 unlike |
| 672 // WindowTreeClientClientTest.InputEventFindTargetAndConversion. |
| 673 const gfx::Point event_location(50, 60); |
| 674 uint32_t event_id = 1; |
| 675 window_delegate1.set_event_id(event_id); |
| 676 window_delegate2.set_event_id(event_id); |
| 677 std::unique_ptr<ui::Event> ui_event( |
| 678 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location, gfx::Point(), |
| 679 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 680 window_tree_client()->OnWindowInputEvent( |
| 681 event_id, server_id(&child1), window_tree_host.display_id(), |
| 682 ui::Event::Clone(*ui_event.get()), 0); |
| 683 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 684 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 685 window_tree()->GetEventResult(event_id)); |
| 686 EXPECT_TRUE(window_delegate1.got_move()); |
| 687 EXPECT_FALSE(window_delegate1.was_acked()); |
| 688 EXPECT_FALSE(window_delegate2.got_move()); |
| 689 EXPECT_FALSE(window_delegate2.was_acked()); |
| 690 EXPECT_EQ(gfx::Point(50, 60), window_delegate1.last_event_location()); |
| 691 window_delegate1.reset(); |
| 692 window_delegate2.reset(); |
| 693 |
| 694 // child1 should get the event even though mus-ws specifies child2 and it's |
| 695 // actually in child2's space. Event location will be transformed. |
| 696 event_id = 2; |
| 697 window_delegate1.set_event_id(event_id); |
| 698 window_delegate2.set_event_id(event_id); |
| 699 window_tree_client()->OnWindowInputEvent( |
| 700 event_id, server_id(&child2), window_tree_host.display_id(), |
| 701 ui::Event::Clone(*ui_event.get()), 0); |
| 702 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 703 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 704 window_tree()->GetEventResult(event_id)); |
| 705 EXPECT_TRUE(window_delegate1.got_move()); |
| 706 EXPECT_FALSE(window_delegate1.was_acked()); |
| 707 EXPECT_FALSE(window_delegate2.got_move()); |
| 708 EXPECT_FALSE(window_delegate2.was_acked()); |
| 709 EXPECT_EQ(gfx::Point(70, 90), window_delegate1.last_event_location()); |
| 710 } |
| 711 |
560 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { | 712 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { |
561 public: | 713 public: |
562 WindowTreeClientPointerObserverTest() {} | 714 WindowTreeClientPointerObserverTest() {} |
563 ~WindowTreeClientPointerObserverTest() override {} | 715 ~WindowTreeClientPointerObserverTest() override {} |
564 | 716 |
565 void DeleteLastEventObserved() { last_event_observed_.reset(); } | 717 void DeleteLastEventObserved() { last_event_observed_.reset(); } |
566 const ui::PointerEvent* last_event_observed() const { | 718 const ui::PointerEvent* last_event_observed() const { |
567 return last_event_observed_.get(); | 719 return last_event_observed_.get(); |
568 } | 720 } |
569 | 721 |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); | 1733 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); |
1582 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 1734 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
1583 display_id, true); | 1735 display_id, true); |
1584 | 1736 |
1585 // aura::Window should operate in DIP and aura::WindowTreeHost should operate | 1737 // aura::Window should operate in DIP and aura::WindowTreeHost should operate |
1586 // in pixels. | 1738 // in pixels. |
1587 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); | 1739 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); |
1588 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); | 1740 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); |
1589 } | 1741 } |
1590 | 1742 |
1591 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDips) { | 1743 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDip) { |
1592 display::Screen* screen = display::Screen::GetScreen(); | 1744 display::Screen* screen = display::Screen::GetScreen(); |
1593 const display::Display primary_display = screen->GetPrimaryDisplay(); | 1745 const display::Display primary_display = screen->GetPrimaryDisplay(); |
1594 ASSERT_EQ(2.0f, primary_display.device_scale_factor()); | 1746 ASSERT_EQ(2.0f, primary_display.device_scale_factor()); |
1595 | 1747 |
1596 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); | 1748 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); |
1597 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 1749 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
1598 top_level->Init(ui::LAYER_NOT_DRAWN); | 1750 top_level->Init(ui::LAYER_NOT_DRAWN); |
1599 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1751 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1600 top_level->Show(); | 1752 top_level->Show(); |
1601 | 1753 |
(...skipping 13 matching lines...) Expand all Loading... |
1615 | 1767 |
1616 // Delegate received the event in Dips. | 1768 // Delegate received the event in Dips. |
1617 const ui::PointerEvent* last_event = last_event_observed(); | 1769 const ui::PointerEvent* last_event = last_event_observed(); |
1618 ASSERT_TRUE(last_event); | 1770 ASSERT_TRUE(last_event); |
1619 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), | 1771 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), |
1620 last_event->location()); | 1772 last_event->location()); |
1621 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), | 1773 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), |
1622 last_event->root_location()); | 1774 last_event->root_location()); |
1623 } | 1775 } |
1624 | 1776 |
| 1777 TEST_F(WindowTreeClientClientTestHighDPI, InputEventsInDip) { |
| 1778 WindowTreeHostMus window_tree_host(window_tree_client_impl()); |
| 1779 display::Screen* screen = display::Screen::GetScreen(); |
| 1780 display::Display display; |
| 1781 ASSERT_TRUE( |
| 1782 screen->GetDisplayWithDisplayId(window_tree_host.display_id(), &display)); |
| 1783 ASSERT_EQ(2.0f, display.device_scale_factor()); |
| 1784 |
| 1785 Window* top_level = window_tree_host.window(); |
| 1786 const gfx::Rect bounds_in_pixels(0, 0, 100, 100); |
| 1787 window_tree_host.SetBoundsInPixels(bounds_in_pixels); |
| 1788 window_tree_host.InitHost(); |
| 1789 window_tree_host.Show(); |
| 1790 EXPECT_EQ(gfx::ConvertRectToDIP(2.0f, bounds_in_pixels), top_level->bounds()); |
| 1791 EXPECT_EQ(bounds_in_pixels, window_tree_host.GetBoundsInPixels()); |
| 1792 |
| 1793 InputEventBasicTestWindowDelegate window_delegate1(window_tree()); |
| 1794 Window child1(&window_delegate1); |
| 1795 child1.Init(ui::LAYER_NOT_DRAWN); |
| 1796 child1.SetEventTargeter(base::MakeUnique<test::TestWindowTargeter>()); |
| 1797 top_level->AddChild(&child1); |
| 1798 child1.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 1799 child1.Show(); |
| 1800 InputEventBasicTestWindowDelegate window_delegate2(window_tree()); |
| 1801 Window child2(&window_delegate2); |
| 1802 child2.Init(ui::LAYER_NOT_DRAWN); |
| 1803 child1.AddChild(&child2); |
| 1804 child2.SetBounds(gfx::Rect(20, 30, 100, 100)); |
| 1805 child2.Show(); |
| 1806 |
| 1807 EXPECT_FALSE(window_delegate1.got_move()); |
| 1808 EXPECT_FALSE(window_delegate1.was_acked()); |
| 1809 EXPECT_FALSE(window_delegate2.got_move()); |
| 1810 EXPECT_FALSE(window_delegate2.was_acked()); |
| 1811 |
| 1812 // child1 has a custom targeter set which would always return itself as the |
| 1813 // target window therefore event should go to child1 and should be in dip. |
| 1814 const gfx::Point event_location_in_pixels(50, 60); |
| 1815 uint32_t event_id = 1; |
| 1816 window_delegate1.set_event_id(event_id); |
| 1817 window_delegate2.set_event_id(event_id); |
| 1818 std::unique_ptr<ui::Event> ui_event( |
| 1819 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_pixels, |
| 1820 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 1821 window_tree_client()->OnWindowInputEvent( |
| 1822 event_id, server_id(&child1), window_tree_host.display_id(), |
| 1823 ui::Event::Clone(*ui_event.get()), 0); |
| 1824 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 1825 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 1826 window_tree()->GetEventResult(event_id)); |
| 1827 EXPECT_TRUE(window_delegate1.got_move()); |
| 1828 EXPECT_FALSE(window_delegate1.was_acked()); |
| 1829 EXPECT_FALSE(window_delegate2.got_move()); |
| 1830 EXPECT_FALSE(window_delegate2.was_acked()); |
| 1831 gfx::Point event_location_in_dip = |
| 1832 gfx::ConvertPointToDIP(2.0f, event_location_in_pixels); |
| 1833 EXPECT_EQ(event_location_in_dip, window_delegate1.last_event_location()); |
| 1834 window_delegate1.reset(); |
| 1835 window_delegate2.reset(); |
| 1836 |
| 1837 // Event location will be transformed and should be in dip. |
| 1838 event_id = 2; |
| 1839 window_delegate1.set_event_id(event_id); |
| 1840 window_delegate2.set_event_id(event_id); |
| 1841 window_tree_client()->OnWindowInputEvent( |
| 1842 event_id, server_id(&child2), window_tree_host.display_id(), |
| 1843 ui::Event::Clone(*ui_event.get()), 0); |
| 1844 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); |
| 1845 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 1846 window_tree()->GetEventResult(event_id)); |
| 1847 EXPECT_TRUE(window_delegate1.got_move()); |
| 1848 EXPECT_FALSE(window_delegate1.was_acked()); |
| 1849 EXPECT_FALSE(window_delegate2.got_move()); |
| 1850 EXPECT_FALSE(window_delegate2.was_acked()); |
| 1851 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, |
| 1852 event_location_in_dip.y() + 30); |
| 1853 EXPECT_EQ(transformed_event_location_in_dip, |
| 1854 window_delegate1.last_event_location()); |
| 1855 } |
| 1856 |
1625 } // namespace aura | 1857 } // namespace aura |
OLD | NEW |