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
3 // found in the LICENSE file.
5 #include "ash/wm/workspace_controller.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/window_animations.h"
12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h"
14 #include "ash/wm/workspace/workspace_event_handler.h"
15 #include "ash/wm/workspace/workspace_layout_manager.h"
16 #include "ui/aura/client/activation_client.h"
17 #include "ui/aura/client/aura_constants.h"
18 #include "ui/aura/root_window.h"
19 #include "ui/aura/window.h"
20 #include "ui/compositor/layer.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/views/corewm/visibility_controller.h"
23 #include "ui/views/corewm/window_animations.h"
29 // Amount of time to pause before animating anything. Only used during initial
30 // animation (when logging in).
31 const int kInitialPauseTimeMS = 750;
33 // Returns true if there are visible docked windows in the same screen as the
35 bool IsDockedAreaVisible(const ShelfLayoutManager* shelf) {
36 return shelf->dock_bounds().width() > 0;
41 WorkspaceController::WorkspaceController(aura::Window* viewport)
42 : viewport_(viewport),
44 event_handler_(new WorkspaceEventHandler),
45 layout_manager_(new WorkspaceLayoutManager(viewport)) {
46 SetWindowVisibilityAnimationTransition(
47 viewport_, views::corewm::ANIMATE_NONE);
49 viewport_->SetLayoutManager(layout_manager_);
50 viewport_->AddPreTargetHandler(event_handler_.get());
51 viewport_->AddPostTargetHandler(event_handler_.get());
54 WorkspaceController::~WorkspaceController() {
55 viewport_->SetLayoutManager(NULL);
56 viewport_->RemovePreTargetHandler(event_handler_.get());
57 viewport_->RemovePostTargetHandler(event_handler_.get());
60 WorkspaceWindowState WorkspaceController::GetWindowState() const {
62 return WORKSPACE_WINDOW_STATE_DEFAULT;
63 const aura::Window* topmost_fullscreen_window = GetRootWindowController(
64 viewport_->GetRootWindow())->GetWindowForFullscreenMode();
65 if (topmost_fullscreen_window &&
66 !wm::GetWindowState(topmost_fullscreen_window)->ignored_by_shelf()) {
67 return WORKSPACE_WINDOW_STATE_FULL_SCREEN;
70 // These are the container ids of containers which may contain windows that
71 // may overlap the launcher shelf and affect its transparency.
72 const int kWindowContainerIds[] = {
73 internal::kShellWindowId_DefaultContainer,
74 internal::kShellWindowId_DockedContainer,
76 const gfx::Rect shelf_bounds(shelf_->GetIdealBounds());
77 bool window_overlaps_launcher = false;
78 for (size_t idx = 0; idx < arraysize(kWindowContainerIds); idx++) {
79 const aura::Window* container = Shell::GetContainer(
80 viewport_->GetRootWindow(), kWindowContainerIds[idx]);
81 const aura::Window::Windows& windows(container->children());
82 for (aura::Window::Windows::const_iterator i = windows.begin();
83 i != windows.end(); ++i) {
84 wm::WindowState* window_state = wm::GetWindowState(*i);
85 if (window_state->ignored_by_shelf())
87 ui::Layer* layer = (*i)->layer();
88 if (!layer->GetTargetVisibility())
90 if (window_state->IsMaximized())
91 return WORKSPACE_WINDOW_STATE_MAXIMIZED;
92 if (!window_overlaps_launcher &&
93 ((*i)->bounds().Intersects(shelf_bounds))) {
94 window_overlaps_launcher = true;
99 return (window_overlaps_launcher || IsDockedAreaVisible(shelf_)) ?
100 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF :
101 WORKSPACE_WINDOW_STATE_DEFAULT;
104 void WorkspaceController::SetShelf(ShelfLayoutManager* shelf) {
106 layout_manager_->SetShelf(shelf);
109 void WorkspaceController::DoInitialAnimation() {
112 viewport_->layer()->SetOpacity(0.0f);
113 SetTransformForScaleAnimation(
114 viewport_->layer(), LAYER_SCALE_ANIMATION_ABOVE);
116 // In order for pause to work we need to stop animations.
117 viewport_->layer()->GetAnimator()->StopAnimating();
120 ui::ScopedLayerAnimationSettings settings(
121 viewport_->layer()->GetAnimator());
123 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
124 viewport_->layer()->GetAnimator()->SchedulePauseForProperties(
125 base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS),
126 ui::LayerAnimationElement::TRANSFORM |
127 ui::LayerAnimationElement::OPACITY |
128 ui::LayerAnimationElement::BRIGHTNESS |
129 ui::LayerAnimationElement::VISIBILITY);
130 settings.SetTweenType(gfx::Tween::EASE_OUT);
131 settings.SetTransitionDuration(
132 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS));
133 viewport_->layer()->SetTransform(gfx::Transform());
134 viewport_->layer()->SetOpacity(1.0f);
138 } // namespace internal