Chromium Code Reviews| Index: ui/aura_shell/workspace/workspace.cc |
| diff --git a/ui/aura_shell/workspace/workspace.cc b/ui/aura_shell/workspace/workspace.cc |
| index c9f6c9aca55443b60921cb226e91684f4779dbf9..7850b1e03294f485672d838f3a56be5753391b5b 100644 |
| --- a/ui/aura_shell/workspace/workspace.cc |
| +++ b/ui/aura_shell/workspace/workspace.cc |
| @@ -7,6 +7,12 @@ |
| #include "base/logging.h" |
| #include "ui/aura/window.h" |
| #include "ui/aura_shell/workspace/workspace_manager.h" |
| +#include "ui/gfx/compositor/layer.h" |
| + |
| +namespace { |
| +// Horizontal margin between windows. |
| +const int kWindowHorizontalMargin = 10; |
| +} |
| namespace aura_shell { |
| @@ -20,17 +26,14 @@ Workspace::~Workspace() { |
| } |
| void Workspace::SetBounds(const gfx::Rect& bounds) { |
| - int dx = bounds.x() - bounds_.x(); |
| + bool bounds_changed = bounds_ != bounds; |
| bounds_ = bounds; |
| + if (bounds_changed) |
| + Layout(NULL); |
| +} |
| - for (aura::Window::Windows::iterator i = windows_.begin(); |
| - i != windows_.end(); |
| - i++) { |
| - aura::Window* window = *i; |
| - gfx::Rect bounds = window->GetTargetBounds(); |
| - bounds.Offset(dx, 0); |
| - window->SetBounds(bounds); |
| - } |
| +gfx::Rect Workspace::GetWorkAreaBounds() const { |
|
sky
2011/10/25 20:58:05
order doesn't match header.
oshima
2011/10/25 23:37:23
fixed
|
| + return workspace_manager_->GetWorkAreaBounds(bounds_); |
| } |
| bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { |
| @@ -38,7 +41,7 @@ bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { |
| return false; |
| DCHECK(!Contains(window)); |
| - if (!after) { // insert at the end; |
| + if (!after) { // insert at the end. |
| windows_.push_back(window); |
| } else { |
| DCHECK(Contains(after)); |
| @@ -46,14 +49,18 @@ bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { |
| std::find(windows_.begin(), windows_.end(), after); |
| windows_.insert(++i, window); |
| } |
| + Layout(window); |
| + |
| return true; |
| } |
| void Workspace::RemoveWindow(aura::Window* window) { |
| DCHECK(Contains(window)); |
| windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
| + Layout(NULL); |
| } |
| + |
| bool Workspace::Contains(aura::Window* window) const { |
| return std::find(windows_.begin(), windows_.end(), window) != windows_.end(); |
| } |
| @@ -62,6 +69,42 @@ void Workspace::Activate() { |
| workspace_manager_->SetActiveWorkspace(this); |
| } |
| +void Workspace::Layout(aura::Window* new_window) { |
| + gfx::Rect work_area = workspace_manager_->GetWorkAreaBounds(bounds_); |
|
sky
2011/10/25 20:58:05
How will popups be handled? For example, the omnib
oshima
2011/10/25 23:37:23
popups/bubbles are excluded in DefaultContainerLay
|
| + int total_width = 0; |
| + for (aura::Window::Windows::const_iterator i = windows_.begin(); |
| + i != windows_.end(); |
| + i++) { |
| + if (total_width) |
| + total_width += kWindowHorizontalMargin; |
| + // TODO(oshima): use restored bounds. |
| + total_width += (*i)->bounds().width(); |
| + } |
| + |
| + if (total_width < work_area.width()) { |
| + int dx = (work_area.width() - total_width) / 2; |
| + for (aura::Window::Windows::iterator i = windows_.begin(); |
| + i != windows_.end(); |
| + i++) { |
| + MoveWindowTo(*i, |
| + gfx::Point(work_area.x() + dx, work_area.y()), |
| + new_window != *i); |
| + dx += (*i)->bounds().width() + kWindowHorizontalMargin; |
| + } |
| + } else { |
| + DCHECK_LT(windows_.size(), 3U); |
| + // TODO(oshima): Figure out general algorithm to layout more than |
| + // 2 windows. |
| + MoveWindowTo(windows_[0],work_area.origin(), new_window != windows_[0]); |
|
sky
2011/10/25 20:58:05
nit: '[0],' -> '[0] ,'
oshima
2011/10/25 23:37:23
Done.
|
| + if (windows_.size() == 2) { |
| + MoveWindowTo(windows_[1], |
| + gfx::Point(work_area.right() - windows_[1]->bounds().width(), |
| + work_area.y()), |
| + new_window != windows_[1]); |
| + } |
| + } |
| +} |
| + |
| int Workspace::GetIndexOf(aura::Window* window) const { |
| aura::Window::Windows::const_iterator i = |
| std::find(windows_.begin(), windows_.end(), window); |
| @@ -75,4 +118,19 @@ bool Workspace::CanAdd(aura::Window* window) const { |
| return windows_.size() < 2; |
| } |
| +void Workspace::MoveWindowTo( |
| + aura::Window* window, const gfx::Point& origin, bool animate) { |
|
sky
2011/10/25 20:58:05
each param on its own line.
oshima
2011/10/25 23:37:23
Done.
|
| + if (window->show_state() == ui::SHOW_STATE_FULLSCREEN) |
| + window->Fullscreen(); |
| + else if (window->show_state() == ui::SHOW_STATE_MAXIMIZED) |
| + window->Maximize(); |
| + else { |
| + gfx::Rect bounds = window->GetTargetBounds(); |
| + bounds.set_origin(origin); |
| + if (animate) |
| + window->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); |
| + window->SetBounds(bounds); |
| + } |
| +} |
| + |
| } // namespace aura_shell |