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 "ash/wm/workspace/workspace_layout_manager_delegate.h"
17 #include "ui/aura/client/aura_constants.h"
18 #include "ui/aura/window.h"
19 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/compositor/layer.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/wm/core/visibility_controller.h"
23 #include "ui/wm/core/window_animations.h"
24 #include "ui/wm/public/activation_client.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_
, ::wm::ANIMATE_NONE
);
49 viewport_
->SetLayoutManager(layout_manager_
);
50 viewport_
->AddPreTargetHandler(event_handler_
.get());
53 WorkspaceController::~WorkspaceController() {
54 viewport_
->SetLayoutManager(NULL
);
55 viewport_
->RemovePreTargetHandler(event_handler_
.get());
58 WorkspaceWindowState
WorkspaceController::GetWindowState() const {
60 return WORKSPACE_WINDOW_STATE_DEFAULT
;
61 const aura::Window
* topmost_fullscreen_window
= GetRootWindowController(
62 viewport_
->GetRootWindow())->GetWindowForFullscreenMode();
63 if (topmost_fullscreen_window
&&
64 !wm::GetWindowState(topmost_fullscreen_window
)->ignored_by_shelf()) {
65 return WORKSPACE_WINDOW_STATE_FULL_SCREEN
;
68 // These are the container ids of containers which may contain windows that
69 // may overlap the launcher shelf and affect its transparency.
70 const int kWindowContainerIds
[] = {kShellWindowId_DefaultContainer
,
71 kShellWindowId_DockedContainer
, };
72 const gfx::Rect
shelf_bounds(shelf_
->GetIdealBounds());
73 bool window_overlaps_launcher
= false;
74 for (size_t idx
= 0; idx
< arraysize(kWindowContainerIds
); idx
++) {
75 const aura::Window
* container
= Shell::GetContainer(
76 viewport_
->GetRootWindow(), kWindowContainerIds
[idx
]);
77 const aura::Window::Windows
& windows(container
->children());
78 for (aura::Window::Windows::const_iterator i
= windows
.begin();
79 i
!= windows
.end(); ++i
) {
80 wm::WindowState
* window_state
= wm::GetWindowState(*i
);
81 if (window_state
->ignored_by_shelf())
83 ui::Layer
* layer
= (*i
)->layer();
84 if (!layer
->GetTargetVisibility())
86 if (window_state
->IsMaximized())
87 return WORKSPACE_WINDOW_STATE_MAXIMIZED
;
88 if (!window_overlaps_launcher
&&
89 ((*i
)->bounds().Intersects(shelf_bounds
))) {
90 window_overlaps_launcher
= true;
95 return (window_overlaps_launcher
|| IsDockedAreaVisible(shelf_
)) ?
96 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF
:
97 WORKSPACE_WINDOW_STATE_DEFAULT
;
100 void WorkspaceController::SetShelf(ShelfLayoutManager
* shelf
) {
102 layout_manager_
->SetShelf(shelf
);
105 void WorkspaceController::DoInitialAnimation() {
108 viewport_
->layer()->SetOpacity(0.0f
);
109 SetTransformForScaleAnimation(
110 viewport_
->layer(), LAYER_SCALE_ANIMATION_ABOVE
);
112 // In order for pause to work we need to stop animations.
113 viewport_
->layer()->GetAnimator()->StopAnimating();
116 ui::ScopedLayerAnimationSettings
settings(
117 viewport_
->layer()->GetAnimator());
119 settings
.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION
);
120 viewport_
->layer()->GetAnimator()->SchedulePauseForProperties(
121 base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS
),
122 ui::LayerAnimationElement::TRANSFORM
|
123 ui::LayerAnimationElement::OPACITY
|
124 ui::LayerAnimationElement::BRIGHTNESS
|
125 ui::LayerAnimationElement::VISIBILITY
);
126 settings
.SetTweenType(gfx::Tween::EASE_OUT
);
127 settings
.SetTransitionDuration(
128 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS
));
129 viewport_
->layer()->SetTransform(gfx::Transform());
130 viewport_
->layer()->SetOpacity(1.0f
);
134 void WorkspaceController::SetMaximizeBackdropDelegate(
135 scoped_ptr
<WorkspaceLayoutManagerDelegate
> delegate
) {
136 layout_manager_
->SetMaximizeBackdropDelegate(delegate
.Pass());