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/window_util.h" | 12 #include "ash/wm/window_util.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
18 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 namespace internal { | 21 namespace internal { |
22 namespace { | 22 namespace { |
23 // True if the extended desktop mode is enabled. | 23 // True if the extended desktop mode is enabled. |
24 bool extended_desktop_enabled = false; | 24 bool extended_desktop_enabled = false; |
25 | 25 } // namespace |
26 // True if the virtual screen coordinates is enabled. | |
27 bool virtual_screen_coordinates_enabled = false; | |
28 } | |
29 | 26 |
30 DisplayController::DisplayController() | 27 DisplayController::DisplayController() |
31 : secondary_display_layout_(RIGHT) { | 28 : secondary_display_layout_(RIGHT) { |
32 aura::Env::GetInstance()->display_manager()->AddObserver(this); | 29 aura::Env::GetInstance()->display_manager()->AddObserver(this); |
33 } | 30 } |
34 | 31 |
35 DisplayController::~DisplayController() { | 32 DisplayController::~DisplayController() { |
36 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | 33 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); |
37 // Delete all root window controllers, which deletes root window | 34 // Delete all root window controllers, which deletes root window |
38 // from the last so that the primary root window gets deleted last. | 35 // from the last so that the primary root window gets deleted last. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 return extended_desktop_enabled || | 235 return extended_desktop_enabled || |
239 CommandLine::ForCurrentProcess()->HasSwitch( | 236 CommandLine::ForCurrentProcess()->HasSwitch( |
240 switches::kAshExtendedDesktop); | 237 switches::kAshExtendedDesktop); |
241 } | 238 } |
242 | 239 |
243 // static | 240 // static |
244 void DisplayController::SetExtendedDesktopEnabled(bool enabled) { | 241 void DisplayController::SetExtendedDesktopEnabled(bool enabled) { |
245 extended_desktop_enabled = enabled; | 242 extended_desktop_enabled = enabled; |
246 } | 243 } |
247 | 244 |
248 // static | |
249 bool DisplayController::IsVirtualScreenCoordinatesEnabled() { | |
250 return IsExtendedDesktopEnabled() && | |
251 (virtual_screen_coordinates_enabled || | |
252 CommandLine::ForCurrentProcess()->HasSwitch( | |
253 switches::kAshVirtualScreenCoordinates)); | |
254 } | |
255 | |
256 // static | |
257 void DisplayController::SetVirtualScreenCoordinatesEnabled(bool enabled) { | |
258 virtual_screen_coordinates_enabled = enabled; | |
259 } | |
260 | |
261 aura::RootWindow* DisplayController::AddRootWindowForDisplay( | 245 aura::RootWindow* DisplayController::AddRootWindowForDisplay( |
262 const gfx::Display& display) { | 246 const gfx::Display& display) { |
263 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> | 247 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> |
264 CreateRootWindowForDisplay(display); | 248 CreateRootWindowForDisplay(display); |
265 root_windows_[display.id()] = root; | 249 root_windows_[display.id()] = root; |
266 // Confine the cursor within the window if | 250 // Confine the cursor within the window if |
267 // 1) Extended desktop is enabled or | 251 // 1) Extended desktop is enabled or |
268 // 2) the display is primary display and the host window | 252 // 2) the display is primary display and the host window |
269 // is set to be fullscreen (this is old behavior). | 253 // is set to be fullscreen (this is old behavior). |
270 if (IsExtendedDesktopEnabled() || | 254 if (IsExtendedDesktopEnabled() || |
271 (aura::DisplayManager::use_fullscreen_host_window() && | 255 (aura::DisplayManager::use_fullscreen_host_window() && |
272 display.id() == 0)) { | 256 display.id() == 0)) { |
273 root->ConfineCursorToWindow(); | 257 root->ConfineCursorToWindow(); |
274 } | 258 } |
275 return root; | 259 return root; |
276 } | 260 } |
277 | 261 |
278 void DisplayController::UpdateDisplayBoundsForLayout() { | 262 void DisplayController::UpdateDisplayBoundsForLayout() { |
279 if (!IsVirtualScreenCoordinatesEnabled() || | 263 if (!IsExtendedDesktopEnabled() || gfx::Screen::GetNumDisplays() <= 1) { |
280 gfx::Screen::GetNumDisplays() <= 1) { | |
281 return; | 264 return; |
282 } | 265 } |
283 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); | 266 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); |
284 aura::DisplayManager* display_manager = | 267 aura::DisplayManager* display_manager = |
285 aura::Env::GetInstance()->display_manager(); | 268 aura::Env::GetInstance()->display_manager(); |
286 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); | 269 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); |
287 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); | 270 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); |
288 const gfx::Rect& secondary_bounds = secondary_display->bounds(); | 271 const gfx::Rect& secondary_bounds = secondary_display->bounds(); |
289 gfx::Point new_secondary_origin = primary_bounds.origin(); | 272 gfx::Point new_secondary_origin = primary_bounds.origin(); |
290 | 273 |
(...skipping 13 matching lines...) Expand all Loading... |
304 break; | 287 break; |
305 } | 288 } |
306 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 289 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
307 secondary_display->set_bounds( | 290 secondary_display->set_bounds( |
308 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 291 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
309 secondary_display->UpdateWorkAreaFromInsets(insets); | 292 secondary_display->UpdateWorkAreaFromInsets(insets); |
310 } | 293 } |
311 | 294 |
312 } // namespace internal | 295 } // namespace internal |
313 } // namespace ash | 296 } // namespace ash |
OLD | NEW |