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/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" 14 15 namespace gfx { 16 class Rect; 17 class Size; 18 } 19 20 namespace ui { 21 class Layer; 22 } 23 24 namespace ash { 25 namespace internal { 26 27 // Displays onscreen animations for session state changes (lock/unlock, sign 28 // out, shut down). 29 class ASH_EXPORT SessionStateAnimator { 30 public: 31 // Animations that can be applied to groups of containers. 32 enum AnimationType { 33 ANIMATION_PARTIAL_CLOSE = 0, 34 ANIMATION_UNDO_PARTIAL_CLOSE, 35 ANIMATION_FULL_CLOSE, 36 ANIMATION_FADE_IN, 37 ANIMATION_FADE_OUT, 38 ANIMATION_HIDE_IMMEDIATELY, 39 ANIMATION_RESTORE, 40 // Animations that raise/lower windows to/from area "in front" of the 41 // screen. 42 ANIMATION_LIFT, 43 ANIMATION_UNDO_LIFT, 44 ANIMATION_DROP, 45 // Animations that raise/lower windows from/to area "behind" of the screen. 46 ANIMATION_RAISE_TO_SCREEN, 47 ANIMATION_LOWER_BELOW_SCREEN, 48 ANIMATION_PARTIAL_FADE_IN, 49 ANIMATION_UNDO_PARTIAL_FADE_IN, 50 ANIMATION_FULL_FADE_IN, 51 ANIMATION_GRAYSCALE_BRIGHTNESS, 52 ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS, 53 }; 54 55 // Constants for determining animation speed. 56 enum AnimationSpeed { 57 // Immediately change state. 58 ANIMATION_SPEED_IMMEDIATE = 0, 59 // Speed for animations associated with user action that can be undone. 60 // Used for pre-lock and pre-shutdown animations. 61 ANIMATION_SPEED_UNDOABLE, 62 // Speed for animation that reverts undoable action. Used for aborting 63 // pre-lock and pre-shutdown animations. 64 ANIMATION_SPEED_REVERT, 65 // Speed for user action that can not be undone, Used for lock and shutdown 66 // animations requested via menus/shortcuts and for animating remaining 67 // parts of partial lock/shutdown animations. 68 ANIMATION_SPEED_FAST, 69 // Speed for lock screen appearance in "old" animation set. 70 ANIMATION_SPEED_SHOW_LOCK_SCREEN, 71 // Speed for workspace-like animations in "new" animation set. 72 ANIMATION_SPEED_MOVE_WINDOWS, 73 // Speed for undoing workspace-like animations in "new" animation set. 74 ANIMATION_SPEED_UNDO_MOVE_WINDOWS, 75 // Speed for shutdown in "new" animation set. 76 ANIMATION_SPEED_SHUTDOWN, 77 // Speed for reverting shutdown in "new" animation set. 78 ANIMATION_SPEED_REVERT_SHUTDOWN, 79 }; 80 81 // Specific containers or groups of containers that can be animated. 82 enum Container { 83 DESKTOP_BACKGROUND = 1 << 0, 84 LAUNCHER = 1 << 1, 85 86 // All user session related containers including system background but 87 // not including desktop background (wallpaper). 88 NON_LOCK_SCREEN_CONTAINERS = 1 << 2, 89 90 // Desktop wallpaper is moved to this layer when screen is locked. 91 // This layer is excluded from lock animation so that wallpaper stays as is, 92 // user session windows are hidden and lock UI is shown on top of it. 93 // This layer is included in shutdown animation. 94 LOCK_SCREEN_BACKGROUND = 1 << 3, 95 96 // Lock screen and lock screen modal containers. 97 LOCK_SCREEN_CONTAINERS = 1 << 4, 98 99 // Multiple system layers belong here like status, menu, tooltip 100 // and overlay layers. 101 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 5, 102 }; 103 104 // Helper class used by tests to access internal state. 105 class ASH_EXPORT TestApi { 106 public: 107 explicit TestApi(SessionStateAnimator* animator) 108 : animator_(animator) {} 109 110 // Returns true if containers of a given |container_mask| 111 // were last animated with |type| (probably; the analysis is fairly ad-hoc). 112 // |container_mask| is a bitfield of a Container. 113 bool ContainersAreAnimated(int container_mask, AnimationType type) const; 114 115 // Returns true if root window was last animated with |type| (probably; 116 // the analysis is fairly ad-hoc). 117 bool RootWindowIsAnimated(AnimationType type) const; 118 119 private: 120 SessionStateAnimator* animator_; // not owned 121 122 DISALLOW_COPY_AND_ASSIGN(TestApi); 123 }; 124 125 // A bitfield mask including LOCK_SCREEN_WALLPAPER, 126 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS. 127 const static int kAllLockScreenContainersMask; 128 129 // A bitfield mask of all containers. 130 const static int kAllContainersMask; 131 132 SessionStateAnimator(); 133 virtual ~SessionStateAnimator(); 134 135 // Reports animation duration for |speed|. 136 static base::TimeDelta GetDuration(AnimationSpeed speed); 137 138 // Fills |containers| with the containers included in |container_mask|. 139 static void GetContainers(int container_mask, 140 aura::Window::Windows* containers); 141 142 // Apply animation |type| to all containers included in |container_mask| with 143 // specified |speed|. 144 void StartAnimation(int container_mask, 145 AnimationType type, 146 AnimationSpeed speed); 147 148 // Apply animation |type| to all containers included in |container_mask| with 149 // specified |speed| and call a |callback| at the end of the animation, if it 150 // is not null. 151 void StartAnimationWithCallback(int container_mask, 152 AnimationType type, 153 AnimationSpeed speed, 154 base::Callback<void(void)>& callback); 155 156 // Apply animation |type| to all containers included in |container_mask| with 157 // specified |speed| and add |observer| to all animations. 158 void StartAnimationWithObserver(int container_mask, 159 AnimationType type, 160 AnimationSpeed speed, 161 ui::LayerAnimationObserver* observer); 162 163 // Applies animation |type| whith specified |speed| to the root container. 164 void StartGlobalAnimation(AnimationType type, 165 AnimationSpeed speed); 166 167 // Apply animation |type| to window |window| with |speed| and add |observer| 168 // if it is not NULL to the last animation sequence. 169 void RunAnimationForWindow(aura::Window* window, 170 AnimationType type, 171 AnimationSpeed speed, 172 ui::LayerAnimationObserver* observer); 173 174 DISALLOW_COPY_AND_ASSIGN(SessionStateAnimator); 175 }; 176 177 } // namespace internal 178 } // namespace ash 179 180 #endif // ASH_WM_SESSION_STATE_ANIMATOR_H_ 181