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 "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/timer/timer.h"
12 #include "ui/aura/window.h"
13 #include "ui/compositor/layer_animation_observer.h"
26 // Displays onscreen animations for session state changes (lock/unlock, sign
28 class ASH_EXPORT SessionStateAnimator
{
30 // Animations that can be applied to groups of containers.
32 ANIMATION_PARTIAL_CLOSE
= 0,
33 ANIMATION_UNDO_PARTIAL_CLOSE
,
37 ANIMATION_HIDE_IMMEDIATELY
,
39 // Animations that raise/lower windows to/from area "in front" of the
44 // Animations that raise/lower windows from/to area "behind" of the screen.
45 ANIMATION_RAISE_TO_SCREEN
,
46 ANIMATION_LOWER_BELOW_SCREEN
,
47 ANIMATION_PARTIAL_FADE_IN
,
48 ANIMATION_UNDO_PARTIAL_FADE_IN
,
49 ANIMATION_FULL_FADE_IN
,
50 ANIMATION_GRAYSCALE_BRIGHTNESS
,
51 ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS
,
54 // Constants for determining animation speed.
56 // Immediately change state.
57 ANIMATION_SPEED_IMMEDIATE
= 0,
58 // Speed for animations associated with user action that can be undone.
59 // Used for pre-lock and pre-shutdown animations.
60 ANIMATION_SPEED_UNDOABLE
,
61 // Speed for animation that reverts undoable action. Used for aborting
62 // pre-lock and pre-shutdown animations.
63 ANIMATION_SPEED_REVERT
,
64 // Speed for user action that can not be undone, Used for lock and shutdown
65 // animations requested via menus/shortcuts and for animating remaining
66 // parts of partial lock/shutdown animations.
68 // Speed for lock screen appearance in "old" animation set.
69 ANIMATION_SPEED_SHOW_LOCK_SCREEN
,
70 // Speed for workspace-like animations in "new" animation set.
71 ANIMATION_SPEED_MOVE_WINDOWS
,
72 // Speed for undoing workspace-like animations in "new" animation set.
73 ANIMATION_SPEED_UNDO_MOVE_WINDOWS
,
74 // Speed for shutdown in "new" animation set.
75 ANIMATION_SPEED_SHUTDOWN
,
76 // Speed for reverting shutdown in "new" animation set.
77 ANIMATION_SPEED_REVERT_SHUTDOWN
,
80 // Specific containers or groups of containers that can be animated.
82 DESKTOP_BACKGROUND
= 1 << 0,
85 // All user session related containers including system background but
86 // not including desktop background (wallpaper).
87 NON_LOCK_SCREEN_CONTAINERS
= 1 << 2,
89 // Desktop wallpaper is moved to this layer when screen is locked.
90 // This layer is excluded from lock animation so that wallpaper stays as is,
91 // user session windows are hidden and lock UI is shown on top of it.
92 // This layer is included in shutdown animation.
93 LOCK_SCREEN_BACKGROUND
= 1 << 3,
95 // Lock screen and lock screen modal containers.
96 LOCK_SCREEN_CONTAINERS
= 1 << 4,
98 // Multiple system layers belong here like status, menu, tooltip
99 // and overlay layers.
100 LOCK_SCREEN_RELATED_CONTAINERS
= 1 << 5,
103 // Helper class used by tests to access internal state.
104 class ASH_EXPORT TestApi
{
106 explicit TestApi(SessionStateAnimator
* animator
)
107 : animator_(animator
) {}
109 // Returns true if containers of a given |container_mask|
110 // were last animated with |type| (probably; the analysis is fairly ad-hoc).
111 // |container_mask| is a bitfield of a Container.
112 bool ContainersAreAnimated(int container_mask
, AnimationType type
) const;
114 // Returns true if root window was last animated with |type| (probably;
115 // the analysis is fairly ad-hoc).
116 bool RootWindowIsAnimated(AnimationType type
) const;
119 SessionStateAnimator
* animator_
; // not owned
121 DISALLOW_COPY_AND_ASSIGN(TestApi
);
124 // A bitfield mask including LOCK_SCREEN_WALLPAPER,
125 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS.
126 const static int kAllLockScreenContainersMask
;
128 // A bitfield mask of all containers.
129 const static int kAllContainersMask
;
131 SessionStateAnimator();
132 virtual ~SessionStateAnimator();
134 // Reports animation duration for |speed|.
135 static base::TimeDelta
GetDuration(AnimationSpeed speed
);
137 // Fills |containers| with the containers included in |container_mask|.
138 static void GetContainers(int container_mask
,
139 aura::Window::Windows
* containers
);
141 // Apply animation |type| to all containers included in |container_mask| with
142 // specified |speed|.
143 void StartAnimation(int container_mask
,
145 AnimationSpeed speed
);
147 // Apply animation |type| to all containers included in |container_mask| with
148 // specified |speed| and call a |callback| at the end of the animation, if it
150 void StartAnimationWithCallback(int container_mask
,
152 AnimationSpeed speed
,
153 base::Callback
<void(void)>& callback
);
155 // Apply animation |type| to all containers included in |container_mask| with
156 // specified |speed| and add |observer| to all animations.
157 void StartAnimationWithObserver(int container_mask
,
159 AnimationSpeed speed
,
160 ui::LayerAnimationObserver
* observer
);
162 // Applies animation |type| whith specified |speed| to the root container.
163 void StartGlobalAnimation(AnimationType type
,
164 AnimationSpeed speed
);
166 // Apply animation |type| to window |window| with |speed| and add |observer|
167 // if it is not NULL to the last animation sequence.
168 void RunAnimationForWindow(aura::Window
* window
,
170 AnimationSpeed speed
,
171 ui::LayerAnimationObserver
* observer
);
173 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator
);
178 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_