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

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

Issue 8381015: Add workspace to desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " 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 #include "ui/aura_shell/workspace/workspace_manager.h" 4 #include "ui/aura_shell/workspace/workspace_manager.h"
5 5
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "base/auto_reset.h"
9 #include "ui/aura/desktop.h"
10 #include "ui/aura/window.h"
11 #include "ui/aura_shell/workspace/workspace.h"
12 #include "ui/aura_shell/workspace/workspace_manager.h"
13 #include "ui/gfx/screen.h"
14 #include "ui/gfx/compositor/layer.h"
15 #include "ui/gfx/compositor/layer_animator.h"
16 #include "ui/gfx/transform.h"
8 #include "base/logging.h" 17 #include "base/logging.h"
9 #include "base/stl_util.h" 18 #include "base/stl_util.h"
10 #include "ui/aura_shell/workspace/workspace.h" 19 #include "ui/aura_shell/workspace/workspace.h"
11 20
12 namespace { 21 namespace {
13 22
14 // The horizontal margein between workspaces in pixels. 23 // The horizontal margein between workspaces in pixels.
15 const int kWorkspaceHorizontalMargin = 50; 24 const int kWorkspaceHorizontalMargin = 50;
25
16 } 26 }
17 27
18 namespace aura_shell { 28 namespace aura_shell {
19 29
20 //////////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////////
21 // WindowManager, public: 31 // WindowManager, public:
22 32
23 WorkspaceManager::WorkspaceManager() 33 WorkspaceManager::WorkspaceManager(aura::Window* viewport)
24 : active_workspace_(NULL) { 34 : viewport_(viewport),
35 active_workspace_(NULL),
36 workspace_size_(
37 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size()),
38 is_overview_(false) {
39 aura::Desktop::GetInstance()->AddObserver(this);
25 } 40 }
26 41
27 WorkspaceManager::~WorkspaceManager() { 42 WorkspaceManager::~WorkspaceManager() {
43 aura::Desktop::GetInstance()->RemoveObserver(this);
28 STLDeleteElements(&workspaces_); 44 STLDeleteElements(&workspaces_);
29 } 45 }
30 46
31 Workspace* WorkspaceManager::CreateWorkspace() { 47 Workspace* WorkspaceManager::CreateWorkspace() {
32 return new Workspace(this); 48 Workspace* workspace = new Workspace(this);
49 LayoutWorkspaces();
50 return workspace;
33 } 51 }
34 52
35 Workspace* WorkspaceManager::GetActiveWorkspace() const { 53 Workspace* WorkspaceManager::GetActiveWorkspace() const {
36 return active_workspace_; 54 return active_workspace_;
37 } 55 }
38 56
39 Workspace* WorkspaceManager::FindBy(aura::Window* window) const { 57 Workspace* WorkspaceManager::FindBy(aura::Window* window) const {
40 for (Workspaces::const_iterator i = workspaces_.begin(); 58 for (Workspaces::const_iterator i = workspaces_.begin();
41 i != workspaces_.end(); 59 i != workspaces_.end();
42 i++) { 60 i++) {
43 if ((*i)->Contains(window)) 61 if ((*i)->Contains(window))
44 return *i; 62 return *i;
45 } 63 }
46 return NULL; 64 return NULL;
47 } 65 }
48 66
49 void WorkspaceManager::Layout() { 67 void WorkspaceManager::LayoutWorkspaces() {
50 gfx::Rect bounds(workspace_size_); 68 gfx::Rect bounds(workspace_size_);
51 int x = 0; 69 int x = 0;
70 Workspaces::const_iterator i = workspaces_.begin();
sky 2011/10/25 20:58:05 remove this.
oshima 2011/10/25 23:37:23 Done.
52 for (Workspaces::const_iterator i = workspaces_.begin(); 71 for (Workspaces::const_iterator i = workspaces_.begin();
53 i != workspaces_.end(); 72 i != workspaces_.end();
54 i++) { 73 i++) {
sky 2011/10/25 20:58:05 ++i
oshima 2011/10/25 23:37:23 Done.
55 Workspace* workspace = *i; 74 Workspace* workspace = *i;
56 bounds.set_x(x); 75 bounds.set_x(x);
57 workspace->SetBounds(bounds); 76 workspace->SetBounds(bounds);
58 x += workspace_size_.width() + kWorkspaceHorizontalMargin; 77 x += bounds.width() + kWorkspaceHorizontalMargin;
59 } 78 }
60 } 79 }
61 80
62 int WorkspaceManager::GetTotalWidth() const { 81 gfx::Rect WorkspaceManager::GetDragAreaBounds() {
63 return !workspaces_.size() ? 0 : 82 gfx::Rect bounds(viewport_->bounds().size());
sky 2011/10/25 20:58:05 Can this be return GetWorkAreaBounds(gfx::Rect(vie
oshima 2011/10/25 23:37:23 Done.
64 workspace_size().width() * workspaces_.size() + 83 bounds.Inset(work_area_insets_);
65 kWorkspaceHorizontalMargin * (workspaces_.size() - 1); 84 return bounds;
85 }
86
87 void WorkspaceManager::SetOverview(bool overview) {
88 if (is_overview_ == overview)
89 return;
90 is_overview_ = overview;
91 gfx::Rect bounds = viewport_->GetTargetBounds();
92
93 ui::Transform transform;
94 if (is_overview_) {
95 float scale = std::min(
96 0.9f,
97 workspace_size_.width() /
98 static_cast<float>(viewport_->bounds().width()));
99 scale = std::max(0.3f, scale);
100
101 transform.SetScale(scale, scale);
102
103 int overview_width = viewport_->bounds().width() * scale;
104 int dx = overview_width < workspace_size_.width() ?
sky 2011/10/25 20:58:05 If line 95 yields a scale < .3f and then you up it
oshima 2011/10/25 23:37:23 Yes, that's one of things I'd like you to look int
105 (workspace_size_.width() - overview_width) /2 : 0;
sky 2011/10/25 20:58:05 '/2' -> '/ 2'
oshima 2011/10/25 23:37:23 Done.
106
107 transform.SetTranslateX(-viewport_->GetTargetBounds().x() + dx);
108 transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2);
109 } else {
110 transform.SetTranslateX(-active_workspace_->bounds().x());
111 }
112
113 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
114 viewport_->layer()->SetTransform(transform);
66 } 115 }
67 116
68 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
69 // WindowManager, private: 118 // WorkspaceManager, Overridden from aura::DesktopObserver:
119
120 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) {
121 workspace_size_ =
122 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size();
123 LayoutWorkspaces();
124 }
125
126 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) {
127 Workspace* workspace = FindBy(active);
128 if (workspace)
129 SetActiveWorkspace(workspace);
130 }
131
132 //////////////////////////h/////////////////////////////////////////////////////
sky 2011/10/25 20:58:05 '/h/' -> ///
oshima 2011/10/25 23:37:23 Done.
133 // WorkspaceManager, private:
70 134
71 void WorkspaceManager::AddWorkspace(Workspace* workspace) { 135 void WorkspaceManager::AddWorkspace(Workspace* workspace) {
72 Workspaces::iterator i = std::find(workspaces_.begin(), 136 Workspaces::iterator i = std::find(workspaces_.begin(),
73 workspaces_.end(), 137 workspaces_.end(),
74 workspace); 138 workspace);
75 DCHECK(i == workspaces_.end()); 139 DCHECK(i == workspaces_.end());
76 workspaces_.push_back(workspace); 140 workspaces_.push_back(workspace);
77 } 141 }
78 142
79 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { 143 void WorkspaceManager::RemoveWorkspace(Workspace* workspace) {
80 Workspaces::iterator i = std::find(workspaces_.begin(), 144 Workspaces::iterator i = std::find(workspaces_.begin(),
81 workspaces_.end(), 145 workspaces_.end(),
82 workspace); 146 workspace);
83 DCHECK(i != workspaces_.end()); 147 DCHECK(i != workspaces_.end());
84 if (workspace == active_workspace_) 148 if (workspace == active_workspace_)
85 active_workspace_ = NULL; 149 active_workspace_ = NULL;
86 workspaces_.erase(i); 150 workspaces_.erase(i);
151 UpdateViewport();
152 LayoutWorkspaces();
87 } 153 }
88 154
89 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { 155 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) {
90 DCHECK(std::find(workspaces_.begin(), 156 DCHECK(std::find(workspaces_.begin(),
91 workspaces_.end(), 157 workspaces_.end(),
92 workspace) 158 workspace)
93 != workspaces_.end()); 159 != workspaces_.end());
94 active_workspace_ = workspace; 160 active_workspace_ = workspace;
161
162 DCHECK(workspaces_.size());
163
164 UpdateViewport();
165 is_overview_ = false;
166
167 ui::Transform transform;
168 transform.SetTranslateX(-active_workspace_->bounds().x());
169 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
170 viewport_->SetTransform(transform);
171 }
172
173 gfx::Rect WorkspaceManager::GetWorkAreaBounds(
174 const gfx::Rect& workspace_bounds) {
175 gfx::Rect bounds = workspace_bounds;
176 bounds.Inset(work_area_insets_);
177 return bounds;
178 }
179
180 void WorkspaceManager::UpdateViewport() {
181 int total_width = workspace_size_.width() * workspaces_.size() +
182 kWorkspaceHorizontalMargin * (workspaces_.size() - 1);
183 gfx::Rect bounds(0, 0, total_width, workspace_size_.height());
184
185 if (viewport_->GetTargetBounds() == bounds)
186 return;
187 viewport_->SetBounds(bounds);
188
189 // Move to active workspace.
190 ui::Transform transform;
sky 2011/10/25 20:58:05 Both SetActiveWorkspace and this share code. Refac
oshima 2011/10/25 23:37:23 The code in SetActiveWorkspace isn't necessary, my
191 transform.SetTranslateX(-active_workspace_->bounds().x());
192 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
193 viewport_->SetTransform(transform);
95 } 194 }
96 195
97 } // namespace aura_shell 196 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698