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