| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "ui/aura_shell/workspace/workspace_manager.h" | 5 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 5 | 6 |
| 6 #include <algorithm> | 7 #include <algorithm> |
| 7 | 8 |
| 8 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" |
| 9 #include "ui/aura/desktop.h" | 12 #include "ui/aura/desktop.h" |
| 10 #include "ui/aura/screen_aura.h" | 13 #include "ui/aura/screen_aura.h" |
| 11 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 12 #include "ui/aura_shell/workspace/workspace.h" | 15 #include "ui/aura_shell/workspace/workspace.h" |
| 13 #include "ui/aura_shell/workspace/workspace_manager.h" | |
| 14 #include "ui/gfx/screen.h" | |
| 15 #include "ui/gfx/compositor/layer.h" | 16 #include "ui/gfx/compositor/layer.h" |
| 16 #include "ui/gfx/compositor/layer_animator.h" | 17 #include "ui/gfx/compositor/layer_animator.h" |
| 18 #include "ui/gfx/screen.h" |
| 17 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 18 #include "base/logging.h" | |
| 19 #include "base/stl_util.h" | |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // The horizontal margein between workspaces in pixels. | 23 // The horizontal margein between workspaces in pixels. |
| 24 const int kWorkspaceHorizontalMargin = 50; | 24 const int kWorkspaceHorizontalMargin = 50; |
| 25 | 25 |
| 26 // Minimum/maximum scale for overview mode. | 26 // Minimum/maximum scale for overview mode. |
| 27 const float kMaxOverviewScale = 0.9f; | 27 const float kMaxOverviewScale = 0.9f; |
| 28 const float kMinOverviewScale = 0.3f; | 28 const float kMinOverviewScale = 0.3f; |
| 29 | 29 |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace aura_shell { | 32 namespace aura_shell { |
| 33 namespace internal { |
| 33 | 34 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
| 35 // WindowManager, public: | 36 // WindowManager, public: |
| 36 | 37 |
| 37 WorkspaceManager::WorkspaceManager(aura::Window* viewport) | 38 WorkspaceManager::WorkspaceManager(aura::Window* viewport) |
| 38 : viewport_(viewport), | 39 : viewport_(viewport), |
| 39 active_workspace_(NULL), | 40 active_workspace_(NULL), |
| 40 workspace_size_( | 41 workspace_size_( |
| 41 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size()), | 42 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size()), |
| 42 is_overview_(false) { | 43 is_overview_(false) { |
| 43 aura::Desktop::GetInstance()->AddObserver(this); | |
| 44 } | 44 } |
| 45 | 45 |
| 46 WorkspaceManager::~WorkspaceManager() { | 46 WorkspaceManager::~WorkspaceManager() { |
| 47 aura::Desktop::GetInstance()->RemoveObserver(this); | |
| 48 std::vector<Workspace*> copy_to_delete(workspaces_); | 47 std::vector<Workspace*> copy_to_delete(workspaces_); |
| 49 STLDeleteElements(©_to_delete); | 48 STLDeleteElements(©_to_delete); |
| 50 } | 49 } |
| 51 | 50 |
| 52 Workspace* WorkspaceManager::CreateWorkspace() { | 51 Workspace* WorkspaceManager::CreateWorkspace() { |
| 53 Workspace* workspace = new Workspace(this); | 52 Workspace* workspace = new Workspace(this); |
| 54 LayoutWorkspaces(); | 53 LayoutWorkspaces(); |
| 55 return workspace; | 54 return workspace; |
| 56 } | 55 } |
| 57 | 56 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 for (int i = target_ws_index; i <= source_ws_index; ++i) { | 157 for (int i = target_ws_index; i <= source_ws_index; ++i) { |
| 159 insert = workspaces_[i]->ShiftWindows( | 158 insert = workspaces_[i]->ShiftWindows( |
| 160 insert, source, target, Workspace::SHIFT_TO_RIGHT); | 159 insert, source, target, Workspace::SHIFT_TO_RIGHT); |
| 161 // |target| can only be in the 1st workspace. | 160 // |target| can only be in the 1st workspace. |
| 162 target = NULL; | 161 target = NULL; |
| 163 } | 162 } |
| 164 } | 163 } |
| 165 } | 164 } |
| 166 } | 165 } |
| 167 | 166 |
| 168 //////////////////////////////////////////////////////////////////////////////// | 167 void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) { |
| 169 // WorkspaceManager, Overridden from aura::DesktopObserver: | 168 if (workspace_size == workspace_size_) |
| 170 | 169 return; |
| 171 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) { | 170 workspace_size_ = workspace_size; |
| 172 workspace_size_ = | |
| 173 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size(); | |
| 174 LayoutWorkspaces(); | 171 LayoutWorkspaces(); |
| 175 } | 172 } |
| 176 | 173 |
| 177 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) { | |
| 178 Workspace* workspace = FindBy(active); | |
| 179 if (workspace) | |
| 180 SetActiveWorkspace(workspace); | |
| 181 } | |
| 182 | |
| 183 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
| 184 // WorkspaceManager, private: | 175 // WorkspaceManager, private: |
| 185 | 176 |
| 186 void WorkspaceManager::AddWorkspace(Workspace* workspace) { | 177 void WorkspaceManager::AddWorkspace(Workspace* workspace) { |
| 187 Workspaces::iterator i = std::find(workspaces_.begin(), | 178 Workspaces::iterator i = std::find(workspaces_.begin(), |
| 188 workspaces_.end(), | 179 workspaces_.end(), |
| 189 workspace); | 180 workspace); |
| 190 DCHECK(i == workspaces_.end()); | 181 DCHECK(i == workspaces_.end()); |
| 191 workspaces_.push_back(workspace); | 182 workspaces_.push_back(workspace); |
| 192 } | 183 } |
| 193 | 184 |
| 194 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { | 185 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { |
| 195 Workspaces::iterator i = std::find(workspaces_.begin(), | 186 Workspaces::iterator i = std::find(workspaces_.begin(), |
| 196 workspaces_.end(), | 187 workspaces_.end(), |
| 197 workspace); | 188 workspace); |
| 198 DCHECK(i != workspaces_.end()); | 189 DCHECK(i != workspaces_.end()); |
| 199 if (workspace == active_workspace_) | 190 if (workspace == active_workspace_) |
| 200 active_workspace_ = NULL; | 191 active_workspace_ = NULL; |
| 201 workspaces_.erase(i); | 192 workspaces_.erase(i); |
| 202 LayoutWorkspaces(); | 193 LayoutWorkspaces(); |
| 203 } | 194 } |
| 204 | 195 |
| 205 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { | 196 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { |
| 206 DCHECK(std::find(workspaces_.begin(), | 197 DCHECK(std::find(workspaces_.begin(), workspaces_.end(), |
| 207 workspaces_.end(), | 198 workspace) != workspaces_.end()); |
| 208 workspace) | |
| 209 != workspaces_.end()); | |
| 210 active_workspace_ = workspace; | 199 active_workspace_ = workspace; |
| 211 | 200 |
| 212 DCHECK(!workspaces_.empty()); | |
| 213 | |
| 214 is_overview_ = false; | 201 is_overview_ = false; |
| 215 UpdateViewport(); | 202 UpdateViewport(); |
| 216 } | 203 } |
| 217 | 204 |
| 218 gfx::Rect WorkspaceManager::GetWorkAreaBounds( | 205 gfx::Rect WorkspaceManager::GetWorkAreaBounds( |
| 219 const gfx::Rect& workspace_bounds) { | 206 const gfx::Rect& workspace_bounds) { |
| 220 gfx::Rect bounds = workspace_bounds; | 207 gfx::Rect bounds = workspace_bounds; |
| 221 bounds.Inset( | 208 bounds.Inset( |
| 222 aura::Desktop::GetInstance()->screen()->work_area_insets()); | 209 aura::Desktop::GetInstance()->screen()->work_area_insets()); |
| 223 return bounds; | 210 return bounds; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 246 // Move to active workspace. | 233 // Move to active workspace. |
| 247 if (active_workspace_) { | 234 if (active_workspace_) { |
| 248 ui::Transform transform; | 235 ui::Transform transform; |
| 249 transform.SetTranslateX(-active_workspace_->bounds().x()); | 236 transform.SetTranslateX(-active_workspace_->bounds().x()); |
| 250 ui::LayerAnimator::ScopedSettings settings( | 237 ui::LayerAnimator::ScopedSettings settings( |
| 251 viewport_->layer()->GetAnimator()); | 238 viewport_->layer()->GetAnimator()); |
| 252 viewport_->SetTransform(transform); | 239 viewport_->SetTransform(transform); |
| 253 } | 240 } |
| 254 } | 241 } |
| 255 | 242 |
| 243 } // namespace internal |
| 256 } // namespace aura_shell | 244 } // namespace aura_shell |
| OLD | NEW |