| 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/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 DisplayController::InitPrimaryDisplay() { | 51 void DisplayController::InitPrimaryDisplay() { |
| 52 aura::DisplayManager* display_manager = | 52 aura::DisplayManager* display_manager = |
| 53 aura::Env::GetInstance()->display_manager(); | 53 aura::Env::GetInstance()->display_manager(); |
| 54 const gfx::Display& display = display_manager->GetDisplayAt(0); | 54 const gfx::Display* display = display_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 DisplayController::InitSecondaryDisplays() { | 60 void DisplayController::InitSecondaryDisplays() { |
| 61 aura::DisplayManager* display_manager = | 61 aura::DisplayManager* display_manager = |
| 62 aura::Env::GetInstance()->display_manager(); | 62 aura::Env::GetInstance()->display_manager(); |
| 63 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { | 63 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { |
| 64 const gfx::Display& display = display_manager->GetDisplayAt(i); | 64 const gfx::Display* display = display_manager->GetDisplayAt(i); |
| 65 aura::RootWindow* root = AddRootWindowForDisplay(display); | 65 aura::RootWindow* root = AddRootWindowForDisplay(*display); |
| 66 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 66 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 aura::RootWindow* DisplayController::GetPrimaryRootWindow() { | 70 aura::RootWindow* DisplayController::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 DisplayController::CloseChildWindows() { | 75 void DisplayController::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 DisplayController::SetSecondaryDisplayLayout( | 116 void DisplayController::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 DisplayController::WarpMouseCursorIfNecessary( | 122 bool DisplayController::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 DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 193 void DisplayController::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 DisplayController::OnDisplayAdded(const gfx::Display& display) { | 198 void DisplayController::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()->InitRootWindowForSecondaryDisplay(root); | 206 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
| 207 UpdateDisplayBoundsForLayout(); |
| 205 } | 208 } |
| 206 | 209 |
| 207 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { | 210 void DisplayController::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 display should never be removed by DisplayManager. | 213 // Primary display should never be removed by DisplayManager. |
| 211 DCHECK(root != Shell::GetPrimaryRootWindow()); | 214 DCHECK(root != Shell::GetPrimaryRootWindow()); |
| 212 // Display for root window will be deleted when the Primary RootWindow | 215 // Display 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 16 matching lines...) Expand all Loading... |
| 231 switches::kAshExtendedDesktop); | 234 switches::kAshExtendedDesktop); |
| 232 } | 235 } |
| 233 | 236 |
| 234 // static | 237 // static |
| 235 void DisplayController::SetExtendedDesktopEnabled(bool enabled) { | 238 void DisplayController::SetExtendedDesktopEnabled(bool enabled) { |
| 236 extended_desktop_enabled = enabled; | 239 extended_desktop_enabled = enabled; |
| 237 } | 240 } |
| 238 | 241 |
| 239 // static | 242 // static |
| 240 bool DisplayController::IsVirtualScreenCoordinatesEnabled() { | 243 bool DisplayController::IsVirtualScreenCoordinatesEnabled() { |
| 241 return virtual_screen_coordinates_enabled || | 244 return IsExtendedDesktopEnabled() && |
| 242 CommandLine::ForCurrentProcess()->HasSwitch( | 245 (virtual_screen_coordinates_enabled || |
| 243 switches::kAshVirtualScreenCoordinates); | 246 CommandLine::ForCurrentProcess()->HasSwitch( |
| 247 switches::kAshVirtualScreenCoordinates)); |
| 244 } | 248 } |
| 245 | 249 |
| 246 // static | 250 // static |
| 247 void DisplayController::SetVirtualScreenCoordinatesEnabled(bool enabled) { | 251 void DisplayController::SetVirtualScreenCoordinatesEnabled(bool enabled) { |
| 248 virtual_screen_coordinates_enabled = enabled; | 252 virtual_screen_coordinates_enabled = enabled; |
| 249 } | 253 } |
| 250 | 254 |
| 251 aura::RootWindow* DisplayController::AddRootWindowForDisplay( | 255 aura::RootWindow* DisplayController::AddRootWindowForDisplay( |
| 252 const gfx::Display& display) { | 256 const gfx::Display& display) { |
| 253 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> | 257 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> |
| 254 CreateRootWindowForDisplay(display); | 258 CreateRootWindowForDisplay(display); |
| 255 root_windows_[display.id()] = root; | 259 root_windows_[display.id()] = root; |
| 256 // Confine the cursor within the window if | 260 // Confine the cursor within the window if |
| 257 // 1) Extended desktop is enabled or | 261 // 1) Extended desktop is enabled or |
| 258 // 2) the display is primary display and the host window | 262 // 2) the display is primary display and the host window |
| 259 // is set to be fullscreen (this is old behavior). | 263 // is set to be fullscreen (this is old behavior). |
| 260 if (IsExtendedDesktopEnabled() || | 264 if (IsExtendedDesktopEnabled() || |
| 261 (aura::DisplayManager::use_fullscreen_host_window() && | 265 (aura::DisplayManager::use_fullscreen_host_window() && |
| 262 display.id() == 0)) { | 266 display.id() == 0)) { |
| 263 root->ConfineCursorToWindow(); | 267 root->ConfineCursorToWindow(); |
| 264 } | 268 } |
| 265 return root; | 269 return root; |
| 266 } | 270 } |
| 267 | 271 |
| 272 void DisplayController::UpdateDisplayBoundsForLayout() { |
| 273 if (!IsVirtualScreenCoordinatesEnabled() || |
| 274 gfx::Screen::GetNumDisplays() <= 1) { |
| 275 return; |
| 276 } |
| 277 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); |
| 278 aura::DisplayManager* display_manager = |
| 279 aura::Env::GetInstance()->display_manager(); |
| 280 const gfx::Rect& primary_bounds = display_manager->GetDisplayAt(0)->bounds(); |
| 281 gfx::Display* secondary_display = display_manager->GetDisplayAt(1); |
| 282 const gfx::Rect& secondary_bounds = secondary_display->bounds(); |
| 283 gfx::Point new_secondary_origin = primary_bounds.origin(); |
| 284 |
| 285 // TODO(oshima|mukai): Implement more flexible layout. |
| 286 switch (secondary_display_layout_) { |
| 287 case TOP: |
| 288 new_secondary_origin.Offset(0, -secondary_bounds.height()); |
| 289 break; |
| 290 case RIGHT: |
| 291 new_secondary_origin.Offset(primary_bounds.width(), 0); |
| 292 break; |
| 293 case BOTTOM: |
| 294 new_secondary_origin.Offset(0, primary_bounds.height()); |
| 295 break; |
| 296 case LEFT: |
| 297 new_secondary_origin.Offset(-secondary_bounds.width(), 0); |
| 298 break; |
| 299 } |
| 300 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 301 secondary_display->set_bounds( |
| 302 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 303 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 304 } |
| 305 |
| 268 } // namespace internal | 306 } // namespace internal |
| 269 } // namespace ash | 307 } // namespace ash |
| OLD | NEW |