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 #include "ui/aura_shell/workspace/workspace_manager.h" | 4 #include "ui/aura_shell/workspace/workspace_manager.h" |
5 | 5 |
6 #include <algorithm> | 6 #include <algorithm> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "ui/aura/desktop.h" | 9 #include "ui/aura/desktop.h" |
10 #include "ui/aura/screen_aura.h" | 10 #include "ui/aura/screen_aura.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 Workspace* workspace = new Workspace(this); | 53 Workspace* workspace = new Workspace(this); |
54 LayoutWorkspaces(); | 54 LayoutWorkspaces(); |
55 return workspace; | 55 return workspace; |
56 } | 56 } |
57 | 57 |
58 Workspace* WorkspaceManager::GetActiveWorkspace() const { | 58 Workspace* WorkspaceManager::GetActiveWorkspace() const { |
59 return active_workspace_; | 59 return active_workspace_; |
60 } | 60 } |
61 | 61 |
62 Workspace* WorkspaceManager::FindBy(aura::Window* window) const { | 62 Workspace* WorkspaceManager::FindBy(aura::Window* window) const { |
| 63 int index = GetWorkspaceIndexContaining(window); |
| 64 return index < 0 ? NULL : workspaces_[index]; |
| 65 } |
| 66 |
| 67 aura::Window* WorkspaceManager::FindRotateWindowForLocation( |
| 68 const gfx::Point& point) { |
63 for (Workspaces::const_iterator i = workspaces_.begin(); | 69 for (Workspaces::const_iterator i = workspaces_.begin(); |
64 i != workspaces_.end(); | 70 i != workspaces_.end(); |
65 ++i) { | 71 ++i) { |
66 if ((*i)->Contains(window)) | 72 aura::Window* window = (*i)->FindRotateWindowForLocation(point); |
67 return *i; | 73 if (window) |
| 74 return window; |
68 } | 75 } |
69 return NULL; | 76 return NULL; |
70 } | 77 } |
71 | 78 |
72 void WorkspaceManager::LayoutWorkspaces() { | 79 void WorkspaceManager::LayoutWorkspaces() { |
73 UpdateViewport(); | 80 UpdateViewport(); |
74 | 81 |
75 gfx::Rect bounds(workspace_size_); | 82 gfx::Rect bounds(workspace_size_); |
76 int x = 0; | 83 int x = 0; |
77 for (Workspaces::const_iterator i = workspaces_.begin(); | 84 for (Workspaces::const_iterator i = workspaces_.begin(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 transform.SetTranslateX(dx); | 128 transform.SetTranslateX(dx); |
122 transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2); | 129 transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2); |
123 } else if (active_workspace_) { | 130 } else if (active_workspace_) { |
124 transform.SetTranslateX(-active_workspace_->bounds().x()); | 131 transform.SetTranslateX(-active_workspace_->bounds().x()); |
125 } | 132 } |
126 | 133 |
127 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); | 134 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); |
128 viewport_->layer()->SetTransform(transform); | 135 viewport_->layer()->SetTransform(transform); |
129 } | 136 } |
130 | 137 |
| 138 void WorkspaceManager::RotateWindows(aura::Window* source, |
| 139 aura::Window* target) { |
| 140 DCHECK(source); |
| 141 DCHECK(target); |
| 142 int source_ws_index = GetWorkspaceIndexContaining(source); |
| 143 int target_ws_index = GetWorkspaceIndexContaining(target); |
| 144 DCHECK(source_ws_index >= 0); |
| 145 DCHECK(target_ws_index >= 0); |
| 146 if (source_ws_index == target_ws_index) { |
| 147 workspaces_[source_ws_index]->RotateWindows(source, target); |
| 148 } else { |
| 149 aura::Window* insert = source; |
| 150 if (source_ws_index < target_ws_index) { |
| 151 for (int i = target_ws_index; i >= source_ws_index; --i) { |
| 152 insert = workspaces_[i]->ShiftWindows( |
| 153 insert, source, target, Workspace::SHIFT_TO_LEFT); |
| 154 // |target| can only be in the 1st workspace. |
| 155 target = NULL; |
| 156 } |
| 157 } else { |
| 158 for (int i = target_ws_index; i <= source_ws_index; ++i) { |
| 159 insert = workspaces_[i]->ShiftWindows( |
| 160 insert, source, target, Workspace::SHIFT_TO_RIGHT); |
| 161 // |target| can only be in the 1st workspace. |
| 162 target = NULL; |
| 163 } |
| 164 } |
| 165 } |
| 166 } |
| 167 |
131 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
132 // WorkspaceManager, Overridden from aura::DesktopObserver: | 169 // WorkspaceManager, Overridden from aura::DesktopObserver: |
133 | 170 |
134 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) { | 171 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) { |
135 workspace_size_ = | 172 workspace_size_ = |
136 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size(); | 173 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size(); |
137 LayoutWorkspaces(); | 174 LayoutWorkspaces(); |
138 } | 175 } |
139 | 176 |
140 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) { | 177 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 216 } |
180 | 217 |
181 gfx::Rect WorkspaceManager::GetWorkAreaBounds( | 218 gfx::Rect WorkspaceManager::GetWorkAreaBounds( |
182 const gfx::Rect& workspace_bounds) { | 219 const gfx::Rect& workspace_bounds) { |
183 gfx::Rect bounds = workspace_bounds; | 220 gfx::Rect bounds = workspace_bounds; |
184 bounds.Inset( | 221 bounds.Inset( |
185 aura::Desktop::GetInstance()->screen()->work_area_insets()); | 222 aura::Desktop::GetInstance()->screen()->work_area_insets()); |
186 return bounds; | 223 return bounds; |
187 } | 224 } |
188 | 225 |
| 226 // Returns the index of the workspace that contains the |window|. |
| 227 int WorkspaceManager::GetWorkspaceIndexContaining(aura::Window* window) const { |
| 228 for (Workspaces::const_iterator i = workspaces_.begin(); |
| 229 i != workspaces_.end(); |
| 230 ++i) { |
| 231 if ((*i)->Contains(window)) |
| 232 return i - workspaces_.begin(); |
| 233 } |
| 234 return -1; |
| 235 } |
| 236 |
189 void WorkspaceManager::UpdateViewport() { | 237 void WorkspaceManager::UpdateViewport() { |
190 int num_workspaces = std::max(1, static_cast<int>(workspaces_.size())); | 238 int num_workspaces = std::max(1, static_cast<int>(workspaces_.size())); |
191 int total_width = workspace_size_.width() * num_workspaces + | 239 int total_width = workspace_size_.width() * num_workspaces + |
192 kWorkspaceHorizontalMargin * (num_workspaces - 1); | 240 kWorkspaceHorizontalMargin * (num_workspaces - 1); |
193 gfx::Rect bounds(0, 0, total_width, workspace_size_.height()); | 241 gfx::Rect bounds(0, 0, total_width, workspace_size_.height()); |
194 | 242 |
195 if (viewport_->GetTargetBounds() != bounds) | 243 if (viewport_->GetTargetBounds() != bounds) |
196 viewport_->SetBounds(bounds); | 244 viewport_->SetBounds(bounds); |
197 | 245 |
198 // Move to active workspace. | 246 // Move to active workspace. |
199 if (active_workspace_) { | 247 if (active_workspace_) { |
200 ui::Transform transform; | 248 ui::Transform transform; |
201 transform.SetTranslateX(-active_workspace_->bounds().x()); | 249 transform.SetTranslateX(-active_workspace_->bounds().x()); |
202 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); | 250 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); |
203 viewport_->SetTransform(transform); | 251 viewport_->SetTransform(transform); |
204 } | 252 } |
205 } | 253 } |
206 | 254 |
207 } // namespace aura_shell | 255 } // namespace aura_shell |
OLD | NEW |