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.h" | 5 #include "ui/aura_shell/workspace/workspace.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/aura/aura_constants.h" |
10 #include "ui/aura/desktop.h" | 11 #include "ui/aura/desktop.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/aura_shell/property_util.h" |
12 #include "ui/aura_shell/workspace/workspace_manager.h" | 14 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 15 #include "ui/base/ui_base_types.h" |
13 #include "ui/gfx/compositor/layer.h" | 16 #include "ui/gfx/compositor/layer.h" |
14 #include "ui/gfx/compositor/layer_animator.h" | 17 #include "ui/gfx/compositor/layer_animator.h" |
15 | 18 |
16 namespace { | 19 namespace { |
17 // Horizontal margin between windows. | 20 // Horizontal margin between windows. |
18 const int kWindowHorizontalMargin = 10; | 21 const int kWindowHorizontalMargin = 10; |
19 | 22 |
20 // Maximum number of windows a workspace can have. | 23 // Maximum number of windows a workspace can have. |
21 size_t g_max_windows_per_workspace = 2; | 24 size_t g_max_windows_per_workspace = 2; |
| 25 |
| 26 // Returns the bounds of the window that should be used to calculate |
| 27 // the layout. It uses the restore bounds if exits, or |
| 28 // the target bounds of the window. The target bounds is the |
| 29 // final destination of |window| if the window's layer is animating, |
| 30 // or the current bounds of the window of no animation is currently |
| 31 // in progress. |
| 32 gfx::Rect GetLayoutBounds(aura::Window* window) { |
| 33 const gfx::Rect* restore_bounds = aura_shell::GetRestoreBounds(window); |
| 34 return restore_bounds ? *restore_bounds : window->GetTargetBounds(); |
22 } | 35 } |
23 | 36 |
| 37 // Returns the width of the window that should be used to calculate |
| 38 // the layout. See |GetLayoutBounds| for more details. |
| 39 int GetLayoutWidth(aura::Window* window) { |
| 40 return GetLayoutBounds(window).width(); |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
24 namespace aura_shell { | 45 namespace aura_shell { |
25 namespace internal { | 46 namespace internal { |
26 | 47 |
27 Workspace::Workspace(WorkspaceManager* manager) | 48 Workspace::Workspace(WorkspaceManager* manager) |
28 : workspace_manager_(manager) { | 49 : workspace_manager_(manager) { |
29 workspace_manager_->AddWorkspace(this); | 50 workspace_manager_->AddWorkspace(this); |
30 } | 51 } |
31 | 52 |
32 Workspace::~Workspace() { | 53 Workspace::~Workspace() { |
33 workspace_manager_->RemoveWorkspace(this); | 54 workspace_manager_->RemoveWorkspace(this); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (total_width < work_area.width()) { | 185 if (total_width < work_area.width()) { |
165 int dx = (work_area.width() - total_width) / 2; | 186 int dx = (work_area.width() - total_width) / 2; |
166 for (aura::Window::Windows::iterator i = windows_.begin(); | 187 for (aura::Window::Windows::iterator i = windows_.begin(); |
167 i != windows_.end(); | 188 i != windows_.end(); |
168 ++i) { | 189 ++i) { |
169 if (*i != ignore) { | 190 if (*i != ignore) { |
170 MoveWindowTo(*i, | 191 MoveWindowTo(*i, |
171 gfx::Point(work_area.x() + dx, work_area.y()), | 192 gfx::Point(work_area.x() + dx, work_area.y()), |
172 no_animation != *i); | 193 no_animation != *i); |
173 } | 194 } |
174 dx += (*i)->bounds().width() + kWindowHorizontalMargin; | 195 dx += GetLayoutWidth(*i) + kWindowHorizontalMargin; |
175 } | 196 } |
176 } else { | 197 } else { |
177 DCHECK_LT(windows_.size(), 3U); | 198 DCHECK_LT(windows_.size(), 3U); |
178 // TODO(oshima): This is messy. Figure out general algorithm to | 199 // TODO(oshima): This is messy. Figure out general algorithm to |
179 // layout more than 2 windows. | 200 // layout more than 2 windows. |
180 if (windows_[0] != ignore) { | 201 if (windows_[0] != ignore) { |
181 MoveWindowTo(windows_[0], | 202 MoveWindowTo(windows_[0], |
182 work_area.origin(), | 203 work_area.origin(), |
183 no_animation != windows_[0]); | 204 no_animation != windows_[0]); |
184 } | 205 } |
185 if (windows_.size() == 2 && windows_[1] != ignore) { | 206 if (windows_.size() == 2 && windows_[1] != ignore) { |
186 MoveWindowTo(windows_[1], | 207 MoveWindowTo(windows_[1], |
187 gfx::Point(work_area.right() - windows_[1]->bounds().width(), | 208 gfx::Point(work_area.right() - GetLayoutWidth(windows_[1]), |
188 work_area.y()), | 209 work_area.y()), |
189 no_animation != windows_[1]); | 210 no_animation != windows_[1]); |
190 } | 211 } |
191 } | 212 } |
192 } | 213 } |
193 | 214 |
| 215 bool Workspace::ContainsFullscreenWindow() const { |
| 216 for (aura::Window::Windows::const_iterator i = windows_.begin(); |
| 217 i != windows_.end(); |
| 218 ++i) { |
| 219 aura::Window* w = *i; |
| 220 if (w->IsVisible() && |
| 221 w->GetIntProperty(aura::kShowStateKey) == ui::SHOW_STATE_FULLSCREEN) |
| 222 return true; |
| 223 } |
| 224 return false; |
| 225 } |
| 226 |
194 int Workspace::GetIndexOf(aura::Window* window) const { | 227 int Workspace::GetIndexOf(aura::Window* window) const { |
195 aura::Window::Windows::const_iterator i = | 228 aura::Window::Windows::const_iterator i = |
196 std::find(windows_.begin(), windows_.end(), window); | 229 std::find(windows_.begin(), windows_.end(), window); |
197 return i == windows_.end() ? -1 : i - windows_.begin(); | 230 return i == windows_.end() ? -1 : i - windows_.begin(); |
198 } | 231 } |
199 | 232 |
200 bool Workspace::CanAdd(aura::Window* window) const { | 233 bool Workspace::CanAdd(aura::Window* window) const { |
201 // TODO(oshima): This should be based on available space and the | 234 // TODO(oshima): This should be based on available space and the |
202 // size of the |window|. | 235 // size of the |window|. |
203 NOTIMPLEMENTED(); | 236 NOTIMPLEMENTED(); |
204 return windows_.size() < g_max_windows_per_workspace; | 237 return windows_.size() < g_max_windows_per_workspace; |
205 } | 238 } |
206 | 239 |
207 void Workspace::MoveWindowTo( | 240 void Workspace::MoveWindowTo( |
208 aura::Window* window, | 241 aura::Window* window, |
209 const gfx::Point& origin, | 242 const gfx::Point& origin, |
210 bool animate) { | 243 bool animate) { |
211 if (window->show_state() == ui::SHOW_STATE_FULLSCREEN) | 244 gfx::Rect bounds = GetLayoutBounds(window); |
212 window->Fullscreen(); | 245 gfx::Rect work_area = GetWorkAreaBounds(); |
213 else if (window->show_state() == ui::SHOW_STATE_MAXIMIZED) | 246 // Make sure the window isn't bigger than the workspace size. |
214 window->Maximize(); | 247 bounds.SetRect(origin.x(), origin.y(), |
215 else { | 248 std::min(work_area.width(), bounds.width()), |
216 gfx::Rect bounds = window->GetTargetBounds(); | 249 std::min(work_area.height(), bounds.height())); |
217 gfx::Rect work_area = GetWorkAreaBounds(); | 250 if (animate) { |
218 // Make sure the window isn't bigger than the workspace size. | 251 ui::LayerAnimator::ScopedSettings settings(window->layer()->GetAnimator()); |
219 bounds.SetRect(origin.x(), origin.y(), | 252 window->SetBounds(bounds); |
220 std::min(work_area.width(), bounds.width()), | 253 } else { |
221 std::min(work_area.height(), bounds.height())); | 254 window->SetBounds(bounds); |
222 if (animate) { | |
223 ui::LayerAnimator::ScopedSettings settings( | |
224 window->layer()->GetAnimator()); | |
225 window->SetBounds(bounds); | |
226 } else { | |
227 window->SetBounds(bounds); | |
228 } | |
229 } | 255 } |
230 } | 256 } |
231 | 257 |
232 int Workspace::GetTotalWindowsWidth() const { | 258 int Workspace::GetTotalWindowsWidth() const { |
233 int total_width = 0; | 259 int total_width = 0; |
234 for (aura::Window::Windows::const_iterator i = windows_.begin(); | 260 for (aura::Window::Windows::const_iterator i = windows_.begin(); |
235 i != windows_.end(); | 261 i != windows_.end(); |
236 ++i) { | 262 ++i) { |
237 if (total_width) | 263 if (total_width) |
238 total_width += kWindowHorizontalMargin; | 264 total_width += kWindowHorizontalMargin; |
239 // TODO(oshima): use restored bounds. | 265 total_width += GetLayoutWidth(*i); |
240 total_width += (*i)->bounds().width(); | |
241 } | 266 } |
242 return total_width; | 267 return total_width; |
243 } | 268 } |
244 | 269 |
245 // static | 270 // static |
246 size_t Workspace::SetMaxWindowsCount(size_t max) { | 271 size_t Workspace::SetMaxWindowsCount(size_t max) { |
247 int old = g_max_windows_per_workspace; | 272 int old = g_max_windows_per_workspace; |
248 g_max_windows_per_workspace = max; | 273 g_max_windows_per_workspace = max; |
249 return old; | 274 return old; |
250 } | 275 } |
251 | 276 |
252 } // namespace internal | 277 } // namespace internal |
253 } // namespace aura_shell | 278 } // namespace aura_shell |
OLD | NEW |