Index: ui/aura_shell/workspace/workspace.cc |
diff --git a/ui/aura_shell/workspace/workspace.cc b/ui/aura_shell/workspace/workspace.cc |
index 5623e43c654a1e8d74557c725a2c48b1821c185d..d2c23d901a692e4823084b9a27bbd496b281e79a 100644 |
--- a/ui/aura_shell/workspace/workspace.cc |
+++ b/ui/aura_shell/workspace/workspace.cc |
@@ -5,6 +5,7 @@ |
#include "ui/aura_shell/workspace/workspace.h" |
#include "base/logging.h" |
+#include "ui/aura/desktop.h" |
#include "ui/aura/window.h" |
#include "ui/aura_shell/workspace/workspace_manager.h" |
#include "ui/gfx/compositor/layer.h" |
@@ -29,7 +30,7 @@ void Workspace::SetBounds(const gfx::Rect& bounds) { |
bool bounds_changed = bounds_ != bounds; |
bounds_ = bounds; |
if (bounds_changed) |
- Layout(NULL); |
+ Layout(NULL, NULL); |
} |
gfx::Rect Workspace::GetWorkAreaBounds() const { |
@@ -49,7 +50,7 @@ bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { |
std::find(windows_.begin(), windows_.end(), after); |
windows_.insert(++i, window); |
} |
- Layout(window); |
+ Layout(NULL, window); |
return true; |
} |
@@ -57,7 +58,7 @@ bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { |
void Workspace::RemoveWindow(aura::Window* window) { |
DCHECK(Contains(window)); |
windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
- Layout(NULL); |
+ Layout(NULL, NULL); |
} |
@@ -65,38 +66,84 @@ bool Workspace::Contains(aura::Window* window) const { |
return std::find(windows_.begin(), windows_.end(), window) != windows_.end(); |
} |
+aura::Window* Workspace::FindSwapWindowForLocation(const gfx::Point& position) { |
+ // If all windows fits to the width of workspace, it returns the |
sky
2011/10/27 00:53:03
Split this comment up and move it into the appropr
oshima
2011/10/27 16:16:27
Done.
|
+ // window which contains |position|'s x coordinate. If windows are |
+ // overlapping, it divides the workspace into regions with the same width, |
+ // and returns the Nth window that corresponds to this region that contains |
+ // the |position|. |
+ aura::Window* active = aura::Desktop::GetInstance()->active_window(); |
+ int total_width = GetTotalWindowsWidth(); |
+ if (total_width < bounds_.width()) { |
sky
2011/10/27 00:53:03
nit: make this if (GetTotalWidth() < bounds_.width
oshima
2011/10/27 16:16:27
Done.
|
+ for (aura::Window::Windows::const_iterator i = windows_.begin(); |
+ i != windows_.end(); |
+ ++i) { |
+ if (active == *i) |
+ continue; |
+ gfx::Rect bounds = (*i)->GetTargetBounds(); |
+ if (bounds.x() < position.x() && position.x() < bounds.right()) |
+ return *i; |
+ } |
+ } else if (bounds_.x() < position.x() && position.x() < bounds_.right()) { |
+ int width = bounds_.width() / windows_.size(); |
+ size_t index = (position.x() - bounds_.x()) / width; |
+ DCHECK(index < windows_.size()); |
+ aura::Window* window = windows_[index]; |
+ if (window != active) |
+ return window; |
+ } |
+ return NULL; |
+} |
+ |
+void Workspace::SwapWindow(aura::Window* drag, aura::Window* target) { |
+ int drag_index = GetIndexOf(drag); |
+ int target_index = GetIndexOf(target); |
+ DCHECK(drag_index >= 0); |
+ DCHECK(target_index >= 0); |
+ std::swap(windows_[drag_index], windows_[target_index]); |
oshima
2011/10/26 22:48:03
I feel there is better way but i somehow found fin
sky
2011/10/27 00:53:03
I can't think of a better way.
|
+ Layout(drag, NULL); |
+} |
+ |
+void Workspace::ReplaceWindow(aura::Window* orig, |
+ aura::Window* with, |
+ bool relayout) { |
+ DCHECK(Contains(orig)); |
+ DCHECK(!Contains(with)); |
+ std::replace(windows_.begin(), windows_.end(), orig, with); |
+ if (relayout) |
+ Layout(NULL, NULL); |
+} |
+ |
void Workspace::Activate() { |
workspace_manager_->SetActiveWorkspace(this); |
} |
-void Workspace::Layout(aura::Window* no_animation) { |
+void Workspace::Layout(aura::Window* ignore, 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(); |
- } |
+ int total_width = GetTotalWindowsWidth(); |
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); |
+ ++i) { |
+ if (*i != ignore) { |
+ 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) { |
+ // TODO(oshima): This is messy. Figure out general algorithm to |
+ // layout more than 2 windows. |
+ if (windows_[0] != ignore) { |
+ MoveWindowTo(windows_[0], |
+ work_area.origin(), |
+ no_animation != windows_[0]); |
+ } |
+ if (windows_.size() == 2 && windows_[1] != ignore) { |
MoveWindowTo(windows_[1], |
gfx::Point(work_area.right() - windows_[1]->bounds().width(), |
work_area.y()), |
@@ -135,4 +182,17 @@ void Workspace::MoveWindowTo( |
} |
} |
+int Workspace::GetTotalWindowsWidth() const { |
+ 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(); |
+ } |
+ return total_width; |
+} |
+ |
} // namespace aura_shell |