OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/workspace/workspace_manager.h" | 5 #include "ash/wm/workspace/workspace_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 pending_workspaces_.insert(workspace); | 257 pending_workspaces_.insert(workspace); |
258 return workspace->window(); | 258 return workspace->window(); |
259 } | 259 } |
260 | 260 |
261 if (!GetTrackedByWorkspace(window) || GetPersistsAcrossAllWorkspaces(window)) | 261 if (!GetTrackedByWorkspace(window) || GetPersistsAcrossAllWorkspaces(window)) |
262 return active_workspace_->window(); | 262 return active_workspace_->window(); |
263 | 263 |
264 return desktop_workspace()->window(); | 264 return desktop_workspace()->window(); |
265 } | 265 } |
266 | 266 |
267 bool WorkspaceManager::CycleToWorkspace(Direction direction) { | |
268 aura::Window* active_window = active_workspace_->GetActiveWindow(); | |
269 | |
270 Workspaces::const_iterator workspace_i(FindWorkspace(active_workspace_)); | |
271 int workspace_offset = 0; | |
272 if (direction == WORKSPACE_ABOVE) { | |
273 workspace_offset = 1; | |
274 if (workspace_i == workspaces_.end() - 1) | |
275 return false; | |
276 } else { | |
277 workspace_offset = -1; | |
278 if (workspace_i == workspaces_.begin()) | |
279 return false; | |
280 } | |
281 | |
282 Workspaces::const_iterator next_workspace_i(workspace_i + workspace_offset); | |
283 SetActiveWorkspace(*next_workspace_i, SWITCH_CYCLE_WORKSPACE, | |
284 base::TimeDelta()); | |
285 | |
286 // The activation controller will pick a window from the just activated | |
287 // workspace to activate as a result of DeactivateWindow(). | |
288 if (active_window) | |
289 wm::DeactivateWindow(active_window); | |
sky
2012/11/28 15:15:34
I don't understand this, why do you need to to do
pkotwicz
2012/11/29 01:01:46
This is a hack. It has the effect of activating a
| |
290 return true; | |
291 } | |
292 | |
267 void WorkspaceManager::DoInitialAnimation() { | 293 void WorkspaceManager::DoInitialAnimation() { |
268 if (active_workspace_->is_maximized()) { | 294 if (active_workspace_->is_maximized()) { |
269 RootWindowController* root_controller = GetRootWindowController( | 295 RootWindowController* root_controller = GetRootWindowController( |
270 contents_view_->GetRootWindow()); | 296 contents_view_->GetRootWindow()); |
271 if (root_controller) { | 297 if (root_controller) { |
272 aura::Window* background = root_controller->GetContainer( | 298 aura::Window* background = root_controller->GetContainer( |
273 kShellWindowId_DesktopBackgroundContainer); | 299 kShellWindowId_DesktopBackgroundContainer); |
274 background->Show(); | 300 background->Show(); |
275 ShowOrHideDesktopBackground(background, SWITCH_INITIAL, | 301 ShowOrHideDesktopBackground(background, SWITCH_INITIAL, |
276 base::TimeDelta(), false); | 302 base::TimeDelta(), false); |
277 } | 303 } |
278 } | 304 } |
279 ShowWorkspace(active_workspace_, active_workspace_, SWITCH_INITIAL); | 305 ShowWorkspace(active_workspace_, active_workspace_, SWITCH_INITIAL); |
280 } | 306 } |
281 | 307 |
308 aura::Window* WorkspaceManager::GetActiveWorkspaceWindow() const { | |
309 return active_workspace_->window(); | |
310 } | |
311 | |
282 void WorkspaceManager::OnAppTerminating() { | 312 void WorkspaceManager::OnAppTerminating() { |
283 app_terminating_ = true; | 313 app_terminating_ = true; |
284 } | 314 } |
285 | 315 |
286 void WorkspaceManager::UpdateShelfVisibility() { | 316 void WorkspaceManager::UpdateShelfVisibility() { |
287 if (shelf_) | 317 if (shelf_) |
288 shelf_->UpdateVisibilityState(); | 318 shelf_->UpdateVisibilityState(); |
289 } | 319 } |
290 | 320 |
291 Workspace* WorkspaceManager::FindBy(Window* window) const { | 321 Workspace* WorkspaceManager::FindBy(Window* window) const { |
292 while (window) { | 322 while (window) { |
293 Workspace* workspace = window->GetProperty(kWorkspaceKey); | 323 Workspace* workspace = window->GetProperty(kWorkspaceKey); |
294 if (workspace) | 324 if (workspace) |
295 return workspace; | 325 return workspace; |
296 window = window->parent(); | 326 window = window->parent(); |
297 } | 327 } |
298 return NULL; | 328 return NULL; |
299 } | 329 } |
300 | 330 |
301 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace, | 331 void WorkspaceManager::SetActiveWorkspace(Workspace* workspace, |
302 SwitchReason reason, | 332 SwitchReason reason, |
303 base::TimeDelta duration) { | 333 base::TimeDelta duration) { |
304 DCHECK(workspace); | 334 DCHECK(workspace); |
305 if (active_workspace_ == workspace) | 335 if (active_workspace_ == workspace) |
306 return; | 336 return; |
307 | 337 |
308 pending_workspaces_.erase(workspace); | 338 pending_workspaces_.erase(workspace); |
309 | 339 |
310 // Adjust the z-order. No need to adjust the z-order for the desktop since | 340 // Adjust the z-order such that the active workspace is at the top of the |
311 // it always stays at the bottom. | 341 // stack. The following exceptions apply: |
312 if (workspace != desktop_workspace() && | 342 // - Do not adjust the desktop's z-order since it should stay at the bottom. |
313 FindWorkspace(workspace) == workspaces_.end()) { | 343 // - Do not adjust the z-order when cycling through windows such that cycling |
344 // is linear. | |
345 if (workspace != desktop_workspace() && reason != SWITCH_CYCLE_WORKSPACE) { | |
346 Workspaces::iterator workspace_i = FindWorkspace(workspace); | |
347 if (workspace_i != workspaces_.end()) | |
348 workspaces_.erase(workspace_i); | |
314 contents_view_->StackChildAbove(workspace->window(), | 349 contents_view_->StackChildAbove(workspace->window(), |
315 workspaces_.back()->window()); | 350 workspaces_.back()->window()); |
316 workspaces_.push_back(workspace); | 351 workspaces_.push_back(workspace); |
317 } | 352 } |
318 | 353 |
319 Workspace* last_active = active_workspace_; | 354 Workspace* last_active = active_workspace_; |
320 active_workspace_ = workspace; | 355 active_workspace_ = workspace; |
321 | 356 |
322 // The display work-area may have changed while |workspace| was not the active | 357 // The display work-area may have changed while |workspace| was not the active |
323 // workspace. Give it a chance to adjust its state for the new work-area. | 358 // workspace. Give it a chance to adjust its state for the new work-area. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 Workspace* workspace, | 410 Workspace* workspace, |
376 Window* stack_beneath, | 411 Window* stack_beneath, |
377 SwitchReason reason) { | 412 SwitchReason reason) { |
378 // We're all ready moving windows. | 413 // We're all ready moving windows. |
379 if (in_move_) | 414 if (in_move_) |
380 return; | 415 return; |
381 | 416 |
382 DCHECK_NE(desktop_workspace(), workspace); | 417 DCHECK_NE(desktop_workspace(), workspace); |
383 | 418 |
384 if (workspace == active_workspace_) | 419 if (workspace == active_workspace_) |
385 SelectNextWorkspace(reason); | 420 SelectWorkspaceBelow(reason); |
386 | 421 |
387 base::AutoReset<bool> setter(&in_move_, true); | 422 base::AutoReset<bool> setter(&in_move_, true); |
388 | 423 |
389 MoveChildrenToDesktop(workspace->window(), stack_beneath); | 424 MoveChildrenToDesktop(workspace->window(), stack_beneath); |
390 | 425 |
391 { | 426 { |
392 Workspaces::iterator workspace_i(FindWorkspace(workspace)); | 427 Workspaces::iterator workspace_i(FindWorkspace(workspace)); |
393 if (workspace_i != workspaces_.end()) | 428 if (workspace_i != workspaces_.end()) |
394 workspaces_.erase(workspace_i); | 429 workspaces_.erase(workspace_i); |
395 } | 430 } |
(...skipping 24 matching lines...) Expand all Loading... | |
420 // (moving may cascade and cause other windows to move). | 455 // (moving may cascade and cause other windows to move). |
421 for (size_t i = 0; i < to_move.size(); ++i) { | 456 for (size_t i = 0; i < to_move.size(); ++i) { |
422 if (std::find(window->children().begin(), window->children().end(), | 457 if (std::find(window->children().begin(), window->children().end(), |
423 to_move[i]) != window->children().end()) { | 458 to_move[i]) != window->children().end()) { |
424 ReparentWindow(to_move[i], desktop_workspace()->window(), | 459 ReparentWindow(to_move[i], desktop_workspace()->window(), |
425 stack_beneath); | 460 stack_beneath); |
426 } | 461 } |
427 } | 462 } |
428 } | 463 } |
429 | 464 |
430 void WorkspaceManager::SelectNextWorkspace(SwitchReason reason) { | 465 void WorkspaceManager::SelectWorkspaceBelow(SwitchReason reason) { |
431 DCHECK_NE(active_workspace_, desktop_workspace()); | |
432 | |
433 Workspaces::const_iterator workspace_i(FindWorkspace(active_workspace_)); | 466 Workspaces::const_iterator workspace_i(FindWorkspace(active_workspace_)); |
434 Workspaces::const_iterator next_workspace_i(workspace_i + 1); | 467 if (workspace_i == workspaces_.begin()) { |
435 if (next_workspace_i != workspaces_.end()) | 468 SetActiveWorkspace(active_workspace_, reason, base::TimeDelta()); |
436 SetActiveWorkspace(*next_workspace_i, reason, base::TimeDelta()); | 469 } else { |
437 else | 470 Workspaces::const_iterator workspace_below_i(workspace_i - 1); |
438 SetActiveWorkspace(*(workspace_i - 1), reason, base::TimeDelta()); | 471 SetActiveWorkspace(*workspace_below_i, reason, base::TimeDelta()); |
472 } | |
439 } | 473 } |
440 | 474 |
441 void WorkspaceManager::ScheduleDelete(Workspace* workspace) { | 475 void WorkspaceManager::ScheduleDelete(Workspace* workspace) { |
442 to_delete_.insert(workspace); | 476 to_delete_.insert(workspace); |
443 delete_timer_.Stop(); | 477 delete_timer_.Stop(); |
444 delete_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, | 478 delete_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, |
445 &WorkspaceManager::ProcessDeletion); | 479 &WorkspaceManager::ProcessDeletion); |
446 } | 480 } |
447 | 481 |
448 void WorkspaceManager::SetUnminimizingWorkspace(Workspace* workspace) { | 482 void WorkspaceManager::SetUnminimizingWorkspace(Workspace* workspace) { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 new_workspace->window()->Show(); | 770 new_workspace->window()->Show(); |
737 ReparentWindow(window, new_workspace->window(), NULL); | 771 ReparentWindow(window, new_workspace->window(), NULL); |
738 if (is_active) { | 772 if (is_active) { |
739 SetActiveWorkspace(new_workspace, SWITCH_TRACKED_BY_WORKSPACE_CHANGED, | 773 SetActiveWorkspace(new_workspace, SWITCH_TRACKED_BY_WORKSPACE_CHANGED, |
740 base::TimeDelta()); | 774 base::TimeDelta()); |
741 } | 775 } |
742 } | 776 } |
743 | 777 |
744 } // namespace internal | 778 } // namespace internal |
745 } // namespace ash | 779 } // namespace ash |
OLD | NEW |