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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // horizontally, with each display being RIGHT of the previous one. | 81 // horizontally, with each display being RIGHT of the previous one. |
82 if (display_manager->GetNumDisplays() > 2) { | 82 if (display_manager->GetNumDisplays() > 2) { |
83 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { | 83 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { |
84 const gfx::Display& left = display_manager->GetDisplayAt(i - 1); | 84 const gfx::Display& left = display_manager->GetDisplayAt(i - 1); |
85 const gfx::Display& right = display_manager->GetDisplayAt(i); | 85 const gfx::Display& right = display_manager->GetDisplayAt(i); |
86 | 86 |
87 AddWarpRegion(CreateVerticalEdgeBounds(left, right, DisplayLayout::RIGHT), | 87 AddWarpRegion(CreateVerticalEdgeBounds(left, right, DisplayLayout::RIGHT), |
88 drag_source != nullptr); | 88 drag_source != nullptr); |
89 } | 89 } |
90 } else { | 90 } else { |
| 91 // Make sure to set |a| as the primary display, and |b| as the secondary |
| 92 // display. DisplayLayout::Position is defined in terms of primary. |
91 DisplayLayout::Position position = | 93 DisplayLayout::Position position = |
92 display_manager->GetCurrentDisplayLayout().position; | 94 display_manager->GetCurrentDisplayLayout().position; |
93 const gfx::Display& a = display_manager->GetDisplayAt(0); | 95 const gfx::Display& a = Shell::GetScreen()->GetPrimaryDisplay(); |
94 const gfx::Display& b = display_manager->GetDisplayAt(1); | 96 const gfx::Display& b = ScreenUtil::GetSecondaryDisplay(); |
95 | 97 |
96 // TODO(oshima): Use ComputeBondary instead. | 98 // TODO(oshima): Use ComputeBondary instead. |
97 if (position == DisplayLayout::TOP || position == DisplayLayout::BOTTOM) | 99 if (position == DisplayLayout::TOP || position == DisplayLayout::BOTTOM) { |
98 AddWarpRegion(CreateHorizontalEdgeBounds(a, b, position), | 100 AddWarpRegion(CreateHorizontalEdgeBounds(a, b, position), |
99 drag_source != nullptr); | 101 drag_source != nullptr); |
100 else | 102 } else { |
101 AddWarpRegion(CreateVerticalEdgeBounds(a, b, position), | 103 AddWarpRegion(CreateVerticalEdgeBounds(a, b, position), |
102 drag_source != nullptr); | 104 drag_source != nullptr); |
| 105 } |
103 } | 106 } |
104 } | 107 } |
105 | 108 |
106 ExtendedMouseWarpController::~ExtendedMouseWarpController() { | 109 ExtendedMouseWarpController::~ExtendedMouseWarpController() { |
107 } | 110 } |
108 | 111 |
109 bool ExtendedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) { | 112 bool ExtendedMouseWarpController::WarpMouseCursor(ui::MouseEvent* event) { |
110 if (Shell::GetScreen()->GetNumDisplays() <= 1 || !enabled_) | 113 if (Shell::GetScreen()->GetNumDisplays() <= 1 || !enabled_) |
111 return false; | 114 return false; |
112 | 115 |
(...skipping 28 matching lines...) Expand all Loading... |
141 | 144 |
142 return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false); | 145 return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen, false); |
143 } | 146 } |
144 | 147 |
145 void ExtendedMouseWarpController::SetEnabled(bool enabled) { | 148 void ExtendedMouseWarpController::SetEnabled(bool enabled) { |
146 enabled_ = enabled; | 149 enabled_ = enabled; |
147 } | 150 } |
148 | 151 |
149 void ExtendedMouseWarpController::AddWarpRegion( | 152 void ExtendedMouseWarpController::AddWarpRegion( |
150 scoped_ptr<WarpRegion> warp_region, | 153 scoped_ptr<WarpRegion> warp_region, |
151 bool drag_source) { | 154 bool has_drag_source) { |
152 if (drag_source) { | 155 if (has_drag_source) { |
153 warp_region->shared_display_edge_indicator.reset( | 156 warp_region->shared_display_edge_indicator.reset( |
154 new SharedDisplayEdgeIndicator); | 157 new SharedDisplayEdgeIndicator); |
155 warp_region->shared_display_edge_indicator->Show( | 158 warp_region->shared_display_edge_indicator->Show( |
156 warp_region->a_indicator_bounds, warp_region->b_indicator_bounds); | 159 warp_region->a_indicator_bounds, warp_region->b_indicator_bounds); |
157 } | 160 } |
158 | 161 |
159 warp_regions_.emplace_back(std::move(warp_region)); | 162 warp_regions_.emplace_back(std::move(warp_region)); |
160 } | 163 } |
161 | 164 |
162 bool ExtendedMouseWarpController::WarpMouseCursorInNativeCoords( | 165 bool ExtendedMouseWarpController::WarpMouseCursorInNativeCoords( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 upper_indicator_y = std::max(upper_indicator_y, upper_shared_y); | 268 upper_indicator_y = std::max(upper_indicator_y, upper_shared_y); |
266 } | 269 } |
267 a_indicator_bounds.set_y(upper_indicator_y); | 270 a_indicator_bounds.set_y(upper_indicator_y); |
268 a_indicator_bounds.set_height(lower_indicator_y - upper_indicator_y); | 271 a_indicator_bounds.set_height(lower_indicator_y - upper_indicator_y); |
269 | 272 |
270 return make_scoped_ptr( | 273 return make_scoped_ptr( |
271 new WarpRegion(a.id(), b.id(), a_indicator_bounds, b_indicator_bounds)); | 274 new WarpRegion(a.id(), b.id(), a_indicator_bounds, b_indicator_bounds)); |
272 } | 275 } |
273 | 276 |
274 } // namespace ash | 277 } // namespace ash |
OLD | NEW |