| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/display/display_util.h" | 10 #include "ash/display/display_util.h" |
| 11 #include "ash/display/mirror_window_controller.h" | 11 #include "ash/display/mirror_window_controller.h" |
| 12 #include "ash/display/window_tree_host_manager.h" | 12 #include "ash/display/window_tree_host_manager.h" |
| 13 #include "ash/host/ash_window_tree_host.h" | 13 #include "ash/host/ash_window_tree_host.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ui/aura/client/cursor_client.h" | 15 #include "ui/aura/client/cursor_client.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
| 18 #include "ui/base/layout.h" | 18 #include "ui/base/layout.h" |
| 19 #include "ui/display/manager/display_layout.h" | 19 #include "ui/display/manager/display_layout.h" |
| 20 #include "ui/display/screen.h" |
| 20 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 21 #include "ui/gfx/screen.h" | |
| 22 #include "ui/wm/core/coordinate_conversion.h" | 22 #include "ui/wm/core/coordinate_conversion.h" |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 AshWindowTreeHost* GetMirroringAshWindowTreeHostForDisplayId( | 28 AshWindowTreeHost* GetMirroringAshWindowTreeHostForDisplayId( |
| 29 int64_t display_id) { | 29 int64_t display_id) { |
| 30 return Shell::GetInstance() | 30 return Shell::GetInstance() |
| 31 ->window_tree_host_manager() | 31 ->window_tree_host_manager() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 47 if (index < 0) | 47 if (index < 0) |
| 48 return nullptr; | 48 return nullptr; |
| 49 return GetMirroringAshWindowTreeHostForDisplayId( | 49 return GetMirroringAshWindowTreeHostForDisplayId( |
| 50 mirroring_display_list[index].id())->AsWindowTreeHost(); | 50 mirroring_display_list[index].id())->AsWindowTreeHost(); |
| 51 } | 51 } |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 UnifiedMouseWarpController::UnifiedMouseWarpController() | 56 UnifiedMouseWarpController::UnifiedMouseWarpController() |
| 57 : current_cursor_display_id_(gfx::Display::kInvalidDisplayID), | 57 : current_cursor_display_id_(display::Display::kInvalidDisplayID), |
| 58 update_location_for_test_(false) {} | 58 update_location_for_test_(false) {} |
| 59 | 59 |
| 60 UnifiedMouseWarpController::~UnifiedMouseWarpController() { | 60 UnifiedMouseWarpController::~UnifiedMouseWarpController() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool UnifiedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) { | 63 bool UnifiedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) { |
| 64 // Mirroring windows are created asynchronously, so compute the edge | 64 // Mirroring windows are created asynchronously, so compute the edge |
| 65 // beounds when we received an event instead of in constructor. | 65 // beounds when we received an event instead of in constructor. |
| 66 if (first_edge_bounds_in_native_.IsEmpty()) | 66 if (first_edge_bounds_in_native_.IsEmpty()) |
| 67 ComputeBounds(); | 67 ComputeBounds(); |
| 68 | 68 |
| 69 aura::Window* target = static_cast<aura::Window*>(event->target()); | 69 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 70 gfx::Point point_in_unified_host = event->location(); | 70 gfx::Point point_in_unified_host = event->location(); |
| 71 ::wm::ConvertPointToScreen(target, &point_in_unified_host); | 71 ::wm::ConvertPointToScreen(target, &point_in_unified_host); |
| 72 // The display bounds of the mirroring windows isn't scaled, so | 72 // The display bounds of the mirroring windows isn't scaled, so |
| 73 // transform back to the host coordinates. | 73 // transform back to the host coordinates. |
| 74 target->GetHost()->GetRootTransform().TransformPoint(&point_in_unified_host); | 74 target->GetHost()->GetRootTransform().TransformPoint(&point_in_unified_host); |
| 75 | 75 |
| 76 if (current_cursor_display_id_ != gfx::Display::kInvalidDisplayID) { | 76 if (current_cursor_display_id_ != display::Display::kInvalidDisplayID) { |
| 77 aura::client::CursorClient* cursor_client = | 77 aura::client::CursorClient* cursor_client = |
| 78 aura::client::GetCursorClient(target->GetRootWindow()); | 78 aura::client::GetCursorClient(target->GetRootWindow()); |
| 79 if (cursor_client) { | 79 if (cursor_client) { |
| 80 display::DisplayList mirroring_display_list = | 80 display::DisplayList mirroring_display_list = |
| 81 Shell::GetInstance() | 81 Shell::GetInstance() |
| 82 ->display_manager() | 82 ->display_manager() |
| 83 ->software_mirroring_display_list(); | 83 ->software_mirroring_display_list(); |
| 84 int index = FindDisplayIndexContainingPoint(mirroring_display_list, | 84 int index = FindDisplayIndexContainingPoint(mirroring_display_list, |
| 85 point_in_unified_host); | 85 point_in_unified_host); |
| 86 if (index >= 0) { | 86 if (index >= 0) { |
| 87 const gfx::Display& new_display = mirroring_display_list[index]; | 87 const display::Display& new_display = mirroring_display_list[index]; |
| 88 if (current_cursor_display_id_ != new_display.id()) { | 88 if (current_cursor_display_id_ != new_display.id()) { |
| 89 cursor_client->SetDisplay(new_display); | 89 cursor_client->SetDisplay(new_display); |
| 90 current_cursor_display_id_ = gfx::Display::kInvalidDisplayID; | 90 current_cursor_display_id_ = display::Display::kInvalidDisplayID; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 // A native event may not exist in unit test. | 96 // A native event may not exist in unit test. |
| 97 if (!event->HasNativeEvent()) | 97 if (!event->HasNativeEvent()) |
| 98 return false; | 98 return false; |
| 99 | 99 |
| 100 gfx::Point point_in_native = | 100 gfx::Point point_in_native = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 display::DisplayList display_list = Shell::GetInstance() | 124 display::DisplayList display_list = Shell::GetInstance() |
| 125 ->display_manager() | 125 ->display_manager() |
| 126 ->software_mirroring_display_list(); | 126 ->software_mirroring_display_list(); |
| 127 | 127 |
| 128 if (display_list.size() < 2) { | 128 if (display_list.size() < 2) { |
| 129 LOG(ERROR) << "Mirroring Display lost during re-configuration"; | 129 LOG(ERROR) << "Mirroring Display lost during re-configuration"; |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 LOG_IF(ERROR, display_list.size() > 2) << "Only two displays are supported"; | 132 LOG_IF(ERROR, display_list.size() > 2) << "Only two displays are supported"; |
| 133 | 133 |
| 134 const gfx::Display& first = display_list[0]; | 134 const display::Display& first = display_list[0]; |
| 135 const gfx::Display& second = display_list[1]; | 135 const display::Display& second = display_list[1]; |
| 136 bool success = ComputeBoundary(first, second, &first_edge_bounds_in_native_, | 136 bool success = ComputeBoundary(first, second, &first_edge_bounds_in_native_, |
| 137 &second_edge_bounds_in_native_); | 137 &second_edge_bounds_in_native_); |
| 138 DCHECK(success); | 138 DCHECK(success); |
| 139 | 139 |
| 140 first_edge_bounds_in_native_ = | 140 first_edge_bounds_in_native_ = |
| 141 GetNativeEdgeBounds(GetMirroringAshWindowTreeHostForDisplayId(first.id()), | 141 GetNativeEdgeBounds(GetMirroringAshWindowTreeHostForDisplayId(first.id()), |
| 142 first_edge_bounds_in_native_); | 142 first_edge_bounds_in_native_); |
| 143 | 143 |
| 144 second_edge_bounds_in_native_ = GetNativeEdgeBounds( | 144 second_edge_bounds_in_native_ = GetNativeEdgeBounds( |
| 145 GetMirroringAshWindowTreeHostForDisplayId(second.id()), | 145 GetMirroringAshWindowTreeHostForDisplayId(second.id()), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 163 in_first_edge ? display_list[0].id() : display_list[1].id(); | 163 in_first_edge ? display_list[0].id() : display_list[1].id(); |
| 164 AshWindowTreeHost* target_ash_host = | 164 AshWindowTreeHost* target_ash_host = |
| 165 GetMirroringAshWindowTreeHostForDisplayId( | 165 GetMirroringAshWindowTreeHostForDisplayId( |
| 166 in_first_edge ? display_list[1].id() : display_list[0].id()); | 166 in_first_edge ? display_list[1].id() : display_list[0].id()); |
| 167 MoveCursorTo(target_ash_host, point_in_unified_host, | 167 MoveCursorTo(target_ash_host, point_in_unified_host, |
| 168 update_mouse_location_now); | 168 update_mouse_location_now); |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace ash | 172 } // namespace ash |
| OLD | NEW |