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/monitor/monitor_controller.h" | 5 #include "ash/monitor/monitor_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/monitor/multi_monitor_manager.h" | 8 #include "ash/monitor/multi_monitor_manager.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 if (controller) | 44 if (controller) |
45 delete controller; | 45 delete controller; |
46 else | 46 else |
47 delete it->second; | 47 delete it->second; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 void MonitorController::InitPrimaryDisplay() { | 51 void MonitorController::InitPrimaryDisplay() { |
52 aura::MonitorManager* monitor_manager = | 52 aura::MonitorManager* monitor_manager = |
53 aura::Env::GetInstance()->monitor_manager(); | 53 aura::Env::GetInstance()->monitor_manager(); |
54 const gfx::Display& display = monitor_manager->GetDisplayAt(0); | 54 const gfx::Display* display = monitor_manager->GetDisplayAt(0); |
55 DCHECK_EQ(0, display.id()); | 55 DCHECK_EQ(0, display->id()); |
56 aura::RootWindow* root = AddRootWindowForDisplay(display); | 56 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
57 root->SetHostBounds(display.bounds_in_pixel()); | 57 root->SetHostBounds(display->bounds_in_pixel()); |
58 } | 58 } |
59 | 59 |
60 void MonitorController::InitSecondaryDisplays() { | 60 void MonitorController::InitSecondaryDisplays() { |
61 aura::MonitorManager* monitor_manager = | 61 aura::MonitorManager* monitor_manager = |
62 aura::Env::GetInstance()->monitor_manager(); | 62 aura::Env::GetInstance()->monitor_manager(); |
63 for (size_t i = 1; i < monitor_manager->GetNumDisplays(); ++i) { | 63 for (size_t i = 1; i < monitor_manager->GetNumDisplays(); ++i) { |
64 const gfx::Display& display = monitor_manager->GetDisplayAt(i); | 64 const gfx::Display* display = monitor_manager->GetDisplayAt(i); |
65 aura::RootWindow* root = AddRootWindowForDisplay(display); | 65 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
66 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); | 66 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 aura::RootWindow* MonitorController::GetPrimaryRootWindow() { | 70 aura::RootWindow* MonitorController::GetPrimaryRootWindow() { |
71 DCHECK(!root_windows_.empty()); | 71 DCHECK(!root_windows_.empty()); |
72 return root_windows_[0]; | 72 return root_windows_[0]; |
73 } | 73 } |
74 | 74 |
75 void MonitorController::CloseChildWindows() { | 75 void MonitorController::CloseChildWindows() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 wm::GetRootWindowController(it->second); | 109 wm::GetRootWindowController(it->second); |
110 if (controller) | 110 if (controller) |
111 controllers.push_back(controller); | 111 controllers.push_back(controller); |
112 } | 112 } |
113 return controllers; | 113 return controllers; |
114 } | 114 } |
115 | 115 |
116 void MonitorController::SetSecondaryDisplayLayout( | 116 void MonitorController::SetSecondaryDisplayLayout( |
117 SecondaryDisplayLayout layout) { | 117 SecondaryDisplayLayout layout) { |
118 secondary_display_layout_ = layout; | 118 secondary_display_layout_ = layout; |
| 119 UpdateDisplayBoundsForLayout(); |
119 } | 120 } |
120 | 121 |
121 bool MonitorController::WarpMouseCursorIfNecessary( | 122 bool MonitorController::WarpMouseCursorIfNecessary( |
122 aura::Window* current_root, | 123 aura::Window* current_root, |
123 const gfx::Point& location_in_root) { | 124 const gfx::Point& location_in_root) { |
124 if (root_windows_.size() < 2) | 125 if (root_windows_.size() < 2) |
125 return false; | 126 return false; |
126 // Only 1 external display is supported in extended desktop mode. | 127 // Only 1 external display is supported in extended desktop mode. |
127 DCHECK_EQ(2U, root_windows_.size()); | 128 DCHECK_EQ(2U, root_windows_.size()); |
128 | 129 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (alternate_root) { | 185 if (alternate_root) { |
185 DCHECK_NE(alternate_root, current_root); | 186 DCHECK_NE(alternate_root, current_root); |
186 alternate_root->MoveCursorTo(alternate_point); | 187 alternate_root->MoveCursorTo(alternate_point); |
187 return true; | 188 return true; |
188 } | 189 } |
189 return false; | 190 return false; |
190 } | 191 } |
191 | 192 |
192 void MonitorController::OnDisplayBoundsChanged(const gfx::Display& display) { | 193 void MonitorController::OnDisplayBoundsChanged(const gfx::Display& display) { |
193 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 194 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); |
| 195 UpdateDisplayBoundsForLayout(); |
194 } | 196 } |
195 | 197 |
196 void MonitorController::OnDisplayAdded(const gfx::Display& display) { | 198 void MonitorController::OnDisplayAdded(const gfx::Display& display) { |
197 if (root_windows_.empty()) { | 199 if (root_windows_.empty()) { |
198 DCHECK_EQ(0, display.id()); | 200 DCHECK_EQ(0, display.id()); |
199 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); | 201 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); |
200 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); | 202 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); |
201 return; | 203 return; |
202 } | 204 } |
203 aura::RootWindow* root = AddRootWindowForDisplay(display); | 205 aura::RootWindow* root = AddRootWindowForDisplay(display); |
204 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); | 206 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); |
| 207 UpdateDisplayBoundsForLayout(); |
205 } | 208 } |
206 | 209 |
207 void MonitorController::OnDisplayRemoved(const gfx::Display& display) { | 210 void MonitorController::OnDisplayRemoved(const gfx::Display& display) { |
208 aura::RootWindow* root = root_windows_[display.id()]; | 211 aura::RootWindow* root = root_windows_[display.id()]; |
209 DCHECK(root); | 212 DCHECK(root); |
210 // Primary monitor should never be removed by MonitorManager. | 213 // Primary monitor should never be removed by MonitorManager. |
211 DCHECK(root != Shell::GetPrimaryRootWindow()); | 214 DCHECK(root != Shell::GetPrimaryRootWindow()); |
212 // Monitor for root window will be deleted when the Primary RootWindow | 215 // Monitor for root window will be deleted when the Primary RootWindow |
213 // is deleted by the Shell. | 216 // is deleted by the Shell. |
214 if (root != Shell::GetPrimaryRootWindow()) { | 217 if (root != Shell::GetPrimaryRootWindow()) { |
(...skipping 14 matching lines...) Expand all Loading... |
229 switches::kAshExtendedDesktop); | 232 switches::kAshExtendedDesktop); |
230 } | 233 } |
231 | 234 |
232 // static | 235 // static |
233 void MonitorController::SetExtendedDesktopEnabled(bool enabled) { | 236 void MonitorController::SetExtendedDesktopEnabled(bool enabled) { |
234 extended_desktop_enabled = enabled; | 237 extended_desktop_enabled = enabled; |
235 } | 238 } |
236 | 239 |
237 // static | 240 // static |
238 bool MonitorController::IsVirtualScreenCoordinatesEnabled() { | 241 bool MonitorController::IsVirtualScreenCoordinatesEnabled() { |
239 return virtual_screen_coordinates_enabled || | 242 return IsExtendedDesktopEnabled() && |
240 CommandLine::ForCurrentProcess()->HasSwitch( | 243 (virtual_screen_coordinates_enabled || |
241 switches::kAshVirtualScreenCoordinates); | 244 CommandLine::ForCurrentProcess()->HasSwitch( |
| 245 switches::kAshVirtualScreenCoordinates)); |
242 } | 246 } |
243 | 247 |
244 // static | 248 // static |
245 void MonitorController::SetVirtualScreenCoordinatesEnabled(bool enabled) { | 249 void MonitorController::SetVirtualScreenCoordinatesEnabled(bool enabled) { |
246 virtual_screen_coordinates_enabled = enabled; | 250 virtual_screen_coordinates_enabled = enabled; |
247 } | 251 } |
248 | 252 |
249 aura::RootWindow* MonitorController::AddRootWindowForDisplay( | 253 aura::RootWindow* MonitorController::AddRootWindowForDisplay( |
250 const gfx::Display& display) { | 254 const gfx::Display& display) { |
251 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> | 255 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> |
252 CreateRootWindowForMonitor(display); | 256 CreateRootWindowForMonitor(display); |
253 root_windows_[display.id()] = root; | 257 root_windows_[display.id()] = root; |
254 // Confine the cursor within the window if | 258 // Confine the cursor within the window if |
255 // 1) Extended desktop is enabled or | 259 // 1) Extended desktop is enabled or |
256 // 2) the display is primary monitor and the host window | 260 // 2) the display is primary monitor and the host window |
257 // is set to be fullscreen (this is old behavior). | 261 // is set to be fullscreen (this is old behavior). |
258 if (IsExtendedDesktopEnabled() || | 262 if (IsExtendedDesktopEnabled() || |
259 (aura::MonitorManager::use_fullscreen_host_window() && | 263 (aura::MonitorManager::use_fullscreen_host_window() && |
260 display.id() == 0)) { | 264 display.id() == 0)) { |
261 root->ConfineCursorToWindow(); | 265 root->ConfineCursorToWindow(); |
262 } | 266 } |
263 return root; | 267 return root; |
264 } | 268 } |
265 | 269 |
| 270 void MonitorController::UpdateDisplayBoundsForLayout() { |
| 271 if (!IsVirtualScreenCoordinatesEnabled() || |
| 272 gfx::Screen::GetNumDisplays() <= 1) { |
| 273 return; |
| 274 } |
| 275 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); |
| 276 aura::MonitorManager* monitor_manager = |
| 277 aura::Env::GetInstance()->monitor_manager(); |
| 278 const gfx::Rect& primary_bounds = monitor_manager->GetDisplayAt(0)->bounds(); |
| 279 gfx::Display* secondary_display = monitor_manager->GetDisplayAt(1); |
| 280 const gfx::Rect& secondary_bounds = secondary_display->bounds(); |
| 281 gfx::Point new_secondary_origin = primary_bounds.origin(); |
| 282 |
| 283 // TODO(oshima|mukai): Implement more flexible layout. |
| 284 switch (secondary_display_layout_) { |
| 285 case TOP: |
| 286 new_secondary_origin.Offset(0, -secondary_bounds.height()); |
| 287 break; |
| 288 case RIGHT: |
| 289 new_secondary_origin.Offset(primary_bounds.width(), 0); |
| 290 break; |
| 291 case BOTTOM: |
| 292 new_secondary_origin.Offset(0, primary_bounds.height()); |
| 293 break; |
| 294 case LEFT: |
| 295 new_secondary_origin.Offset(-secondary_bounds.width(), 0); |
| 296 break; |
| 297 } |
| 298 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 299 secondary_display->set_bounds( |
| 300 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 301 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 302 } |
| 303 |
266 } // namespace internal | 304 } // namespace internal |
267 } // namespace ash | 305 } // namespace ash |
OLD | NEW |