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 #ifndef ASH_WM_SESSION_STATE_ANIMATOR_H_
6 #define ASH_WM_SESSION_STATE_ANIMATOR_H_
8 #include "ash/ash_export.h"
9 #include "ash/wm/workspace/colored_window_controller.h"
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/timer/timer.h"
13 #include "ui/aura/window.h"
14 #include "ui/compositor/layer_animation_observer.h"
28 // Displays onscreen animations for session state changes (lock/unlock, sign
30 class ASH_EXPORT SessionStateAnimator
{
32 // Animations that can be applied to groups of containers.
34 ANIMATION_PARTIAL_CLOSE
= 0,
35 ANIMATION_UNDO_PARTIAL_CLOSE
,
39 ANIMATION_HIDE_IMMEDIATELY
,
41 // Animations that raise/lower windows to/from area "in front" of the
46 // Animations that raise/lower windows from/to area "behind" of the screen.
47 ANIMATION_RAISE_TO_SCREEN
,
48 ANIMATION_LOWER_BELOW_SCREEN
,
49 ANIMATION_PARTIAL_FADE_IN
,
50 ANIMATION_UNDO_PARTIAL_FADE_IN
,
51 ANIMATION_FULL_FADE_IN
,
52 ANIMATION_GRAYSCALE_BRIGHTNESS
,
53 ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS
,
56 // Constants for determining animation speed.
58 // Immediately change state.
59 ANIMATION_SPEED_IMMEDIATE
= 0,
60 // Speed for animations associated with user action that can be undone.
61 // Used for pre-lock and pre-shutdown animations.
62 ANIMATION_SPEED_UNDOABLE
,
63 // Speed for animation that reverts undoable action. Used for aborting
64 // pre-lock and pre-shutdown animations.
65 ANIMATION_SPEED_REVERT
,
66 // Speed for user action that can not be undone, Used for lock and shutdown
67 // animations requested via menus/shortcuts and for animating remaining
68 // parts of partial lock/shutdown animations.
70 // Speed for lock screen appearance in "old" animation set.
71 ANIMATION_SPEED_SHOW_LOCK_SCREEN
,
72 // Speed for workspace-like animations in "new" animation set.
73 ANIMATION_SPEED_MOVE_WINDOWS
,
74 // Speed for undoing workspace-like animations in "new" animation set.
75 ANIMATION_SPEED_UNDO_MOVE_WINDOWS
,
76 // Speed for shutdown in "new" animation set.
77 ANIMATION_SPEED_SHUTDOWN
,
78 // Speed for reverting shutdown in "new" animation set.
79 ANIMATION_SPEED_REVERT_SHUTDOWN
,
82 // Specific containers or groups of containers that can be animated.
84 DESKTOP_BACKGROUND
= 1 << 0,
87 // All user session related containers including system background but
88 // not including desktop background (wallpaper).
89 NON_LOCK_SCREEN_CONTAINERS
= 1 << 2,
91 // Desktop wallpaper is moved to this layer when screen is locked.
92 // This layer is excluded from lock animation so that wallpaper stays as is,
93 // user session windows are hidden and lock UI is shown on top of it.
94 // This layer is included in shutdown animation.
95 LOCK_SCREEN_BACKGROUND
= 1 << 3,
97 // Lock screen and lock screen modal containers.
98 LOCK_SCREEN_CONTAINERS
= 1 << 4,
100 // Multiple system layers belong here like status, menu, tooltip
101 // and overlay layers.
102 LOCK_SCREEN_RELATED_CONTAINERS
= 1 << 5,
105 // Helper class used by tests to access internal state.
106 class ASH_EXPORT TestApi
{
108 explicit TestApi(SessionStateAnimator
* animator
)
109 : animator_(animator
) {}
111 // Returns true if containers of a given |container_mask|
112 // were last animated with |type| (probably; the analysis is fairly ad-hoc).
113 // |container_mask| is a bitfield of a Container.
114 bool ContainersAreAnimated(int container_mask
, AnimationType type
) const;
116 // Returns true if root window was last animated with |type| (probably;
117 // the analysis is fairly ad-hoc).
118 bool RootWindowIsAnimated(AnimationType type
) const;
121 SessionStateAnimator
* animator_
; // not owned
123 DISALLOW_COPY_AND_ASSIGN(TestApi
);
126 // A bitfield mask including LOCK_SCREEN_WALLPAPER,
127 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS.
128 const static int kAllLockScreenContainersMask
;
130 // A bitfield mask of all containers.
131 const static int kAllContainersMask
;
133 SessionStateAnimator();
134 virtual ~SessionStateAnimator();
136 // Reports animation duration for |speed|.
137 static base::TimeDelta
GetDuration(AnimationSpeed speed
);
139 // Fills |containers| with the containers included in |container_mask|.
140 static void GetContainers(int container_mask
,
141 aura::Window::Windows
* containers
);
143 // Create |foreground_| layer if it doesn't already exist, but makes it
144 // completely transparent.
145 void CreateForeground();
146 // Destroy |foreground_| when it is not needed anymore.
147 void DropForeground();
149 // Apply animation |type| to all containers included in |container_mask| with
150 // specified |speed|.
151 void StartAnimation(int container_mask
,
153 AnimationSpeed speed
);
155 // Apply animation |type| to all containers included in |container_mask| with
156 // specified |speed| and call a |callback| at the end of the animation, if it
158 void StartAnimationWithCallback(int container_mask
,
160 AnimationSpeed speed
,
161 base::Callback
<void(void)>& callback
);
163 // Apply animation |type| to all containers included in |container_mask| with
164 // specified |speed| and add |observer| to all animations.
165 void StartAnimationWithObserver(int container_mask
,
167 AnimationSpeed speed
,
168 ui::LayerAnimationObserver
* observer
);
170 // Applies animation |type| whith specified |speed| to the root container.
171 void StartGlobalAnimation(AnimationType type
,
172 AnimationSpeed speed
);
174 // Apply animation |type| to window |window| with |speed| and add |observer|
175 // if it is not NULL to the last animation sequence.
176 void RunAnimationForWindow(aura::Window
* window
,
178 AnimationSpeed speed
,
179 ui::LayerAnimationObserver
* observer
);
181 // White foreground that is used during shutdown animation to "fade
182 // everything into white".
183 scoped_ptr
<ColoredWindowController
> foreground_
;
185 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator
);
188 } // namespace internal
191 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_