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