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/shelf/shelf_layout_manager.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/base_layout_manager.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;
35 WorkspaceController::WorkspaceController(aura::Window
* viewport
)
36 : viewport_(viewport
),
38 event_handler_(new WorkspaceEventHandler(viewport_
)) {
39 SetWindowVisibilityAnimationTransition(
40 viewport_
, views::corewm::ANIMATE_NONE
);
42 // The layout-manager cannot be created in the initializer list since it
43 // depends on the window to have been initialized.
44 layout_manager_
= new WorkspaceLayoutManager(viewport_
);
45 viewport_
->SetLayoutManager(layout_manager_
);
50 WorkspaceController::~WorkspaceController() {
51 viewport_
->SetLayoutManager(NULL
);
52 viewport_
->SetEventFilter(NULL
);
53 viewport_
->RemovePreTargetHandler(event_handler_
.get());
54 viewport_
->RemovePostTargetHandler(event_handler_
.get());
57 WorkspaceWindowState
WorkspaceController::GetWindowState() const {
59 return WORKSPACE_WINDOW_STATE_DEFAULT
;
61 const gfx::Rect
shelf_bounds(shelf_
->GetIdealBounds());
62 const aura::Window::Windows
& windows(viewport_
->children());
63 bool window_overlaps_launcher
= false;
64 bool has_maximized_window
= false;
65 for (aura::Window::Windows::const_iterator i
= windows
.begin();
66 i
!= windows
.end(); ++i
) {
67 wm::WindowState
* window_state
= wm::GetWindowState(*i
);
68 if (window_state
->ignored_by_shelf())
70 ui::Layer
* layer
= (*i
)->layer();
71 if (!layer
->GetTargetVisibility() || layer
->GetTargetOpacity() == 0.0f
)
73 if (window_state
->IsMaximized()) {
74 // An untracked window may still be fullscreen so we keep iterating when
75 // we hit a maximized window.
76 has_maximized_window
= true;
77 } else if (window_state
->IsFullscreen()) {
78 return WORKSPACE_WINDOW_STATE_FULL_SCREEN
;
80 if (!window_overlaps_launcher
&& (*i
)->bounds().Intersects(shelf_bounds
))
81 window_overlaps_launcher
= true;
83 if (has_maximized_window
)
84 return WORKSPACE_WINDOW_STATE_MAXIMIZED
;
86 return window_overlaps_launcher
?
87 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF
:
88 WORKSPACE_WINDOW_STATE_DEFAULT
;
91 void WorkspaceController::SetShelf(ShelfLayoutManager
* shelf
) {
93 layout_manager_
->SetShelf(shelf
);
96 void WorkspaceController::DoInitialAnimation() {
99 viewport_
->layer()->SetOpacity(0.0f
);
100 SetTransformForScaleAnimation(
101 viewport_
->layer(), LAYER_SCALE_ANIMATION_ABOVE
);
103 // In order for pause to work we need to stop animations.
104 viewport_
->layer()->GetAnimator()->StopAnimating();
107 ui::ScopedLayerAnimationSettings
settings(
108 viewport_
->layer()->GetAnimator());
110 settings
.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION
);
111 viewport_
->layer()->GetAnimator()->SchedulePauseForProperties(
112 base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS
),
113 ui::LayerAnimationElement::TRANSFORM
,
114 ui::LayerAnimationElement::OPACITY
,
115 ui::LayerAnimationElement::BRIGHTNESS
,
116 ui::LayerAnimationElement::VISIBILITY
,
119 settings
.SetTweenType(gfx::Tween::EASE_OUT
);
120 settings
.SetTransitionDuration(
121 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS
));
122 viewport_
->layer()->SetTransform(gfx::Transform());
123 viewport_
->layer()->SetOpacity(1.0f
);
127 } // namespace internal