OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 5 #ifndef ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
| 10 #include "ash/wm/session_state_animator.h" |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "base/timer.h" | 14 #include "base/timer.h" |
14 #include "ui/aura/root_window_observer.h" | 15 #include "ui/aura/root_window_observer.h" |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 class Rect; | 18 class Rect; |
18 class Size; | 19 class Size; |
19 } | 20 } |
(...skipping 15 matching lines...) Expand all Loading... |
35 | 36 |
36 private: | 37 private: |
37 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); | 38 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); |
38 }; | 39 }; |
39 | 40 |
40 // Displays onscreen animations and locks or suspends the system in response to | 41 // Displays onscreen animations and locks or suspends the system in response to |
41 // the power button being pressed or released. | 42 // the power button being pressed or released. |
42 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, | 43 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, |
43 public ShellObserver { | 44 public ShellObserver { |
44 public: | 45 public: |
45 // Animations that can be applied to groups of containers. | |
46 // Exposed here for TestApi::ContainersAreAnimated(). | |
47 enum AnimationType { | |
48 ANIMATION_SLOW_CLOSE = 0, | |
49 ANIMATION_UNDO_SLOW_CLOSE, | |
50 ANIMATION_FAST_CLOSE, | |
51 ANIMATION_FADE_IN, | |
52 ANIMATION_HIDE, | |
53 ANIMATION_RESTORE, | |
54 }; | |
55 | |
56 // Specific containers or groups of containers that can be animated. | |
57 // Exposed here for TestApi::ContainersAreAnimated(). | |
58 enum Container { | |
59 DESKTOP_BACKGROUND = 1 << 0, | |
60 | |
61 // All user session related containers including system background but | |
62 // not including desktop background (wallpaper). | |
63 NON_LOCK_SCREEN_CONTAINERS = 1 << 1, | |
64 | |
65 // Desktop wallpaper is moved to this layer when screen is locked. | |
66 // This layer is excluded from lock animation so that wallpaper stays as is, | |
67 // user session windows are hidden and lock UI is shown on top of it. | |
68 // This layer is included in shutdown animation. | |
69 LOCK_SCREEN_BACKGROUND = 1 << 2, | |
70 | |
71 // Lock screen and lock screen modal containers. | |
72 LOCK_SCREEN_CONTAINERS = 1 << 3, | |
73 | |
74 // Multiple system layers belong here like status, menu, tooltip | |
75 // and overlay layers. | |
76 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 4, | |
77 }; | |
78 | 46 |
79 // Helper class used by tests to access internal state. | 47 // Helper class used by tests to access internal state. |
80 class ASH_EXPORT TestApi { | 48 class ASH_EXPORT TestApi { |
81 public: | 49 public: |
82 explicit TestApi(PowerButtonController* controller) | 50 explicit TestApi(PowerButtonController* controller) |
83 : controller_(controller) {} | 51 : controller_(controller), |
| 52 animator_api_(new SessionStateAnimator::TestApi( |
| 53 controller->animator_.get())) {} |
| 54 |
| 55 virtual ~TestApi() {} |
84 | 56 |
85 bool lock_timer_is_running() const { | 57 bool lock_timer_is_running() const { |
86 return controller_->lock_timer_.IsRunning(); | 58 return controller_->lock_timer_.IsRunning(); |
87 } | 59 } |
88 bool lock_fail_timer_is_running() const { | 60 bool lock_fail_timer_is_running() const { |
89 return controller_->lock_fail_timer_.IsRunning(); | 61 return controller_->lock_fail_timer_.IsRunning(); |
90 } | 62 } |
91 bool lock_to_shutdown_timer_is_running() const { | 63 bool lock_to_shutdown_timer_is_running() const { |
92 return controller_->lock_to_shutdown_timer_.IsRunning(); | 64 return controller_->lock_to_shutdown_timer_.IsRunning(); |
93 } | 65 } |
94 bool shutdown_timer_is_running() const { | 66 bool shutdown_timer_is_running() const { |
95 return controller_->shutdown_timer_.IsRunning(); | 67 return controller_->shutdown_timer_.IsRunning(); |
96 } | 68 } |
97 bool real_shutdown_timer_is_running() const { | 69 bool real_shutdown_timer_is_running() const { |
98 return controller_->real_shutdown_timer_.IsRunning(); | 70 return controller_->real_shutdown_timer_.IsRunning(); |
99 } | 71 } |
100 bool hide_black_layer_timer_is_running() const { | 72 bool hide_black_layer_timer_is_running() const { |
101 return controller_->hide_black_layer_timer_.IsRunning(); | 73 return animator_api_->hide_black_layer_timer_is_running(); |
102 } | 74 } |
103 | 75 |
104 void trigger_lock_timeout() { | 76 void trigger_lock_timeout() { |
105 controller_->OnLockTimeout(); | 77 controller_->OnLockTimeout(); |
106 controller_->lock_timer_.Stop(); | 78 controller_->lock_timer_.Stop(); |
107 } | 79 } |
108 void trigger_lock_fail_timeout() { | 80 void trigger_lock_fail_timeout() { |
109 controller_->OnLockFailTimeout(); | 81 controller_->OnLockFailTimeout(); |
110 controller_->lock_fail_timer_.Stop(); | 82 controller_->lock_fail_timer_.Stop(); |
111 } | 83 } |
112 void trigger_lock_to_shutdown_timeout() { | 84 void trigger_lock_to_shutdown_timeout() { |
113 controller_->OnLockToShutdownTimeout(); | 85 controller_->OnLockToShutdownTimeout(); |
114 controller_->lock_to_shutdown_timer_.Stop(); | 86 controller_->lock_to_shutdown_timer_.Stop(); |
115 } | 87 } |
116 void trigger_shutdown_timeout() { | 88 void trigger_shutdown_timeout() { |
117 controller_->OnShutdownTimeout(); | 89 controller_->OnShutdownTimeout(); |
118 controller_->shutdown_timer_.Stop(); | 90 controller_->shutdown_timer_.Stop(); |
119 } | 91 } |
120 void trigger_real_shutdown_timeout() { | 92 void trigger_real_shutdown_timeout() { |
121 controller_->OnRealShutdownTimeout(); | 93 controller_->OnRealShutdownTimeout(); |
122 controller_->real_shutdown_timer_.Stop(); | 94 controller_->real_shutdown_timer_.Stop(); |
123 } | 95 } |
124 void trigger_hide_black_layer_timeout() { | 96 void TriggerHideBlackLayerTimeout() { |
125 controller_->HideBlackLayer(); | 97 animator_api_->TriggerHideBlackLayerTimeout(); |
126 controller_->hide_black_layer_timer_.Stop(); | |
127 } | 98 } |
128 | 99 |
129 // Returns true if containers of a given |container_mask| | 100 // Returns true if containers of a given |container_mask| |
130 // were last animated with |type| (probably; the analysis is fairly ad-hoc). | 101 // were last animated with |type| (probably; the analysis is fairly ad-hoc). |
131 // |container_mask| is a bitfield of a Container. | 102 // |container_mask| is a bitfield of a Container. |
132 bool ContainersAreAnimated(int container_mask, AnimationType type) const; | 103 bool ContainersAreAnimated(int container_mask, |
| 104 SessionStateAnimator::AnimationType type) const { |
| 105 return animator_api_->ContainersAreAnimated(container_mask, type); |
| 106 } |
133 | 107 |
134 // Returns true if |black_layer_| is non-NULL and visible. | 108 // Returns true if |black_layer_| is non-NULL and visible. |
135 bool BlackLayerIsVisible() const; | 109 bool BlackLayerIsVisible() { |
| 110 return animator_api_->BlackLayerIsVisible(); |
| 111 } |
136 | 112 |
137 // Returns |black_layer_|'s bounds, or an empty rect if the layer is | 113 // Returns |black_layer_|'s bounds, or an empty rect if the layer is |
138 // NULL. | 114 // NULL. |
139 gfx::Rect GetBlackLayerBounds() const; | 115 gfx::Rect GetBlackLayerBounds() const { |
| 116 return animator_api_->GetBlackLayerBounds(); |
| 117 } |
140 | 118 |
141 private: | 119 private: |
142 PowerButtonController* controller_; // not owned | 120 PowerButtonController* controller_; // not owned |
143 | 121 |
| 122 scoped_ptr<SessionStateAnimator::TestApi> animator_api_; |
| 123 |
144 DISALLOW_COPY_AND_ASSIGN(TestApi); | 124 DISALLOW_COPY_AND_ASSIGN(TestApi); |
145 }; | 125 }; |
146 | 126 |
147 // Helper method that returns a bitfield mask of all containers. | |
148 static int GetAllContainersMask(); | |
149 | |
150 // Helper method that returns a bitfield mask including LOCK_SCREEN_WALLPAPER, | |
151 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS. | |
152 static int GetAllLockScreenContainersMask(); | |
153 | |
154 PowerButtonController(); | 127 PowerButtonController(); |
155 virtual ~PowerButtonController(); | 128 virtual ~PowerButtonController(); |
156 | 129 |
157 void set_delegate(PowerButtonControllerDelegate* delegate) { | 130 void set_delegate(PowerButtonControllerDelegate* delegate) { |
158 delegate_.reset(delegate); | 131 delegate_.reset(delegate); |
159 } | 132 } |
160 | 133 |
161 void set_has_legacy_power_button_for_test(bool legacy) { | 134 void set_has_legacy_power_button_for_test(bool legacy) { |
162 has_legacy_power_button_ = legacy; | 135 has_legacy_power_button_ = legacy; |
163 } | 136 } |
164 | 137 |
165 // Called when the current screen brightness changes. | 138 // Called when the current screen brightness changes. |
166 void OnScreenBrightnessChanged(double percent); | 139 void OnScreenBrightnessChanged(double percent); |
167 | 140 |
168 // Called when Chrome gets a request to display the lock screen. | 141 // Called when Chrome gets a request to display the lock screen. |
169 void OnStartingLock(); | 142 void OnStartingLock(); |
170 | 143 |
171 // Called when the power or lock buttons are pressed or released. | 144 // Called when the power or lock buttons are pressed or released. |
172 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 145 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
173 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 146 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
174 | 147 |
175 // Displays the shutdown animation and requests shutdown when it's done. | 148 // Displays the shutdown animation and requests shutdown when it's done. |
176 void RequestShutdown(); | 149 void RequestShutdown(); |
177 | 150 |
178 // aura::RootWindowObserver overrides: | |
179 virtual void OnRootWindowResized(const aura::RootWindow* root, | |
180 const gfx::Size& old_size) OVERRIDE; | |
181 virtual void OnRootWindowHostCloseRequested( | 151 virtual void OnRootWindowHostCloseRequested( |
182 const aura::RootWindow* root) OVERRIDE; | 152 const aura::RootWindow* root) OVERRIDE; |
183 | 153 |
184 // ShellObserver overrides: | 154 // ShellObserver overrides: |
185 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | 155 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; |
186 virtual void OnAppTerminating() OVERRIDE; | 156 virtual void OnAppTerminating() OVERRIDE; |
187 virtual void OnLockStateChanged(bool locked) OVERRIDE; | 157 virtual void OnLockStateChanged(bool locked) OVERRIDE; |
188 | 158 |
189 private: | 159 private: |
190 bool LoggedInAsNonGuest() const; | 160 bool LoggedInAsNonGuest() const; |
(...skipping 13 matching lines...) Expand all Loading... |
204 // Requests that the machine be shut down. | 174 // Requests that the machine be shut down. |
205 void OnRealShutdownTimeout(); | 175 void OnRealShutdownTimeout(); |
206 | 176 |
207 // Puts us into the pre-lock or pre-shutdown state. | 177 // Puts us into the pre-lock or pre-shutdown state. |
208 void StartLockTimer(); | 178 void StartLockTimer(); |
209 void StartShutdownTimer(); | 179 void StartShutdownTimer(); |
210 | 180 |
211 // Displays the shutdown animation and starts |real_shutdown_timer_|. | 181 // Displays the shutdown animation and starts |real_shutdown_timer_|. |
212 void StartShutdownAnimationAndRequestShutdown(); | 182 void StartShutdownAnimationAndRequestShutdown(); |
213 | 183 |
214 // Shows or hides |black_layer_|. The show method creates and | |
215 // initializes the layer if it doesn't already exist. | |
216 void ShowBlackLayer(); | |
217 void HideBlackLayer(); | |
218 | |
219 scoped_ptr<PowerButtonControllerDelegate> delegate_; | 184 scoped_ptr<PowerButtonControllerDelegate> delegate_; |
220 | 185 |
221 // The current login status. | 186 // The current login status. |
222 user::LoginStatus login_status_; | 187 user::LoginStatus login_status_; |
223 | 188 |
224 // Original login status during locked. LOGGED_IN_NONE if it's not locked. | 189 // Original login status during locked. LOGGED_IN_NONE if it's not locked. |
225 user::LoginStatus unlocked_login_status_; | 190 user::LoginStatus unlocked_login_status_; |
226 | 191 |
227 // Are the power or lock buttons currently held? | 192 // Are the power or lock buttons currently held? |
228 bool power_button_down_; | 193 bool power_button_down_; |
229 bool lock_button_down_; | 194 bool lock_button_down_; |
230 | 195 |
231 // Is the screen currently turned off? | 196 // Is the screen currently turned off? |
232 bool screen_is_off_; | 197 bool screen_is_off_; |
233 | 198 |
234 // Are we in the process of shutting the machine down? | 199 // Are we in the process of shutting the machine down? |
235 bool shutting_down_; | 200 bool shutting_down_; |
236 | 201 |
237 // Was a command-line switch set telling us that we're running on hardware | 202 // Was a command-line switch set telling us that we're running on hardware |
238 // that misreports power button releases? | 203 // that misreports power button releases? |
239 bool has_legacy_power_button_; | 204 bool has_legacy_power_button_; |
240 | 205 |
241 // Layer that's stacked under all of the root window's children to provide a | |
242 // black background when we're scaling all of the other windows down. | |
243 // TODO(derat): Remove this in favor of having the compositor only clear the | |
244 // viewport when there are regions not covered by a layer: | |
245 // http://crbug.com/113445 | |
246 scoped_ptr<ui::Layer> black_layer_; | |
247 | |
248 // Started when the user first presses the power button while in a | 206 // Started when the user first presses the power button while in a |
249 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the | 207 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the |
250 // screen. | 208 // screen. |
251 base::OneShotTimer<PowerButtonController> lock_timer_; | 209 base::OneShotTimer<PowerButtonController> lock_timer_; |
252 | 210 |
253 // Started when we request that the screen be locked. When it fires, we | 211 // Started when we request that the screen be locked. When it fires, we |
254 // assume that our request got dropped. | 212 // assume that our request got dropped. |
255 base::OneShotTimer<PowerButtonController> lock_fail_timer_; | 213 base::OneShotTimer<PowerButtonController> lock_fail_timer_; |
256 | 214 |
257 // Started when the screen is locked while the power button is held. Adds a | 215 // Started when the screen is locked while the power button is held. Adds a |
258 // delay between the appearance of the lock screen and the beginning of the | 216 // delay between the appearance of the lock screen and the beginning of the |
259 // pre-shutdown animation. | 217 // pre-shutdown animation. |
260 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; | 218 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; |
261 | 219 |
262 // Started when we begin displaying the pre-shutdown animation. When it | 220 // Started when we begin displaying the pre-shutdown animation. When it |
263 // fires, we start the shutdown animation and get ready to request shutdown. | 221 // fires, we start the shutdown animation and get ready to request shutdown. |
264 base::OneShotTimer<PowerButtonController> shutdown_timer_; | 222 base::OneShotTimer<PowerButtonController> shutdown_timer_; |
265 | 223 |
266 // Started when we display the shutdown animation. When it fires, we actually | 224 // Started when we display the shutdown animation. When it fires, we actually |
267 // request shutdown. Gives the animation time to complete before Chrome, X, | 225 // request shutdown. Gives the animation time to complete before Chrome, X, |
268 // etc. are shut down. | 226 // etc. are shut down. |
269 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; | 227 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; |
270 | 228 |
271 // Started when we abort the pre-lock state. When it fires, we hide | 229 scoped_ptr<SessionStateAnimator> animator_; |
272 // |black_layer_|, as the desktop background is now covering the whole | |
273 // screen. | |
274 base::OneShotTimer<PowerButtonController> hide_black_layer_timer_; | |
275 | 230 |
276 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 231 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
277 }; | 232 }; |
278 | 233 |
279 } // namespace ash | 234 } // namespace ash |
280 | 235 |
281 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 236 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
OLD | NEW |