Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1664)

Side by Side Diff: ui/aura_shell/workspace/workspace_manager.cc

Issue 8400067: Fixes bug where windows weren't being moved and resized if the desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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(&copy_to_delete); 48 STLDeleteElements(&copy_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
57 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) {
58 DCHECK(std::find(workspaces_.begin(),
59 workspaces_.end(),
60 workspace)
61 != workspaces_.end());
62 active_workspace_ = workspace;
63
64 DCHECK(!workspaces_.empty());
65
66 is_overview_ = false;
67 UpdateViewport();
68 }
69
58 Workspace* WorkspaceManager::GetActiveWorkspace() const { 70 Workspace* WorkspaceManager::GetActiveWorkspace() const {
59 return active_workspace_; 71 return active_workspace_;
60 } 72 }
61 73
62 Workspace* WorkspaceManager::FindBy(aura::Window* window) const { 74 Workspace* WorkspaceManager::FindBy(aura::Window* window) const {
63 int index = GetWorkspaceIndexContaining(window); 75 int index = GetWorkspaceIndexContaining(window);
64 return index < 0 ? NULL : workspaces_[index]; 76 return index < 0 ? NULL : workspaces_[index];
65 } 77 }
66 78
67 aura::Window* WorkspaceManager::FindRotateWindowForLocation( 79 aura::Window* WorkspaceManager::FindRotateWindowForLocation(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 for (int i = target_ws_index; i <= source_ws_index; ++i) { 170 for (int i = target_ws_index; i <= source_ws_index; ++i) {
159 insert = workspaces_[i]->ShiftWindows( 171 insert = workspaces_[i]->ShiftWindows(
160 insert, source, target, Workspace::SHIFT_TO_RIGHT); 172 insert, source, target, Workspace::SHIFT_TO_RIGHT);
161 // |target| can only be in the 1st workspace. 173 // |target| can only be in the 1st workspace.
162 target = NULL; 174 target = NULL;
163 } 175 }
164 } 176 }
165 } 177 }
166 } 178 }
167 179
168 //////////////////////////////////////////////////////////////////////////////// 180 void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) {
169 // WorkspaceManager, Overridden from aura::DesktopObserver: 181 if (workspace_size == workspace_size_)
170 182 return;
171 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) { 183 workspace_size_ = workspace_size;
172 workspace_size_ =
173 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size();
174 LayoutWorkspaces(); 184 LayoutWorkspaces();
175 } 185 }
176 186
177 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) {
178 Workspace* workspace = FindBy(active);
179 if (workspace)
180 SetActiveWorkspace(workspace);
181 }
182
183 //////////////////////////////////////////////////////////////////////////////// 187 ////////////////////////////////////////////////////////////////////////////////
184 // WorkspaceManager, private: 188 // WorkspaceManager, private:
185 189
186 void WorkspaceManager::AddWorkspace(Workspace* workspace) { 190 void WorkspaceManager::AddWorkspace(Workspace* workspace) {
187 Workspaces::iterator i = std::find(workspaces_.begin(), 191 Workspaces::iterator i = std::find(workspaces_.begin(),
188 workspaces_.end(), 192 workspaces_.end(),
189 workspace); 193 workspace);
190 DCHECK(i == workspaces_.end()); 194 DCHECK(i == workspaces_.end());
191 workspaces_.push_back(workspace); 195 workspaces_.push_back(workspace);
192 } 196 }
193 197
194 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { 198 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) {
195 Workspaces::iterator i = std::find(workspaces_.begin(), 199 Workspaces::iterator i = std::find(workspaces_.begin(),
196 workspaces_.end(), 200 workspaces_.end(),
197 workspace); 201 workspace);
198 DCHECK(i != workspaces_.end()); 202 DCHECK(i != workspaces_.end());
199 if (workspace == active_workspace_) 203 if (workspace == active_workspace_)
200 active_workspace_ = NULL; 204 active_workspace_ = NULL;
201 workspaces_.erase(i); 205 workspaces_.erase(i);
202 LayoutWorkspaces(); 206 LayoutWorkspaces();
203 } 207 }
204 208
205 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) {
206 DCHECK(std::find(workspaces_.begin(),
207 workspaces_.end(),
208 workspace)
209 != workspaces_.end());
210 active_workspace_ = workspace;
211
212 DCHECK(!workspaces_.empty());
213
214 is_overview_ = false;
215 UpdateViewport();
216 }
217
218 gfx::Rect WorkspaceManager::GetWorkAreaBounds( 209 gfx::Rect WorkspaceManager::GetWorkAreaBounds(
219 const gfx::Rect& workspace_bounds) { 210 const gfx::Rect& workspace_bounds) {
220 gfx::Rect bounds = workspace_bounds; 211 gfx::Rect bounds = workspace_bounds;
221 bounds.Inset( 212 bounds.Inset(
222 aura::Desktop::GetInstance()->screen()->work_area_insets()); 213 aura::Desktop::GetInstance()->screen()->work_area_insets());
223 return bounds; 214 return bounds;
224 } 215 }
225 216
226 // Returns the index of the workspace that contains the |window|. 217 // Returns the index of the workspace that contains the |window|.
227 int WorkspaceManager::GetWorkspaceIndexContaining(aura::Window* window) const { 218 int WorkspaceManager::GetWorkspaceIndexContaining(aura::Window* window) const {
(...skipping 18 matching lines...) Expand all
246 // Move to active workspace. 237 // Move to active workspace.
247 if (active_workspace_) { 238 if (active_workspace_) {
248 ui::Transform transform; 239 ui::Transform transform;
249 transform.SetTranslateX(-active_workspace_->bounds().x()); 240 transform.SetTranslateX(-active_workspace_->bounds().x());
250 ui::LayerAnimator::ScopedSettings settings( 241 ui::LayerAnimator::ScopedSettings settings(
251 viewport_->layer()->GetAnimator()); 242 viewport_->layer()->GetAnimator());
252 viewport_->SetTransform(transform); 243 viewport_->SetTransform(transform);
253 } 244 }
254 } 245 }
255 246
247 } // namespace internal
256 } // namespace aura_shell 248 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698