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

Unified Diff: ui/aura_shell/workspace/workspace.cc

Issue 8381015: Add workspace to desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: temporarily exlucde tests failing on win Created 9 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura_shell/workspace/workspace.h ('k') | ui/aura_shell/workspace/workspace_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5623e43c654a1e8d74557c725a2c48b1821c185d 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 {
+ 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* no_animation) {
+ gfx::Rect work_area = workspace_manager_->GetWorkAreaBounds(bounds_);
+ 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()),
+ no_animation != *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(), no_animation != windows_[0]);
+ if (windows_.size() == 2) {
+ MoveWindowTo(windows_[1],
+ gfx::Point(work_area.right() - windows_[1]->bounds().width(),
+ work_area.y()),
+ no_animation != 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,21 @@ bool Workspace::CanAdd(aura::Window* window) const {
return windows_.size() < 2;
}
+void Workspace::MoveWindowTo(
+ aura::Window* window,
+ const gfx::Point& origin,
+ bool animate) {
+ 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
« no previous file with comments | « ui/aura_shell/workspace/workspace.h ('k') | ui/aura_shell/workspace/workspace_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698