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/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "base/command_line.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/time.h" | 12 #include "base/time.h" |
11 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
12 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
14 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/compositor/layer.h" | 17 #include "ui/gfx/compositor/layer.h" |
16 #include "ui/gfx/compositor/layer_animation_element.h" | 18 #include "ui/gfx/compositor/layer_animation_element.h" |
17 #include "ui/gfx/compositor/layer_animation_sequence.h" | 19 #include "ui/gfx/compositor/layer_animation_sequence.h" |
18 #include "ui/gfx/compositor/layer_animator.h" | 20 #include "ui/gfx/compositor/layer_animator.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 315 |
314 private: | 316 private: |
315 DISALLOW_COPY_AND_ASSIGN(BackgroundLayerDelegate); | 317 DISALLOW_COPY_AND_ASSIGN(BackgroundLayerDelegate); |
316 }; | 318 }; |
317 | 319 |
318 PowerButtonController::PowerButtonController() | 320 PowerButtonController::PowerButtonController() |
319 : logged_in_as_non_guest_(false), | 321 : logged_in_as_non_guest_(false), |
320 locked_(false), | 322 locked_(false), |
321 power_button_down_(false), | 323 power_button_down_(false), |
322 lock_button_down_(false), | 324 lock_button_down_(false), |
323 shutting_down_(false) { | 325 shutting_down_(false), |
| 326 has_legacy_power_button_( |
| 327 CommandLine::ForCurrentProcess()->HasSwitch( |
| 328 switches::kAuraLegacyPowerButton)) { |
324 } | 329 } |
325 | 330 |
326 PowerButtonController::~PowerButtonController() { | 331 PowerButtonController::~PowerButtonController() { |
327 } | 332 } |
328 | 333 |
329 void PowerButtonController::OnLoginStateChange(bool logged_in, bool is_guest) { | 334 void PowerButtonController::OnLoginStateChange(bool logged_in, bool is_guest) { |
330 logged_in_as_non_guest_ = logged_in && !is_guest; | 335 logged_in_as_non_guest_ = logged_in && !is_guest; |
331 } | 336 } |
332 | 337 |
333 void PowerButtonController::OnLockStateChange(bool locked) { | 338 void PowerButtonController::OnLockStateChange(bool locked) { |
334 if (shutting_down_ || locked_ == locked) | 339 if (shutting_down_ || locked_ == locked) |
335 return; | 340 return; |
336 | 341 |
337 locked_ = locked; | 342 locked_ = locked; |
338 if (locked) { | 343 if (locked) { |
339 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); | 344 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); |
340 lock_timer_.Stop(); | 345 lock_timer_.Stop(); |
341 lock_fail_timer_.Stop(); | 346 lock_fail_timer_.Stop(); |
342 | 347 |
343 #if !defined(CHROMEOS_LEGACY_POWER_BUTTON) | 348 if (!has_legacy_power_button_ && power_button_down_) { |
344 if (power_button_down_) { | |
345 lock_to_shutdown_timer_.Stop(); | 349 lock_to_shutdown_timer_.Stop(); |
346 lock_to_shutdown_timer_.Start( | 350 lock_to_shutdown_timer_.Start( |
347 FROM_HERE, | 351 FROM_HERE, |
348 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 352 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
349 this, &PowerButtonController::OnLockToShutdownTimeout); | 353 this, &PowerButtonController::OnLockToShutdownTimeout); |
350 } | 354 } |
351 #endif | |
352 } else { | 355 } else { |
353 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 356 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
354 ANIMATION_RESTORE); | 357 ANIMATION_RESTORE); |
355 HideBackgroundLayer(); | 358 HideBackgroundLayer(); |
356 } | 359 } |
357 } | 360 } |
358 | 361 |
359 void PowerButtonController::OnStartingLock() { | 362 void PowerButtonController::OnStartingLock() { |
360 if (shutting_down_ || locked_) | 363 if (shutting_down_ || locked_) |
361 return; | 364 return; |
362 | 365 |
363 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 366 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
364 ANIMATION_FAST_CLOSE); | 367 ANIMATION_FAST_CLOSE); |
365 | 368 |
366 // Hide the screen locker containers so we can make them fade in later. | 369 // Hide the screen locker containers so we can make them fade in later. |
367 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); | 370 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); |
368 } | 371 } |
369 | 372 |
370 void PowerButtonController::OnPowerButtonEvent( | 373 void PowerButtonController::OnPowerButtonEvent( |
371 bool down, const base::TimeTicks& timestamp) { | 374 bool down, const base::TimeTicks& timestamp) { |
372 power_button_down_ = down; | 375 power_button_down_ = down; |
373 | 376 |
374 if (shutting_down_) | 377 if (shutting_down_) |
375 return; | 378 return; |
376 | 379 |
377 #if defined(CHROMEOS_LEGACY_POWER_BUTTON) | 380 if (has_legacy_power_button_) { |
378 // If power button releases won't get reported correctly because we're not | 381 // 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 | 382 // running on official hardware, just lock the screen or shut down |
380 // immediately. | 383 // immediately. |
381 if (down) { | 384 if (down) { |
382 ShowBackgroundLayer(); | 385 ShowBackgroundLayer(); |
383 if (logged_in_as_non_guest_ && !locked_) { | 386 if (logged_in_as_non_guest_ && !locked_) { |
384 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 387 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
385 ANIMATION_SLOW_CLOSE); | 388 ANIMATION_SLOW_CLOSE); |
386 OnLockTimeout(); | 389 OnLockTimeout(); |
387 } else { | 390 } else { |
388 OnShutdownTimeout(); | 391 OnShutdownTimeout(); |
| 392 } |
| 393 } |
| 394 } else { // !has_legacy_power_button_ |
| 395 if (down) { |
| 396 // If we already have a pending request to lock the screen, wait. |
| 397 if (lock_fail_timer_.IsRunning()) |
| 398 return; |
| 399 |
| 400 if (logged_in_as_non_guest_ && !locked_) |
| 401 StartLockTimer(); |
| 402 else |
| 403 StartShutdownTimer(); |
| 404 } else { // Button is up. |
| 405 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) |
| 406 StartAnimation( |
| 407 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, |
| 408 ANIMATION_UNDO_SLOW_CLOSE); |
| 409 |
| 410 // Drop the background layer after the undo animation finishes. |
| 411 if (lock_timer_.IsRunning() || |
| 412 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest_)) { |
| 413 hide_background_layer_timer_.Stop(); |
| 414 hide_background_layer_timer_.Start( |
| 415 FROM_HERE, |
| 416 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
| 417 this, &PowerButtonController::HideBackgroundLayer); |
| 418 } |
| 419 |
| 420 lock_timer_.Stop(); |
| 421 shutdown_timer_.Stop(); |
| 422 lock_to_shutdown_timer_.Stop(); |
389 } | 423 } |
390 } | 424 } |
391 #else | |
392 if (down) { | |
393 // If we already have a pending request to lock the screen, wait. | |
394 if (lock_fail_timer_.IsRunning()) | |
395 return; | |
396 | |
397 if (logged_in_as_non_guest_ && !locked_) | |
398 StartLockTimer(); | |
399 else | |
400 StartShutdownTimer(); | |
401 } else { // Button is up. | |
402 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) | |
403 StartAnimation( | |
404 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, | |
405 ANIMATION_UNDO_SLOW_CLOSE); | |
406 | |
407 // Drop the background layer after the undo animation finishes. | |
408 if (lock_timer_.IsRunning() || | |
409 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest_)) { | |
410 hide_background_layer_timer_.Stop(); | |
411 hide_background_layer_timer_.Start( | |
412 FROM_HERE, | |
413 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | |
414 this, &PowerButtonController::HideBackgroundLayer); | |
415 } | |
416 | |
417 lock_timer_.Stop(); | |
418 shutdown_timer_.Stop(); | |
419 lock_to_shutdown_timer_.Stop(); | |
420 } | |
421 #endif | |
422 } | 425 } |
423 | 426 |
424 void PowerButtonController::OnLockButtonEvent( | 427 void PowerButtonController::OnLockButtonEvent( |
425 bool down, const base::TimeTicks& timestamp) { | 428 bool down, const base::TimeTicks& timestamp) { |
426 lock_button_down_ = down; | 429 lock_button_down_ = down; |
427 | 430 |
428 if (shutting_down_ || !logged_in_as_non_guest_) | 431 if (shutting_down_ || !logged_in_as_non_guest_) |
429 return; | 432 return; |
430 | 433 |
431 // Bail if we're already locked or are in the process of locking. Also give | 434 // 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... |
528 root_layer->StackAtBottom(background_layer_.get()); | 531 root_layer->StackAtBottom(background_layer_.get()); |
529 } | 532 } |
530 background_layer_->SetVisible(true); | 533 background_layer_->SetVisible(true); |
531 } | 534 } |
532 | 535 |
533 void PowerButtonController::HideBackgroundLayer() { | 536 void PowerButtonController::HideBackgroundLayer() { |
534 background_layer_.reset(); | 537 background_layer_.reset(); |
535 } | 538 } |
536 | 539 |
537 } // namespace ash | 540 } // namespace ash |
OLD | NEW |