| 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_manager.h" | 5 #include "ash/wm/workspace/workspace_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 24 #include "ui/base/ui_base_types.h" | 24 #include "ui/base/ui_base_types.h" |
| 25 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
| 26 #include "ui/compositor/layer_animator.h" | 26 #include "ui/compositor/layer_animator.h" |
| 27 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 29 #include "ui/gfx/transform.h" | 29 #include "ui/gfx/transform.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Returns a list of all the windows with layers in |result|. Optionally | 33 // Returns a list of all the windows with layers in |result|. |
| 34 // ignores the window |ignore_window|. | |
| 35 void BuildWindowList(const std::vector<aura::Window*>& windows, | 34 void BuildWindowList(const std::vector<aura::Window*>& windows, |
| 36 aura::Window* ignore_window, | |
| 37 std::vector<aura::Window*>* result) { | 35 std::vector<aura::Window*>* result) { |
| 38 for (size_t i = 0; i < windows.size(); ++i) { | 36 for (size_t i = 0; i < windows.size(); ++i) { |
| 39 if (windows[i] == ignore_window) | |
| 40 continue; | |
| 41 if (windows[i]->layer()) | 37 if (windows[i]->layer()) |
| 42 result->push_back(windows[i]); | 38 result->push_back(windows[i]); |
| 43 BuildWindowList(windows[i]->transient_children(), ignore_window, result); | 39 BuildWindowList(windows[i]->transient_children(), result); |
| 44 } | 40 } |
| 45 } | 41 } |
| 46 | 42 |
| 47 } | 43 } |
| 48 | 44 |
| 49 namespace ash { | 45 namespace ash { |
| 50 namespace internal { | 46 namespace internal { |
| 51 | 47 |
| 52 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
| 53 // WindowManager, public: | 49 // WindowManager, public: |
| 54 | 50 |
| 55 WorkspaceManager::WorkspaceManager(aura::Window* contents_view) | 51 WorkspaceManager::WorkspaceManager(aura::Window* contents_view) |
| 56 : contents_view_(contents_view), | 52 : contents_view_(contents_view), |
| 57 active_workspace_(NULL), | 53 active_workspace_(NULL), |
| 58 maximize_restore_window_(NULL), | 54 ignored_window_(NULL), |
| 59 grid_size_(0), | 55 grid_size_(0), |
| 60 shelf_(NULL) { | 56 shelf_(NULL) { |
| 61 DCHECK(contents_view); | 57 DCHECK(contents_view); |
| 62 } | 58 } |
| 63 | 59 |
| 64 WorkspaceManager::~WorkspaceManager() { | 60 WorkspaceManager::~WorkspaceManager() { |
| 65 std::vector<Workspace*> copy_to_delete(workspaces_); | 61 std::vector<Workspace*> copy_to_delete(workspaces_); |
| 66 STLDeleteElements(©_to_delete); | 62 STLDeleteElements(©_to_delete); |
| 67 } | 63 } |
| 68 | 64 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 else | 205 else |
| 210 active_workspace_ = NULL; | 206 active_workspace_ = NULL; |
| 211 } | 207 } |
| 212 } | 208 } |
| 213 | 209 |
| 214 void WorkspaceManager::SetVisibilityOfWorkspaceWindows( | 210 void WorkspaceManager::SetVisibilityOfWorkspaceWindows( |
| 215 ash::internal::Workspace* workspace, | 211 ash::internal::Workspace* workspace, |
| 216 AnimateChangeType change_type, | 212 AnimateChangeType change_type, |
| 217 bool value) { | 213 bool value) { |
| 218 std::vector<aura::Window*> children; | 214 std::vector<aura::Window*> children; |
| 219 BuildWindowList(workspace->windows(), maximize_restore_window_, &children); | 215 BuildWindowList(workspace->windows(), &children); |
| 220 SetWindowLayerVisibility(children, change_type, value); | 216 SetWindowLayerVisibility(children, change_type, value); |
| 221 } | 217 } |
| 222 | 218 |
| 223 void WorkspaceManager::SetWindowLayerVisibility( | 219 void WorkspaceManager::SetWindowLayerVisibility( |
| 224 const std::vector<aura::Window*>& windows, | 220 const std::vector<aura::Window*>& windows, |
| 225 AnimateChangeType change_type, | 221 AnimateChangeType change_type, |
| 226 bool value) { | 222 bool value) { |
| 227 for (size_t i = 0; i < windows.size(); ++i) { | 223 for (size_t i = 0; i < windows.size(); ++i) { |
| 228 ui::Layer* layer = windows[i]->layer(); | 224 ui::Layer* layer = windows[i]->layer(); |
| 229 // Only show the layer for windows that want to be visible. | 225 // Only show the layer for windows that want to be visible. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 i != workspaces_.end(); | 282 i != workspaces_.end(); |
| 287 ++i) { | 283 ++i) { |
| 288 if ((*i)->Contains(window)) | 284 if ((*i)->Contains(window)) |
| 289 return i - workspaces_.begin(); | 285 return i - workspaces_.begin(); |
| 290 } | 286 } |
| 291 return -1; | 287 return -1; |
| 292 } | 288 } |
| 293 | 289 |
| 294 void WorkspaceManager::SetWindowBounds(aura::Window* window, | 290 void WorkspaceManager::SetWindowBounds(aura::Window* window, |
| 295 const gfx::Rect& bounds) { | 291 const gfx::Rect& bounds) { |
| 292 ignored_window_ = window; |
| 296 window->SetBounds(bounds); | 293 window->SetBounds(bounds); |
| 294 ignored_window_ = NULL; |
| 297 } | 295 } |
| 298 | 296 |
| 299 void WorkspaceManager::OnTypeOfWorkspacedNeededChanged(aura::Window* window) { | 297 void WorkspaceManager::OnTypeOfWorkspacedNeededChanged(aura::Window* window) { |
| 300 DCHECK(IsManagedWindow(window)); | 298 DCHECK(IsManagedWindow(window)); |
| 301 Workspace* current_workspace = FindBy(window); | 299 Workspace* current_workspace = FindBy(window); |
| 302 DCHECK(current_workspace); | 300 DCHECK(current_workspace); |
| 303 Workspace* new_workspace = NULL; | 301 Workspace* new_workspace = NULL; |
| 304 if (Workspace::TypeForWindow(window) == Workspace::TYPE_MAXIMIZED) { | 302 if (Workspace::TypeForWindow(window) == Workspace::TYPE_MAXIMIZED) { |
| 305 // Unmaximized -> maximized; create a new workspace. | 303 // Unmaximized -> maximized; create a new workspace. |
| 306 current_workspace->RemoveWindow(window); | 304 current_workspace->RemoveWindow(window); |
| 307 new_workspace = CreateWorkspace(Workspace::TYPE_MAXIMIZED); | 305 new_workspace = CreateWorkspace(Workspace::TYPE_MAXIMIZED); |
| 308 new_workspace->AddWindowAfter(window, NULL); | 306 new_workspace->AddWindowAfter(window, NULL); |
| 309 } else { | 307 } else { |
| 310 // Maximized -> unmaximized; move window to unmaximized workspace. | 308 // Maximized -> unmaximized; move window to unmaximized workspace. |
| 311 new_workspace = GetManagedWorkspace(); | 309 new_workspace = GetManagedWorkspace(); |
| 312 current_workspace->RemoveWindow(window); | 310 current_workspace->RemoveWindow(window); |
| 313 if (!new_workspace) | 311 if (!new_workspace) |
| 314 new_workspace = CreateWorkspace(Workspace::TYPE_MANAGED); | 312 new_workspace = CreateWorkspace(Workspace::TYPE_MANAGED); |
| 315 new_workspace->AddWindowAfter(window, NULL); | 313 new_workspace->AddWindowAfter(window, NULL); |
| 316 } | 314 } |
| 317 maximize_restore_window_ = window; | |
| 318 SetActiveWorkspace(new_workspace); | 315 SetActiveWorkspace(new_workspace); |
| 319 maximize_restore_window_ = NULL; | |
| 320 // Delete at the end so that we don't attempt to switch to another | 316 // Delete at the end so that we don't attempt to switch to another |
| 321 // workspace in RemoveWorkspace(). | 317 // workspace in RemoveWorkspace(). |
| 322 CleanupWorkspace(current_workspace); | 318 CleanupWorkspace(current_workspace); |
| 323 } | 319 } |
| 324 | 320 |
| 325 Workspace* WorkspaceManager::GetManagedWorkspace() { | 321 Workspace* WorkspaceManager::GetManagedWorkspace() { |
| 326 for (size_t i = 0; i < workspaces_.size(); ++i) { | 322 for (size_t i = 0; i < workspaces_.size(); ++i) { |
| 327 if (workspaces_[i]->type() == Workspace::TYPE_MANAGED) | 323 if (workspaces_[i]->type() == Workspace::TYPE_MANAGED) |
| 328 return workspaces_[i]; | 324 return workspaces_[i]; |
| 329 } | 325 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 340 return workspace; | 336 return workspace; |
| 341 } | 337 } |
| 342 | 338 |
| 343 void WorkspaceManager::CleanupWorkspace(Workspace* workspace) { | 339 void WorkspaceManager::CleanupWorkspace(Workspace* workspace) { |
| 344 if (workspace->type() != Workspace::TYPE_MANAGED && workspace->is_empty()) | 340 if (workspace->type() != Workspace::TYPE_MANAGED && workspace->is_empty()) |
| 345 delete workspace; | 341 delete workspace; |
| 346 } | 342 } |
| 347 | 343 |
| 348 } // namespace internal | 344 } // namespace internal |
| 349 } // namespace ash | 345 } // namespace ash |
| OLD | NEW |