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

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

Issue 1631023002: Fix moving the mouse between two displays after the secondary display becomes primary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Rename UpdateDisplaysTo to UpdateDisplaysWith Created 4 years, 11 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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return Shell::GetScreen()->GetDisplayNearestWindow(window); 45 return Shell::GetScreen()->GetDisplayNearestWindow(window);
46 } 46 }
47 47
48 } // namespace 48 } // namespace
49 49
50 ExtendedMouseWarpController::WarpRegion::WarpRegion( 50 ExtendedMouseWarpController::WarpRegion::WarpRegion(
51 int64_t a_display_id, 51 int64_t a_display_id,
52 int64_t b_display_id, 52 int64_t b_display_id,
53 const gfx::Rect& a_indicator_bounds, 53 const gfx::Rect& a_indicator_bounds,
54 const gfx::Rect& b_indicator_bounds) 54 const gfx::Rect& b_indicator_bounds)
55 : a_display_id(a_display_id), 55 : a_display_id_(a_display_id),
56 b_display_id(b_display_id), 56 b_display_id_(b_display_id),
57 a_indicator_bounds(a_indicator_bounds), 57 a_indicator_bounds_(a_indicator_bounds),
58 b_indicator_bounds(b_indicator_bounds), 58 b_indicator_bounds_(b_indicator_bounds),
59 shared_display_edge_indicator(nullptr) { 59 shared_display_edge_indicator_(nullptr) {
60 // Initialize edge bounds from indicator bounds. 60 // Initialize edge bounds from indicator bounds.
61 aura::Window* a_window = GetRootWindowForDisplayId(a_display_id); 61 aura::Window* a_window = GetRootWindowForDisplayId(a_display_id);
62 aura::Window* b_window = GetRootWindowForDisplayId(b_display_id); 62 aura::Window* b_window = GetRootWindowForDisplayId(b_display_id);
63 63
64 AshWindowTreeHost* a_ash_host = GetRootWindowController(a_window)->ash_host(); 64 AshWindowTreeHost* a_ash_host = GetRootWindowController(a_window)->ash_host();
65 AshWindowTreeHost* b_ash_host = GetRootWindowController(b_window)->ash_host(); 65 AshWindowTreeHost* b_ash_host = GetRootWindowController(b_window)->ash_host();
66 66
67 a_edge_bounds_in_native = GetNativeEdgeBounds(a_ash_host, a_indicator_bounds); 67 a_edge_bounds_in_native_ =
68 b_edge_bounds_in_native = GetNativeEdgeBounds(b_ash_host, b_indicator_bounds); 68 GetNativeEdgeBounds(a_ash_host, a_indicator_bounds);
69 b_edge_bounds_in_native_ =
70 GetNativeEdgeBounds(b_ash_host, b_indicator_bounds);
69 } 71 }
70 72
71 ExtendedMouseWarpController::WarpRegion::~WarpRegion() {} 73 ExtendedMouseWarpController::WarpRegion::~WarpRegion() {}
72 74
73 ExtendedMouseWarpController::ExtendedMouseWarpController( 75 ExtendedMouseWarpController::ExtendedMouseWarpController(
74 aura::Window* drag_source) 76 aura::Window* drag_source)
75 : drag_source_root_(drag_source), 77 : drag_source_root_(drag_source),
76 allow_non_native_event_(false) { 78 allow_non_native_event_(false) {
77 ash::DisplayManager* display_manager = 79 ash::DisplayManager* display_manager =
78 Shell::GetInstance()->display_manager(); 80 Shell::GetInstance()->display_manager();
79 81
80 // For the time being, 3 or more displays are always always laid out 82 // For the time being, 3 or more displays are always always laid out
81 // horizontally, with each display being RIGHT of the previous one. 83 // horizontally, with each display being RIGHT of the previous one.
82 if (display_manager->GetNumDisplays() > 2) { 84 if (display_manager->GetNumDisplays() > 2) {
83 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { 85 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) {
84 const gfx::Display& left = display_manager->GetDisplayAt(i - 1); 86 const gfx::Display& left = display_manager->GetDisplayAt(i - 1);
85 const gfx::Display& right = display_manager->GetDisplayAt(i); 87 const gfx::Display& right = display_manager->GetDisplayAt(i);
86 88
87 AddWarpRegion(CreateVerticalEdgeBounds(left, right, DisplayLayout::RIGHT), 89 AddWarpRegion(CreateVerticalEdgeBounds(left, right, DisplayLayout::RIGHT),
88 drag_source != nullptr); 90 drag_source != nullptr);
89 } 91 }
90 } else { 92 } else {
93 // Make sure to set |a| as the primary display, and |b| as the secondary
94 // display. DisplayLayout::Position is defined in terms of primary.
91 DisplayLayout::Position position = 95 DisplayLayout::Position position =
92 display_manager->GetCurrentDisplayLayout().position; 96 display_manager->GetCurrentDisplayLayout().position;
93 const gfx::Display& a = display_manager->GetDisplayAt(0); 97 const gfx::Display& a = Shell::GetScreen()->GetPrimaryDisplay();
94 const gfx::Display& b = display_manager->GetDisplayAt(1); 98 const gfx::Display& b = ScreenUtil::GetSecondaryDisplay();
95 99
96 // TODO(oshima): Use ComputeBondary instead. 100 // TODO(oshima): Use ComputeBondary instead.
97 if (position == DisplayLayout::TOP || position == DisplayLayout::BOTTOM) 101 if (position == DisplayLayout::TOP || position == DisplayLayout::BOTTOM) {
98 AddWarpRegion(CreateHorizontalEdgeBounds(a, b, position), 102 AddWarpRegion(CreateHorizontalEdgeBounds(a, b, position),
99 drag_source != nullptr); 103 drag_source != nullptr);
100 else 104 } else {
101 AddWarpRegion(CreateVerticalEdgeBounds(a, b, position), 105 AddWarpRegion(CreateVerticalEdgeBounds(a, b, position),
102 drag_source != nullptr); 106 drag_source != nullptr);
107 }
103 } 108 }
104 } 109 }
105 110
106 ExtendedMouseWarpController::~ExtendedMouseWarpController() { 111 ExtendedMouseWarpController::~ExtendedMouseWarpController() {
107 } 112 }
108 113
109 bool ExtendedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) { 114 bool ExtendedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) {
110 if (Shell::GetScreen()->GetNumDisplays() <= 1 || !enabled_) 115 if (Shell::GetScreen()->GetNumDisplays() <= 1 || !enabled_)
111 return false; 116 return false;
112 117
(...skipping 28 matching lines...) Expand all
141 146
142 return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false); 147 return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false);
143 } 148 }
144 149
145 void ExtendedMouseWarpController::SetEnabled(bool enabled) { 150 void ExtendedMouseWarpController::SetEnabled(bool enabled) {
146 enabled_ = enabled; 151 enabled_ = enabled;
147 } 152 }
148 153
149 void ExtendedMouseWarpController::AddWarpRegion( 154 void ExtendedMouseWarpController::AddWarpRegion(
150 scoped_ptr<WarpRegion> warp_region, 155 scoped_ptr<WarpRegion> warp_region,
151 bool drag_source) { 156 bool has_drag_source) {
152 if (drag_source) { 157 if (has_drag_source) {
153 warp_region->shared_display_edge_indicator.reset( 158 warp_region->shared_display_edge_indicator_.reset(
154 new SharedDisplayEdgeIndicator); 159 new SharedDisplayEdgeIndicator);
155 warp_region->shared_display_edge_indicator->Show( 160 warp_region->shared_display_edge_indicator_->Show(
156 warp_region->a_indicator_bounds, warp_region->b_indicator_bounds); 161 warp_region->a_indicator_bounds_, warp_region->b_indicator_bounds_);
157 } 162 }
158 163
159 warp_regions_.emplace_back(std::move(warp_region)); 164 warp_regions_.emplace_back(std::move(warp_region));
160 } 165 }
161 166
162 bool ExtendedMouseWarpController::WarpMouseCursorInNativeCoords( 167 bool ExtendedMouseWarpController::WarpMouseCursorInNativeCoords(
163 const gfx::Point& point_in_native, 168 const gfx::Point& point_in_native,
164 const gfx::Point& point_in_screen, 169 const gfx::Point& point_in_screen,
165 bool update_mouse_location_now) { 170 bool update_mouse_location_now) {
166 for (const scoped_ptr<WarpRegion>& warp : warp_regions_) { 171 for (const scoped_ptr<WarpRegion>& warp : warp_regions_) {
167 bool in_a_edge = warp->a_edge_bounds_in_native.Contains(point_in_native); 172 bool in_a_edge = warp->a_edge_bounds_in_native_.Contains(point_in_native);
168 bool in_b_edge = warp->b_edge_bounds_in_native.Contains(point_in_native); 173 bool in_b_edge = warp->b_edge_bounds_in_native_.Contains(point_in_native);
169 if (!in_a_edge && !in_b_edge) 174 if (!in_a_edge && !in_b_edge)
170 continue; 175 continue;
171 176
172 // The mouse must move. 177 // The mouse must move.
173 aura::Window* dst_window = GetRootWindowForDisplayId( 178 aura::Window* dst_window = GetRootWindowForDisplayId(
174 in_a_edge ? warp->b_display_id : warp->a_display_id); 179 in_a_edge ? warp->b_display_id_ : warp->a_display_id_);
175 AshWindowTreeHost* target_ash_host = 180 AshWindowTreeHost* target_ash_host =
176 GetRootWindowController(dst_window)->ash_host(); 181 GetRootWindowController(dst_window)->ash_host();
177 182
178 MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now); 183 MoveCursorTo(target_ash_host, point_in_screen, update_mouse_location_now);
179 return true; 184 return true;
180 } 185 }
181 186
182 return false; 187 return false;
183 } 188 }
184 189
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 upper_indicator_y = std::max(upper_indicator_y, upper_shared_y); 270 upper_indicator_y = std::max(upper_indicator_y, upper_shared_y);
266 } 271 }
267 a_indicator_bounds.set_y(upper_indicator_y); 272 a_indicator_bounds.set_y(upper_indicator_y);
268 a_indicator_bounds.set_height(lower_indicator_y - upper_indicator_y); 273 a_indicator_bounds.set_height(lower_indicator_y - upper_indicator_y);
269 274
270 return make_scoped_ptr( 275 return make_scoped_ptr(
271 new WarpRegion(a.id(), b.id(), a_indicator_bounds, b_indicator_bounds)); 276 new WarpRegion(a.id(), b.id(), a_indicator_bounds, b_indicator_bounds));
272 } 277 }
273 278
274 } // namespace ash 279 } // 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