OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 #include "ash/wm/lock_state_controller_impl2.h" | |
6 | |
7 #include "ash/ash_switches.h" | |
8 #include "ash/cancel_mode.h" | |
9 #include "ash/shell.h" | |
10 #include "ash/shell_delegate.h" | |
11 #include "ash/shell_window_ids.h" | |
12 #include "ash/wm/session_state_animator.h" | |
13 #include "base/bind_helpers.h" | |
14 #include "base/command_line.h" | |
15 #include "base/sys_info.h" | |
16 #include "base/timer/timer.h" | |
17 #include "ui/aura/root_window.h" | |
18 #include "ui/compositor/layer_animation_sequence.h" | |
19 #include "ui/compositor/scoped_layer_animation_settings.h" | |
20 #include "ui/views/corewm/compound_event_filter.h" | |
21 | |
22 namespace ash { | |
23 | |
24 namespace { | |
25 | |
26 aura::Window* GetBackground() { | |
27 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | |
28 return Shell::GetContainer(root_window, | |
29 internal::kShellWindowId_DesktopBackgroundContainer); | |
30 } | |
31 | |
32 bool IsBackgroundHidden() { | |
33 return !GetBackground()->IsVisible(); | |
34 } | |
35 | |
36 void ShowBackground() { | |
37 ui::ScopedLayerAnimationSettings settings( | |
38 GetBackground()->layer()->GetAnimator()); | |
39 settings.SetTransitionDuration(base::TimeDelta()); | |
40 GetBackground()->Show(); | |
41 } | |
42 | |
43 void HideBackground() { | |
44 ui::ScopedLayerAnimationSettings settings( | |
45 GetBackground()->layer()->GetAnimator()); | |
46 settings.SetTransitionDuration(base::TimeDelta()); | |
47 GetBackground()->Hide(); | |
48 } | |
49 | |
50 // This observer is intended to use in cases when some action has to be taken | |
51 // once some animation successfully completes (i.e. it was not aborted). | |
52 // Observer will count a number of sequences it is attached to, and a number of | |
53 // finished sequences (either Ended or Aborted). Once these two numbers are | |
54 // equal, observer will delete itself, calling callback passed to constructor if | |
55 // there were no aborted animations. | |
56 // This way it can be either used to wait for some animation to be finished in | |
57 // multiple layers, to wait once a sequence of animations is finished in one | |
58 // layer or the mixture of both. | |
59 class AnimationFinishedObserver : public ui::LayerAnimationObserver { | |
60 public: | |
61 explicit AnimationFinishedObserver(base::Closure &callback) | |
62 : callback_(callback), | |
63 sequences_attached_(0), | |
64 sequences_completed_(0), | |
65 paused_(false) { | |
66 } | |
67 | |
68 // Pauses observer: no checks will be made while paused. It can be used when | |
69 // a sequence has some immediate animations in the beginning, and for | |
70 // animations that can be tested with flag that makes all animations | |
71 // immediate. | |
72 void Pause() { | |
73 paused_ = true; | |
74 } | |
75 | |
76 // Unpauses observer. It does a check and calls callback if conditions are | |
77 // met. | |
78 void Unpause() { | |
79 if (!paused_) | |
80 return; | |
81 paused_ = false; | |
82 if (sequences_completed_ == sequences_attached_) { | |
83 callback_.Run(); | |
84 delete this; | |
85 } | |
86 } | |
87 | |
88 private: | |
89 virtual ~AnimationFinishedObserver() { | |
90 } | |
91 | |
92 // LayerAnimationObserver implementation | |
93 virtual void OnLayerAnimationEnded( | |
94 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
95 sequences_completed_++; | |
96 if ((sequences_completed_ == sequences_attached_) && !paused_) { | |
97 callback_.Run(); | |
98 delete this; | |
99 } | |
100 } | |
101 | |
102 virtual void OnLayerAnimationAborted( | |
103 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
104 sequences_completed_++; | |
105 if ((sequences_completed_ == sequences_attached_) && !paused_) | |
106 delete this; | |
107 } | |
108 | |
109 virtual void OnLayerAnimationScheduled( | |
110 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
111 } | |
112 | |
113 virtual void OnAttachedToSequence( | |
114 ui::LayerAnimationSequence* sequence) OVERRIDE { | |
115 LayerAnimationObserver::OnAttachedToSequence(sequence); | |
116 sequences_attached_++; | |
117 } | |
118 | |
119 // Callback to be called. | |
120 base::Closure callback_; | |
121 | |
122 // Number of sequences this observer was attached to. | |
123 int sequences_attached_; | |
124 | |
125 // Number of sequences either ended or aborted. | |
126 int sequences_completed_; | |
127 | |
128 bool paused_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(AnimationFinishedObserver); | |
131 }; | |
132 | |
133 } // namespace | |
134 | |
135 LockStateControllerImpl2::TestApi::TestApi( | |
136 LockStateControllerImpl2* controller) | |
137 : controller_(controller) { | |
138 } | |
139 | |
140 LockStateControllerImpl2::TestApi::~TestApi() { | |
141 } | |
142 | |
143 LockStateControllerImpl2::LockStateControllerImpl2() | |
144 : login_status_(user::LOGGED_IN_NONE), | |
145 system_is_locked_(false), | |
146 shutting_down_(false), | |
147 shutdown_after_lock_(false), | |
148 animating_lock_(false), | |
149 can_cancel_lock_animation_(false) { | |
150 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); | |
151 } | |
152 | |
153 LockStateControllerImpl2::~LockStateControllerImpl2() { | |
154 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); | |
155 } | |
156 | |
157 void LockStateControllerImpl2::OnLoginStateChanged( | |
158 user::LoginStatus status) { | |
159 if (status != user::LOGGED_IN_LOCKED) | |
160 login_status_ = status; | |
161 system_is_locked_ = (status == user::LOGGED_IN_LOCKED); | |
162 } | |
163 | |
164 void LockStateControllerImpl2::OnAppTerminating() { | |
165 // If we hear that Chrome is exiting but didn't request it ourselves, all we | |
166 // can really hope for is that we'll have time to clear the screen. | |
167 // This is also the case when the user signs off. | |
168 if (!shutting_down_) { | |
169 shutting_down_ = true; | |
170 Shell* shell = ash::Shell::GetInstance(); | |
171 shell->env_filter()->set_cursor_hidden_by_filter(false); | |
172 shell->cursor_manager()->HideCursor(); | |
173 animator_->StartAnimation( | |
174 internal::SessionStateAnimator::kAllContainersMask, | |
175 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
176 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
177 } | |
178 } | |
179 | |
180 void LockStateControllerImpl2::OnLockStateChanged(bool locked) { | |
181 if (shutting_down_ || (system_is_locked_ == locked)) | |
182 return; | |
183 | |
184 system_is_locked_ = locked; | |
185 | |
186 if (locked) { | |
187 StartPostLockAnimation(); | |
188 lock_fail_timer_.Stop(); | |
189 } else { | |
190 StartUnlockAnimationAfterUIDestroyed(); | |
191 } | |
192 } | |
193 | |
194 void LockStateControllerImpl2::SetLockScreenDisplayedCallback( | |
195 base::Closure& callback) { | |
196 lock_screen_displayed_callback_ = callback; | |
197 } | |
198 | |
199 void LockStateControllerImpl2::OnStartingLock() { | |
200 if (shutting_down_ || system_is_locked_) | |
201 return; | |
202 if (animating_lock_) | |
203 return; | |
204 StartImmediatePreLockAnimation(false /* request_lock_on_completion */); | |
205 } | |
206 | |
207 void LockStateControllerImpl2::StartLockAnimationAndLockImmediately() { | |
208 if (animating_lock_) | |
209 return; | |
210 StartImmediatePreLockAnimation(true /* request_lock_on_completion */); | |
211 } | |
212 | |
213 void LockStateControllerImpl2::StartLockAnimation( | |
214 bool shutdown_after_lock) { | |
215 if (animating_lock_) | |
216 return; | |
217 shutdown_after_lock_ = shutdown_after_lock; | |
218 can_cancel_lock_animation_ = true; | |
219 | |
220 StartCancellablePreLockAnimation(); | |
221 } | |
222 | |
223 bool LockStateControllerImpl2::LockRequested() { | |
224 return lock_fail_timer_.IsRunning(); | |
225 } | |
226 | |
227 bool LockStateControllerImpl2::ShutdownRequested() { | |
228 return shutting_down_; | |
229 } | |
230 | |
231 bool LockStateControllerImpl2::CanCancelLockAnimation() { | |
232 return can_cancel_lock_animation_; | |
233 } | |
234 | |
235 void LockStateControllerImpl2::CancelLockAnimation() { | |
236 if (!CanCancelLockAnimation()) | |
237 return; | |
238 shutdown_after_lock_ = false; | |
239 animating_lock_ = false; | |
240 CancelPreLockAnimation(); | |
241 } | |
242 | |
243 bool LockStateControllerImpl2::CanCancelShutdownAnimation() { | |
244 return pre_shutdown_timer_.IsRunning() || | |
245 shutdown_after_lock_ || | |
246 lock_to_shutdown_timer_.IsRunning(); | |
247 } | |
248 | |
249 void LockStateControllerImpl2::StartShutdownAnimation() { | |
250 StartCancellableShutdownAnimation(); | |
251 } | |
252 | |
253 void LockStateControllerImpl2::CancelShutdownAnimation() { | |
254 if (!CanCancelShutdownAnimation()) | |
255 return; | |
256 if (lock_to_shutdown_timer_.IsRunning()) { | |
257 lock_to_shutdown_timer_.Stop(); | |
258 return; | |
259 } | |
260 if (shutdown_after_lock_) { | |
261 shutdown_after_lock_ = false; | |
262 return; | |
263 } | |
264 | |
265 animator_->StartGlobalAnimation( | |
266 internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS, | |
267 internal::SessionStateAnimator::ANIMATION_SPEED_REVERT_SHUTDOWN); | |
268 pre_shutdown_timer_.Stop(); | |
269 } | |
270 | |
271 void LockStateControllerImpl2::RequestShutdown() { | |
272 if (!shutting_down_) | |
273 RequestShutdownImpl(); | |
274 } | |
275 | |
276 void LockStateControllerImpl2::RequestShutdownImpl() { | |
277 DCHECK(!shutting_down_); | |
278 shutting_down_ = true; | |
279 | |
280 Shell* shell = ash::Shell::GetInstance(); | |
281 shell->env_filter()->set_cursor_hidden_by_filter(false); | |
282 shell->cursor_manager()->HideCursor(); | |
283 | |
284 StartShutdownAnimationImpl(); | |
285 } | |
286 | |
287 void LockStateControllerImpl2::OnRootWindowHostCloseRequested( | |
288 const aura::RootWindow*) { | |
289 Shell::GetInstance()->delegate()->Exit(); | |
290 } | |
291 | |
292 void LockStateControllerImpl2::OnLockFailTimeout() { | |
293 DCHECK(!system_is_locked_); | |
294 // Undo lock animation. | |
295 StartUnlockAnimationAfterUIDestroyed(); | |
296 } | |
297 | |
298 void LockStateControllerImpl2::StartLockToShutdownTimer() { | |
299 shutdown_after_lock_ = false; | |
300 lock_to_shutdown_timer_.Stop(); | |
301 lock_to_shutdown_timer_.Start( | |
302 FROM_HERE, | |
303 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | |
304 this, &LockStateControllerImpl2::OnLockToShutdownTimeout); | |
305 } | |
306 | |
307 void LockStateControllerImpl2::OnLockToShutdownTimeout() { | |
308 DCHECK(system_is_locked_); | |
309 StartCancellableShutdownAnimation(); | |
310 } | |
311 | |
312 void LockStateControllerImpl2::StartCancellableShutdownAnimation() { | |
313 Shell* shell = ash::Shell::GetInstance(); | |
314 // Hide cursor, but let it reappear if the mouse moves. | |
315 shell->env_filter()->set_cursor_hidden_by_filter(true); | |
316 shell->cursor_manager()->HideCursor(); | |
317 | |
318 animator_->StartGlobalAnimation( | |
319 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, | |
320 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | |
321 StartPreShutdownAnimationTimer(); | |
322 } | |
323 | |
324 void LockStateControllerImpl2::StartShutdownAnimationImpl() { | |
325 animator_->StartGlobalAnimation( | |
326 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, | |
327 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | |
328 StartRealShutdownTimer(true); | |
329 } | |
330 | |
331 void LockStateControllerImpl2::StartPreShutdownAnimationTimer() { | |
332 pre_shutdown_timer_.Stop(); | |
333 pre_shutdown_timer_.Start( | |
334 FROM_HERE, | |
335 animator_-> | |
336 GetDuration(internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN), | |
337 this, | |
338 &LockStateControllerImpl2::OnPreShutdownAnimationTimeout); | |
339 } | |
340 | |
341 void LockStateControllerImpl2::OnPreShutdownAnimationTimeout() { | |
342 shutting_down_ = true; | |
343 | |
344 Shell* shell = ash::Shell::GetInstance(); | |
345 shell->env_filter()->set_cursor_hidden_by_filter(false); | |
346 shell->cursor_manager()->HideCursor(); | |
347 | |
348 StartRealShutdownTimer(false); | |
349 } | |
350 | |
351 void LockStateControllerImpl2::StartRealShutdownTimer( | |
352 bool with_animation_time) { | |
353 base::TimeDelta duration = | |
354 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); | |
355 if (with_animation_time) { | |
356 duration += animator_->GetDuration( | |
357 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | |
358 } | |
359 real_shutdown_timer_.Start( | |
360 FROM_HERE, | |
361 duration, | |
362 this, | |
363 &LockStateControllerImpl2::OnRealShutdownTimeout); | |
364 } | |
365 | |
366 void LockStateControllerImpl2::OnRealShutdownTimeout() { | |
367 DCHECK(shutting_down_); | |
368 #if defined(OS_CHROMEOS) | |
369 if (!base::SysInfo::IsRunningOnChromeOS()) { | |
370 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | |
371 if (delegate) { | |
372 delegate->Exit(); | |
373 return; | |
374 } | |
375 } | |
376 #endif | |
377 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | |
378 UMA_ACCEL_SHUT_DOWN_POWER_BUTTON); | |
379 delegate_->RequestShutdown(); | |
380 } | |
381 | |
382 void LockStateControllerImpl2::OnLockScreenHide( | |
383 base::Callback<void(void)>& callback) { | |
384 StartUnlockAnimationBeforeUIDestroyed(callback); | |
385 } | |
386 | |
387 void LockStateControllerImpl2::LockAnimationCancelled() { | |
388 can_cancel_lock_animation_ = false; | |
389 RestoreUnlockedProperties(); | |
390 } | |
391 | |
392 void LockStateControllerImpl2::PreLockAnimationFinished( | |
393 bool request_lock) { | |
394 can_cancel_lock_animation_ = false; | |
395 | |
396 if (request_lock) { | |
397 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | |
398 shutdown_after_lock_ ? | |
399 UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON : | |
400 UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON); | |
401 delegate_->RequestLockScreen(); | |
402 } | |
403 | |
404 lock_fail_timer_.Start( | |
405 FROM_HERE, | |
406 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | |
407 this, | |
408 &LockStateControllerImpl2::OnLockFailTimeout); | |
409 } | |
410 | |
411 void LockStateControllerImpl2::PostLockAnimationFinished() { | |
412 animating_lock_ = false; | |
413 | |
414 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
415 OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_FINISHED)); | |
416 if (!lock_screen_displayed_callback_.is_null()) { | |
417 lock_screen_displayed_callback_.Run(); | |
418 lock_screen_displayed_callback_.Reset(); | |
419 } | |
420 if (shutdown_after_lock_) { | |
421 shutdown_after_lock_ = false; | |
422 StartLockToShutdownTimer(); | |
423 } | |
424 } | |
425 | |
426 void LockStateControllerImpl2:: | |
427 UnlockAnimationAfterUIDestroyedFinished() { | |
428 RestoreUnlockedProperties(); | |
429 } | |
430 | |
431 void LockStateControllerImpl2::StartImmediatePreLockAnimation( | |
432 bool request_lock_on_completion) { | |
433 animating_lock_ = true; | |
434 | |
435 StoreUnlockedProperties(); | |
436 | |
437 base::Closure next_animation_starter = | |
438 base::Bind(&LockStateControllerImpl2::PreLockAnimationFinished, | |
439 base::Unretained(this), request_lock_on_completion); | |
440 AnimationFinishedObserver* observer = | |
441 new AnimationFinishedObserver(next_animation_starter); | |
442 | |
443 observer->Pause(); | |
444 | |
445 animator_->StartAnimationWithObserver( | |
446 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
447 internal::SessionStateAnimator::ANIMATION_LIFT, | |
448 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
449 observer); | |
450 animator_->StartAnimationWithObserver( | |
451 internal::SessionStateAnimator::LAUNCHER, | |
452 internal::SessionStateAnimator::ANIMATION_FADE_OUT, | |
453 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
454 observer); | |
455 // Hide the screen locker containers so we can raise them later. | |
456 animator_->StartAnimation( | |
457 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
458 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
459 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
460 AnimateBackgroundAppearanceIfNecessary( | |
461 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
462 observer); | |
463 | |
464 observer->Unpause(); | |
465 | |
466 DispatchCancelMode(); | |
467 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
468 OnLockStateEvent(LockStateObserver::EVENT_LOCK_ANIMATION_STARTED)); | |
469 } | |
470 | |
471 void LockStateControllerImpl2::StartCancellablePreLockAnimation() { | |
472 animating_lock_ = true; | |
473 StoreUnlockedProperties(); | |
474 | |
475 base::Closure next_animation_starter = | |
476 base::Bind(&LockStateControllerImpl2::PreLockAnimationFinished, | |
477 base::Unretained(this), true /* request_lock */); | |
478 AnimationFinishedObserver* observer = | |
479 new AnimationFinishedObserver(next_animation_starter); | |
480 | |
481 observer->Pause(); | |
482 | |
483 animator_->StartAnimationWithObserver( | |
484 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
485 internal::SessionStateAnimator::ANIMATION_LIFT, | |
486 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, | |
487 observer); | |
488 animator_->StartAnimationWithObserver( | |
489 internal::SessionStateAnimator::LAUNCHER, | |
490 internal::SessionStateAnimator::ANIMATION_FADE_OUT, | |
491 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, | |
492 observer); | |
493 // Hide the screen locker containers so we can raise them later. | |
494 animator_->StartAnimation( | |
495 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
496 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
497 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
498 AnimateBackgroundAppearanceIfNecessary( | |
499 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, | |
500 observer); | |
501 | |
502 DispatchCancelMode(); | |
503 FOR_EACH_OBSERVER(LockStateObserver, observers_, | |
504 OnLockStateEvent(LockStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); | |
505 observer->Unpause(); | |
506 } | |
507 | |
508 void LockStateControllerImpl2::CancelPreLockAnimation() { | |
509 base::Closure next_animation_starter = | |
510 base::Bind(&LockStateControllerImpl2::LockAnimationCancelled, | |
511 base::Unretained(this)); | |
512 AnimationFinishedObserver* observer = | |
513 new AnimationFinishedObserver(next_animation_starter); | |
514 | |
515 observer->Pause(); | |
516 | |
517 animator_->StartAnimationWithObserver( | |
518 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
519 internal::SessionStateAnimator::ANIMATION_UNDO_LIFT, | |
520 internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, | |
521 observer); | |
522 animator_->StartAnimationWithObserver( | |
523 internal::SessionStateAnimator::LAUNCHER, | |
524 internal::SessionStateAnimator::ANIMATION_FADE_IN, | |
525 internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, | |
526 observer); | |
527 AnimateBackgroundHidingIfNecessary( | |
528 internal::SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS, | |
529 observer); | |
530 | |
531 observer->Unpause(); | |
532 } | |
533 | |
534 void LockStateControllerImpl2::StartPostLockAnimation() { | |
535 base::Closure next_animation_starter = | |
536 base::Bind(&LockStateControllerImpl2::PostLockAnimationFinished, | |
537 base::Unretained(this)); | |
538 | |
539 AnimationFinishedObserver* observer = | |
540 new AnimationFinishedObserver(next_animation_starter); | |
541 | |
542 observer->Pause(); | |
543 animator_->StartAnimationWithObserver( | |
544 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
545 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN, | |
546 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
547 observer); | |
548 observer->Unpause(); | |
549 } | |
550 | |
551 void LockStateControllerImpl2::StartUnlockAnimationBeforeUIDestroyed( | |
552 base::Closure& callback) { | |
553 animator_->StartAnimationWithCallback( | |
554 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
555 internal::SessionStateAnimator::ANIMATION_LIFT, | |
556 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
557 callback); | |
558 } | |
559 | |
560 void LockStateControllerImpl2::StartUnlockAnimationAfterUIDestroyed() { | |
561 base::Closure next_animation_starter = | |
562 base::Bind( | |
563 &LockStateControllerImpl2:: | |
564 UnlockAnimationAfterUIDestroyedFinished, | |
565 base::Unretained(this)); | |
566 | |
567 AnimationFinishedObserver* observer = | |
568 new AnimationFinishedObserver(next_animation_starter); | |
569 | |
570 observer->Pause(); | |
571 | |
572 animator_->StartAnimationWithObserver( | |
573 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
574 internal::SessionStateAnimator::ANIMATION_DROP, | |
575 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
576 observer); | |
577 animator_->StartAnimationWithObserver( | |
578 internal::SessionStateAnimator::LAUNCHER, | |
579 internal::SessionStateAnimator::ANIMATION_FADE_IN, | |
580 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
581 observer); | |
582 AnimateBackgroundHidingIfNecessary( | |
583 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
584 observer); | |
585 observer->Unpause(); | |
586 } | |
587 | |
588 void LockStateControllerImpl2::StoreUnlockedProperties() { | |
589 if (!unlocked_properties_) { | |
590 unlocked_properties_.reset(new UnlockedStateProperties()); | |
591 unlocked_properties_->background_is_hidden = IsBackgroundHidden(); | |
592 } | |
593 if (unlocked_properties_->background_is_hidden) { | |
594 // Hide background so that it can be animated later. | |
595 animator_->StartAnimation( | |
596 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | |
597 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
598 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
599 ShowBackground(); | |
600 } | |
601 } | |
602 | |
603 void LockStateControllerImpl2::RestoreUnlockedProperties() { | |
604 if (!unlocked_properties_) | |
605 return; | |
606 if (unlocked_properties_->background_is_hidden) { | |
607 HideBackground(); | |
608 // Restore background visibility. | |
609 animator_->StartAnimation( | |
610 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | |
611 internal::SessionStateAnimator::ANIMATION_FADE_IN, | |
612 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
613 } | |
614 unlocked_properties_.reset(); | |
615 } | |
616 | |
617 void LockStateControllerImpl2::AnimateBackgroundAppearanceIfNecessary( | |
618 internal::SessionStateAnimator::AnimationSpeed speed, | |
619 ui::LayerAnimationObserver* observer) { | |
620 if (unlocked_properties_.get() && | |
621 unlocked_properties_->background_is_hidden) { | |
622 animator_->StartAnimationWithObserver( | |
623 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | |
624 internal::SessionStateAnimator::ANIMATION_FADE_IN, | |
625 speed, | |
626 observer); | |
627 } | |
628 } | |
629 | |
630 void LockStateControllerImpl2::AnimateBackgroundHidingIfNecessary( | |
631 internal::SessionStateAnimator::AnimationSpeed speed, | |
632 ui::LayerAnimationObserver* observer) { | |
633 if (unlocked_properties_.get() && | |
634 unlocked_properties_->background_is_hidden) { | |
635 animator_->StartAnimationWithObserver( | |
636 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | |
637 internal::SessionStateAnimator::ANIMATION_FADE_OUT, | |
638 speed, | |
639 observer); | |
640 } | |
641 } | |
642 | |
643 } // namespace ash | |
OLD | NEW |