Chromium Code Reviews| Index: ui/aura_shell/workspace/workspace_manager.cc |
| diff --git a/ui/aura_shell/workspace/workspace_manager.cc b/ui/aura_shell/workspace/workspace_manager.cc |
| index f8f5a3e930cc04b206d85cb35c2880b1986a6819..3f289ab1b10e1cbb276dbd08f7553c4f640e98bc 100644 |
| --- a/ui/aura_shell/workspace/workspace_manager.cc |
| +++ b/ui/aura_shell/workspace/workspace_manager.cc |
| @@ -5,6 +5,15 @@ |
| #include <algorithm> |
| +#include "base/auto_reset.h" |
| +#include "ui/aura/desktop.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/aura_shell/workspace/workspace.h" |
| +#include "ui/aura_shell/workspace/workspace_manager.h" |
| +#include "ui/gfx/screen.h" |
| +#include "ui/gfx/compositor/layer.h" |
| +#include "ui/gfx/compositor/layer_animator.h" |
| +#include "ui/gfx/transform.h" |
| #include "base/logging.h" |
| #include "base/stl_util.h" |
| #include "ui/aura_shell/workspace/workspace.h" |
| @@ -13,6 +22,7 @@ namespace { |
| // The horizontal margein between workspaces in pixels. |
| const int kWorkspaceHorizontalMargin = 50; |
| + |
| } |
| namespace aura_shell { |
| @@ -20,16 +30,24 @@ namespace aura_shell { |
| //////////////////////////////////////////////////////////////////////////////// |
| // WindowManager, public: |
| -WorkspaceManager::WorkspaceManager() |
| - : active_workspace_(NULL) { |
| +WorkspaceManager::WorkspaceManager(aura::Window* viewport) |
| + : viewport_(viewport), |
| + active_workspace_(NULL), |
| + workspace_size_( |
| + gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size()), |
| + is_overview_(false) { |
| + aura::Desktop::GetInstance()->AddObserver(this); |
| } |
| WorkspaceManager::~WorkspaceManager() { |
| + aura::Desktop::GetInstance()->RemoveObserver(this); |
| STLDeleteElements(&workspaces_); |
| } |
| Workspace* WorkspaceManager::CreateWorkspace() { |
| - return new Workspace(this); |
| + Workspace* workspace = new Workspace(this); |
| + LayoutWorkspaces(); |
| + return workspace; |
| } |
| Workspace* WorkspaceManager::GetActiveWorkspace() const { |
| @@ -46,27 +64,73 @@ Workspace* WorkspaceManager::FindBy(aura::Window* window) const { |
| return NULL; |
| } |
| -void WorkspaceManager::Layout() { |
| +void WorkspaceManager::LayoutWorkspaces() { |
| gfx::Rect bounds(workspace_size_); |
| int x = 0; |
| + Workspaces::const_iterator i = workspaces_.begin(); |
|
sky
2011/10/25 20:58:05
remove this.
oshima
2011/10/25 23:37:23
Done.
|
| for (Workspaces::const_iterator i = workspaces_.begin(); |
| i != workspaces_.end(); |
| i++) { |
|
sky
2011/10/25 20:58:05
++i
oshima
2011/10/25 23:37:23
Done.
|
| Workspace* workspace = *i; |
| bounds.set_x(x); |
| workspace->SetBounds(bounds); |
| - x += workspace_size_.width() + kWorkspaceHorizontalMargin; |
| + x += bounds.width() + kWorkspaceHorizontalMargin; |
| } |
| } |
| -int WorkspaceManager::GetTotalWidth() const { |
| - return !workspaces_.size() ? 0 : |
| - workspace_size().width() * workspaces_.size() + |
| - kWorkspaceHorizontalMargin * (workspaces_.size() - 1); |
| +gfx::Rect WorkspaceManager::GetDragAreaBounds() { |
| + 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.
|
| + bounds.Inset(work_area_insets_); |
| + return bounds; |
| +} |
| + |
| +void WorkspaceManager::SetOverview(bool overview) { |
| + if (is_overview_ == overview) |
| + return; |
| + is_overview_ = overview; |
| + gfx::Rect bounds = viewport_->GetTargetBounds(); |
| + |
| + ui::Transform transform; |
| + if (is_overview_) { |
| + float scale = std::min( |
| + 0.9f, |
| + workspace_size_.width() / |
| + static_cast<float>(viewport_->bounds().width())); |
| + scale = std::max(0.3f, scale); |
| + |
| + transform.SetScale(scale, scale); |
| + |
| + int overview_width = viewport_->bounds().width() * scale; |
| + 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
|
| + (workspace_size_.width() - overview_width) /2 : 0; |
|
sky
2011/10/25 20:58:05
'/2' -> '/ 2'
oshima
2011/10/25 23:37:23
Done.
|
| + |
| + transform.SetTranslateX(-viewport_->GetTargetBounds().x() + dx); |
| + transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2); |
| + } else { |
| + transform.SetTranslateX(-active_workspace_->bounds().x()); |
| + } |
| + |
| + viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); |
| + viewport_->layer()->SetTransform(transform); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// WindowManager, private: |
| +// WorkspaceManager, Overridden from aura::DesktopObserver: |
| + |
| +void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) { |
| + workspace_size_ = |
| + gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size(); |
| + LayoutWorkspaces(); |
| +} |
| + |
| +void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) { |
| + Workspace* workspace = FindBy(active); |
| + if (workspace) |
| + SetActiveWorkspace(workspace); |
| +} |
| + |
| +//////////////////////////h///////////////////////////////////////////////////// |
|
sky
2011/10/25 20:58:05
'/h/' -> ///
oshima
2011/10/25 23:37:23
Done.
|
| +// WorkspaceManager, private: |
| void WorkspaceManager::AddWorkspace(Workspace* workspace) { |
| Workspaces::iterator i = std::find(workspaces_.begin(), |
| @@ -84,6 +148,8 @@ void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { |
| if (workspace == active_workspace_) |
| active_workspace_ = NULL; |
| workspaces_.erase(i); |
| + UpdateViewport(); |
| + LayoutWorkspaces(); |
| } |
| void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { |
| @@ -92,6 +158,39 @@ void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { |
| workspace) |
| != workspaces_.end()); |
| active_workspace_ = workspace; |
| + |
| + DCHECK(workspaces_.size()); |
| + |
| + UpdateViewport(); |
| + is_overview_ = false; |
| + |
| + ui::Transform transform; |
| + transform.SetTranslateX(-active_workspace_->bounds().x()); |
| + viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); |
| + viewport_->SetTransform(transform); |
| +} |
| + |
| +gfx::Rect WorkspaceManager::GetWorkAreaBounds( |
| + const gfx::Rect& workspace_bounds) { |
| + gfx::Rect bounds = workspace_bounds; |
| + bounds.Inset(work_area_insets_); |
| + return bounds; |
| +} |
| + |
| +void WorkspaceManager::UpdateViewport() { |
| + int total_width = workspace_size_.width() * workspaces_.size() + |
| + kWorkspaceHorizontalMargin * (workspaces_.size() - 1); |
| + gfx::Rect bounds(0, 0, total_width, workspace_size_.height()); |
| + |
| + if (viewport_->GetTargetBounds() == bounds) |
| + return; |
| + viewport_->SetBounds(bounds); |
| + |
| + // Move to active workspace. |
| + 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
|
| + transform.SetTranslateX(-active_workspace_->bounds().x()); |
| + viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); |
| + viewport_->SetTransform(transform); |
| } |
| } // namespace aura_shell |