Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura_shell/workspace/workspace_manager.h" | 9 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 10 #include "ui/gfx/compositor/layer.h" | |
| 11 | |
| 12 namespace { | |
| 13 // Horizontal margin between windows. | |
| 14 const int kWindowHorizontalMargin = 10; | |
| 15 } | |
| 10 | 16 |
| 11 namespace aura_shell { | 17 namespace aura_shell { |
| 12 | 18 |
| 13 Workspace::Workspace(WorkspaceManager* manager) | 19 Workspace::Workspace(WorkspaceManager* manager) |
| 14 : workspace_manager_(manager) { | 20 : workspace_manager_(manager) { |
| 15 workspace_manager_->AddWorkspace(this); | 21 workspace_manager_->AddWorkspace(this); |
| 16 } | 22 } |
| 17 | 23 |
| 18 Workspace::~Workspace() { | 24 Workspace::~Workspace() { |
| 19 workspace_manager_->RemoveWorkspace(this); | 25 workspace_manager_->RemoveWorkspace(this); |
| 20 } | 26 } |
| 21 | 27 |
| 22 void Workspace::SetBounds(const gfx::Rect& bounds) { | 28 void Workspace::SetBounds(const gfx::Rect& bounds) { |
| 23 int dx = bounds.x() - bounds_.x(); | 29 bool bounds_changed = bounds_ != bounds; |
| 24 bounds_ = bounds; | 30 bounds_ = bounds; |
| 31 if (bounds_changed) | |
| 32 Layout(NULL); | |
| 33 } | |
| 25 | 34 |
| 26 for (aura::Window::Windows::iterator i = windows_.begin(); | 35 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
| |
| 27 i != windows_.end(); | 36 return workspace_manager_->GetWorkAreaBounds(bounds_); |
| 28 i++) { | |
| 29 aura::Window* window = *i; | |
| 30 gfx::Rect bounds = window->GetTargetBounds(); | |
| 31 bounds.Offset(dx, 0); | |
| 32 window->SetBounds(bounds); | |
| 33 } | |
| 34 } | 37 } |
| 35 | 38 |
| 36 bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { | 39 bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { |
| 37 if (!CanAdd(window)) | 40 if (!CanAdd(window)) |
| 38 return false; | 41 return false; |
| 39 DCHECK(!Contains(window)); | 42 DCHECK(!Contains(window)); |
| 40 | 43 |
| 41 if (!after) { // insert at the end; | 44 if (!after) { // insert at the end. |
| 42 windows_.push_back(window); | 45 windows_.push_back(window); |
| 43 } else { | 46 } else { |
| 44 DCHECK(Contains(after)); | 47 DCHECK(Contains(after)); |
| 45 aura::Window::Windows::iterator i = | 48 aura::Window::Windows::iterator i = |
| 46 std::find(windows_.begin(), windows_.end(), after); | 49 std::find(windows_.begin(), windows_.end(), after); |
| 47 windows_.insert(++i, window); | 50 windows_.insert(++i, window); |
| 48 } | 51 } |
| 52 Layout(window); | |
| 53 | |
| 49 return true; | 54 return true; |
| 50 } | 55 } |
| 51 | 56 |
| 52 void Workspace::RemoveWindow(aura::Window* window) { | 57 void Workspace::RemoveWindow(aura::Window* window) { |
| 53 DCHECK(Contains(window)); | 58 DCHECK(Contains(window)); |
| 54 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); | 59 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
| 60 Layout(NULL); | |
| 55 } | 61 } |
| 56 | 62 |
| 63 | |
| 57 bool Workspace::Contains(aura::Window* window) const { | 64 bool Workspace::Contains(aura::Window* window) const { |
| 58 return std::find(windows_.begin(), windows_.end(), window) != windows_.end(); | 65 return std::find(windows_.begin(), windows_.end(), window) != windows_.end(); |
| 59 } | 66 } |
| 60 | 67 |
| 61 void Workspace::Activate() { | 68 void Workspace::Activate() { |
| 62 workspace_manager_->SetActiveWorkspace(this); | 69 workspace_manager_->SetActiveWorkspace(this); |
| 63 } | 70 } |
| 64 | 71 |
| 72 void Workspace::Layout(aura::Window* new_window) { | |
| 73 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
| |
| 74 int total_width = 0; | |
| 75 for (aura::Window::Windows::const_iterator i = windows_.begin(); | |
| 76 i != windows_.end(); | |
| 77 i++) { | |
| 78 if (total_width) | |
| 79 total_width += kWindowHorizontalMargin; | |
| 80 // TODO(oshima): use restored bounds. | |
| 81 total_width += (*i)->bounds().width(); | |
| 82 } | |
| 83 | |
| 84 if (total_width < work_area.width()) { | |
| 85 int dx = (work_area.width() - total_width) / 2; | |
| 86 for (aura::Window::Windows::iterator i = windows_.begin(); | |
| 87 i != windows_.end(); | |
| 88 i++) { | |
| 89 MoveWindowTo(*i, | |
| 90 gfx::Point(work_area.x() + dx, work_area.y()), | |
| 91 new_window != *i); | |
| 92 dx += (*i)->bounds().width() + kWindowHorizontalMargin; | |
| 93 } | |
| 94 } else { | |
| 95 DCHECK_LT(windows_.size(), 3U); | |
| 96 // TODO(oshima): Figure out general algorithm to layout more than | |
| 97 // 2 windows. | |
| 98 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.
| |
| 99 if (windows_.size() == 2) { | |
| 100 MoveWindowTo(windows_[1], | |
| 101 gfx::Point(work_area.right() - windows_[1]->bounds().width(), | |
| 102 work_area.y()), | |
| 103 new_window != windows_[1]); | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 | |
| 65 int Workspace::GetIndexOf(aura::Window* window) const { | 108 int Workspace::GetIndexOf(aura::Window* window) const { |
| 66 aura::Window::Windows::const_iterator i = | 109 aura::Window::Windows::const_iterator i = |
| 67 std::find(windows_.begin(), windows_.end(), window); | 110 std::find(windows_.begin(), windows_.end(), window); |
| 68 return i == windows_.end() ? -1 : i - windows_.begin(); | 111 return i == windows_.end() ? -1 : i - windows_.begin(); |
| 69 } | 112 } |
| 70 | 113 |
| 71 bool Workspace::CanAdd(aura::Window* window) const { | 114 bool Workspace::CanAdd(aura::Window* window) const { |
| 72 // TODO(oshima): This should be based on available space and the | 115 // TODO(oshima): This should be based on available space and the |
| 73 // size of the |window|. | 116 // size of the |window|. |
| 74 NOTIMPLEMENTED(); | 117 NOTIMPLEMENTED(); |
| 75 return windows_.size() < 2; | 118 return windows_.size() < 2; |
| 76 } | 119 } |
| 77 | 120 |
| 121 void Workspace::MoveWindowTo( | |
| 122 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.
| |
| 123 if (window->show_state() == ui::SHOW_STATE_FULLSCREEN) | |
| 124 window->Fullscreen(); | |
| 125 else if (window->show_state() == ui::SHOW_STATE_MAXIMIZED) | |
| 126 window->Maximize(); | |
| 127 else { | |
| 128 gfx::Rect bounds = window->GetTargetBounds(); | |
| 129 bounds.set_origin(origin); | |
| 130 if (animate) | |
| 131 window->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); | |
| 132 window->SetBounds(bounds); | |
| 133 } | |
| 134 } | |
| 135 | |
| 78 } // namespace aura_shell | 136 } // namespace aura_shell |
| OLD | NEW |