| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 DisplayController::DisplayController() | 26 DisplayController::DisplayController() |
| 27 : secondary_display_layout_(RIGHT), | 27 : secondary_display_layout_(RIGHT), |
| 28 dont_warp_mouse_(false) { | 28 dont_warp_mouse_(false) { |
| 29 aura::Env::GetInstance()->display_manager()->AddObserver(this); | 29 aura::Env::GetInstance()->display_manager()->AddObserver(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 DisplayController::~DisplayController() { | 32 DisplayController::~DisplayController() { |
| 33 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | 33 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); |
| 34 // Delete all root window controllers, which deletes root window | 34 // Delete all root window controllers, which deletes root window |
| 35 // 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. |
| 36 for (std::map<int, aura::RootWindow*>::const_reverse_iterator it = | 36 for (std::map<int64, aura::RootWindow*>::const_reverse_iterator it = |
| 37 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 37 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { |
| 38 internal::RootWindowController* controller = | 38 internal::RootWindowController* controller = |
| 39 GetRootWindowController(it->second); | 39 GetRootWindowController(it->second); |
| 40 // RootWindow may not have RootWindowController in non | 40 // RootWindow may not have RootWindowController in non |
| 41 // extended desktop mode. | 41 // extended desktop mode. |
| 42 if (controller) | 42 if (controller) |
| 43 delete controller; | 43 delete controller; |
| 44 else | 44 else |
| 45 delete it->second; | 45 delete it->second; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 void DisplayController::InitPrimaryDisplay() { | 49 void DisplayController::InitPrimaryDisplay() { |
| 50 aura::DisplayManager* display_manager = | 50 aura::DisplayManager* display_manager = |
| 51 aura::Env::GetInstance()->display_manager(); | 51 aura::Env::GetInstance()->display_manager(); |
| 52 const gfx::Display* display = display_manager->GetDisplayAt(0); | 52 const gfx::Display* display = display_manager->GetDisplayAt(0); |
| 53 DCHECK_EQ(0, display->id()); | 53 aura::RootWindow* root = AddRootWindowForDisplay(*display, true); |
| 54 aura::RootWindow* root = AddRootWindowForDisplay(*display); | |
| 55 root->SetHostBounds(display->bounds_in_pixel()); | 54 root->SetHostBounds(display->bounds_in_pixel()); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void DisplayController::InitSecondaryDisplays() { | 57 void DisplayController::InitSecondaryDisplays() { |
| 59 aura::DisplayManager* display_manager = | 58 aura::DisplayManager* display_manager = |
| 60 aura::Env::GetInstance()->display_manager(); | 59 aura::Env::GetInstance()->display_manager(); |
| 61 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { | 60 for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) { |
| 62 const gfx::Display* display = display_manager->GetDisplayAt(i); | 61 const gfx::Display* display = display_manager->GetDisplayAt(i); |
| 63 aura::RootWindow* root = AddRootWindowForDisplay(*display); | 62 aura::RootWindow* root = AddRootWindowForDisplay(*display, false); |
| 64 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 63 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
| 65 } | 64 } |
| 66 UpdateDisplayBoundsForLayout(); | 65 UpdateDisplayBoundsForLayout(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 aura::RootWindow* DisplayController::GetPrimaryRootWindow() { | 68 aura::RootWindow* DisplayController::GetPrimaryRootWindow() { |
| 70 DCHECK(!root_windows_.empty()); | 69 DCHECK(!root_windows_.empty()); |
| 71 return root_windows_[0]; | 70 aura::DisplayManager* display_manager = |
| 71 aura::Env::GetInstance()->display_manager(); |
| 72 return root_windows_[display_manager->GetDisplayAt(0)->id()]; |
| 72 } | 73 } |
| 73 | 74 |
| 74 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int id) { | 75 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int id) { |
| 75 return root_windows_[id]; | 76 return root_windows_[id]; |
| 76 } | 77 } |
| 77 | 78 |
| 78 void DisplayController::CloseChildWindows() { | 79 void DisplayController::CloseChildWindows() { |
| 79 for (std::map<int, aura::RootWindow*>::const_iterator it = | 80 for (std::map<int64, aura::RootWindow*>::const_iterator it = |
| 80 root_windows_.begin(); it != root_windows_.end(); ++it) { | 81 root_windows_.begin(); it != root_windows_.end(); ++it) { |
| 81 aura::RootWindow* root_window = it->second; | 82 aura::RootWindow* root_window = it->second; |
| 82 internal::RootWindowController* controller = | 83 internal::RootWindowController* controller = |
| 83 GetRootWindowController(root_window); | 84 GetRootWindowController(root_window); |
| 84 if (controller) { | 85 if (controller) { |
| 85 controller->CloseChildWindows(); | 86 controller->CloseChildWindows(); |
| 86 } else { | 87 } else { |
| 87 while (!root_window->children().empty()) { | 88 while (!root_window->children().empty()) { |
| 88 aura::Window* child = root_window->children()[0]; | 89 aura::Window* child = root_window->children()[0]; |
| 89 delete child; | 90 delete child; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 std::vector<aura::RootWindow*> DisplayController::GetAllRootWindows() { | 96 std::vector<aura::RootWindow*> DisplayController::GetAllRootWindows() { |
| 96 std::vector<aura::RootWindow*> windows; | 97 std::vector<aura::RootWindow*> windows; |
| 97 for (std::map<int, aura::RootWindow*>::const_iterator it = | 98 for (std::map<int64, aura::RootWindow*>::const_iterator it = |
| 98 root_windows_.begin(); it != root_windows_.end(); ++it) { | 99 root_windows_.begin(); it != root_windows_.end(); ++it) { |
| 99 DCHECK(it->second); | 100 DCHECK(it->second); |
| 100 if (GetRootWindowController(it->second)) | 101 if (GetRootWindowController(it->second)) |
| 101 windows.push_back(it->second); | 102 windows.push_back(it->second); |
| 102 } | 103 } |
| 103 return windows; | 104 return windows; |
| 104 } | 105 } |
| 105 | 106 |
| 106 std::vector<internal::RootWindowController*> | 107 std::vector<internal::RootWindowController*> |
| 107 DisplayController::GetAllRootWindowControllers() { | 108 DisplayController::GetAllRootWindowControllers() { |
| 108 std::vector<internal::RootWindowController*> controllers; | 109 std::vector<internal::RootWindowController*> controllers; |
| 109 for (std::map<int, aura::RootWindow*>::const_iterator it = | 110 for (std::map<int64, aura::RootWindow*>::const_iterator it = |
| 110 root_windows_.begin(); it != root_windows_.end(); ++it) { | 111 root_windows_.begin(); it != root_windows_.end(); ++it) { |
| 111 internal::RootWindowController* controller = | 112 internal::RootWindowController* controller = |
| 112 GetRootWindowController(it->second); | 113 GetRootWindowController(it->second); |
| 113 if (controller) | 114 if (controller) |
| 114 controllers.push_back(controller); | 115 controllers.push_back(controller); |
| 115 } | 116 } |
| 116 return controllers; | 117 return controllers; |
| 117 } | 118 } |
| 118 | 119 |
| 119 void DisplayController::SetSecondaryDisplayLayout( | 120 void DisplayController::SetSecondaryDisplayLayout( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return false; | 169 return false; |
| 169 } | 170 } |
| 170 | 171 |
| 171 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 172 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 172 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); | 173 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); |
| 173 UpdateDisplayBoundsForLayout(); | 174 UpdateDisplayBoundsForLayout(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void DisplayController::OnDisplayAdded(const gfx::Display& display) { | 177 void DisplayController::OnDisplayAdded(const gfx::Display& display) { |
| 177 if (root_windows_.empty()) { | 178 if (root_windows_.empty()) { |
| 178 DCHECK_EQ(0, display.id()); | |
| 179 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); | 179 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); |
| 180 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); | 180 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); |
| 181 return; | 181 return; |
| 182 } | 182 } |
| 183 aura::RootWindow* root = AddRootWindowForDisplay(display); | 183 aura::RootWindow* root = AddRootWindowForDisplay(display, false); |
| 184 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); | 184 Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root); |
| 185 UpdateDisplayBoundsForLayout(); | 185 UpdateDisplayBoundsForLayout(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { | 188 void DisplayController::OnDisplayRemoved(const gfx::Display& display) { |
| 189 aura::RootWindow* root = root_windows_[display.id()]; | 189 aura::RootWindow* root = root_windows_[display.id()]; |
| 190 DCHECK(root); | 190 DCHECK(root); |
| 191 // Primary display should never be removed by DisplayManager. | 191 // Primary display should never be removed by DisplayManager. |
| 192 DCHECK(root != Shell::GetPrimaryRootWindow()); | 192 DCHECK(root != Shell::GetPrimaryRootWindow()); |
| 193 // Display for root window will be deleted when the Primary RootWindow | 193 // Display for root window will be deleted when the Primary RootWindow |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 | 207 |
| 208 // static | 208 // static |
| 209 bool DisplayController::IsExtendedDesktopEnabled(){ | 209 bool DisplayController::IsExtendedDesktopEnabled(){ |
| 210 static bool extended_desktop_disabled = | 210 static bool extended_desktop_disabled = |
| 211 CommandLine::ForCurrentProcess()->HasSwitch( | 211 CommandLine::ForCurrentProcess()->HasSwitch( |
| 212 switches::kAshExtendedDesktopDisabled); | 212 switches::kAshExtendedDesktopDisabled); |
| 213 return !extended_desktop_disabled; | 213 return !extended_desktop_disabled; |
| 214 } | 214 } |
| 215 | 215 |
| 216 aura::RootWindow* DisplayController::AddRootWindowForDisplay( | 216 aura::RootWindow* DisplayController::AddRootWindowForDisplay( |
| 217 const gfx::Display& display) { | 217 const gfx::Display& display, bool is_primary) { |
| 218 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> | 218 aura::RootWindow* root = aura::Env::GetInstance()->display_manager()-> |
| 219 CreateRootWindowForDisplay(display); | 219 CreateRootWindowForDisplay(display); |
| 220 root_windows_[display.id()] = root; | 220 root_windows_[display.id()] = root; |
| 221 // Confine the cursor within the window if | 221 // Confine the cursor within the window if |
| 222 // 1) Extended desktop is enabled or | 222 // 1) Extended desktop is enabled or |
| 223 // 2) the display is primary display and the host window | 223 // 2) the display is primary display and the host window |
| 224 // is set to be fullscreen (this is old behavior). | 224 // is set to be fullscreen (this is old behavior). |
| 225 if (IsExtendedDesktopEnabled() || | 225 if (IsExtendedDesktopEnabled() || |
| 226 (aura::DisplayManager::use_fullscreen_host_window() && | 226 (aura::DisplayManager::use_fullscreen_host_window() && is_primary)) { |
| 227 display.id() == 0)) { | |
| 228 root->ConfineCursorToWindow(); | 227 root->ConfineCursorToWindow(); |
| 229 } | 228 } |
| 230 return root; | 229 return root; |
| 231 } | 230 } |
| 232 | 231 |
| 233 void DisplayController::UpdateDisplayBoundsForLayout() { | 232 void DisplayController::UpdateDisplayBoundsForLayout() { |
| 234 if (!IsExtendedDesktopEnabled() || gfx::Screen::GetNumDisplays() <= 1) { | 233 if (!IsExtendedDesktopEnabled() || gfx::Screen::GetNumDisplays() <= 1) { |
| 235 return; | 234 return; |
| 236 } | 235 } |
| 237 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); | 236 DCHECK_EQ(2, gfx::Screen::GetNumDisplays()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 258 break; | 257 break; |
| 259 } | 258 } |
| 260 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 259 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 261 secondary_display->set_bounds( | 260 secondary_display->set_bounds( |
| 262 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 261 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 263 secondary_display->UpdateWorkAreaFromInsets(insets); | 262 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 264 } | 263 } |
| 265 | 264 |
| 266 } // namespace internal | 265 } // namespace internal |
| 267 } // namespace ash | 266 } // namespace ash |
| OLD | NEW |