Permission message rules: Each rule must have >= 1 required permissions
[chromium-blink-merge.git] / ash / wm / session_state_animator.h
blobb293b470afbfc221941b31ff010a257bb923f389
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/callback.h"
11 #include "base/time/time.h"
13 namespace ash {
15 // Displays onscreen animations for session state changes (lock/unlock, sign
16 // out, shut down).
17 class ASH_EXPORT SessionStateAnimator {
18 public:
19 // Animations that can be applied to groups of containers.
20 enum AnimationType {
21 ANIMATION_PARTIAL_CLOSE = 0,
22 ANIMATION_UNDO_PARTIAL_CLOSE,
23 ANIMATION_FULL_CLOSE,
24 ANIMATION_FADE_IN,
25 ANIMATION_FADE_OUT,
26 ANIMATION_HIDE_IMMEDIATELY,
27 ANIMATION_RESTORE,
28 // Animations that raise/lower windows to/from area "in front" of the
29 // screen.
30 ANIMATION_LIFT,
31 ANIMATION_UNDO_LIFT,
32 ANIMATION_DROP,
33 // Animations that raise/lower windows from/to area "behind" of the screen.
34 ANIMATION_RAISE_TO_SCREEN,
35 ANIMATION_LOWER_BELOW_SCREEN,
36 ANIMATION_PARTIAL_FADE_IN,
37 ANIMATION_UNDO_PARTIAL_FADE_IN,
38 ANIMATION_FULL_FADE_IN,
39 ANIMATION_GRAYSCALE_BRIGHTNESS,
40 ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS,
43 // Constants for determining animation speed.
44 enum AnimationSpeed {
45 // Immediately change state.
46 ANIMATION_SPEED_IMMEDIATE = 0,
47 // Speed for animations associated with user action that can be undone.
48 // Used for pre-lock and pre-shutdown animations.
49 ANIMATION_SPEED_UNDOABLE,
50 // Speed for animation that reverts undoable action. Used for aborting
51 // pre-lock and pre-shutdown animations.
52 ANIMATION_SPEED_REVERT,
53 // Speed for user action that can not be undone, Used for lock and shutdown
54 // animations requested via menus/shortcuts and for animating remaining
55 // parts of partial lock/shutdown animations.
56 ANIMATION_SPEED_FAST,
57 // Speed for lock screen appearance in "old" animation set.
58 ANIMATION_SPEED_SHOW_LOCK_SCREEN,
59 // Speed for workspace-like animations in "new" animation set.
60 ANIMATION_SPEED_MOVE_WINDOWS,
61 // Speed for undoing workspace-like animations in "new" animation set.
62 ANIMATION_SPEED_UNDO_MOVE_WINDOWS,
63 // Speed for shutdown in "new" animation set.
64 ANIMATION_SPEED_SHUTDOWN,
65 // Speed for reverting shutdown in "new" animation set.
66 ANIMATION_SPEED_REVERT_SHUTDOWN,
69 // Specific containers or groups of containers that can be animated.
70 enum Container {
71 DESKTOP_BACKGROUND = 1 << 0,
72 LAUNCHER = 1 << 1,
74 // All user session related containers including system background but
75 // not including desktop background (wallpaper).
76 NON_LOCK_SCREEN_CONTAINERS = 1 << 2,
78 // Desktop wallpaper is moved to this layer when screen is locked.
79 // This layer is excluded from lock animation so that wallpaper stays as is,
80 // user session windows are hidden and lock UI is shown on top of it.
81 // This layer is included in shutdown animation.
82 LOCK_SCREEN_BACKGROUND = 1 << 3,
84 // Lock screen and lock screen modal containers.
85 LOCK_SCREEN_CONTAINERS = 1 << 4,
87 // Multiple system layers belong here like status, menu, tooltip
88 // and overlay layers.
89 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5,
91 // The primary root window.
92 ROOT_CONTAINER = 1 << 6,
95 // A bitfield mask including LOCK_SCREEN_WALLPAPER,
96 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS.
97 static const int kAllLockScreenContainersMask;
99 // A bitfield mask of all containers except the ROOT_CONTAINER.
100 static const int kAllNonRootContainersMask;
102 // The AnimationSequence groups together multiple animations and invokes a
103 // callback once all contained animations are completed successfully.
104 // Subclasses of AnimationSequence should call one of OnAnimationCompleted or
105 // OnAnimationAborted once and behaviour is undefined if called multiple
106 // times.
107 // AnimationSequences will destroy themselves once EndSquence and one of
108 // OnAnimationCompleted or OnAnimationAborted has been called.
110 // Typical usage:
111 // AnimationSequence* animation_sequence =
112 // session_state_animator->BeginAnimationSequence(some_callback);
113 // animation_sequence->StartAnimation(
114 // SessionStateAnimator::LAUNCHER,
115 // SessionStateAnimator::ANIMATION_FADE_IN,
116 // SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
117 // animation_sequence->StartAnimation(
118 // SessionStateAnimator::LAUNCHER,
119 // SessionStateAnimator::ANIMATION_FADE_IN,
120 // SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
121 // animation_sequence->EndSequence();
122 // // some_callback won't be called until here even if the animations
123 // // were completed before the EndSequence call.
125 class ASH_EXPORT AnimationSequence {
126 public:
127 virtual ~AnimationSequence();
129 // Apply animation |type| to all containers included in |container_mask|
130 // with specified |speed|.
131 virtual void StartAnimation(int container_mask,
132 AnimationType type,
133 AnimationSpeed speed) = 0;
135 // Ends the animation sequence and enables the callback to be invoked
136 // when the animation sequence has completed. No more animations should be
137 // started after EndSequence is called because the AnimationSequenceObserver
138 // may have destroyed itself.
139 // NOTE: Clients of AnimationSequence should not access it after EndSequence
140 // has been called.
141 virtual void EndSequence();
143 protected:
144 // AnimationSequence should not be instantiated directly, only through
145 // subclasses.
146 explicit AnimationSequence(base::Closure callback);
148 // Subclasses should call this when the contained animations completed
149 // successfully.
150 // NOTE: This should NOT be accessed after OnAnimationCompleted has been
151 // called.
152 virtual void OnAnimationCompleted();
154 // Subclasses should call this when the contained animations did NOT
155 // complete successfully.
156 // NOTE: This should NOT be accessed after OnAnimationAborted has been
157 // called.
158 virtual void OnAnimationAborted();
160 private:
161 // Destroys this and calls the callback if the contained animations
162 // completed successfully.
163 void CleanupIfSequenceCompleted();
165 // Tracks whether the sequence has ended.
166 bool sequence_ended_;
168 // Track whether the contained animations have completed or not, both
169 // successfully and unsuccessfully.
170 bool animation_completed_;
172 // Flag to specify whether the callback should be invoked once the sequence
173 // has completed.
174 bool invoke_callback_;
176 // Callback to be called.
177 base::Closure callback_;
179 DISALLOW_COPY_AND_ASSIGN(AnimationSequence);
182 SessionStateAnimator();
183 virtual ~SessionStateAnimator();
185 // Reports animation duration for |speed|.
186 virtual base::TimeDelta GetDuration(AnimationSpeed speed);
188 // Apply animation |type| to all containers included in |container_mask| with
189 // specified |speed|.
190 virtual void StartAnimation(int container_mask,
191 AnimationType type,
192 AnimationSpeed speed) = 0;
194 // Apply animation |type| to all containers included in |container_mask| with
195 // specified |speed| and call a |callback| at the end of the animation, if it
196 // is not null.
197 virtual void StartAnimationWithCallback(
198 int container_mask,
199 AnimationType type,
200 AnimationSpeed speed,
201 base::Closure callback) = 0;
203 // Begins an animation sequence. Use this when you need to be notified when
204 // a group of animations are completed. See AnimationSequence documentation
205 // for more details.
206 virtual AnimationSequence* BeginAnimationSequence(
207 base::Closure callback) = 0;
209 // Retruns true if the background is hidden.
210 virtual bool IsBackgroundHidden() const = 0;
212 // Shows the background immediately.
213 virtual void ShowBackground() = 0;
215 // Hides the background immediately.
216 virtual void HideBackground() = 0;
218 private:
219 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator);
222 } // namespace ash
224 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_