| 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 18 matching lines...) Expand all Loading... |
| 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/window.h" | 34 #include "ui/aura/window.h" |
| 35 #include "ui/aura/window_tracker.h" | 35 #include "ui/aura/window_tracker.h" |
| 36 #include "ui/aura/window_tree_host_observer.h" | 36 #include "ui/aura/window_tree_host_observer.h" |
| 37 #include "ui/base/class_property.h" | 37 #include "ui/base/class_property.h" |
| 38 #include "ui/compositor/compositor.h" | 38 #include "ui/compositor/compositor.h" |
| 39 #include "ui/display/display.h" |
| 39 #include "ui/display/display_switches.h" | 40 #include "ui/display/display_switches.h" |
| 41 #include "ui/display/screen.h" |
| 40 #include "ui/events/event.h" | 42 #include "ui/events/event.h" |
| 41 #include "ui/events/event_utils.h" | 43 #include "ui/events/event_utils.h" |
| 44 #include "ui/gfx/geometry/dip_util.h" |
| 42 #include "ui/gfx/geometry/rect.h" | 45 #include "ui/gfx/geometry/rect.h" |
| 43 | 46 |
| 44 namespace aura { | 47 namespace aura { |
| 45 | 48 |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); | 51 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); |
| 49 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); | 52 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); |
| 50 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey3, false); | 53 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey3, false); |
| 51 | 54 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 private: | 105 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestHighDPI); | 106 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestHighDPI); |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 // WindowTreeClientClientTest with --force-device-scale-factor=2. | 109 // WindowTreeClientClientTest with --force-device-scale-factor=2. |
| 107 class WindowTreeClientClientTestHighDPI : public WindowTreeClientClientTest { | 110 class WindowTreeClientClientTestHighDPI : public WindowTreeClientClientTest { |
| 108 public: | 111 public: |
| 109 WindowTreeClientClientTestHighDPI() {} | 112 WindowTreeClientClientTestHighDPI() {} |
| 110 ~WindowTreeClientClientTestHighDPI() override {} | 113 ~WindowTreeClientClientTestHighDPI() override {} |
| 111 | 114 |
| 115 const ui::PointerEvent* last_event_observed() const { |
| 116 return last_event_observed_.get(); |
| 117 } |
| 118 |
| 112 // WindowTreeClientClientTest: | 119 // WindowTreeClientClientTest: |
| 113 void SetUp() override { | 120 void SetUp() override { |
| 114 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 121 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 115 switches::kForceDeviceScaleFactor, "2"); | 122 switches::kForceDeviceScaleFactor, "2"); |
| 116 WindowTreeClientClientTest::SetUp(); | 123 WindowTreeClientClientTest::SetUp(); |
| 117 } | 124 } |
| 125 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 126 Window* target) override { |
| 127 last_event_observed_.reset(new ui::PointerEvent(event)); |
| 128 } |
| 118 | 129 |
| 119 private: | 130 private: |
| 131 std::unique_ptr<ui::PointerEvent> last_event_observed_; |
| 120 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientClientTestHighDPI); | 132 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientClientTestHighDPI); |
| 121 }; | 133 }; |
| 122 | 134 |
| 123 // Verifies bounds are reverted if the server replied that the change failed. | 135 // Verifies bounds are reverted if the server replied that the change failed. |
| 124 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { | 136 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { |
| 125 Window window(nullptr); | 137 Window window(nullptr); |
| 126 window.Init(ui::LAYER_NOT_DRAWN); | 138 window.Init(ui::LAYER_NOT_DRAWN); |
| 127 const gfx::Rect original_bounds(window.bounds()); | 139 const gfx::Rect original_bounds(window.bounds()); |
| 128 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 140 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
| 129 ASSERT_NE(new_bounds, window.bounds()); | 141 ASSERT_NE(new_bounds, window.bounds()); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 child.SetBounds(gfx::Rect(10, 10, 100, 100)); | 539 child.SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 528 child.Show(); | 540 child.Show(); |
| 529 EXPECT_FALSE(window_delegate.got_move()); | 541 EXPECT_FALSE(window_delegate.got_move()); |
| 530 EXPECT_FALSE(window_delegate.was_acked()); | 542 EXPECT_FALSE(window_delegate.was_acked()); |
| 531 const gfx::Point event_location_in_child(2, 3); | 543 const gfx::Point event_location_in_child(2, 3); |
| 532 std::unique_ptr<ui::Event> ui_event( | 544 std::unique_ptr<ui::Event> ui_event( |
| 533 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, | 545 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child, |
| 534 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); | 546 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 535 window_tree_client()->OnWindowInputEvent( | 547 window_tree_client()->OnWindowInputEvent( |
| 536 InputEventBasicTestWindowDelegate::kEventId, server_id(&child), | 548 InputEventBasicTestWindowDelegate::kEventId, server_id(&child), |
| 537 ui::Event::Clone(*ui_event.get()), 0); | 549 window_tree_host.display_id(), ui::Event::Clone(*ui_event.get()), 0); |
| 538 EXPECT_TRUE(window_tree()->WasEventAcked( | 550 EXPECT_TRUE(window_tree()->WasEventAcked( |
| 539 InputEventBasicTestWindowDelegate::kEventId)); | 551 InputEventBasicTestWindowDelegate::kEventId)); |
| 540 EXPECT_EQ(ui::mojom::EventResult::HANDLED, | 552 EXPECT_EQ(ui::mojom::EventResult::HANDLED, |
| 541 window_tree()->GetEventResult( | 553 window_tree()->GetEventResult( |
| 542 InputEventBasicTestWindowDelegate::kEventId)); | 554 InputEventBasicTestWindowDelegate::kEventId)); |
| 543 EXPECT_TRUE(window_delegate.got_move()); | 555 EXPECT_TRUE(window_delegate.got_move()); |
| 544 EXPECT_FALSE(window_delegate.was_acked()); | 556 EXPECT_FALSE(window_delegate.was_acked()); |
| 545 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); | 557 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location()); |
| 546 } | 558 } |
| 547 | 559 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 578 | 590 |
| 579 // Start a pointer watcher for all events excluding move events. | 591 // Start a pointer watcher for all events excluding move events. |
| 580 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */); | 592 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */); |
| 581 | 593 |
| 582 // Simulate the server sending an observed event. | 594 // Simulate the server sending an observed event. |
| 583 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( | 595 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( |
| 584 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, | 596 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, |
| 585 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), | 597 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), |
| 586 base::TimeTicks())); | 598 base::TimeTicks())); |
| 587 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_down), | 599 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_down), |
| 588 0u); | 600 0u, 0); |
| 589 | 601 |
| 590 // Delegate sensed the event. | 602 // Delegate sensed the event. |
| 591 const ui::PointerEvent* last_event = last_event_observed(); | 603 const ui::PointerEvent* last_event = last_event_observed(); |
| 592 ASSERT_TRUE(last_event); | 604 ASSERT_TRUE(last_event); |
| 593 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); | 605 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); |
| 594 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 606 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 595 DeleteLastEventObserved(); | 607 DeleteLastEventObserved(); |
| 596 | 608 |
| 597 // Stop the pointer watcher. | 609 // Stop the pointer watcher. |
| 598 window_tree_client_impl()->StopPointerWatcher(); | 610 window_tree_client_impl()->StopPointerWatcher(); |
| 599 | 611 |
| 600 // Simulate another event from the server. | 612 // Simulate another event from the server. |
| 601 std::unique_ptr<ui::PointerEvent> pointer_event_up(new ui::PointerEvent( | 613 std::unique_ptr<ui::PointerEvent> pointer_event_up(new ui::PointerEvent( |
| 602 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, 0, | 614 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, 0, |
| 603 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), | 615 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), |
| 604 base::TimeTicks())); | 616 base::TimeTicks())); |
| 605 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_up), 0u); | 617 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_up), 0u, |
| 618 0); |
| 606 | 619 |
| 607 // No event was sensed. | 620 // No event was sensed. |
| 608 EXPECT_FALSE(last_event_observed()); | 621 EXPECT_FALSE(last_event_observed()); |
| 609 } | 622 } |
| 610 | 623 |
| 611 // Tests pointer watchers triggered by events that hit this window tree. | 624 // Tests pointer watchers triggered by events that hit this window tree. |
| 612 TEST_F(WindowTreeClientPointerObserverTest, | 625 TEST_F(WindowTreeClientPointerObserverTest, |
| 613 OnWindowInputEventWithPointerWatcher) { | 626 OnWindowInputEventWithPointerWatcher) { |
| 614 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); | 627 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); |
| 615 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 628 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 616 top_level->Init(ui::LAYER_NOT_DRAWN); | 629 top_level->Init(ui::LAYER_NOT_DRAWN); |
| 617 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); | 630 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 618 top_level->Show(); | 631 top_level->Show(); |
| 619 | 632 |
| 620 // Start a pointer watcher for all events excluding move events. | 633 // Start a pointer watcher for all events excluding move events. |
| 621 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */); | 634 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */); |
| 622 | 635 |
| 623 // Simulate the server dispatching an event that also matched the observer. | 636 // Simulate the server dispatching an event that also matched the observer. |
| 624 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( | 637 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( |
| 625 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, | 638 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, |
| 626 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), | 639 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), |
| 627 base::TimeTicks::Now())); | 640 base::TimeTicks::Now())); |
| 628 window_tree_client()->OnWindowInputEvent(1, server_id(top_level.get()), | 641 window_tree_client()->OnWindowInputEvent(1, server_id(top_level.get()), 0, |
| 629 std::move(pointer_event_down), true); | 642 std::move(pointer_event_down), true); |
| 630 | 643 |
| 631 // Delegate sensed the event. | 644 // Delegate sensed the event. |
| 632 const ui::Event* last_event = last_event_observed(); | 645 const ui::Event* last_event = last_event_observed(); |
| 633 ASSERT_TRUE(last_event); | 646 ASSERT_TRUE(last_event); |
| 634 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); | 647 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); |
| 635 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 648 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 636 } | 649 } |
| 637 | 650 |
| 638 // Verifies focus is reverted if the server replied that the change failed. | 651 // Verifies focus is reverted if the server replied that the change failed. |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); | 1581 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); |
| 1569 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 1582 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 1570 display_id, true); | 1583 display_id, true); |
| 1571 | 1584 |
| 1572 // aura::Window should operate in DIP and aura::WindowTreeHost should operate | 1585 // aura::Window should operate in DIP and aura::WindowTreeHost should operate |
| 1573 // in pixels. | 1586 // in pixels. |
| 1574 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); | 1587 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); |
| 1575 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); | 1588 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); |
| 1576 } | 1589 } |
| 1577 | 1590 |
| 1591 TEST_F(WindowTreeClientClientTestHighDPI, PointerEventsInDips) { |
| 1592 display::Screen* screen = display::Screen::GetScreen(); |
| 1593 const display::Display primary_display = screen->GetPrimaryDisplay(); |
| 1594 ASSERT_EQ(2.0f, primary_display.device_scale_factor()); |
| 1595 |
| 1596 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); |
| 1597 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 1598 top_level->Init(ui::LAYER_NOT_DRAWN); |
| 1599 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1600 top_level->Show(); |
| 1601 |
| 1602 // Start a pointer watcher for all events excluding move events. |
| 1603 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */); |
| 1604 |
| 1605 // Simulate the server sending an observed event. |
| 1606 const gfx::Point location_pixels(10, 12); |
| 1607 const gfx::Point root_location_pixels(14, 16); |
| 1608 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( |
| 1609 ui::ET_POINTER_DOWN, location_pixels, root_location_pixels, |
| 1610 ui::EF_CONTROL_DOWN, 1, 0, |
| 1611 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), |
| 1612 base::TimeTicks())); |
| 1613 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_down), |
| 1614 0u, primary_display.id()); |
| 1615 |
| 1616 // Delegate received the event in Dips. |
| 1617 const ui::PointerEvent* last_event = last_event_observed(); |
| 1618 ASSERT_TRUE(last_event); |
| 1619 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, location_pixels), |
| 1620 last_event->location()); |
| 1621 EXPECT_EQ(gfx::ConvertPointToDIP(2.0f, root_location_pixels), |
| 1622 last_event->root_location()); |
| 1623 } |
| 1624 |
| 1578 } // namespace aura | 1625 } // namespace aura |
| OLD | NEW |