Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / ash / multi_user / user_switch_animator_chromeos.h
blobe3e627a586418b50b543bb7079b470fe70c92bfc
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_USER_SWITCH_ANIMATOR_CHROMEOS_H_
6 #define CHROME_BROWSER_UI_ASH_MULTI_USER_USER_SWITCH_ANIMATOR_CHROMEOS_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/timer/timer.h"
13 #include "ui/aura/window.h"
15 namespace chrome {
17 class MultiUserWindowManagerChromeOS;
19 // A class which performs transitions animations between users. Upon creation,
20 // the animation gets started and upon destruction the animation gets finished
21 // if not done yet.
22 // Specifying |animation_disabled| upon creation will perform the transition
23 // without visible animations.
24 class UserSwitchAnimatorChromeOS {
25 public:
26 // The animation step for the user change animation.
27 enum AnimationStep {
28 ANIMATION_STEP_HIDE_OLD_USER, // Hiding the old user (and shelf).
29 ANIMATION_STEP_SHOW_NEW_USER, // Show the shelf of the new user.
30 ANIMATION_STEP_FINALIZE, // All animations are done - final cleanup.
31 ANIMATION_STEP_ENDED // The animation has ended.
34 UserSwitchAnimatorChromeOS(MultiUserWindowManagerChromeOS* owner,
35 const std::string& new_user_id,
36 int animation_speed_ms);
37 ~UserSwitchAnimatorChromeOS();
39 // Check if a window is covering the entire work area of the screen it is on.
40 static bool CoversScreen(aura::Window* window);
42 bool IsAnimationFinished() {
43 return animation_step_ == ANIMATION_STEP_ENDED;
46 // Returns the user id for which the wallpaper is currently shown.
47 // If a wallpaper is transitioning to B it will be returned as "->B".
48 const std::string& wallpaper_user_id_for_test() { return wallpaper_user_id_; }
50 // Advances the user switch animation to the next step. It reads the current
51 // step from |animation_step_| and increments it thereafter. When
52 // |ANIMATION_STEP_FINALIZE| gets executed, the animation is finished and the
53 // timer (if one exists) will get destroyed.
54 void AdvanceUserTransitionAnimation();
56 // When the system is shutting down, the animation can be stopped without
57 // ending it.
58 void CancelAnimation();
60 private:
61 // The window configuration of screen covering windows before an animation.
62 enum TransitioningScreenCover {
63 NO_USER_COVERS_SCREEN, // No window covers the entire screen.
64 OLD_USER_COVERS_SCREEN, // The current user has at least one window
65 // covering the entire screen.
66 NEW_USER_COVERS_SCREEN, // The user which becomes active has at least one
67 // window covering the entire screen.
68 BOTH_USERS_COVER_SCREEN // Both users have at least one window each
69 // covering the entire screen.
72 // Finalizes the animation and ends the timer (if there is one).
73 void FinalizeAnimation();
75 // Execute the user wallpaper animations for |animation_step|.
76 void TransitionWallpaper(AnimationStep animtion_step);
78 // Execute the user shelf animations for |animation_step|.
79 void TransitionUserShelf(AnimationStep animtion_step);
81 // Execute the window animations for |animation_step|.
82 void TransitionWindows(AnimationStep animation_step);
84 // Check if a window is maximized / fullscreen / covering the entire screen.
85 // If a |root_window| is given, the screen coverage of that root_window is
86 // tested, otherwise all screens.
87 TransitioningScreenCover GetScreenCover(aura::Window* root_window);
89 // Builds the map that a user ID to the list of windows that should be shown
90 // for this user. This operation happens once upon the construction of this
91 // animation.
92 void BuildUserToWindowsListMap();
94 // The owning window manager.
95 MultiUserWindowManagerChromeOS* owner_;
97 // The new user to set.
98 std::string new_user_id_;
100 // The animation speed in ms. If 0, animations are disabled.
101 int animation_speed_ms_;
103 // The next animation step for AdvanceUserTransitionAnimation().
104 AnimationStep animation_step_;
106 // The screen cover status before the animation has started.
107 TransitioningScreenCover screen_cover_;
109 // Mapping users IDs to the list of windows to show for these users.
110 typedef std::map<std::string, aura::Window::Windows> UserToWindowsMap;
111 UserToWindowsMap windows_by_user_id_;
113 // A timer which watches to executes the second part of a "user changed"
114 // animation. Note that this timer exists only during such an animation.
115 scoped_ptr<base::Timer> user_changed_animation_timer_;
117 // For unit tests: Check which wallpaper was set.
118 std::string wallpaper_user_id_;
120 DISALLOW_COPY_AND_ASSIGN(UserSwitchAnimatorChromeOS);
123 } // namespace chrome
125 #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_USER_SWITCH_ANIMATOR_CHROMEOS_H_