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 #include "ash/wm/power_button_controller.h" | 5 #include "ash/wm/power_button_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/wm/cursor_manager.h" | 11 #include "ash/wm/cursor_manager.h" |
12 #include "ash/wm/session_state_animator.h" | |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/time.h" | 15 #include "base/time.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
16 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
17 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
18 #include "ui/aura/shared/compound_event_filter.h" | 19 #include "ui/aura/shared/compound_event_filter.h" |
19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
Daniel Erat
2012/08/31 17:02:12
please go through all of these headers and remove
Denis Kuznetsov (DE-MUC)
2012/09/28 11:52:43
Done.
| |
21 #include "ui/compositor/layer_animation_element.h" | 22 #include "ui/compositor/layer_animation_element.h" |
22 #include "ui/compositor/layer_animation_sequence.h" | 23 #include "ui/compositor/layer_animation_sequence.h" |
23 #include "ui/compositor/layer_animator.h" | 24 #include "ui/compositor/layer_animator.h" |
24 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
27 #include "ui/gfx/transform.h" | 28 #include "ui/gfx/transform.h" |
28 | 29 |
29 namespace ash { | 30 namespace ash { |
30 | 31 |
(...skipping 21 matching lines...) Expand all Loading... | |
52 | 53 |
53 // Amount of time taken to scale the snapshot of the screen back to its original | 54 // Amount of time taken to scale the snapshot of the screen back to its original |
54 // size when the button is released. | 55 // size when the button is released. |
55 const int kUndoSlowCloseAnimMs = 100; | 56 const int kUndoSlowCloseAnimMs = 100; |
56 | 57 |
57 // Amount of time taken to scale the snapshot down to a point in the center of | 58 // Amount of time taken to scale the snapshot down to a point in the center of |
58 // the screen once the screen has been locked or we've been notified that the | 59 // the screen once the screen has been locked or we've been notified that the |
59 // system is shutting down. | 60 // system is shutting down. |
60 const int kFastCloseAnimMs = 150; | 61 const int kFastCloseAnimMs = 150; |
61 | 62 |
62 // Amount of time taken to make the lock window fade in when the screen is | |
63 // locked. | |
64 const int kLockFadeInAnimMs = 500; | |
65 | |
66 // Additional time (beyond kFastCloseAnimMs) to wait after starting the | 63 // Additional time (beyond kFastCloseAnimMs) to wait after starting the |
67 // fast-close shutdown animation before actually requesting shutdown, to give | 64 // fast-close shutdown animation before actually requesting shutdown, to give |
68 // the animation time to finish. | 65 // the animation time to finish. |
69 const int kShutdownRequestDelayMs = 50; | 66 const int kShutdownRequestDelayMs = 50; |
70 | 67 |
71 // Slightly-smaller size that we scale the screen down to for the pre-lock and | |
72 // pre-shutdown states. | |
73 const float kSlowCloseSizeRatio = 0.95f; | |
74 | |
75 // Returns the transform that should be applied to containers for the slow-close | |
76 // animation. | |
77 ui::Transform GetSlowCloseTransform() { | |
78 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); | |
79 ui::Transform transform; | |
80 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); | |
81 transform.ConcatTranslate( | |
82 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), | |
83 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); | |
84 return transform; | |
85 } | |
86 | |
87 // Returns the transform that should be applied to containers for the fast-close | |
88 // animation. | |
89 ui::Transform GetFastCloseTransform() { | |
90 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); | |
91 ui::Transform transform; | |
92 transform.SetScale(0.0, 0.0); | |
93 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), | |
94 floor(0.5 * root_size.height() + 0.5)); | |
95 return transform; | |
96 } | |
97 | |
98 // Slowly shrinks |window| to a slightly-smaller size. | |
99 void StartSlowCloseAnimationForWindow(aura::Window* window) { | |
100 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | |
101 animator->set_preemption_strategy( | |
102 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
103 animator->StartAnimation( | |
104 new ui::LayerAnimationSequence( | |
105 ui::LayerAnimationElement::CreateTransformElement( | |
106 GetSlowCloseTransform(), | |
107 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs)))); | |
108 } | |
109 | |
110 // Quickly undoes the effects of the slow-close animation on |window|. | |
111 void StartUndoSlowCloseAnimationForWindow(aura::Window* window) { | |
112 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | |
113 animator->set_preemption_strategy( | |
114 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
115 animator->StartAnimation( | |
116 new ui::LayerAnimationSequence( | |
117 ui::LayerAnimationElement::CreateTransformElement( | |
118 ui::Transform(), | |
119 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs)))); | |
120 } | |
121 | |
122 // Quickly shrinks |window| down to a point in the center of the screen and | |
123 // fades it out to 0 opacity. | |
124 void StartFastCloseAnimationForWindow(aura::Window* window) { | |
125 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | |
126 animator->set_preemption_strategy( | |
127 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
128 animator->StartAnimation( | |
129 new ui::LayerAnimationSequence( | |
130 ui::LayerAnimationElement::CreateTransformElement( | |
131 GetFastCloseTransform(), | |
132 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); | |
133 animator->StartAnimation( | |
134 new ui::LayerAnimationSequence( | |
135 ui::LayerAnimationElement::CreateOpacityElement( | |
136 0.0, base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); | |
137 } | |
138 | |
139 // Fades |window| in to full opacity. | |
140 void FadeInWindow(aura::Window* window) { | |
141 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | |
142 animator->set_preemption_strategy( | |
143 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
144 animator->StartAnimation( | |
145 new ui::LayerAnimationSequence( | |
146 ui::LayerAnimationElement::CreateOpacityElement( | |
147 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs)))); | |
148 } | |
149 | |
150 // Makes |window| fully transparent instantaneously. | |
151 void HideWindow(aura::Window* window) { | |
152 window->layer()->SetOpacity(0.0); | |
153 } | |
154 | |
155 // Restores |window| to its original position and scale and full opacity | |
156 // instantaneously. | |
157 void RestoreWindow(aura::Window* window) { | |
158 window->layer()->SetTransform(ui::Transform()); | |
159 window->layer()->SetOpacity(1.0); | |
160 } | |
161 | |
162 // Fills |containers| with the containers described by |group|. | |
163 void GetContainers(PowerButtonController::ContainerGroup group, | |
164 aura::Window::Windows* containers) { | |
165 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | |
166 | |
167 aura::Window* non_lock_screen_containers = Shell::GetContainer( | |
168 root_window, | |
169 internal::kShellWindowId_NonLockScreenContainersContainer); | |
170 aura::Window* lock_screen_containers = Shell::GetContainer( | |
171 root_window, | |
172 internal::kShellWindowId_LockScreenContainersContainer); | |
173 aura::Window* lock_screen_related_containers = Shell::GetContainer( | |
174 root_window, | |
175 internal::kShellWindowId_LockScreenRelatedContainersContainer); | |
176 | |
177 containers->clear(); | |
178 switch (group) { | |
179 case PowerButtonController::ALL_CONTAINERS: | |
180 containers->push_back(non_lock_screen_containers); | |
181 containers->push_back(lock_screen_containers); | |
182 containers->push_back(lock_screen_related_containers); | |
183 break; | |
184 case PowerButtonController::SCREEN_LOCKER_CONTAINERS: | |
185 containers->push_back(lock_screen_containers); | |
186 break; | |
187 case PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS: | |
188 containers->push_back(lock_screen_containers); | |
189 containers->push_back(lock_screen_related_containers); | |
190 break; | |
191 case PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS: | |
192 containers->push_back(non_lock_screen_containers); | |
193 break; | |
194 default: | |
195 NOTREACHED() << "Unhandled container group " << group; | |
196 } | |
197 } | |
198 | |
199 // Apply animation |type| to all containers described by |group|. | |
200 void StartAnimation(PowerButtonController::ContainerGroup group, | |
201 PowerButtonController::AnimationType type) { | |
202 aura::Window::Windows containers; | |
203 GetContainers(group, &containers); | |
204 | |
205 for (aura::Window::Windows::const_iterator it = containers.begin(); | |
206 it != containers.end(); ++it) { | |
207 aura::Window* window = *it; | |
208 switch (type) { | |
209 case PowerButtonController::ANIMATION_SLOW_CLOSE: | |
210 StartSlowCloseAnimationForWindow(window); | |
211 break; | |
212 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: | |
213 StartUndoSlowCloseAnimationForWindow(window); | |
214 break; | |
215 case PowerButtonController::ANIMATION_FAST_CLOSE: | |
216 StartFastCloseAnimationForWindow(window); | |
217 break; | |
218 case PowerButtonController::ANIMATION_FADE_IN: | |
219 FadeInWindow(window); | |
220 break; | |
221 case PowerButtonController::ANIMATION_HIDE: | |
222 HideWindow(window); | |
223 break; | |
224 case PowerButtonController::ANIMATION_RESTORE: | |
225 RestoreWindow(window); | |
226 break; | |
227 default: | |
228 NOTREACHED() << "Unhandled animation type " << type; | |
229 } | |
230 } | |
231 } | |
232 | |
233 } // namespace | 68 } // namespace |
234 | 69 |
235 bool PowerButtonController::TestApi::ContainerGroupIsAnimated( | |
236 ContainerGroup group, AnimationType type) const { | |
237 aura::Window::Windows containers; | |
238 GetContainers(group, &containers); | |
239 for (aura::Window::Windows::const_iterator it = containers.begin(); | |
240 it != containers.end(); ++it) { | |
241 aura::Window* window = *it; | |
242 ui::Layer* layer = window->layer(); | |
243 | |
244 switch (type) { | |
245 case PowerButtonController::ANIMATION_SLOW_CLOSE: | |
246 if (layer->GetTargetTransform() != GetSlowCloseTransform()) | |
247 return false; | |
248 break; | |
249 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: | |
250 if (layer->GetTargetTransform() != ui::Transform()) | |
251 return false; | |
252 break; | |
253 case PowerButtonController::ANIMATION_FAST_CLOSE: | |
254 if (layer->GetTargetTransform() != GetFastCloseTransform() || | |
255 layer->GetTargetOpacity() > 0.0001) | |
256 return false; | |
257 break; | |
258 case PowerButtonController::ANIMATION_FADE_IN: | |
259 if (layer->GetTargetOpacity() < 0.9999) | |
260 return false; | |
261 break; | |
262 case PowerButtonController::ANIMATION_HIDE: | |
263 if (layer->GetTargetOpacity() > 0.0001) | |
264 return false; | |
265 break; | |
266 case PowerButtonController::ANIMATION_RESTORE: | |
267 if (layer->opacity() < 0.9999 || layer->transform() != ui::Transform()) | |
268 return false; | |
269 break; | |
270 default: | |
271 NOTREACHED() << "Unhandled animation type " << type; | |
272 return false; | |
273 } | |
274 } | |
275 return true; | |
276 } | |
277 | |
278 bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const { | |
279 return controller_->background_layer_.get() && | |
280 controller_->background_layer_->visible(); | |
281 } | |
282 | |
283 gfx::Rect PowerButtonController::TestApi::GetBackgroundLayerBounds() const { | |
284 ui::Layer* layer = controller_->background_layer_.get(); | |
285 return layer ? layer->bounds() : gfx::Rect(); | |
286 } | |
287 | |
288 PowerButtonController::PowerButtonController() | 70 PowerButtonController::PowerButtonController() |
289 : login_status_(user::LOGGED_IN_NONE), | 71 : login_status_(user::LOGGED_IN_NONE), |
290 unlocked_login_status_(user::LOGGED_IN_NONE), | 72 unlocked_login_status_(user::LOGGED_IN_NONE), |
291 power_button_down_(false), | 73 power_button_down_(false), |
292 lock_button_down_(false), | 74 lock_button_down_(false), |
293 screen_is_off_(false), | 75 screen_is_off_(false), |
294 shutting_down_(false), | 76 shutting_down_(false), |
295 has_legacy_power_button_( | 77 has_legacy_power_button_( |
296 CommandLine::ForCurrentProcess()->HasSwitch( | 78 CommandLine::ForCurrentProcess()->HasSwitch( |
297 switches::kAuraLegacyPowerButton)) { | 79 switches::kAuraLegacyPowerButton)), |
80 animator_(new SessionStateAnimator()) { | |
298 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); | 81 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); |
299 } | 82 } |
300 | 83 |
301 PowerButtonController::~PowerButtonController() { | 84 PowerButtonController::~PowerButtonController() { |
302 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); | 85 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); |
86 delete animator_; | |
303 } | 87 } |
304 | 88 |
305 void PowerButtonController::OnLoginStateChanged(user::LoginStatus status) { | 89 void PowerButtonController::OnLoginStateChanged(user::LoginStatus status) { |
306 login_status_ = status; | 90 login_status_ = status; |
307 unlocked_login_status_ = user::LOGGED_IN_NONE; | 91 unlocked_login_status_ = user::LOGGED_IN_NONE; |
308 } | 92 } |
309 | 93 |
310 void PowerButtonController::OnAppTerminating() { | 94 void PowerButtonController::OnAppTerminating() { |
311 // If we hear that Chrome is exiting but didn't request it ourselves, all we | 95 // If we hear that Chrome is exiting but didn't request it ourselves, all we |
312 // can really hope for is that we'll have time to clear the screen. | 96 // can really hope for is that we'll have time to clear the screen. |
313 if (!shutting_down_) { | 97 if (!shutting_down_) { |
314 shutting_down_ = true; | 98 shutting_down_ = true; |
315 Shell* shell = ash::Shell::GetInstance(); | 99 Shell* shell = ash::Shell::GetInstance(); |
316 shell->env_filter()->set_update_cursor_visibility(false); | 100 shell->env_filter()->set_update_cursor_visibility(false); |
317 shell->cursor_manager()->ShowCursor(false); | 101 shell->cursor_manager()->ShowCursor(false); |
318 ShowBackgroundLayer(); | 102 animator_->ShowBackgroundLayer(); |
319 StartAnimation(ALL_CONTAINERS, ANIMATION_HIDE); | 103 animator_->StartAnimation(SessionStateAnimator::ALL_CONTAINERS, |
104 SessionStateAnimator::HIDE); | |
320 } | 105 } |
321 } | 106 } |
322 | 107 |
323 void PowerButtonController::OnLockStateChanged(bool locked) { | 108 void PowerButtonController::OnLockStateChanged(bool locked) { |
324 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) | 109 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) |
325 return; | 110 return; |
326 | 111 |
327 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { | 112 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { |
328 login_status_ = unlocked_login_status_; | 113 login_status_ = unlocked_login_status_; |
329 unlocked_login_status_ = user::LOGGED_IN_NONE; | 114 unlocked_login_status_ = user::LOGGED_IN_NONE; |
330 } else { | 115 } else { |
331 unlocked_login_status_ = login_status_; | 116 unlocked_login_status_ = login_status_; |
332 login_status_ = user::LOGGED_IN_LOCKED; | 117 login_status_ = user::LOGGED_IN_LOCKED; |
333 } | 118 } |
334 | 119 |
335 if (locked) { | 120 if (locked) { |
336 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); | 121 animator_->StartAnimation(SessionStateAnimator::SCREEN_LOCKER_CONTAINERS, |
122 SessionStateAnimator::FADE_IN); | |
337 lock_timer_.Stop(); | 123 lock_timer_.Stop(); |
338 lock_fail_timer_.Stop(); | 124 lock_fail_timer_.Stop(); |
339 | 125 |
340 if (!has_legacy_power_button_ && power_button_down_) { | 126 if (!has_legacy_power_button_ && power_button_down_) { |
341 lock_to_shutdown_timer_.Stop(); | 127 lock_to_shutdown_timer_.Stop(); |
342 lock_to_shutdown_timer_.Start( | 128 lock_to_shutdown_timer_.Start( |
343 FROM_HERE, | 129 FROM_HERE, |
344 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 130 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
345 this, &PowerButtonController::OnLockToShutdownTimeout); | 131 this, &PowerButtonController::OnLockToShutdownTimeout); |
346 } | 132 } |
347 } else { | 133 } else { |
348 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 134 animator_->StartAnimation( |
349 ANIMATION_RESTORE); | 135 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
350 HideBackgroundLayer(); | 136 SessionStateAnimator::RESTORE); |
137 animator_->HideBackgroundLayer(); | |
351 } | 138 } |
352 } | 139 } |
353 | 140 |
354 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 141 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
355 screen_is_off_ = percent <= 0.001; | 142 screen_is_off_ = percent <= 0.001; |
356 } | 143 } |
357 | 144 |
358 void PowerButtonController::OnStartingLock() { | 145 void PowerButtonController::OnStartingLock() { |
359 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) | 146 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) |
360 return; | 147 return; |
361 | 148 |
362 // Ensure that the background layer is visible -- if the screen was locked via | 149 // Ensure that the background layer is visible -- if the screen was locked via |
363 // the wrench menu, we won't have already shown the background as part of the | 150 // the wrench menu, we won't have already shown the background as part of the |
364 // slow-close animation. | 151 // slow-close animation. |
365 ShowBackgroundLayer(); | 152 animator_->ShowBackgroundLayer(); |
366 | 153 |
367 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 154 animator_->StartAnimation( |
368 ANIMATION_FAST_CLOSE); | 155 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
156 SessionStateAnimator::FAST_CLOSE); | |
369 | 157 |
370 // Hide the screen locker containers so we can make them fade in later. | 158 // Hide the screen locker containers so we can make them fade in later. |
371 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); | 159 animator_->StartAnimation( |
160 SessionStateAnimator::SCREEN_LOCKER_CONTAINERS, | |
161 SessionStateAnimator::HIDE); | |
372 } | 162 } |
373 | 163 |
374 void PowerButtonController::OnPowerButtonEvent( | 164 void PowerButtonController::OnPowerButtonEvent( |
375 bool down, const base::TimeTicks& timestamp) { | 165 bool down, const base::TimeTicks& timestamp) { |
376 power_button_down_ = down; | 166 power_button_down_ = down; |
377 | 167 |
378 if (shutting_down_) | 168 if (shutting_down_) |
379 return; | 169 return; |
380 | 170 |
381 // Avoid starting the lock/shutdown sequence if the power button is pressed | 171 // Avoid starting the lock/shutdown sequence if the power button is pressed |
382 // while the screen is off (http://crbug.com/128451). | 172 // while the screen is off (http://crbug.com/128451). |
383 if (screen_is_off_) | 173 if (screen_is_off_) |
384 return; | 174 return; |
385 | 175 |
386 if (has_legacy_power_button_) { | 176 if (has_legacy_power_button_) { |
387 // If power button releases won't get reported correctly because we're not | 177 // If power button releases won't get reported correctly because we're not |
388 // running on official hardware, just lock the screen or shut down | 178 // running on official hardware, just lock the screen or shut down |
389 // immediately. | 179 // immediately. |
390 if (down) { | 180 if (down) { |
391 ShowBackgroundLayer(); | 181 animator_->ShowBackgroundLayer(); |
392 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) { | 182 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) { |
393 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 183 animator_->StartAnimation( |
394 ANIMATION_SLOW_CLOSE); | 184 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
185 SessionStateAnimator::SLOW_CLOSE); | |
395 OnLockTimeout(); | 186 OnLockTimeout(); |
396 } else { | 187 } else { |
397 OnShutdownTimeout(); | 188 OnShutdownTimeout(); |
398 } | 189 } |
399 } | 190 } |
400 } else { // !has_legacy_power_button_ | 191 } else { // !has_legacy_power_button_ |
401 if (down) { | 192 if (down) { |
402 // If we already have a pending request to lock the screen, wait. | 193 // If we already have a pending request to lock the screen, wait. |
403 if (lock_fail_timer_.IsRunning()) | 194 if (lock_fail_timer_.IsRunning()) |
404 return; | 195 return; |
405 | 196 |
406 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) | 197 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) |
407 StartLockTimer(); | 198 StartLockTimer(); |
408 else | 199 else |
409 StartShutdownTimer(); | 200 StartShutdownTimer(); |
410 } else { // Button is up. | 201 } else { // Button is up. |
411 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) | 202 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) |
412 StartAnimation( | 203 animator_->StartAnimation( |
413 (login_status_ == user::LOGGED_IN_LOCKED) ? | 204 (login_status_ == user::LOGGED_IN_LOCKED) ? |
414 SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, | 205 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS : |
415 ANIMATION_UNDO_SLOW_CLOSE); | 206 SessionStateAnimator::ALL_CONTAINERS, |
207 SessionStateAnimator::UNDO_SLOW_CLOSE); | |
416 | 208 |
417 // Drop the background layer after the undo animation finishes. | 209 // Drop the background layer after the undo animation finishes. |
418 if (lock_timer_.IsRunning() || | 210 if (lock_timer_.IsRunning() || |
419 (shutdown_timer_.IsRunning() && !LoggedInAsNonGuest())) { | 211 (shutdown_timer_.IsRunning() && !LoggedInAsNonGuest())) { |
420 hide_background_layer_timer_.Stop(); | 212 animator_->DropBackgroundLayer(); |
421 hide_background_layer_timer_.Start( | |
422 FROM_HERE, | |
423 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | |
424 this, &PowerButtonController::HideBackgroundLayer); | |
425 } | 213 } |
426 | 214 |
427 lock_timer_.Stop(); | 215 lock_timer_.Stop(); |
428 shutdown_timer_.Stop(); | 216 shutdown_timer_.Stop(); |
429 lock_to_shutdown_timer_.Stop(); | 217 lock_to_shutdown_timer_.Stop(); |
430 } | 218 } |
431 } | 219 } |
432 } | 220 } |
433 | 221 |
434 void PowerButtonController::OnLockButtonEvent( | 222 void PowerButtonController::OnLockButtonEvent( |
435 bool down, const base::TimeTicks& timestamp) { | 223 bool down, const base::TimeTicks& timestamp) { |
436 lock_button_down_ = down; | 224 lock_button_down_ = down; |
437 | 225 |
438 if (shutting_down_ || !LoggedInAsNonGuest()) | 226 if (shutting_down_ || !LoggedInAsNonGuest()) |
439 return; | 227 return; |
440 | 228 |
441 // Bail if we're already locked or are in the process of locking. Also give | 229 // Bail if we're already locked or are in the process of locking. Also give |
442 // the power button precedence over the lock button (we don't expect both | 230 // the power button precedence over the lock button (we don't expect both |
443 // buttons to be present, so this is just making sure that we don't do | 231 // buttons to be present, so this is just making sure that we don't do |
444 // something completely stupid if that assumption changes later). | 232 // something completely stupid if that assumption changes later). |
445 if (login_status_ == user::LOGGED_IN_LOCKED || | 233 if (login_status_ == user::LOGGED_IN_LOCKED || |
446 lock_fail_timer_.IsRunning() || power_button_down_) | 234 lock_fail_timer_.IsRunning() || power_button_down_) |
447 return; | 235 return; |
448 | 236 |
449 if (down) { | 237 if (down) { |
450 StartLockTimer(); | 238 StartLockTimer(); |
451 } else { | 239 } else { |
452 if (lock_timer_.IsRunning()) { | 240 if (lock_timer_.IsRunning()) { |
453 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 241 animator_->StartAnimation( |
454 ANIMATION_UNDO_SLOW_CLOSE); | 242 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
455 hide_background_layer_timer_.Stop(); | 243 SessionStateAnimator::UNDO_SLOW_CLOSE); |
456 hide_background_layer_timer_.Start( | 244 animator_->DropBackgroundLayer(); |
457 FROM_HERE, | |
458 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | |
459 this, &PowerButtonController::HideBackgroundLayer); | |
460 lock_timer_.Stop(); | 245 lock_timer_.Stop(); |
461 } | 246 } |
462 } | 247 } |
463 } | 248 } |
464 | 249 |
465 void PowerButtonController::RequestShutdown() { | 250 void PowerButtonController::RequestShutdown() { |
466 if (!shutting_down_) | 251 if (!shutting_down_) |
467 StartShutdownAnimationAndRequestShutdown(); | 252 StartShutdownAnimationAndRequestShutdown(); |
468 } | 253 } |
469 | 254 |
470 void PowerButtonController::OnRootWindowResized(const aura::RootWindow* root, | |
471 const gfx::Size& new_size) { | |
472 if (background_layer_.get()) | |
473 background_layer_->SetBounds(gfx::Rect(root->bounds().size())); | |
474 } | |
475 | |
476 void PowerButtonController::OnRootWindowHostCloseRequested( | 255 void PowerButtonController::OnRootWindowHostCloseRequested( |
477 const aura::RootWindow*) { | 256 const aura::RootWindow*) { |
478 if(Shell::GetInstance() && Shell::GetInstance()->delegate()) | 257 if(Shell::GetInstance() && Shell::GetInstance()->delegate()) |
479 Shell::GetInstance()->delegate()->Exit(); | 258 Shell::GetInstance()->delegate()->Exit(); |
480 } | 259 } |
481 | 260 |
482 bool PowerButtonController::LoggedInAsNonGuest() const { | 261 bool PowerButtonController::LoggedInAsNonGuest() const { |
483 if (login_status_ == user::LOGGED_IN_NONE) | 262 if (login_status_ == user::LOGGED_IN_NONE) |
484 return false; | 263 return false; |
485 if (login_status_ == user::LOGGED_IN_GUEST) | 264 if (login_status_ == user::LOGGED_IN_GUEST) |
486 return false; | 265 return false; |
487 // TODO(mukai): think about kiosk mode. | 266 // TODO(mukai): think about kiosk mode. |
488 return true; | 267 return true; |
489 } | 268 } |
490 | 269 |
491 void PowerButtonController::OnLockTimeout() { | 270 void PowerButtonController::OnLockTimeout() { |
492 delegate_->RequestLockScreen(); | 271 delegate_->RequestLockScreen(); |
493 lock_fail_timer_.Start( | 272 lock_fail_timer_.Start( |
494 FROM_HERE, | 273 FROM_HERE, |
495 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | 274 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), |
496 this, &PowerButtonController::OnLockFailTimeout); | 275 this, &PowerButtonController::OnLockFailTimeout); |
497 } | 276 } |
498 | 277 |
499 void PowerButtonController::OnLockFailTimeout() { | 278 void PowerButtonController::OnLockFailTimeout() { |
500 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); | 279 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); |
501 LOG(ERROR) << "Screen lock request timed out"; | 280 LOG(ERROR) << "Screen lock request timed out"; |
502 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 281 animator_->StartAnimation( |
503 ANIMATION_RESTORE); | 282 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
504 HideBackgroundLayer(); | 283 SessionStateAnimator::RESTORE); |
284 animator_->HideBackgroundLayer(); | |
505 } | 285 } |
506 | 286 |
507 void PowerButtonController::OnLockToShutdownTimeout() { | 287 void PowerButtonController::OnLockToShutdownTimeout() { |
508 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); | 288 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); |
509 StartShutdownTimer(); | 289 StartShutdownTimer(); |
510 } | 290 } |
511 | 291 |
512 void PowerButtonController::OnShutdownTimeout() { | 292 void PowerButtonController::OnShutdownTimeout() { |
513 if (!shutting_down_) | 293 if (!shutting_down_) |
514 StartShutdownAnimationAndRequestShutdown(); | 294 StartShutdownAnimationAndRequestShutdown(); |
515 } | 295 } |
516 | 296 |
517 void PowerButtonController::OnRealShutdownTimeout() { | 297 void PowerButtonController::OnRealShutdownTimeout() { |
518 DCHECK(shutting_down_); | 298 DCHECK(shutting_down_); |
519 delegate_->RequestShutdown(); | 299 delegate_->RequestShutdown(); |
520 } | 300 } |
521 | 301 |
522 void PowerButtonController::StartLockTimer() { | 302 void PowerButtonController::StartLockTimer() { |
523 ShowBackgroundLayer(); | 303 animator_->ShowBackgroundLayer(); |
524 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 304 animator_->StartAnimation( |
525 ANIMATION_SLOW_CLOSE); | 305 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
306 SessionStateAnimator::SLOW_CLOSE); | |
526 lock_timer_.Stop(); | 307 lock_timer_.Stop(); |
527 lock_timer_.Start(FROM_HERE, | 308 lock_timer_.Start(FROM_HERE, |
528 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs), | 309 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs), |
529 this, &PowerButtonController::OnLockTimeout); | 310 this, &PowerButtonController::OnLockTimeout); |
530 } | 311 } |
531 | 312 |
532 void PowerButtonController::StartShutdownTimer() { | 313 void PowerButtonController::StartShutdownTimer() { |
533 ShowBackgroundLayer(); | 314 animator_->ShowBackgroundLayer(); |
534 StartAnimation(ALL_CONTAINERS, ANIMATION_SLOW_CLOSE); | 315 animator_->StartAnimation( |
316 SessionStateAnimator::ALL_CONTAINERS, | |
317 SessionStateAnimator::SLOW_CLOSE); | |
535 shutdown_timer_.Stop(); | 318 shutdown_timer_.Stop(); |
536 shutdown_timer_.Start( | 319 shutdown_timer_.Start( |
537 FROM_HERE, | 320 FROM_HERE, |
538 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), | 321 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), |
539 this, &PowerButtonController::OnShutdownTimeout); | 322 this, &PowerButtonController::OnShutdownTimeout); |
540 } | 323 } |
541 | 324 |
542 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { | 325 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { |
543 DCHECK(!shutting_down_); | 326 DCHECK(!shutting_down_); |
544 shutting_down_ = true; | 327 shutting_down_ = true; |
545 | 328 |
546 Shell* shell = ash::Shell::GetInstance(); | 329 Shell* shell = ash::Shell::GetInstance(); |
547 shell->env_filter()->set_update_cursor_visibility(false); | 330 shell->env_filter()->set_update_cursor_visibility(false); |
548 shell->cursor_manager()->ShowCursor(false); | 331 shell->cursor_manager()->ShowCursor(false); |
549 | 332 |
550 ShowBackgroundLayer(); | 333 animator_->ShowBackgroundLayer(); |
551 if (login_status_ != user::LOGGED_IN_NONE) { | 334 if (login_status_ != user::LOGGED_IN_NONE) { |
552 // Hide the other containers before starting the animation. | 335 // Hide the other containers before starting the animation. |
553 // ANIMATION_FAST_CLOSE will make the screen locker windows partially | 336 // FAST_CLOSE will make the screen locker windows partially |
554 // transparent, and we don't want the other windows to show through. | 337 // transparent, and we don't want the other windows to show through. |
555 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 338 animator_->StartAnimation( |
556 ANIMATION_HIDE); | 339 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
557 StartAnimation(SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_FAST_CLOSE); | 340 SessionStateAnimator::HIDE); |
341 animator_->StartAnimation( | |
342 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
343 SessionStateAnimator::FAST_CLOSE); | |
558 } else { | 344 } else { |
559 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE); | 345 animator_->StartAnimation(SessionStateAnimator::ALL_CONTAINERS, |
346 SessionStateAnimator::FAST_CLOSE); | |
560 } | 347 } |
561 | 348 |
562 real_shutdown_timer_.Start( | 349 real_shutdown_timer_.Start( |
563 FROM_HERE, | 350 FROM_HERE, |
564 base::TimeDelta::FromMilliseconds( | 351 base::TimeDelta::FromMilliseconds( |
565 kFastCloseAnimMs + kShutdownRequestDelayMs), | 352 kFastCloseAnimMs + kShutdownRequestDelayMs), |
566 this, &PowerButtonController::OnRealShutdownTimeout); | 353 this, &PowerButtonController::OnRealShutdownTimeout); |
567 } | 354 } |
568 | 355 |
569 void PowerButtonController::ShowBackgroundLayer() { | |
570 if (hide_background_layer_timer_.IsRunning()) | |
571 hide_background_layer_timer_.Stop(); | |
572 | |
573 if (!background_layer_.get()) { | |
574 background_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | |
575 background_layer_->SetColor(SK_ColorBLACK); | |
576 | |
577 ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer(); | |
578 background_layer_->SetBounds(root_layer->bounds()); | |
579 root_layer->Add(background_layer_.get()); | |
580 root_layer->StackAtBottom(background_layer_.get()); | |
581 } | |
582 background_layer_->SetVisible(true); | |
583 } | |
584 | |
585 void PowerButtonController::HideBackgroundLayer() { | |
586 background_layer_.reset(); | |
587 } | |
588 | |
589 } // namespace ash | 356 } // namespace ash |
OLD | NEW |