session_state_animator.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. #ifndef ASH_WM_SESSION_STATE_ANIMATOR_H_
  5. #define ASH_WM_SESSION_STATE_ANIMATOR_H_
  6. #include "ash/ash_export.h"
  7. #include "base/callback.h"
  8. #include "base/time/time.h"
  9. namespace ash {
  10. // Displays onscreen animations for session state changes (lock/unlock, sign
  11. // out, shut down).
  12. class ASH_EXPORT SessionStateAnimator {
  13. public:
  14. // Animations that can be applied to groups of containers.
  15. enum AnimationType {
  16. ANIMATION_FADE_IN,
  17. ANIMATION_FADE_OUT,
  18. ANIMATION_HIDE_IMMEDIATELY,
  19. // Animations that raise/lower windows to/from area "in front" of the
  20. // screen.
  21. ANIMATION_LIFT,
  22. ANIMATION_UNDO_LIFT,
  23. ANIMATION_DROP,
  24. // Animations that raise/lower windows from/to area "behind" of the screen.
  25. ANIMATION_RAISE_TO_SCREEN,
  26. ANIMATION_GRAYSCALE_BRIGHTNESS,
  27. ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS,
  28. // Pseudo animation type to copy layer.
  29. ANIMATION_COPY_LAYER,
  30. };
  31. // Constants for determining animation speed.
  32. enum AnimationSpeed {
  33. // Immediately change state.
  34. ANIMATION_SPEED_IMMEDIATE = 0,
  35. // Speed for animations associated with user action that can be undone.
  36. // Used for pre-lock and pre-shutdown animations.
  37. ANIMATION_SPEED_UNDOABLE,
  38. // Speed for workspace-like animations in "new" animation set.
  39. ANIMATION_SPEED_MOVE_WINDOWS,
  40. // Speed for undoing workspace-like animations in "new" animation set.
  41. ANIMATION_SPEED_UNDO_MOVE_WINDOWS,
  42. // Speed for shutdown in "new" animation set.
  43. ANIMATION_SPEED_SHUTDOWN,
  44. // Speed for reverting shutdown in "new" animation set.
  45. ANIMATION_SPEED_REVERT_SHUTDOWN,
  46. };
  47. // Specific containers or groups of containers that can be animated.
  48. enum Container {
  49. WALLPAPER = 1 << 0,
  50. SHELF = 1 << 1,
  51. // All user session related containers including the system wallpaper but
  52. // not including the user's wallpaper.
  53. NON_LOCK_SCREEN_CONTAINERS = 1 << 2,
  54. // Desktop wallpaper is moved to this layer when screen is locked.
  55. // This layer is excluded from lock animation so that wallpaper stays as is,
  56. // user session windows are hidden and lock UI is shown on top of it.
  57. // This layer is included in shutdown animation.
  58. LOCK_SCREEN_WALLPAPER = 1 << 3,
  59. // Lock screen and lock screen modal containers.
  60. LOCK_SCREEN_CONTAINERS = 1 << 4,
  61. // Multiple system layers belong here like status, menu, tooltip
  62. // and overlay layers.
  63. LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5,
  64. // The primary root window.
  65. ROOT_CONTAINER = 1 << 6,
  66. };
  67. using AnimationCallback = base::OnceCallback<void(bool)>;
  68. // A bitfield mask including LOCK_SCREEN_WALLPAPER,
  69. // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS.
  70. static const int kAllLockScreenContainersMask;
  71. // A bitfield mask of all containers except the ROOT_CONTAINER.
  72. static const int kAllNonRootContainersMask;
  73. // The AnimationSequence groups together multiple animations and invokes a
  74. // callback once all contained animations are completed successfully.
  75. // Subclasses of AnimationSequence should call one of OnAnimationCompleted or
  76. // OnAnimationAborted once and behaviour is undefined if called multiple
  77. // times.
  78. // AnimationSequences will destroy themselves once EndSquence and one of
  79. // OnAnimationCompleted or OnAnimationAborted has been called.
  80. //
  81. // Typical usage:
  82. // AnimationSequence* animation_sequence =
  83. // session_state_animator->BeginAnimationSequence(some_callback);
  84. // animation_sequence->StartAnimation(
  85. // SessionStateAnimator::LAUNCHER,
  86. // SessionStateAnimator::ANIMATION_FADE_IN,
  87. // SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
  88. // animation_sequence->StartAnimation(
  89. // SessionStateAnimator::LAUNCHER,
  90. // SessionStateAnimator::ANIMATION_FADE_IN,
  91. // SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
  92. // animation_sequence->EndSequence();
  93. // // some_callback won't be called until here even if the animations
  94. // // were completed before the EndSequence call.
  95. //
  96. class ASH_EXPORT AnimationSequence {
  97. public:
  98. AnimationSequence(const AnimationSequence&) = delete;
  99. AnimationSequence& operator=(const AnimationSequence&) = delete;
  100. virtual ~AnimationSequence();
  101. // Apply animation |type| to all containers included in |container_mask|
  102. // with specified |speed|.
  103. virtual void StartAnimation(int container_mask,
  104. AnimationType type,
  105. AnimationSpeed speed) = 0;
  106. // Ends the animation sequence and enables the callback to be invoked
  107. // when the animation sequence has completed. No more animations should be
  108. // started after EndSequence is called because the AnimationSequenceObserver
  109. // may have destroyed itself.
  110. // NOTE: Clients of AnimationSequence should not access it after EndSequence
  111. // has been called.
  112. virtual void EndSequence();
  113. protected:
  114. // AnimationSequence should not be instantiated directly, only through
  115. // subclasses.
  116. explicit AnimationSequence(AnimationCallback callback);
  117. // Subclasses should call this when the contained animations completed
  118. // successfully.
  119. // NOTE: This should NOT be accessed after OnAnimationCompleted has been
  120. // called.
  121. virtual void OnAnimationCompleted();
  122. // Subclasses should call this when the contained animations did NOT
  123. // complete successfully.
  124. // NOTE: This should NOT be accessed after OnAnimationAborted has been
  125. // called.
  126. virtual void OnAnimationAborted();
  127. private:
  128. // Destroys this and calls the callback if the contained animations
  129. // completed successfully.
  130. void CleanupIfSequenceCompleted();
  131. // Tracks whether the sequence has ended.
  132. bool sequence_ended_ = false;
  133. // Track whether the contained animations have completed or not, both
  134. // successfully and unsuccessfully.
  135. bool animation_finished_ = false;
  136. // Flag to specify whether the callback should be invoked once the sequence
  137. // has completed.
  138. bool animation_aborted_ = false;
  139. // Callback to be called when the aniamtion is finished or aborted.
  140. AnimationCallback callback_;
  141. };
  142. SessionStateAnimator();
  143. SessionStateAnimator(const SessionStateAnimator&) = delete;
  144. SessionStateAnimator& operator=(const SessionStateAnimator&) = delete;
  145. virtual ~SessionStateAnimator();
  146. // Reports animation duration for |speed|.
  147. virtual base::TimeDelta GetDuration(AnimationSpeed speed);
  148. // Apply animation |type| to all containers included in |container_mask| with
  149. // specified |speed|.
  150. virtual void StartAnimation(int container_mask,
  151. AnimationType type,
  152. AnimationSpeed speed) = 0;
  153. // Apply animation |type| to all containers included in |container_mask| with
  154. // specified |speed| and call a |callback| once at the end of the animations,
  155. // if it is not null.
  156. virtual void StartAnimationWithCallback(int container_mask,
  157. AnimationType type,
  158. AnimationSpeed speed,
  159. base::OnceClosure callback) = 0;
  160. // Begins an animation sequence. Use this when you need to be notified when
  161. // a group of animations are completed. See AnimationSequence documentation
  162. // for more details.
  163. virtual AnimationSequence* BeginAnimationSequence(
  164. AnimationCallback callback) = 0;
  165. // Returns true if the wallpaper is hidden.
  166. virtual bool IsWallpaperHidden() const = 0;
  167. // Shows the wallpaper immediately.
  168. virtual void ShowWallpaper() = 0;
  169. // Hides the wallpaper immediately.
  170. virtual void HideWallpaper() = 0;
  171. };
  172. } // namespace ash
  173. #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_