| 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 |
| 5 #include "ui/aura_shell/workspace/workspace_manager.h" | 5 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "ui/aura/desktop.h" | 12 #include "ui/aura/desktop.h" |
| 13 #include "ui/aura/screen_aura.h" | 13 #include "ui/aura/screen_aura.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura_shell/workspace/workspace.h" | 15 #include "ui/aura_shell/workspace/workspace.h" |
| 16 #include "ui/aura_shell/workspace/workspace_observer.h" |
| 16 #include "ui/gfx/compositor/layer.h" | 17 #include "ui/gfx/compositor/layer.h" |
| 17 #include "ui/gfx/compositor/layer_animator.h" | 18 #include "ui/gfx/compositor/layer_animator.h" |
| 18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 19 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // The horizontal margein between workspaces in pixels. | 24 // The horizontal margein between workspaces in pixels. |
| 24 const int kWorkspaceHorizontalMargin = 50; | 25 const int kWorkspaceHorizontalMargin = 50; |
| 25 | 26 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 DCHECK(source); | 140 DCHECK(source); |
| 140 DCHECK(target); | 141 DCHECK(target); |
| 141 int source_ws_index = GetWorkspaceIndexContaining(source); | 142 int source_ws_index = GetWorkspaceIndexContaining(source); |
| 142 int target_ws_index = GetWorkspaceIndexContaining(target); | 143 int target_ws_index = GetWorkspaceIndexContaining(target); |
| 143 DCHECK(source_ws_index >= 0); | 144 DCHECK(source_ws_index >= 0); |
| 144 DCHECK(target_ws_index >= 0); | 145 DCHECK(target_ws_index >= 0); |
| 145 if (source_ws_index == target_ws_index) { | 146 if (source_ws_index == target_ws_index) { |
| 146 workspaces_[source_ws_index]->RotateWindows(source, target); | 147 workspaces_[source_ws_index]->RotateWindows(source, target); |
| 147 } else { | 148 } else { |
| 148 aura::Window* insert = source; | 149 aura::Window* insert = source; |
| 150 aura::Window* target_to_insert = target; |
| 149 if (source_ws_index < target_ws_index) { | 151 if (source_ws_index < target_ws_index) { |
| 150 for (int i = target_ws_index; i >= source_ws_index; --i) { | 152 for (int i = target_ws_index; i >= source_ws_index; --i) { |
| 151 insert = workspaces_[i]->ShiftWindows( | 153 insert = workspaces_[i]->ShiftWindows( |
| 152 insert, source, target, Workspace::SHIFT_TO_LEFT); | 154 insert, source, target_to_insert, Workspace::SHIFT_TO_LEFT); |
| 153 // |target| can only be in the 1st workspace. | 155 // |target| can only be in the 1st workspace. |
| 154 target = NULL; | 156 target_to_insert = NULL; |
| 155 } | 157 } |
| 156 } else { | 158 } else { |
| 157 for (int i = target_ws_index; i <= source_ws_index; ++i) { | 159 for (int i = target_ws_index; i <= source_ws_index; ++i) { |
| 158 insert = workspaces_[i]->ShiftWindows( | 160 insert = workspaces_[i]->ShiftWindows( |
| 159 insert, source, target, Workspace::SHIFT_TO_RIGHT); | 161 insert, source, target_to_insert, Workspace::SHIFT_TO_RIGHT); |
| 160 // |target| can only be in the 1st workspace. | 162 // |target| can only be in the 1st workspace. |
| 161 target = NULL; | 163 target_to_insert = NULL; |
| 162 } | 164 } |
| 163 } | 165 } |
| 164 } | 166 } |
| 167 FOR_EACH_OBSERVER(WorkspaceObserver, observers_, |
| 168 WindowMoved(this, source, target)); |
| 165 } | 169 } |
| 166 | 170 |
| 167 void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) { | 171 void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) { |
| 168 if (workspace_size == workspace_size_) | 172 if (workspace_size == workspace_size_) |
| 169 return; | 173 return; |
| 170 workspace_size_ = workspace_size; | 174 workspace_size_ = workspace_size; |
| 171 LayoutWorkspaces(); | 175 LayoutWorkspaces(); |
| 172 } | 176 } |
| 173 | 177 |
| 178 void WorkspaceManager::AddObserver(WorkspaceObserver* observer) { |
| 179 observers_.AddObserver(observer); |
| 180 } |
| 181 |
| 182 void WorkspaceManager::RemoveObserver(WorkspaceObserver* observer) { |
| 183 observers_.RemoveObserver(observer); |
| 184 } |
| 185 |
| 174 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
| 175 // WorkspaceManager, private: | 187 // WorkspaceManager, private: |
| 176 | 188 |
| 177 void WorkspaceManager::AddWorkspace(Workspace* workspace) { | 189 void WorkspaceManager::AddWorkspace(Workspace* workspace) { |
| 178 Workspaces::iterator i = std::find(workspaces_.begin(), | 190 Workspaces::iterator i = std::find(workspaces_.begin(), |
| 179 workspaces_.end(), | 191 workspaces_.end(), |
| 180 workspace); | 192 workspace); |
| 181 DCHECK(i == workspaces_.end()); | 193 DCHECK(i == workspaces_.end()); |
| 182 workspaces_.push_back(workspace); | 194 workspaces_.push_back(workspace); |
| 183 } | 195 } |
| 184 | 196 |
| 185 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { | 197 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { |
| 186 Workspaces::iterator i = std::find(workspaces_.begin(), | 198 Workspaces::iterator i = std::find(workspaces_.begin(), |
| 187 workspaces_.end(), | 199 workspaces_.end(), |
| 188 workspace); | 200 workspace); |
| 189 DCHECK(i != workspaces_.end()); | 201 DCHECK(i != workspaces_.end()); |
| 190 if (workspace == active_workspace_) | 202 Workspace* old = NULL; |
| 203 |
| 204 if (workspace == active_workspace_) { |
| 205 old = active_workspace_; |
| 191 active_workspace_ = NULL; | 206 active_workspace_ = NULL; |
| 207 } |
| 192 workspaces_.erase(i); | 208 workspaces_.erase(i); |
| 193 LayoutWorkspaces(); | 209 LayoutWorkspaces(); |
| 210 |
| 211 if (old) { |
| 212 FOR_EACH_OBSERVER(WorkspaceObserver, observers_, |
| 213 ActiveWorkspaceChanged(this, old)); |
| 214 } |
| 194 } | 215 } |
| 195 | 216 |
| 196 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { | 217 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { |
| 197 DCHECK(std::find(workspaces_.begin(), workspaces_.end(), | 218 DCHECK(std::find(workspaces_.begin(), workspaces_.end(), |
| 198 workspace) != workspaces_.end()); | 219 workspace) != workspaces_.end()); |
| 220 Workspace* old = active_workspace_; |
| 199 active_workspace_ = workspace; | 221 active_workspace_ = workspace; |
| 200 | 222 |
| 201 is_overview_ = false; | 223 is_overview_ = false; |
| 202 UpdateViewport(); | 224 UpdateViewport(); |
| 225 |
| 226 FOR_EACH_OBSERVER(WorkspaceObserver, observers_, |
| 227 ActiveWorkspaceChanged(this, old)); |
| 203 } | 228 } |
| 204 | 229 |
| 205 gfx::Rect WorkspaceManager::GetWorkAreaBounds( | 230 gfx::Rect WorkspaceManager::GetWorkAreaBounds( |
| 206 const gfx::Rect& workspace_bounds) { | 231 const gfx::Rect& workspace_bounds) { |
| 207 gfx::Rect bounds = workspace_bounds; | 232 gfx::Rect bounds = workspace_bounds; |
| 208 bounds.Inset( | 233 bounds.Inset( |
| 209 aura::Desktop::GetInstance()->screen()->work_area_insets()); | 234 aura::Desktop::GetInstance()->screen()->work_area_insets()); |
| 210 return bounds; | 235 return bounds; |
| 211 } | 236 } |
| 212 | 237 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 235 ui::Transform transform; | 260 ui::Transform transform; |
| 236 transform.SetTranslateX(-active_workspace_->bounds().x()); | 261 transform.SetTranslateX(-active_workspace_->bounds().x()); |
| 237 ui::LayerAnimator::ScopedSettings settings( | 262 ui::LayerAnimator::ScopedSettings settings( |
| 238 viewport_->layer()->GetAnimator()); | 263 viewport_->layer()->GetAnimator()); |
| 239 viewport_->SetTransform(transform); | 264 viewport_->SetTransform(transform); |
| 240 } | 265 } |
| 241 } | 266 } |
| 242 | 267 |
| 243 } // namespace internal | 268 } // namespace internal |
| 244 } // namespace aura_shell | 269 } // namespace aura_shell |
| OLD | NEW |