| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_WM_SESSION_STATE_ANIMATOR_H_ | 5 #ifndef ASH_WM_SESSION_STATE_ANIMATOR_H_ |
| 6 #define ASH_WM_SESSION_STATE_ANIMATOR_H_ | 6 #define ASH_WM_SESSION_STATE_ANIMATOR_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/callback.h" |
| 11 #include "base/timer/timer.h" | 11 #include "base/time/time.h" |
| 12 #include "ui/aura/window.h" | |
| 13 #include "ui/compositor/layer_animation_observer.h" | |
| 14 | |
| 15 namespace gfx { | |
| 16 class Rect; | |
| 17 class Size; | |
| 18 } | |
| 19 | |
| 20 namespace ui { | |
| 21 class Layer; | |
| 22 } | |
| 23 | 12 |
| 24 namespace ash { | 13 namespace ash { |
| 25 | 14 |
| 26 // Displays onscreen animations for session state changes (lock/unlock, sign | 15 // Displays onscreen animations for session state changes (lock/unlock, sign |
| 27 // out, shut down). | 16 // out, shut down). |
| 28 class ASH_EXPORT SessionStateAnimator { | 17 class ASH_EXPORT SessionStateAnimator { |
| 29 public: | 18 public: |
| 30 // Animations that can be applied to groups of containers. | 19 // Animations that can be applied to groups of containers. |
| 31 enum AnimationType { | 20 enum AnimationType { |
| 32 ANIMATION_PARTIAL_CLOSE = 0, | 21 ANIMATION_PARTIAL_CLOSE = 0, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // user session windows are hidden and lock UI is shown on top of it. | 80 // user session windows are hidden and lock UI is shown on top of it. |
| 92 // This layer is included in shutdown animation. | 81 // This layer is included in shutdown animation. |
| 93 LOCK_SCREEN_BACKGROUND = 1 << 3, | 82 LOCK_SCREEN_BACKGROUND = 1 << 3, |
| 94 | 83 |
| 95 // Lock screen and lock screen modal containers. | 84 // Lock screen and lock screen modal containers. |
| 96 LOCK_SCREEN_CONTAINERS = 1 << 4, | 85 LOCK_SCREEN_CONTAINERS = 1 << 4, |
| 97 | 86 |
| 98 // Multiple system layers belong here like status, menu, tooltip | 87 // Multiple system layers belong here like status, menu, tooltip |
| 99 // and overlay layers. | 88 // and overlay layers. |
| 100 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5, | 89 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5, |
| 101 }; | |
| 102 | 90 |
| 103 // Helper class used by tests to access internal state. | 91 // The primary root window. |
| 104 class ASH_EXPORT TestApi { | 92 ROOT_CONTAINER = 1 << 6, |
| 105 public: | |
| 106 explicit TestApi(SessionStateAnimator* animator) | |
| 107 : animator_(animator) {} | |
| 108 | |
| 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; | |
| 113 | |
| 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; | |
| 117 | |
| 118 private: | |
| 119 SessionStateAnimator* animator_; // not owned | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
| 122 }; | 93 }; |
| 123 | 94 |
| 124 // A bitfield mask including LOCK_SCREEN_WALLPAPER, | 95 // A bitfield mask including LOCK_SCREEN_WALLPAPER, |
| 125 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS. | 96 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS. |
| 126 const static int kAllLockScreenContainersMask; | 97 static const int kAllLockScreenContainersMask; |
| 127 | 98 |
| 128 // A bitfield mask of all containers. | 99 // A bitfield mask of all containers except the ROOT_CONTAINER. |
| 129 const static int kAllContainersMask; | 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::Closure 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::Closure callback_; |
| 178 |
| 179 DISALLOW_COPY_AND_ASSIGN(AnimationSequence); |
| 180 }; |
| 130 | 181 |
| 131 SessionStateAnimator(); | 182 SessionStateAnimator(); |
| 132 virtual ~SessionStateAnimator(); | 183 virtual ~SessionStateAnimator(); |
| 133 | 184 |
| 134 // Reports animation duration for |speed|. | 185 // Reports animation duration for |speed|. |
| 135 static base::TimeDelta GetDuration(AnimationSpeed speed); | 186 virtual base::TimeDelta GetDuration(AnimationSpeed speed); |
| 136 | |
| 137 // Fills |containers| with the containers included in |container_mask|. | |
| 138 static void GetContainers(int container_mask, | |
| 139 aura::Window::Windows* containers); | |
| 140 | 187 |
| 141 // Apply animation |type| to all containers included in |container_mask| with | 188 // Apply animation |type| to all containers included in |container_mask| with |
| 142 // specified |speed|. | 189 // specified |speed|. |
| 143 void StartAnimation(int container_mask, | 190 virtual void StartAnimation(int container_mask, |
| 144 AnimationType type, | 191 AnimationType type, |
| 145 AnimationSpeed speed); | 192 AnimationSpeed speed) = 0; |
| 146 | 193 |
| 147 // Apply animation |type| to all containers included in |container_mask| with | 194 // 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 | 195 // specified |speed| and call a |callback| at the end of the animation, if it |
| 149 // is not null. | 196 // is not null. |
| 150 void StartAnimationWithCallback(int container_mask, | 197 virtual void StartAnimationWithCallback( |
| 151 AnimationType type, | 198 int container_mask, |
| 152 AnimationSpeed speed, | 199 AnimationType type, |
| 153 base::Callback<void(void)>& callback); | 200 AnimationSpeed speed, |
| 201 base::Closure callback) = 0; |
| 154 | 202 |
| 155 // Apply animation |type| to all containers included in |container_mask| with | 203 // Begins an animation sequence. Use this when you need to be notified when |
| 156 // specified |speed| and add |observer| to all animations. | 204 // a group of animations are completed. See AnimationSequence documentation |
| 157 void StartAnimationWithObserver(int container_mask, | 205 // for more details. |
| 158 AnimationType type, | 206 virtual AnimationSequence* BeginAnimationSequence( |
| 159 AnimationSpeed speed, | 207 base::Closure callback) = 0; |
| 160 ui::LayerAnimationObserver* observer); | |
| 161 | 208 |
| 162 // Applies animation |type| whith specified |speed| to the root container. | 209 // Retruns true if the background is hidden. |
| 163 void StartGlobalAnimation(AnimationType type, | 210 virtual bool IsBackgroundHidden() const = 0; |
| 164 AnimationSpeed speed); | |
| 165 | 211 |
| 166 // Apply animation |type| to window |window| with |speed| and add |observer| | 212 // Shows the background immediately. |
| 167 // if it is not NULL to the last animation sequence. | 213 virtual void ShowBackground() = 0; |
| 168 void RunAnimationForWindow(aura::Window* window, | |
| 169 AnimationType type, | |
| 170 AnimationSpeed speed, | |
| 171 ui::LayerAnimationObserver* observer); | |
| 172 | 214 |
| 215 // Hides the background immediately. |
| 216 virtual void HideBackground() = 0; |
| 217 |
| 218 private: |
| 173 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator); | 219 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator); |
| 174 }; | 220 }; |
| 175 | 221 |
| 176 } // namespace ash | 222 } // namespace ash |
| 177 | 223 |
| 178 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_ | 224 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_ |
| OLD | NEW |