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/extended_mouse_warp_controller.h" | 5 #include "ash/display/extended_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/shared_display_edge_indicator.h" | 11 #include "ash/display/shared_display_edge_indicator.h" |
12 #include "ash/display/window_tree_host_manager.h" | 12 #include "ash/display/window_tree_host_manager.h" |
13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
14 #include "ash/screen_util.h" | 14 #include "ash/screen_util.h" |
15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "base/memory/ptr_util.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/display/manager/display_layout.h" | 18 #include "ui/display/manager/display_layout.h" |
18 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
19 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
20 #include "ui/wm/core/coordinate_conversion.h" | 21 #include "ui/wm/core/coordinate_conversion.h" |
21 | 22 |
22 namespace ash { | 23 namespace ash { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 : gfx::Display::kInvalidDisplayID; | 107 : gfx::Display::kInvalidDisplayID; |
107 display::DisplayList display_list = display_manager->active_display_list(); | 108 display::DisplayList display_list = display_manager->active_display_list(); |
108 // Try to create a Warp region for all possible two displays combination. | 109 // Try to create a Warp region for all possible two displays combination. |
109 // The following code does it by poping the last element in the list | 110 // The following code does it by poping the last element in the list |
110 // and then pairing with remaining displays in the list, until the list | 111 // and then pairing with remaining displays in the list, until the list |
111 // becomes single element. | 112 // becomes single element. |
112 while (display_list.size() > 1) { | 113 while (display_list.size() > 1) { |
113 gfx::Display display = display_list.back(); | 114 gfx::Display display = display_list.back(); |
114 display_list.pop_back(); | 115 display_list.pop_back(); |
115 for (const gfx::Display& peer : display_list) { | 116 for (const gfx::Display& peer : display_list) { |
116 scoped_ptr<WarpRegion> region = | 117 std::unique_ptr<WarpRegion> region = |
117 CreateWarpRegion(display, peer, drag_source_id); | 118 CreateWarpRegion(display, peer, drag_source_id); |
118 if (region) | 119 if (region) |
119 AddWarpRegion(std::move(region), drag_source != nullptr); | 120 AddWarpRegion(std::move(region), drag_source != nullptr); |
120 } | 121 } |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 ExtendedMouseWarpController::~ExtendedMouseWarpController() { | 125 ExtendedMouseWarpController::~ExtendedMouseWarpController() { |
125 } | 126 } |
126 | 127 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 #endif | 159 #endif |
159 | 160 |
160 return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false); | 161 return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false); |
161 } | 162 } |
162 | 163 |
163 void ExtendedMouseWarpController::SetEnabled(bool enabled) { | 164 void ExtendedMouseWarpController::SetEnabled(bool enabled) { |
164 enabled_ = enabled; | 165 enabled_ = enabled; |
165 } | 166 } |
166 | 167 |
167 void ExtendedMouseWarpController::AddWarpRegion( | 168 void ExtendedMouseWarpController::AddWarpRegion( |
168 scoped_ptr<WarpRegion> warp_region, | 169 std::unique_ptr<WarpRegion> warp_region, |
169 bool has_drag_source) { | 170 bool has_drag_source) { |
170 if (has_drag_source) { | 171 if (has_drag_source) { |
171 warp_region->shared_display_edge_indicator_.reset( | 172 warp_region->shared_display_edge_indicator_.reset( |
172 new SharedDisplayEdgeIndicator); | 173 new SharedDisplayEdgeIndicator); |
173 warp_region->shared_display_edge_indicator_->Show( | 174 warp_region->shared_display_edge_indicator_->Show( |
174 warp_region->a_indicator_bounds_, warp_region->b_indicator_bounds_); | 175 warp_region->a_indicator_bounds_, warp_region->b_indicator_bounds_); |
175 } | 176 } |
176 | 177 |
177 warp_regions_.emplace_back(std::move(warp_region)); | 178 warp_regions_.emplace_back(std::move(warp_region)); |
178 } | 179 } |
179 | 180 |
180 bool ExtendedMouseWarpController::WarpMouseCursorInNativeCoords( | 181 bool ExtendedMouseWarpController::WarpMouseCursorInNativeCoords( |
181 const gfx::Point& point_in_native, | 182 const gfx::Point& point_in_native, |
182 const gfx::Point& point_in_screen, | 183 const gfx::Point& point_in_screen, |
183 bool update_mouse_location_now) { | 184 bool update_mouse_location_now) { |
184 for (const scoped_ptr<WarpRegion>& warp : warp_regions_) { | 185 for (const std::unique_ptr<WarpRegion>& warp : warp_regions_) { |
185 bool in_a_edge = warp->a_edge_bounds_in_native_.Contains(point_in_native); | 186 bool in_a_edge = warp->a_edge_bounds_in_native_.Contains(point_in_native); |
186 bool in_b_edge = warp->b_edge_bounds_in_native_.Contains(point_in_native); | 187 bool in_b_edge = warp->b_edge_bounds_in_native_.Contains(point_in_native); |
187 if (!in_a_edge && !in_b_edge) | 188 if (!in_a_edge && !in_b_edge) |
188 continue; | 189 continue; |
189 | 190 |
190 // The mouse must move. | 191 // The mouse must move. |
191 aura::Window* dst_window = GetRootWindowForDisplayId( | 192 aura::Window* dst_window = GetRootWindowForDisplayId( |
192 in_a_edge ? warp->b_display_id_ : warp->a_display_id_); | 193 in_a_edge ? warp->b_display_id_ : warp->a_display_id_); |
193 AshWindowTreeHost* target_ash_host = | 194 AshWindowTreeHost* target_ash_host = |
194 GetRootWindowController(dst_window)->ash_host(); | 195 GetRootWindowController(dst_window)->ash_host(); |
195 | 196 |
196 MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now); | 197 MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now); |
197 return true; | 198 return true; |
198 } | 199 } |
199 | 200 |
200 return false; | 201 return false; |
201 } | 202 } |
202 | 203 |
203 scoped_ptr<ExtendedMouseWarpController::WarpRegion> | 204 std::unique_ptr<ExtendedMouseWarpController::WarpRegion> |
204 ExtendedMouseWarpController::CreateWarpRegion(const gfx::Display& a, | 205 ExtendedMouseWarpController::CreateWarpRegion(const gfx::Display& a, |
205 const gfx::Display& b, | 206 const gfx::Display& b, |
206 int64_t drag_source_id) { | 207 int64_t drag_source_id) { |
207 gfx::Rect a_edge; | 208 gfx::Rect a_edge; |
208 gfx::Rect b_edge; | 209 gfx::Rect b_edge; |
209 int snap_barrier = drag_source_id == gfx::Display::kInvalidDisplayID | 210 int snap_barrier = drag_source_id == gfx::Display::kInvalidDisplayID |
210 ? 0 | 211 ? 0 |
211 : kMaximumSnapHeight; | 212 : kMaximumSnapHeight; |
212 | 213 |
213 if (!ComputeBoundary(a, b, &a_edge, &b_edge)) | 214 if (!ComputeBoundary(a, b, &a_edge, &b_edge)) |
214 return nullptr; | 215 return nullptr; |
215 | 216 |
216 // Creates the snap window barrirer only when horizontally connected. | 217 // Creates the snap window barrirer only when horizontally connected. |
217 if (a_edge.height() > a_edge.width()) { | 218 if (a_edge.height() > a_edge.width()) { |
218 if (drag_source_id == a.id()) | 219 if (drag_source_id == a.id()) |
219 AdjustSourceEdgeBounds(a.bounds(), snap_barrier, &a_edge); | 220 AdjustSourceEdgeBounds(a.bounds(), snap_barrier, &a_edge); |
220 else if (drag_source_id == b.id()) | 221 else if (drag_source_id == b.id()) |
221 AdjustSourceEdgeBounds(b.bounds(), snap_barrier, &b_edge); | 222 AdjustSourceEdgeBounds(b.bounds(), snap_barrier, &b_edge); |
222 } | 223 } |
223 | 224 |
224 return make_scoped_ptr(new WarpRegion(a.id(), b.id(), a_edge, b_edge)); | 225 return base::WrapUnique(new WarpRegion(a.id(), b.id(), a_edge, b_edge)); |
225 } | 226 } |
226 | 227 |
227 } // namespace ash | 228 } // namespace ash |
OLD | NEW |