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. 4 5 #ifndef ASH_WM_SESSION_STATE_ANIMATOR_H_ 6 #define ASH_WM_SESSION_STATE_ANIMATOR_H_ 7 8 #include "ash/ash_export.h" 9 #include "base/callback.h" 10 #include "base/macros.h" 11 #include "base/time/time.h" 12 13 namespace ash { 14 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, 41 }; 42 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, 67 }; 68 69 // Specific containers or groups of containers that can be animated. 70 enum Container { 71 WALLPAPER = 1 << 0, 72 SHELF = 1 << 1, 73 74 // All user session related containers including the system wallpaper but 75 // not including the user's wallpaper. 76 NON_LOCK_SCREEN_CONTAINERS = 1 << 2, 77 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_WALLPAPER = 1 << 3, 83 84 // Lock screen and lock screen modal containers. 85 LOCK_SCREEN_CONTAINERS = 1 << 4, 86 87 // Multiple system layers belong here like status, menu, tooltip 88 // and overlay layers. 89 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5, 90 91 // The primary root window. 92 ROOT_CONTAINER = 1 << 6, 93 }; 94 95 // A bitfield mask including LOCK_SCREEN_WALLPAPER, 96 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS. 97 static const int kAllLockScreenContainersMask; 98 99 // A bitfield mask of all containers except the ROOT_CONTAINER. 100 static const int kAllNonRootContainersMask; 101 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. 109 // 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. 124 // 125 class ASH_EXPORT AnimationSequence { 126 public: 127 virtual ~AnimationSequence(); 128 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; 134 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(); 142 143 protected: 144 // AnimationSequence should not be instantiated directly, only through 145 // subclasses. 146 explicit AnimationSequence(base::OnceClosure callback); 147 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(); 153 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(); 159 160 private: 161 // Destroys this and calls the callback if the contained animations 162 // completed successfully. 163 void CleanupIfSequenceCompleted(); 164 165 // Tracks whether the sequence has ended. 166 bool sequence_ended_; 167 168 // Track whether the contained animations have completed or not, both 169 // successfully and unsuccessfully. 170 bool animation_completed_; 171 172 // Flag to specify whether the callback should be invoked once the sequence 173 // has completed. 174 bool invoke_callback_; 175 176 // Callback to be called. 177 base::OnceClosure callback_; 178 179 DISALLOW_COPY_AND_ASSIGN(AnimationSequence); 180 }; 181 182 SessionStateAnimator(); 183 virtual ~SessionStateAnimator(); 184 185 // Reports animation duration for |speed|. 186 virtual base::TimeDelta GetDuration(AnimationSpeed speed); 187 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; 193 194 // Apply animation |type| to all containers included in |container_mask| with 195 // specified |speed| and call a |callback| once at the end of the animations, 196 // if it is not null. 197 virtual void StartAnimationWithCallback(int container_mask, 198 AnimationType type, 199 AnimationSpeed speed, 200 base::OnceClosure callback) = 0; 201 202 // Begins an animation sequence. Use this when you need to be notified when 203 // a group of animations are completed. See AnimationSequence documentation 204 // for more details. 205 virtual AnimationSequence* BeginAnimationSequence( 206 base::OnceClosure callback) = 0; 207 208 // Retruns true if the wallpaper is hidden. 209 virtual bool IsWallpaperHidden() const = 0; 210 211 // Shows the wallpaper immediately. 212 virtual void ShowWallpaper() = 0; 213 214 // Hides the wallpaper immediately. 215 virtual void HideWallpaper() = 0; 216 217 private: 218 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator); 219 }; 220 221 } // namespace ash 222 223 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_ 224