| 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 "ash/display/unified_mouse_warp_controller.h" | 5 #include "ash/display/unified_mouse_warp_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/display/display_util.h" | 8 #include "ash/display/display_util.h" |
| 9 #include "ash/display/mirror_window_controller.h" | 9 #include "ash/display/mirror_window_controller.h" |
| 10 #include "ash/display/mouse_cursor_event_filter.h" | 10 #include "ash/display/mouse_cursor_event_filter.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace ash { | 23 namespace ash { |
| 24 | 24 |
| 25 class UnifiedMouseWarpControllerTest : public test::AshTestBase { | 25 class UnifiedMouseWarpControllerTest : public test::AshTestBase { |
| 26 public: | 26 public: |
| 27 UnifiedMouseWarpControllerTest() {} | 27 UnifiedMouseWarpControllerTest() {} |
| 28 ~UnifiedMouseWarpControllerTest() override {} | 28 ~UnifiedMouseWarpControllerTest() override {} |
| 29 | 29 |
| 30 void SetUp() override { | 30 void SetUp() override { |
| 31 test::AshTestBase::SetUp(); | 31 test::AshTestBase::SetUp(); |
| 32 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); | 32 display_manager()->SetUnifiedDesktopEnabled(true); |
| 33 } | 33 } |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 bool FindMirrroingDisplayIdContainingNativePoint( | 36 bool FindMirrroingDisplayIdContainingNativePoint( |
| 37 const gfx::Point& point_in_native, | 37 const gfx::Point& point_in_native, |
| 38 int64_t* display_id, | 38 int64_t* display_id, |
| 39 gfx::Point* point_in_mirroring_host, | 39 gfx::Point* point_in_mirroring_host, |
| 40 gfx::Point* point_in_unified_host) { | 40 gfx::Point* point_in_unified_host) { |
| 41 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 41 for (auto display : display_manager()->software_mirroring_display_list()) { |
| 42 for (auto display : display_manager->software_mirroring_display_list()) { | |
| 43 display::ManagedDisplayInfo info = | 42 display::ManagedDisplayInfo info = |
| 44 display_manager->GetDisplayInfo(display.id()); | 43 display_manager()->GetDisplayInfo(display.id()); |
| 45 if (info.bounds_in_native().Contains(point_in_native)) { | 44 if (info.bounds_in_native().Contains(point_in_native)) { |
| 46 *display_id = info.id(); | 45 *display_id = info.id(); |
| 47 *point_in_unified_host = point_in_native; | 46 *point_in_unified_host = point_in_native; |
| 48 const gfx::Point& origin = info.bounds_in_native().origin(); | 47 const gfx::Point& origin = info.bounds_in_native().origin(); |
| 49 // Convert to mirroring host. | 48 // Convert to mirroring host. |
| 50 point_in_unified_host->Offset(-origin.x(), -origin.y()); | 49 point_in_unified_host->Offset(-origin.x(), -origin.y()); |
| 51 *point_in_mirroring_host = *point_in_unified_host; | 50 *point_in_mirroring_host = *point_in_unified_host; |
| 52 // Convert from mirroring host to unified host. | 51 // Convert from mirroring host to unified host. |
| 53 AshWindowTreeHost* ash_host = | 52 AshWindowTreeHost* ash_host = |
| 54 Shell::GetInstance() | 53 Shell::GetInstance() |
| 55 ->window_tree_host_manager() | 54 ->window_tree_host_manager() |
| 56 ->mirror_window_controller() | 55 ->mirror_window_controller() |
| 57 ->GetAshWindowTreeHostForDisplayId(info.id()); | 56 ->GetAshWindowTreeHostForDisplayId(info.id()); |
| 58 ash_host->AsWindowTreeHost()->ConvertPointFromHost( | 57 ash_host->AsWindowTreeHost()->ConvertPointFromHost( |
| 59 point_in_unified_host); | 58 point_in_unified_host); |
| 60 return true; | 59 return true; |
| 61 } | 60 } |
| 62 } | 61 } |
| 63 return false; | 62 return false; |
| 64 } | 63 } |
| 65 | 64 |
| 66 bool TestIfMouseWarpsAt(const gfx::Point& point_in_native) { | 65 bool TestIfMouseWarpsAt(const gfx::Point& point_in_native) { |
| 67 static_cast<UnifiedMouseWarpController*>( | 66 static_cast<UnifiedMouseWarpController*>( |
| 68 Shell::GetInstance() | 67 Shell::GetInstance() |
| 69 ->mouse_cursor_filter() | 68 ->mouse_cursor_filter() |
| 70 ->mouse_warp_controller_for_test()) | 69 ->mouse_warp_controller_for_test()) |
| 71 ->update_location_for_test(); | 70 ->update_location_for_test(); |
| 72 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 73 int64_t orig_mirroring_display_id; | 71 int64_t orig_mirroring_display_id; |
| 74 gfx::Point point_in_unified_host; | 72 gfx::Point point_in_unified_host; |
| 75 gfx::Point point_in_mirroring_host; | 73 gfx::Point point_in_mirroring_host; |
| 76 if (!FindMirrroingDisplayIdContainingNativePoint( | 74 if (!FindMirrroingDisplayIdContainingNativePoint( |
| 77 point_in_native, &orig_mirroring_display_id, | 75 point_in_native, &orig_mirroring_display_id, |
| 78 &point_in_mirroring_host, &point_in_unified_host)) { | 76 &point_in_mirroring_host, &point_in_unified_host)) { |
| 79 return false; | 77 return false; |
| 80 } | 78 } |
| 81 #if defined(USE_OZONE) | 79 #if defined(USE_OZONE) |
| 82 // The location of the ozone's native event is relative to the host. | 80 // The location of the ozone's native event is relative to the host. |
| 83 GetEventGenerator().MoveMouseToWithNative(point_in_unified_host, | 81 GetEventGenerator().MoveMouseToWithNative(point_in_unified_host, |
| 84 point_in_mirroring_host); | 82 point_in_mirroring_host); |
| 85 #else | 83 #else |
| 86 GetEventGenerator().MoveMouseToWithNative(point_in_unified_host, | 84 GetEventGenerator().MoveMouseToWithNative(point_in_unified_host, |
| 87 point_in_native); | 85 point_in_native); |
| 88 #endif | 86 #endif |
| 89 aura::Window* root = Shell::GetPrimaryRootWindow(); | 87 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 90 gfx::Point new_location_in_unified_host = | 88 gfx::Point new_location_in_unified_host = |
| 91 aura::Env::GetInstance()->last_mouse_location(); | 89 aura::Env::GetInstance()->last_mouse_location(); |
| 92 // Convert screen to the host. | 90 // Convert screen to the host. |
| 93 root->GetHost()->ConvertPointToHost(&new_location_in_unified_host); | 91 root->GetHost()->ConvertPointToHost(&new_location_in_unified_host); |
| 94 | 92 |
| 95 int new_index = display::FindDisplayIndexContainingPoint( | 93 int new_index = display::FindDisplayIndexContainingPoint( |
| 96 display_manager->software_mirroring_display_list(), | 94 display_manager()->software_mirroring_display_list(), |
| 97 new_location_in_unified_host); | 95 new_location_in_unified_host); |
| 98 if (new_index < 0) | 96 if (new_index < 0) |
| 99 return false; | 97 return false; |
| 100 return orig_mirroring_display_id != | 98 return orig_mirroring_display_id != |
| 101 display_manager->software_mirroring_display_list()[new_index].id(); | 99 display_manager()->software_mirroring_display_list()[new_index].id(); |
| 102 } | 100 } |
| 103 | 101 |
| 104 MouseCursorEventFilter* event_filter() { | 102 MouseCursorEventFilter* event_filter() { |
| 105 return Shell::GetInstance()->mouse_cursor_filter(); | 103 return Shell::GetInstance()->mouse_cursor_filter(); |
| 106 } | 104 } |
| 107 | 105 |
| 108 UnifiedMouseWarpController* mouse_warp_controller() { | 106 UnifiedMouseWarpController* mouse_warp_controller() { |
| 109 return static_cast<UnifiedMouseWarpController*>( | 107 return static_cast<UnifiedMouseWarpController*>( |
| 110 event_filter()->mouse_warp_controller_for_test()); | 108 event_filter()->mouse_warp_controller_for_test()); |
| 111 } | 109 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(600, 10))); | 254 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(600, 10))); |
| 257 EXPECT_EQ("249,5", // moved to 498 by 2px, divided by 2 (dsf). | 255 EXPECT_EQ("249,5", // moved to 498 by 2px, divided by 2 (dsf). |
| 258 aura::Env::GetInstance()->last_mouse_location().ToString()); | 256 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 259 { | 257 { |
| 260 SCOPED_TRACE("1x2 NO WARP"); | 258 SCOPED_TRACE("1x2 NO WARP"); |
| 261 NoWarpTestBody(); | 259 NoWarpTestBody(); |
| 262 } | 260 } |
| 263 } | 261 } |
| 264 | 262 |
| 265 } // namespace aura | 263 } // namespace aura |
| OLD | NEW |