Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: ash/display/extended_mouse_warp_controller.cc

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/ptr_util.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/display/manager/display_layout.h" 18 #include "ui/display/manager/display_layout.h"
19 #include "ui/display/screen.h"
19 #include "ui/events/event_utils.h" 20 #include "ui/events/event_utils.h"
20 #include "ui/gfx/screen.h"
21 #include "ui/wm/core/coordinate_conversion.h" 21 #include "ui/wm/core/coordinate_conversion.h"
22 22
23 namespace ash { 23 namespace ash {
24 24
25 namespace { 25 namespace {
26 26
27 // Maximum size on the display edge that initiate snapping phantom window, 27 // Maximum size on the display edge that initiate snapping phantom window,
28 // from the corner of the display. 28 // from the corner of the display.
29 const int kMaximumSnapHeight = 16; 29 const int kMaximumSnapHeight = 16;
30 30
31 // Minimum height of an indicator on the display edge that allows 31 // Minimum height of an indicator on the display edge that allows
32 // dragging a window. If two displays shares the edge smaller than 32 // dragging a window. If two displays shares the edge smaller than
33 // this, entire edge will be used as a draggable space. 33 // this, entire edge will be used as a draggable space.
34 const int kMinimumIndicatorHeight = 200; 34 const int kMinimumIndicatorHeight = 200;
35 35
36 // Helper method that maps a gfx::Display to an aura::Window. 36 // Helper method that maps a display::Display to an aura::Window.
37 aura::Window* GetRootWindowForDisplayId(int64_t display_id) { 37 aura::Window* GetRootWindowForDisplayId(int64_t display_id) {
38 return Shell::GetInstance() 38 return Shell::GetInstance()
39 ->window_tree_host_manager() 39 ->window_tree_host_manager()
40 ->GetRootWindowForDisplayId(display_id); 40 ->GetRootWindowForDisplayId(display_id);
41 } 41 }
42 42
43 // Helper method that maps an aura::Window to display id; 43 // Helper method that maps an aura::Window to display id;
44 int64_t GetDisplayIdFromWindow(aura::Window* window) { 44 int64_t GetDisplayIdFromWindow(aura::Window* window) {
45 return gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).id(); 45 return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id();
46 } 46 }
47 47
48 // Adjust the edge so that it has |barrier_size| gap at the top to 48 // Adjust the edge so that it has |barrier_size| gap at the top to
49 // trigger snap window action. 49 // trigger snap window action.
50 void AdjustSourceEdgeBounds(const gfx::Rect& display_bounds, 50 void AdjustSourceEdgeBounds(const gfx::Rect& display_bounds,
51 int barrier_size, 51 int barrier_size,
52 gfx::Rect* edge) { 52 gfx::Rect* edge) {
53 DCHECK_GT(edge->height(), edge->width()); 53 DCHECK_GT(edge->height(), edge->width());
54 int target_y = display_bounds.y() + barrier_size; 54 int target_y = display_bounds.y() + barrier_size;
55 if (target_y < edge->y()) 55 if (target_y < edge->y())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return b_indicator_bounds_; 97 return b_indicator_bounds_;
98 } 98 }
99 99
100 ExtendedMouseWarpController::ExtendedMouseWarpController( 100 ExtendedMouseWarpController::ExtendedMouseWarpController(
101 aura::Window* drag_source) 101 aura::Window* drag_source)
102 : drag_source_root_(drag_source), 102 : drag_source_root_(drag_source),
103 allow_non_native_event_(false) { 103 allow_non_native_event_(false) {
104 ash::DisplayManager* display_manager = 104 ash::DisplayManager* display_manager =
105 Shell::GetInstance()->display_manager(); 105 Shell::GetInstance()->display_manager();
106 int64_t drag_source_id = drag_source ? GetDisplayIdFromWindow(drag_source) 106 int64_t drag_source_id = drag_source ? GetDisplayIdFromWindow(drag_source)
107 : gfx::Display::kInvalidDisplayID; 107 : display::Display::kInvalidDisplayID;
108 display::DisplayList display_list = display_manager->active_display_list(); 108 display::DisplayList display_list = display_manager->active_display_list();
109 // 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.
110 // 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
111 // 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
112 // becomes single element. 112 // becomes single element.
113 while (display_list.size() > 1) { 113 while (display_list.size() > 1) {
114 gfx::Display display = display_list.back(); 114 display::Display display = display_list.back();
115 display_list.pop_back(); 115 display_list.pop_back();
116 for (const gfx::Display& peer : display_list) { 116 for (const display::Display& peer : display_list) {
117 std::unique_ptr<WarpRegion> region = 117 std::unique_ptr<WarpRegion> region =
118 CreateWarpRegion(display, peer, drag_source_id); 118 CreateWarpRegion(display, peer, drag_source_id);
119 if (region) 119 if (region)
120 AddWarpRegion(std::move(region), drag_source != nullptr); 120 AddWarpRegion(std::move(region), drag_source != nullptr);
121 } 121 }
122 } 122 }
123 } 123 }
124 124
125 ExtendedMouseWarpController::~ExtendedMouseWarpController() { 125 ExtendedMouseWarpController::~ExtendedMouseWarpController() {
126 } 126 }
127 127
128 bool ExtendedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) { 128 bool ExtendedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) {
129 if (gfx::Screen::GetScreen()->GetNumDisplays() <= 1 || !enabled_) 129 if (display::Screen::GetScreen()->GetNumDisplays() <= 1 || !enabled_)
130 return false; 130 return false;
131 131
132 aura::Window* target = static_cast<aura::Window*>(event->target()); 132 aura::Window* target = static_cast<aura::Window*>(event->target());
133 gfx::Point point_in_screen = event->location(); 133 gfx::Point point_in_screen = event->location();
134 ::wm::ConvertPointToScreen(target, &point_in_screen); 134 ::wm::ConvertPointToScreen(target, &point_in_screen);
135 135
136 // A native event may not exist in unit test. Generate the native point 136 // A native event may not exist in unit test. Generate the native point
137 // from the screen point instead. 137 // from the screen point instead.
138 if (!event->HasNativeEvent()) { 138 if (!event->HasNativeEvent()) {
139 if (!allow_non_native_event_) 139 if (!allow_non_native_event_)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 GetRootWindowController(dst_window)->ash_host(); 195 GetRootWindowController(dst_window)->ash_host();
196 196
197 MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now); 197 MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now);
198 return true; 198 return true;
199 } 199 }
200 200
201 return false; 201 return false;
202 } 202 }
203 203
204 std::unique_ptr<ExtendedMouseWarpController::WarpRegion> 204 std::unique_ptr<ExtendedMouseWarpController::WarpRegion>
205 ExtendedMouseWarpController::CreateWarpRegion(const gfx::Display& a, 205 ExtendedMouseWarpController::CreateWarpRegion(const display::Display& a,
206 const gfx::Display& b, 206 const display::Display& b,
207 int64_t drag_source_id) { 207 int64_t drag_source_id) {
208 gfx::Rect a_edge; 208 gfx::Rect a_edge;
209 gfx::Rect b_edge; 209 gfx::Rect b_edge;
210 int snap_barrier = drag_source_id == gfx::Display::kInvalidDisplayID 210 int snap_barrier = drag_source_id == display::Display::kInvalidDisplayID
211 ? 0 211 ? 0
212 : kMaximumSnapHeight; 212 : kMaximumSnapHeight;
213 213
214 if (!ComputeBoundary(a, b, &a_edge, &b_edge)) 214 if (!ComputeBoundary(a, b, &a_edge, &b_edge))
215 return nullptr; 215 return nullptr;
216 216
217 // Creates the snap window barrirer only when horizontally connected. 217 // Creates the snap window barrirer only when horizontally connected.
218 if (a_edge.height() > a_edge.width()) { 218 if (a_edge.height() > a_edge.width()) {
219 if (drag_source_id == a.id()) 219 if (drag_source_id == a.id())
220 AdjustSourceEdgeBounds(a.bounds(), snap_barrier, &a_edge); 220 AdjustSourceEdgeBounds(a.bounds(), snap_barrier, &a_edge);
221 else if (drag_source_id == b.id()) 221 else if (drag_source_id == b.id())
222 AdjustSourceEdgeBounds(b.bounds(), snap_barrier, &b_edge); 222 AdjustSourceEdgeBounds(b.bounds(), snap_barrier, &b_edge);
223 } 223 }
224 224
225 return base::WrapUnique(new WarpRegion(a.id(), b.id(), a_edge, b_edge)); 225 return base::WrapUnique(new WarpRegion(a.id(), b.id(), a_edge, b_edge));
226 } 226 }
227 227
228 } // namespace ash 228 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/extended_mouse_warp_controller.h ('k') | ash/display/extended_mouse_warp_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698