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

Side by Side Diff: ui/aura_shell/workspace/workspace_manager.cc

Issue 8391035: Drag and rotate windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rotate windows Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 transform.SetTranslateX(-viewport_->GetTargetBounds().x() + dx); 121 transform.SetTranslateX(-viewport_->GetTargetBounds().x() + dx);
115 transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2); 122 transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2);
116 } else { 123 } else {
117 transform.SetTranslateX(-active_workspace_->bounds().x()); 124 transform.SetTranslateX(-active_workspace_->bounds().x());
118 } 125 }
119 126
120 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); 127 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
121 viewport_->layer()->SetTransform(transform); 128 viewport_->layer()->SetTransform(transform);
122 } 129 }
123 130
131 void WorkspaceManager::RotateWindows(aura::Window* source,
132 aura::Window* target) {
133 DCHECK(source);
134 DCHECK(target);
135 int source_ws_index = GetWorkspaceIndexContaining(source);
136 int target_ws_index = GetWorkspaceIndexContaining(target);
137 DCHECK(source_ws_index >= 0);
138 DCHECK(target_ws_index >= 0);
139 if (source_ws_index == target_ws_index) {
140 workspaces_[source_ws_index]->RotateWindows(source, target);
141 } else {
142 aura::Window* insert = source;
143 if (source_ws_index < target_ws_index) {
144 for (int i = target_ws_index; i >= source_ws_index; --i) {
145 insert = workspaces_[i]->ShiftWindows(
146 insert, source, Workspace::SHIFT_TO_LEFT);
147 }
148 } else {
149 for (int i = target_ws_index; i <= source_ws_index; ++i) {
150 insert = workspaces_[i]->ShiftWindows(
151 insert, source, Workspace::SHIFT_TO_RIGHT);
152 }
153 }
154 }
155 }
156
124 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
125 // WorkspaceManager, Overridden from aura::DesktopObserver: 158 // WorkspaceManager, Overridden from aura::DesktopObserver:
126 159
127 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) { 160 void WorkspaceManager::OnDesktopResized(const gfx::Size& new_size) {
128 workspace_size_ = 161 workspace_size_ =
129 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size(); 162 gfx::Screen::GetMonitorAreaNearestWindow(viewport_).size();
130 LayoutWorkspaces(); 163 LayoutWorkspaces();
131 } 164 }
132 165
133 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) { 166 void WorkspaceManager::OnActiveWindowChanged(aura::Window* active) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 205 }
173 206
174 gfx::Rect WorkspaceManager::GetWorkAreaBounds( 207 gfx::Rect WorkspaceManager::GetWorkAreaBounds(
175 const gfx::Rect& workspace_bounds) { 208 const gfx::Rect& workspace_bounds) {
176 gfx::Rect bounds = workspace_bounds; 209 gfx::Rect bounds = workspace_bounds;
177 bounds.Inset( 210 bounds.Inset(
178 aura::Desktop::GetInstance()->screen()->work_area_insets()); 211 aura::Desktop::GetInstance()->screen()->work_area_insets());
179 return bounds; 212 return bounds;
180 } 213 }
181 214
215 // Returns the index of the workspace that contains the |window|.
216 int WorkspaceManager::GetWorkspaceIndexContaining(aura::Window* window) const {
217 for (Workspaces::const_iterator i = workspaces_.begin();
218 i != workspaces_.end();
219 ++i) {
220 if ((*i)->Contains(window))
221 return i - workspaces_.begin();
222 }
223 return -1;
224 }
225
182 void WorkspaceManager::UpdateViewport() { 226 void WorkspaceManager::UpdateViewport() {
183 int num_workspaces = std::max(1, static_cast<int>(workspaces_.size())); 227 int num_workspaces = std::max(1, static_cast<int>(workspaces_.size()));
184 int total_width = workspace_size_.width() * num_workspaces + 228 int total_width = workspace_size_.width() * num_workspaces +
185 kWorkspaceHorizontalMargin * (num_workspaces - 1); 229 kWorkspaceHorizontalMargin * (num_workspaces - 1);
186 gfx::Rect bounds(0, 0, total_width, workspace_size_.height()); 230 gfx::Rect bounds(0, 0, total_width, workspace_size_.height());
187 231
188 if (viewport_->GetTargetBounds() != bounds) 232 if (viewport_->GetTargetBounds() != bounds)
189 viewport_->SetBounds(bounds); 233 viewport_->SetBounds(bounds);
190 234
191 // Move to active workspace. 235 // Move to active workspace.
192 if (active_workspace_) { 236 if (active_workspace_) {
193 ui::Transform transform; 237 ui::Transform transform;
194 transform.SetTranslateX(-active_workspace_->bounds().x()); 238 transform.SetTranslateX(-active_workspace_->bounds().x());
195 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation()); 239 viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
196 viewport_->SetTransform(transform); 240 viewport_->SetTransform(transform);
197 } 241 }
198 } 242 }
199 243
200 } // namespace aura_shell 244 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698