OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/multi_display_manager.h" | 8 #include "ash/display/multi_display_manager.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/wm/property_util.h" | 12 #include "ash/wm/property_util.h" |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "ui/aura/client/screen_position_client.h" |
15 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
16 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
18 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
19 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
20 | 21 |
21 namespace ash { | 22 namespace ash { |
22 namespace internal { | 23 namespace internal { |
23 | 24 |
24 DisplayController::DisplayController() | 25 DisplayController::DisplayController() |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return controllers; | 114 return controllers; |
114 } | 115 } |
115 | 116 |
116 void DisplayController::SetSecondaryDisplayLayout( | 117 void DisplayController::SetSecondaryDisplayLayout( |
117 SecondaryDisplayLayout layout) { | 118 SecondaryDisplayLayout layout) { |
118 secondary_display_layout_ = layout; | 119 secondary_display_layout_ = layout; |
119 UpdateDisplayBoundsForLayout(); | 120 UpdateDisplayBoundsForLayout(); |
120 } | 121 } |
121 | 122 |
122 bool DisplayController::WarpMouseCursorIfNecessary( | 123 bool DisplayController::WarpMouseCursorIfNecessary( |
123 aura::Window* current_root, | 124 aura::RootWindow* current_root, |
124 const gfx::Point& location_in_root) { | 125 const gfx::Point& point_in_root) { |
125 if (root_windows_.size() < 2) | 126 if (root_windows_.size() < 2) |
126 return false; | 127 return false; |
127 // Only 1 external display is supported in extended desktop mode. | |
128 DCHECK_EQ(2U, root_windows_.size()); | |
129 | 128 |
130 bool in_primary = current_root == root_windows_[0]; | 129 gfx::Rect root_bounds = current_root->bounds(); |
| 130 int offset_x = 0; |
| 131 int offset_y = 0; |
| 132 if (point_in_root.x() <= root_bounds.x()) { |
| 133 offset_x = -1; |
| 134 } else if (point_in_root.x() >= root_bounds.right() - 1) { |
| 135 offset_x = 1; |
| 136 } else if (point_in_root.y() <= root_bounds.y()) { |
| 137 offset_y = -1; |
| 138 } else if (point_in_root.y() >= root_bounds.bottom() - 1) { |
| 139 offset_y = 1; |
| 140 } else { |
| 141 return false; |
| 142 } |
131 | 143 |
132 std::map<int, aura::RootWindow*>::iterator iter = root_windows_.begin(); | 144 gfx::Point point_in_screen(point_in_root); |
133 aura::RootWindow* alternate_root = iter->second != current_root ? | 145 aura::client::ScreenPositionClient* screen_position_client = |
134 iter->second : (++iter)->second; | 146 aura::client::GetScreenPositionClient(current_root); |
135 gfx::Rect alternate_bounds = alternate_root->bounds(); | 147 screen_position_client->ConvertPointToScreen(current_root, |
136 gfx::Point alternate_point; | 148 &point_in_screen); |
| 149 point_in_screen.Offset(offset_x, offset_y); |
| 150 aura::RootWindow* dst_root = Shell::GetRootWindowAt(point_in_screen); |
| 151 gfx::Point point_in_dst_root(point_in_screen); |
137 | 152 |
138 // TODO(oshima): This is temporary code until the virtual screen | 153 screen_position_client->ConvertPointFromScreen(dst_root, |
139 // coordinate is fully implemented. | 154 &point_in_dst_root); |
140 gfx::Rect display_area(ScreenAsh::ConvertRectFromScreen( | 155 if (dst_root->bounds().Contains(point_in_dst_root)) { |
141 current_root, | 156 DCHECK_NE(dst_root, current_root); |
142 gfx::Screen::GetDisplayNearestWindow(current_root).bounds())); | 157 dst_root->MoveCursorTo(point_in_dst_root); |
143 | |
144 if (location_in_root.x() <= display_area.x()) { | |
145 if (location_in_root.y() < alternate_bounds.height() && | |
146 ((in_primary && secondary_display_layout_ == LEFT) || | |
147 (!in_primary && secondary_display_layout_ == RIGHT))) { | |
148 alternate_point = gfx::Point( | |
149 alternate_bounds.right() - (location_in_root.x() - display_area.x()), | |
150 location_in_root.y()); | |
151 } else { | |
152 alternate_root = NULL; | |
153 } | |
154 } else if (location_in_root.x() >= display_area.right() - 1) { | |
155 if (location_in_root.y() < alternate_bounds.height() && | |
156 ((in_primary && secondary_display_layout_ == RIGHT) || | |
157 (!in_primary && secondary_display_layout_ == LEFT))) { | |
158 alternate_point = gfx::Point(location_in_root.x() - display_area.right(), | |
159 location_in_root.y()); | |
160 } else { | |
161 alternate_root = NULL; | |
162 } | |
163 } else if (location_in_root.y() < display_area.y()) { | |
164 if (location_in_root.x() < alternate_bounds.width() && | |
165 ((in_primary && secondary_display_layout_ == TOP) || | |
166 (!in_primary && secondary_display_layout_ == BOTTOM))) { | |
167 alternate_point = gfx::Point( | |
168 location_in_root.x(), | |
169 alternate_bounds.bottom() - | |
170 (location_in_root.y() - display_area.y())); | |
171 } else { | |
172 alternate_root = NULL; | |
173 } | |
174 } else if (location_in_root.y() >= display_area.bottom() - 1) { | |
175 if (location_in_root.x() < alternate_bounds.width() && | |
176 ((in_primary && secondary_display_layout_ == BOTTOM) || | |
177 (!in_primary && secondary_display_layout_ == TOP))) { | |
178 alternate_point = gfx::Point( | |
179 location_in_root.x(), location_in_root.y() - display_area.bottom()); | |
180 } else { | |
181 alternate_root = NULL; | |
182 } | |
183 } else { | |
184 alternate_root = NULL; | |
185 } | |
186 if (alternate_root) { | |
187 DCHECK_NE(alternate_root, current_root); | |
188 alternate_root->MoveCursorTo(alternate_point); | |
189 return true; | 158 return true; |
190 } | 159 } |
191 return false; | 160 return false; |
192 } | 161 } |
193 | 162 |
194 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 163 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
195 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 164 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); |
196 UpdateDisplayBoundsForLayout(); | 165 UpdateDisplayBoundsForLayout(); |
197 } | 166 } |
198 | 167 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 break; | 250 break; |
282 } | 251 } |
283 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 252 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
284 secondary_display->set_bounds( | 253 secondary_display->set_bounds( |
285 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 254 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
286 secondary_display->UpdateWorkAreaFromInsets(insets); | 255 secondary_display->UpdateWorkAreaFromInsets(insets); |
287 } | 256 } |
288 | 257 |
289 } // namespace internal | 258 } // namespace internal |
290 } // namespace ash | 259 } // namespace ash |
OLD | NEW |