| 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/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 void PowerButtonController::OnLockStateChange(bool locked) { | 333 void PowerButtonController::OnLockStateChange(bool locked) { |
| 334 if (shutting_down_ || locked_ == locked) | 334 if (shutting_down_ || locked_ == locked) |
| 335 return; | 335 return; |
| 336 | 336 |
| 337 locked_ = locked; | 337 locked_ = locked; |
| 338 if (locked) { | 338 if (locked) { |
| 339 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); | 339 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); |
| 340 lock_timer_.Stop(); | 340 lock_timer_.Stop(); |
| 341 lock_fail_timer_.Stop(); | 341 lock_fail_timer_.Stop(); |
| 342 | 342 |
| 343 #if !defined(CHROMEOS_LEGACY_POWER_BUTTON) |
| 343 if (power_button_down_) { | 344 if (power_button_down_) { |
| 344 lock_to_shutdown_timer_.Stop(); | 345 lock_to_shutdown_timer_.Stop(); |
| 345 lock_to_shutdown_timer_.Start( | 346 lock_to_shutdown_timer_.Start( |
| 346 FROM_HERE, | 347 FROM_HERE, |
| 347 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 348 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
| 348 this, &PowerButtonController::OnLockToShutdownTimeout); | 349 this, &PowerButtonController::OnLockToShutdownTimeout); |
| 349 } | 350 } |
| 351 #endif |
| 350 } else { | 352 } else { |
| 351 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 353 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 352 ANIMATION_RESTORE); | 354 ANIMATION_RESTORE); |
| 353 HideBackgroundLayer(); | 355 HideBackgroundLayer(); |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 | 358 |
| 357 void PowerButtonController::OnStartingLock() { | 359 void PowerButtonController::OnStartingLock() { |
| 358 if (shutting_down_ || locked_) | 360 if (shutting_down_ || locked_) |
| 359 return; | 361 return; |
| 360 | 362 |
| 361 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 363 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 362 ANIMATION_FAST_CLOSE); | 364 ANIMATION_FAST_CLOSE); |
| 363 | 365 |
| 364 // Hide the screen locker containers so we can make them fade in later. | 366 // Hide the screen locker containers so we can make them fade in later. |
| 365 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); | 367 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); |
| 366 } | 368 } |
| 367 | 369 |
| 368 void PowerButtonController::OnPowerButtonEvent( | 370 void PowerButtonController::OnPowerButtonEvent( |
| 369 bool down, const base::TimeTicks& timestamp) { | 371 bool down, const base::TimeTicks& timestamp) { |
| 370 power_button_down_ = down; | 372 power_button_down_ = down; |
| 371 | 373 |
| 372 if (shutting_down_) | 374 if (shutting_down_) |
| 373 return; | 375 return; |
| 374 | 376 |
| 377 #if defined(CHROMEOS_LEGACY_POWER_BUTTON) |
| 378 // If power button releases won't get reported correctly because we're not |
| 379 // running on official hardware, just lock the screen or shut down |
| 380 // immediately. |
| 381 if (down) { |
| 382 ShowBackgroundLayer(); |
| 383 if (logged_in_as_non_guest_ && !locked_) { |
| 384 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 385 ANIMATION_SLOW_CLOSE); |
| 386 OnLockTimeout(); |
| 387 } else { |
| 388 OnShutdownTimeout(); |
| 389 } |
| 390 } |
| 391 #else |
| 375 if (down) { | 392 if (down) { |
| 376 // If we already have a pending request to lock the screen, wait. | 393 // If we already have a pending request to lock the screen, wait. |
| 377 if (lock_fail_timer_.IsRunning()) | 394 if (lock_fail_timer_.IsRunning()) |
| 378 return; | 395 return; |
| 379 | 396 |
| 380 if (logged_in_as_non_guest_ && !locked_) | 397 if (logged_in_as_non_guest_ && !locked_) |
| 381 StartLockTimer(); | 398 StartLockTimer(); |
| 382 else | 399 else |
| 383 StartShutdownTimer(); | 400 StartShutdownTimer(); |
| 384 } else { // Button is up. | 401 } else { // Button is up. |
| 385 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) | 402 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) |
| 386 StartAnimation( | 403 StartAnimation( |
| 387 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, | 404 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, |
| 388 ANIMATION_UNDO_SLOW_CLOSE); | 405 ANIMATION_UNDO_SLOW_CLOSE); |
| 389 | 406 |
| 390 // Drop the background layer after the undo animation finishes. | 407 // Drop the background layer after the undo animation finishes. |
| 391 if (lock_timer_.IsRunning() || | 408 if (lock_timer_.IsRunning() || |
| 392 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest_)) { | 409 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest_)) { |
| 393 hide_background_layer_timer_.Stop(); | 410 hide_background_layer_timer_.Stop(); |
| 394 hide_background_layer_timer_.Start( | 411 hide_background_layer_timer_.Start( |
| 395 FROM_HERE, | 412 FROM_HERE, |
| 396 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 413 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
| 397 this, &PowerButtonController::HideBackgroundLayer); | 414 this, &PowerButtonController::HideBackgroundLayer); |
| 398 } | 415 } |
| 399 | 416 |
| 400 lock_timer_.Stop(); | 417 lock_timer_.Stop(); |
| 401 shutdown_timer_.Stop(); | 418 shutdown_timer_.Stop(); |
| 402 lock_to_shutdown_timer_.Stop(); | 419 lock_to_shutdown_timer_.Stop(); |
| 403 } | 420 } |
| 421 #endif |
| 404 } | 422 } |
| 405 | 423 |
| 406 void PowerButtonController::OnLockButtonEvent( | 424 void PowerButtonController::OnLockButtonEvent( |
| 407 bool down, const base::TimeTicks& timestamp) { | 425 bool down, const base::TimeTicks& timestamp) { |
| 408 lock_button_down_ = down; | 426 lock_button_down_ = down; |
| 409 | 427 |
| 410 if (shutting_down_ || !logged_in_as_non_guest_) | 428 if (shutting_down_ || !logged_in_as_non_guest_) |
| 411 return; | 429 return; |
| 412 | 430 |
| 413 // Bail if we're already locked or are in the process of locking. Also give | 431 // Bail if we're already locked or are in the process of locking. Also give |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 root_layer->StackAtBottom(background_layer_.get()); | 528 root_layer->StackAtBottom(background_layer_.get()); |
| 511 } | 529 } |
| 512 background_layer_->SetVisible(true); | 530 background_layer_->SetVisible(true); |
| 513 } | 531 } |
| 514 | 532 |
| 515 void PowerButtonController::HideBackgroundLayer() { | 533 void PowerButtonController::HideBackgroundLayer() { |
| 516 background_layer_.reset(); | 534 background_layer_.reset(); |
| 517 } | 535 } |
| 518 | 536 |
| 519 } // namespace ash | 537 } // namespace ash |
| OLD | NEW |