| 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/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/session_state_delegate.h" | 9 #include "ash/session_state_delegate.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 aura::Window* window) { | 67 aura::Window* window) { |
| 68 if (window->GetProperty(aura::client::kConstrainedWindowKey)) { | 68 if (window->GetProperty(aura::client::kConstrainedWindowKey)) { |
| 69 BoundsMap::const_iterator i = bounds_map.find(window); | 69 BoundsMap::const_iterator i = bounds_map.find(window); |
| 70 if (i != bounds_map.end()) | 70 if (i != bounds_map.end()) |
| 71 window->SetBounds(i->second); | 71 window->SetBounds(i->second); |
| 72 } | 72 } |
| 73 for (size_t i = 0; i < window->children().size(); ++i) | 73 for (size_t i = 0; i < window->children().size(); ++i) |
| 74 ResetConstrainedWindowBoundsIfNecessary(bounds_map, window->children()[i]); | 74 ResetConstrainedWindowBoundsIfNecessary(bounds_map, window->children()[i]); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool IsMaximizedState(ui::WindowShowState state) { |
| 78 return state == ui::SHOW_STATE_MAXIMIZED || |
| 79 state == ui::SHOW_STATE_FULLSCREEN; |
| 80 } |
| 81 |
| 77 } // namespace | 82 } // namespace |
| 78 | 83 |
| 79 WorkspaceLayoutManager::WorkspaceLayoutManager(Workspace* workspace) | 84 WorkspaceLayoutManager::WorkspaceLayoutManager(Workspace* workspace) |
| 80 : root_window_(workspace->window()->GetRootWindow()), | 85 : root_window_(workspace->window()->GetRootWindow()), |
| 81 workspace_(workspace), | 86 workspace_(workspace), |
| 82 work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 87 work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| 83 workspace->window()->parent())) { | 88 workspace->window()->parent())) { |
| 84 Shell::GetInstance()->AddShellObserver(this); | 89 Shell::GetInstance()->AddShellObserver(this); |
| 85 root_window_->AddRootWindowObserver(this); | 90 root_window_->AddRootWindowObserver(this); |
| 86 root_window_->AddObserver(this); | 91 root_window_->AddObserver(this); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 174 |
| 170 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, | 175 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, |
| 171 const void* key, | 176 const void* key, |
| 172 intptr_t old) { | 177 intptr_t old) { |
| 173 if (key == aura::client::kShowStateKey) { | 178 if (key == aura::client::kShowStateKey) { |
| 174 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | 179 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); |
| 175 ui::WindowShowState new_state = | 180 ui::WindowShowState new_state = |
| 176 window->GetProperty(aura::client::kShowStateKey); | 181 window->GetProperty(aura::client::kShowStateKey); |
| 177 if (old_state != ui::SHOW_STATE_MINIMIZED && | 182 if (old_state != ui::SHOW_STATE_MINIMIZED && |
| 178 GetRestoreBoundsInScreen(window) == NULL && | 183 GetRestoreBoundsInScreen(window) == NULL && |
| 179 WorkspaceManager::IsMaximizedState(new_state) && | 184 IsMaximizedState(new_state) && |
| 180 !WorkspaceManager::IsMaximizedState(old_state)) { | 185 !IsMaximizedState(old_state)) { |
| 181 SetRestoreBoundsInParent(window, window->bounds()); | 186 SetRestoreBoundsInParent(window, window->bounds()); |
| 182 } | 187 } |
| 183 // When restoring from a minimized state, we want to restore to the | 188 // When restoring from a minimized state, we want to restore to the |
| 184 // previous (maybe L/R maximized) state. Since we do also want to keep the | 189 // previous (maybe L/R maximized) state. Since we do also want to keep the |
| 185 // restore rectangle, we set the restore rectangle to the rectangle we want | 190 // restore rectangle, we set the restore rectangle to the rectangle we want |
| 186 // to restore to and restore it after we switched so that it is preserved. | 191 // to restore to and restore it after we switched so that it is preserved. |
| 187 gfx::Rect restore; | 192 gfx::Rect restore; |
| 188 if (old_state == ui::SHOW_STATE_MINIMIZED && | 193 if (old_state == ui::SHOW_STATE_MINIMIZED && |
| 189 (new_state == ui::SHOW_STATE_NORMAL || | 194 (new_state == ui::SHOW_STATE_NORMAL || |
| 190 new_state == ui::SHOW_STATE_DEFAULT) && | 195 new_state == ui::SHOW_STATE_DEFAULT) && |
| 191 GetRestoreBoundsInScreen(window) && | 196 GetRestoreBoundsInScreen(window) && |
| 192 !GetWindowAlwaysRestoresToRestoreBounds(window)) { | 197 !GetWindowAlwaysRestoresToRestoreBounds(window)) { |
| 193 restore = *GetRestoreBoundsInScreen(window); | 198 restore = *GetRestoreBoundsInScreen(window); |
| 194 SetRestoreBoundsInScreen(window, window->GetBoundsInScreen()); | 199 SetRestoreBoundsInScreen(window, window->GetBoundsInScreen()); |
| 195 } | 200 } |
| 196 | 201 |
| 197 // If maximizing or restoring, clone the layer. WorkspaceManager will use it | 202 // If the new state requires |window| to be in a workspace, clone the layer. |
| 198 // (and take ownership of it) when animating. Ideally we could use that of | 203 // WorkspaceManager will use it (and take ownership of it) when animating. |
| 199 // BaseLayoutManager, but that proves problematic. In particular when | 204 // Ideally we could use that of BaseLayoutManager, but that proves |
| 200 // restoring we need to animate on top of the workspace animating in. | 205 // problematic. In particular when restoring we need to animate on top of |
| 206 // the workspace animating in. |
| 201 ui::Layer* cloned_layer = NULL; | 207 ui::Layer* cloned_layer = NULL; |
| 202 BoundsMap bounds_map; | 208 BoundsMap bounds_map; |
| 203 if (wm::IsActiveWindow(window) && | 209 if (wm::IsActiveWindow(window) && |
| 204 ((WorkspaceManager::IsMaximizedState(new_state) && | 210 ((new_state == ui::SHOW_STATE_FULLSCREEN && |
| 205 wm::IsWindowStateNormal(old_state)) || | 211 wm::IsWindowStateNormal(old_state)) || |
| 206 (!WorkspaceManager::IsMaximizedState(new_state) && | 212 (new_state != ui::SHOW_STATE_FULLSCREEN && |
| 207 WorkspaceManager::IsMaximizedState(old_state) && | 213 old_state == ui::SHOW_STATE_FULLSCREEN && |
| 208 new_state != ui::SHOW_STATE_MINIMIZED))) { | 214 new_state != ui::SHOW_STATE_MINIMIZED))) { |
| 209 BuildWindowBoundsMap(window, &bounds_map); | 215 BuildWindowBoundsMap(window, &bounds_map); |
| 210 cloned_layer = views::corewm::RecreateWindowLayers(window, false); | 216 cloned_layer = views::corewm::RecreateWindowLayers(window, false); |
| 211 // Constrained windows don't get their bounds reset when we update the | 217 // Constrained windows don't get their bounds reset when we update the |
| 212 // window bounds. Leaving them empty is unexpected, so we reset them now. | 218 // window bounds. Leaving them empty is unexpected, so we reset them now. |
| 213 ResetConstrainedWindowBoundsIfNecessary(bounds_map, window); | 219 ResetConstrainedWindowBoundsIfNecessary(bounds_map, window); |
| 214 } | 220 } |
| 215 UpdateBoundsFromShowState(window); | 221 UpdateBoundsFromShowState(window); |
| 216 | 222 |
| 217 if (cloned_layer) { | 223 if (cloned_layer) { |
| 218 // Even though we just set the bounds not all descendants may have valid | 224 // Even though we just set the bounds not all descendants may have valid |
| 219 // bounds. For example, constrained windows don't resize with the parent. | 225 // bounds. For example, constrained windows don't resize with the parent. |
| 220 // Ensure that all windows that had a bounds before we cloned the layer | 226 // Ensure that all windows that had a bounds before we cloned the layer |
| 221 // have a bounds now. | 227 // have a bounds now. |
| 222 ResetBoundsIfNecessary(bounds_map, window); | 228 ResetBoundsIfNecessary(bounds_map, window); |
| 223 } | 229 } |
| 224 | 230 |
| 225 ShowStateChanged(window, old_state, cloned_layer); | 231 ShowStateChanged(window, old_state, cloned_layer); |
| 226 | 232 |
| 227 // Set the restore rectangle to the previously set restore rectangle. | 233 // Set the restore rectangle to the previously set restore rectangle. |
| 228 if (!restore.IsEmpty()) | 234 if (!restore.IsEmpty()) |
| 229 SetRestoreBoundsInScreen(window, restore); | 235 SetRestoreBoundsInScreen(window, restore); |
| 230 } | 236 } |
| 231 | 237 |
| 232 if (key == internal::kWindowTrackedByWorkspaceKey && | 238 if (key == internal::kWindowTrackedByWorkspaceKey && |
| 233 GetTrackedByWorkspace(window)) { | 239 GetTrackedByWorkspace(window)) { |
| 234 workspace_manager()->OnTrackedByWorkspaceChanged(workspace_, window); | 240 workspace_manager()->OnTrackedByWorkspaceChanged(workspace_, window); |
| 241 if (wm::IsWindowMaximized(window)) { |
| 242 SetChildBoundsDirect( |
| 243 window, ScreenAsh::GetMaximizedWindowBoundsInParent( |
| 244 window->parent()->parent())); |
| 245 } |
| 235 } | 246 } |
| 236 | 247 |
| 237 if (key == aura::client::kAlwaysOnTopKey && | 248 if (key == aura::client::kAlwaysOnTopKey && |
| 238 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 249 window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
| 239 internal::AlwaysOnTopController* controller = | 250 internal::AlwaysOnTopController* controller = |
| 240 window->GetRootWindow()->GetProperty( | 251 window->GetRootWindow()->GetProperty( |
| 241 internal::kAlwaysOnTopControllerKey); | 252 internal::kAlwaysOnTopControllerKey); |
| 242 controller->GetContainer(window)->AddChild(window); | 253 controller->GetContainer(window)->AddChild(window); |
| 243 } | 254 } |
| 244 } | 255 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 397 } |
| 387 return false; | 398 return false; |
| 388 } | 399 } |
| 389 | 400 |
| 390 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() { | 401 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() { |
| 391 return workspace_->workspace_manager(); | 402 return workspace_->workspace_manager(); |
| 392 } | 403 } |
| 393 | 404 |
| 394 } // namespace internal | 405 } // namespace internal |
| 395 } // namespace ash | 406 } // namespace ash |
| OLD | NEW |