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