| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/maximize_mode/maximize_mode_window_manager.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" |
| 7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 8 #include "ash/switchable_windows.h" | 9 #include "ash/switchable_windows.h" |
| 9 #include "ash/wm/mru_window_tracker.h" | 10 #include "ash/wm/mru_window_tracker.h" |
| 11 #include "ash/wm/workspace_controller.h" |
| 10 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 11 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
| 12 | 14 |
| 13 namespace ash { | 15 namespace ash { |
| 14 namespace internal { | 16 namespace internal { |
| 15 | 17 |
| 16 MaximizeModeWindowManager::~MaximizeModeWindowManager() { | 18 MaximizeModeWindowManager::~MaximizeModeWindowManager() { |
| 19 Shell::GetInstance()->RemoveShellObserver(this); |
| 17 Shell::GetScreen()->RemoveObserver(this); | 20 Shell::GetScreen()->RemoveObserver(this); |
| 21 EnableBackdropBehindTopWindowOnEachDisplay(false); |
| 18 RemoveWindowCreationObservers(); | 22 RemoveWindowCreationObservers(); |
| 19 RestoreAllWindows(); | 23 RestoreAllWindows(); |
| 20 } | 24 } |
| 21 | 25 |
| 22 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { | 26 int MaximizeModeWindowManager::GetNumberOfManagedWindows() { |
| 23 return initial_show_state_.size(); | 27 return initial_show_state_.size(); |
| 24 } | 28 } |
| 25 | 29 |
| 30 void MaximizeModeWindowManager::OnOverviewModeStarted() { |
| 31 if (backdrops_hidden_) |
| 32 return; |
| 33 |
| 34 EnableBackdropBehindTopWindowOnEachDisplay(false); |
| 35 backdrops_hidden_ = true; |
| 36 } |
| 37 |
| 38 void MaximizeModeWindowManager::OnOverviewModeEnded() { |
| 39 if (!backdrops_hidden_) |
| 40 return; |
| 41 |
| 42 backdrops_hidden_ = false; |
| 43 EnableBackdropBehindTopWindowOnEachDisplay(true); |
| 44 } |
| 45 |
| 26 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) { | 46 void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) { |
| 27 // If a known window gets destroyed we need to remove all knowledge about it. | 47 // If a known window gets destroyed we need to remove all knowledge about it. |
| 28 if (!IsContainerWindow(window)) | 48 if (!IsContainerWindow(window)) |
| 29 ForgetWindow(window); | 49 ForgetWindow(window); |
| 30 } | 50 } |
| 31 | 51 |
| 32 void MaximizeModeWindowManager::OnWindowAdded( | 52 void MaximizeModeWindowManager::OnWindowAdded( |
| 33 aura::Window* window) { | 53 aura::Window* window) { |
| 34 // A window can get removed and then re-added by a drag and drop operation. | 54 // A window can get removed and then re-added by a drag and drop operation. |
| 35 if (IsContainerWindow(window->parent()) && | 55 if (IsContainerWindow(window->parent()) && |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 CenterWindow(it->first); | 71 CenterWindow(it->first); |
| 52 } | 72 } |
| 53 } | 73 } |
| 54 | 74 |
| 55 void MaximizeModeWindowManager::OnDisplayBoundsChanged( | 75 void MaximizeModeWindowManager::OnDisplayBoundsChanged( |
| 56 const gfx::Display& display) { | 76 const gfx::Display& display) { |
| 57 // Nothing to do here. | 77 // Nothing to do here. |
| 58 } | 78 } |
| 59 | 79 |
| 60 void MaximizeModeWindowManager::OnDisplayAdded(const gfx::Display& display) { | 80 void MaximizeModeWindowManager::OnDisplayAdded(const gfx::Display& display) { |
| 61 RemoveWindowCreationObservers(); | 81 DisplayConfigurationChanged(); |
| 62 AddWindowCreationObservers(); | |
| 63 | |
| 64 } | |
| 65 void MaximizeModeWindowManager::OnDisplayRemoved(const gfx::Display& display) { | |
| 66 RemoveWindowCreationObservers(); | |
| 67 AddWindowCreationObservers(); | |
| 68 } | 82 } |
| 69 | 83 |
| 70 MaximizeModeWindowManager::MaximizeModeWindowManager() { | 84 void MaximizeModeWindowManager::OnDisplayRemoved(const gfx::Display& display) { |
| 85 DisplayConfigurationChanged(); |
| 86 } |
| 87 |
| 88 MaximizeModeWindowManager::MaximizeModeWindowManager() |
| 89 : backdrops_hidden_(false) { |
| 71 MaximizeAllWindows(); | 90 MaximizeAllWindows(); |
| 72 AddWindowCreationObservers(); | 91 AddWindowCreationObservers(); |
| 92 EnableBackdropBehindTopWindowOnEachDisplay(true); |
| 73 Shell::GetScreen()->AddObserver(this); | 93 Shell::GetScreen()->AddObserver(this); |
| 94 Shell::GetInstance()->AddShellObserver(this); |
| 74 } | 95 } |
| 75 | 96 |
| 76 void MaximizeModeWindowManager::MaximizeAllWindows() { | 97 void MaximizeModeWindowManager::MaximizeAllWindows() { |
| 77 MruWindowTracker::WindowList windows = | 98 MruWindowTracker::WindowList windows = |
| 78 MruWindowTracker::BuildWindowList(false); | 99 MruWindowTracker::BuildWindowList(false); |
| 79 // Add all existing Mru windows. | 100 // Add all existing Mru windows. |
| 101 // TODO(skuhne): The MRUWindowTracker also includes always on top and panel |
| 102 // windows. Panel windows shouldn't be a problem, but always on top might be. |
| 80 for (MruWindowTracker::WindowList::iterator window = windows.begin(); | 103 for (MruWindowTracker::WindowList::iterator window = windows.begin(); |
| 81 window != windows.end(); ++window) { | 104 window != windows.end(); ++window) { |
| 82 MaximizeAndTrackWindow(*window); | 105 MaximizeAndTrackWindow(*window); |
| 83 } | 106 } |
| 84 } | 107 } |
| 85 | 108 |
| 86 void MaximizeModeWindowManager::RestoreAllWindows() { | 109 void MaximizeModeWindowManager::RestoreAllWindows() { |
| 87 WindowToShowState::iterator it = initial_show_state_.begin(); | 110 WindowToShowState::iterator it = initial_show_state_.begin(); |
| 88 while (it != initial_show_state_.end()) { | 111 while (it != initial_show_state_.end()) { |
| 89 RestoreAndForgetWindow(it->first); | 112 RestoreAndForgetWindow(it->first); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 109 // This window type should not be able to have a restore state set (since | 132 // This window type should not be able to have a restore state set (since |
| 110 // it cannot maximize). | 133 // it cannot maximize). |
| 111 DCHECK(!window_state->HasRestoreBounds()); | 134 DCHECK(!window_state->HasRestoreBounds()); |
| 112 // Store the coordinates as restore coordinates. | 135 // Store the coordinates as restore coordinates. |
| 113 gfx::Rect initial_rect = window->bounds(); | 136 gfx::Rect initial_rect = window->bounds(); |
| 114 if (window->parent()) | 137 if (window->parent()) |
| 115 window_state->SetRestoreBoundsInParent(initial_rect); | 138 window_state->SetRestoreBoundsInParent(initial_rect); |
| 116 else | 139 else |
| 117 window_state->SetRestoreBoundsInScreen(initial_rect); | 140 window_state->SetRestoreBoundsInScreen(initial_rect); |
| 118 CenterWindow(window); | 141 CenterWindow(window); |
| 119 // TODO(skuhne): Add a background cover layer. | |
| 120 } else { | 142 } else { |
| 121 // Minimized windows can remain as they are. | 143 // Minimized windows can remain as they are. |
| 122 if (state != ui::SHOW_STATE_MINIMIZED) | 144 if (state != ui::SHOW_STATE_MINIMIZED) |
| 123 ash::wm::GetWindowState(window)->Maximize(); | 145 ash::wm::GetWindowState(window)->Maximize(); |
| 124 } | 146 } |
| 125 } | 147 } |
| 126 } | 148 } |
| 127 | 149 |
| 128 void MaximizeModeWindowManager::RestoreAndForgetWindow( | 150 void MaximizeModeWindowManager::RestoreAndForgetWindow( |
| 129 aura::Window* window) { | 151 aura::Window* window) { |
| 130 ui::WindowShowState state = ForgetWindow(window); | 152 ui::WindowShowState state = ForgetWindow(window); |
| 131 // Restore window if it can be restored. | 153 // Restore window if it can be restored. |
| 132 if (state != ui::SHOW_STATE_MAXIMIZED) { | 154 if (state != ui::SHOW_STATE_MAXIMIZED) { |
| 133 if (!CanMaximize(window)) { | 155 if (!CanMaximize(window)) { |
| 134 // TODO(skuhne): Remove the background cover layer. | |
| 135 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); | 156 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); |
| 136 DCHECK(window_state->HasRestoreBounds()); | 157 DCHECK(window_state->HasRestoreBounds()); |
| 137 gfx::Rect initial_bounds = | 158 gfx::Rect initial_bounds = |
| 138 window->parent() ? window_state->GetRestoreBoundsInParent() : | 159 window->parent() ? window_state->GetRestoreBoundsInParent() : |
| 139 window_state->GetRestoreBoundsInScreen(); | 160 window_state->GetRestoreBoundsInScreen(); |
| 140 window_state->ClearRestoreBounds(); | 161 window_state->ClearRestoreBounds(); |
| 141 // TODO(skuhne): The screen might have changed and we should make it | 162 // TODO(skuhne): The screen might have changed and we should make it |
| 142 // visible area again. | 163 // visible area again. |
| 143 window->SetBounds(initial_bounds); | 164 window->SetBounds(initial_bounds); |
| 144 } else { | 165 } else { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 window->SetBounds(window_bounds); | 207 window->SetBounds(window_bounds); |
| 187 } | 208 } |
| 188 | 209 |
| 189 void MaximizeModeWindowManager::AddWindowCreationObservers() { | 210 void MaximizeModeWindowManager::AddWindowCreationObservers() { |
| 190 DCHECK(observed_container_windows_.empty()); | 211 DCHECK(observed_container_windows_.empty()); |
| 191 // Observe window activations and switchable containers on all root windows | 212 // Observe window activations and switchable containers on all root windows |
| 192 // for newly created windows during overview. | 213 // for newly created windows during overview. |
| 193 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 214 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 194 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | 215 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| 195 iter != root_windows.end(); ++iter) { | 216 iter != root_windows.end(); ++iter) { |
| 217 // TODO(skuhne): We might only need the DefaultContainer here. |
| 196 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { | 218 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { |
| 197 aura::Window* container = Shell::GetContainer(*iter, | 219 aura::Window* container = Shell::GetContainer(*iter, |
| 198 kSwitchableWindowContainerIds[i]); | 220 kSwitchableWindowContainerIds[i]); |
| 199 DCHECK(observed_container_windows_.find(container) == | 221 DCHECK(observed_container_windows_.find(container) == |
| 200 observed_container_windows_.end()); | 222 observed_container_windows_.end()); |
| 201 container->AddObserver(this); | 223 container->AddObserver(this); |
| 202 observed_container_windows_.insert(container); | 224 observed_container_windows_.insert(container); |
| 203 } | 225 } |
| 204 } | 226 } |
| 205 } | 227 } |
| 206 | 228 |
| 207 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { | 229 void MaximizeModeWindowManager::RemoveWindowCreationObservers() { |
| 208 for (std::set<aura::Window*>::iterator iter = | 230 for (std::set<aura::Window*>::iterator iter = |
| 209 observed_container_windows_.begin(); | 231 observed_container_windows_.begin(); |
| 210 iter != observed_container_windows_.end(); ++iter) { | 232 iter != observed_container_windows_.end(); ++iter) { |
| 211 (*iter)->RemoveObserver(this); | 233 (*iter)->RemoveObserver(this); |
| 212 } | 234 } |
| 213 observed_container_windows_.clear(); | 235 observed_container_windows_.clear(); |
| 214 } | 236 } |
| 215 | 237 |
| 238 void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( |
| 239 bool enable) { |
| 240 if (backdrops_hidden_) |
| 241 return; |
| 242 // Inform the WorkspaceLayoutManager that we want to show a backdrop behind |
| 243 // the topmost window of its container. |
| 244 Shell::RootWindowControllerList controllers = |
| 245 Shell::GetAllRootWindowControllers(); |
| 246 for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); |
| 247 iter != controllers.end(); ++iter) { |
| 248 RootWindowController* controller = *iter; |
| 249 controller->workspace_controller()->AddBackdropBehindTopWindow(enable); |
| 250 } |
| 251 } |
| 252 |
| 216 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { | 253 bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) { |
| 217 return observed_container_windows_.find(window) != | 254 return observed_container_windows_.find(window) != |
| 218 observed_container_windows_.end(); | 255 observed_container_windows_.end(); |
| 219 } | 256 } |
| 220 | 257 |
| 258 void MaximizeModeWindowManager::DisplayConfigurationChanged() { |
| 259 EnableBackdropBehindTopWindowOnEachDisplay(false); |
| 260 RemoveWindowCreationObservers(); |
| 261 AddWindowCreationObservers(); |
| 262 EnableBackdropBehindTopWindowOnEachDisplay(true); |
| 263 } |
| 264 |
| 221 } // namespace internal | 265 } // namespace internal |
| 222 } // namespace ash | 266 } // namespace ash |
| OLD | NEW |