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/property_util.h"
12 #include "ash/wm/window_animations.h"
13 #include "ash/wm/window_properties.h"
14 #include "ash/wm/window_util.h"
15 #include "ash/wm/workspace/workspace_event_handler.h"
16 #include "ash/wm/workspace/workspace_layout_manager.h"
17 #include "ui/aura/client/activation_client.h"
18 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/root_window.h"
20 #include "ui/aura/window.h"
21 #include "ui/compositor/layer.h"
22 #include "ui/compositor/scoped_layer_animation_settings.h"
23 #include "ui/views/corewm/visibility_controller.h"
24 #include "ui/views/corewm/window_animations.h"
30 // Amount of time to pause before animating anything. Only used during initial
31 // animation (when logging in).
32 const int kInitialPauseTimeMS
= 750;
36 WorkspaceController::WorkspaceController(aura::Window
* viewport
)
37 : viewport_(viewport
),
39 event_handler_(new WorkspaceEventHandler(viewport_
)) {
40 SetWindowVisibilityAnimationTransition(
41 viewport_
, views::corewm::ANIMATE_NONE
);
43 // The layout-manager cannot be created in the initializer list since it
44 // depends on the window to have been initialized.
45 layout_manager_
= new WorkspaceLayoutManager(viewport_
);
46 viewport_
->SetLayoutManager(layout_manager_
);
51 WorkspaceController::~WorkspaceController() {
52 viewport_
->SetLayoutManager(NULL
);
53 viewport_
->SetEventFilter(NULL
);
54 viewport_
->RemovePreTargetHandler(event_handler_
.get());
55 viewport_
->RemovePostTargetHandler(event_handler_
.get());
58 WorkspaceWindowState
WorkspaceController::GetWindowState() const {
60 return WORKSPACE_WINDOW_STATE_DEFAULT
;
62 const gfx::Rect
shelf_bounds(shelf_
->GetIdealBounds());
63 const aura::Window::Windows
& windows(viewport_
->children());
64 bool window_overlaps_launcher
= false;
65 bool has_maximized_window
= false;
66 for (aura::Window::Windows::const_iterator i
= windows
.begin();
67 i
!= windows
.end(); ++i
) {
68 if (GetIgnoredByShelf(*i
))
70 ui::Layer
* layer
= (*i
)->layer();
71 if (!layer
->GetTargetVisibility() || layer
->GetTargetOpacity() == 0.0f
)
73 if (wm::IsWindowMaximized(*i
)) {
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 (wm::IsWindowFullscreen(*i
)) {
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(ui::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