| 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_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // the animation time to finish. | 65 // the animation time to finish. |
| 66 const int kShutdownRequestDelayMs = 50; | 66 const int kShutdownRequestDelayMs = 50; |
| 67 | 67 |
| 68 // Slightly-smaller size that we scale the screen down to for the pre-lock and | 68 // Slightly-smaller size that we scale the screen down to for the pre-lock and |
| 69 // pre-shutdown states. | 69 // pre-shutdown states. |
| 70 const float kSlowCloseSizeRatio = 0.95f; | 70 const float kSlowCloseSizeRatio = 0.95f; |
| 71 | 71 |
| 72 // Returns the transform that should be applied to containers for the slow-close | 72 // Returns the transform that should be applied to containers for the slow-close |
| 73 // animation. | 73 // animation. |
| 74 ui::Transform GetSlowCloseTransform() { | 74 ui::Transform GetSlowCloseTransform() { |
| 75 gfx::Size root_size = Shell::GetRootWindow()->bounds().size(); | 75 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
| 76 ui::Transform transform; | 76 ui::Transform transform; |
| 77 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); | 77 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); |
| 78 transform.ConcatTranslate( | 78 transform.ConcatTranslate( |
| 79 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), | 79 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), |
| 80 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); | 80 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); |
| 81 return transform; | 81 return transform; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Returns the transform that should be applied to containers for the fast-close | 84 // Returns the transform that should be applied to containers for the fast-close |
| 85 // animation. | 85 // animation. |
| 86 ui::Transform GetFastCloseTransform() { | 86 ui::Transform GetFastCloseTransform() { |
| 87 gfx::Size root_size = Shell::GetRootWindow()->bounds().size(); | 87 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
| 88 ui::Transform transform; | 88 ui::Transform transform; |
| 89 transform.SetScale(0.0, 0.0); | 89 transform.SetScale(0.0, 0.0); |
| 90 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), | 90 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), |
| 91 floor(0.5 * root_size.height() + 0.5)); | 91 floor(0.5 * root_size.height() + 0.5)); |
| 92 return transform; | 92 return transform; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Slowly shrinks |window| to a slightly-smaller size. | 95 // Slowly shrinks |window| to a slightly-smaller size. |
| 96 void StartSlowCloseAnimationForWindow(aura::Window* window) { | 96 void StartSlowCloseAnimationForWindow(aura::Window* window) { |
| 97 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 97 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 PowerButtonController::PowerButtonController() | 283 PowerButtonController::PowerButtonController() |
| 284 : login_status_(user::LOGGED_IN_NONE), | 284 : login_status_(user::LOGGED_IN_NONE), |
| 285 unlocked_login_status_(user::LOGGED_IN_NONE), | 285 unlocked_login_status_(user::LOGGED_IN_NONE), |
| 286 power_button_down_(false), | 286 power_button_down_(false), |
| 287 lock_button_down_(false), | 287 lock_button_down_(false), |
| 288 screen_is_off_(false), | 288 screen_is_off_(false), |
| 289 shutting_down_(false), | 289 shutting_down_(false), |
| 290 has_legacy_power_button_( | 290 has_legacy_power_button_( |
| 291 CommandLine::ForCurrentProcess()->HasSwitch( | 291 CommandLine::ForCurrentProcess()->HasSwitch( |
| 292 switches::kAuraLegacyPowerButton)) { | 292 switches::kAuraLegacyPowerButton)) { |
| 293 Shell::GetInstance()->GetRootWindow()->AddRootWindowObserver(this); | 293 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); |
| 294 } | 294 } |
| 295 | 295 |
| 296 PowerButtonController::~PowerButtonController() { | 296 PowerButtonController::~PowerButtonController() { |
| 297 Shell::GetInstance()->GetRootWindow()->RemoveRootWindowObserver(this); | 297 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void PowerButtonController::OnLoginStateChanged(user::LoginStatus status) { | 300 void PowerButtonController::OnLoginStateChanged(user::LoginStatus status) { |
| 301 login_status_ = status; | 301 login_status_ = status; |
| 302 unlocked_login_status_ = user::LOGGED_IN_NONE; | 302 unlocked_login_status_ = user::LOGGED_IN_NONE; |
| 303 } | 303 } |
| 304 | 304 |
| 305 void PowerButtonController::OnAppTerminating() { | 305 void PowerButtonController::OnAppTerminating() { |
| 306 // If we hear that Chrome is exiting but didn't request it ourselves, all we | 306 // If we hear that Chrome is exiting but didn't request it ourselves, all we |
| 307 // can really hope for is that we'll have time to clear the screen. | 307 // can really hope for is that we'll have time to clear the screen. |
| 308 if (!shutting_down_) { | 308 if (!shutting_down_) { |
| 309 shutting_down_ = true; | 309 shutting_down_ = true; |
| 310 ash::Shell::GetInstance()->root_filter()-> | 310 ash::Shell::GetInstance()->root_filter()-> |
| 311 set_update_cursor_visibility(false); | 311 set_update_cursor_visibility(false); |
| 312 Shell::GetRootWindow()->ShowCursor(false); | 312 Shell::GetPrimaryRootWindow()->ShowCursor(false); |
| 313 ShowBackgroundLayer(); | 313 ShowBackgroundLayer(); |
| 314 StartAnimation(ALL_CONTAINERS, ANIMATION_HIDE); | 314 StartAnimation(ALL_CONTAINERS, ANIMATION_HIDE); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void PowerButtonController::OnLockStateChanged(bool locked) { | 318 void PowerButtonController::OnLockStateChanged(bool locked) { |
| 319 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) | 319 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) |
| 320 return; | 320 return; |
| 321 | 321 |
| 322 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { | 322 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 FROM_HERE, | 526 FROM_HERE, |
| 527 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), | 527 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), |
| 528 this, &PowerButtonController::OnShutdownTimeout); | 528 this, &PowerButtonController::OnShutdownTimeout); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { | 531 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { |
| 532 DCHECK(!shutting_down_); | 532 DCHECK(!shutting_down_); |
| 533 shutting_down_ = true; | 533 shutting_down_ = true; |
| 534 | 534 |
| 535 ash::Shell::GetInstance()->root_filter()->set_update_cursor_visibility(false); | 535 ash::Shell::GetInstance()->root_filter()->set_update_cursor_visibility(false); |
| 536 Shell::GetRootWindow()->ShowCursor(false); | 536 Shell::GetPrimaryRootWindow()->ShowCursor(false); |
| 537 | 537 |
| 538 ShowBackgroundLayer(); | 538 ShowBackgroundLayer(); |
| 539 if (login_status_ != user::LOGGED_IN_NONE) { | 539 if (login_status_ != user::LOGGED_IN_NONE) { |
| 540 // Hide the other containers before starting the animation. | 540 // Hide the other containers before starting the animation. |
| 541 // ANIMATION_FAST_CLOSE will make the screen locker windows partially | 541 // ANIMATION_FAST_CLOSE will make the screen locker windows partially |
| 542 // transparent, and we don't want the other windows to show through. | 542 // transparent, and we don't want the other windows to show through. |
| 543 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 543 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 544 ANIMATION_HIDE); | 544 ANIMATION_HIDE); |
| 545 StartAnimation(SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_FAST_CLOSE); | 545 StartAnimation(SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_FAST_CLOSE); |
| 546 } else { | 546 } else { |
| 547 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE); | 547 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE); |
| 548 } | 548 } |
| 549 | 549 |
| 550 real_shutdown_timer_.Start( | 550 real_shutdown_timer_.Start( |
| 551 FROM_HERE, | 551 FROM_HERE, |
| 552 base::TimeDelta::FromMilliseconds( | 552 base::TimeDelta::FromMilliseconds( |
| 553 kFastCloseAnimMs + kShutdownRequestDelayMs), | 553 kFastCloseAnimMs + kShutdownRequestDelayMs), |
| 554 this, &PowerButtonController::OnRealShutdownTimeout); | 554 this, &PowerButtonController::OnRealShutdownTimeout); |
| 555 } | 555 } |
| 556 | 556 |
| 557 void PowerButtonController::ShowBackgroundLayer() { | 557 void PowerButtonController::ShowBackgroundLayer() { |
| 558 if (hide_background_layer_timer_.IsRunning()) | 558 if (hide_background_layer_timer_.IsRunning()) |
| 559 hide_background_layer_timer_.Stop(); | 559 hide_background_layer_timer_.Stop(); |
| 560 | 560 |
| 561 if (!background_layer_.get()) { | 561 if (!background_layer_.get()) { |
| 562 background_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 562 background_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 563 background_layer_->SetColor(SK_ColorBLACK); | 563 background_layer_->SetColor(SK_ColorBLACK); |
| 564 | 564 |
| 565 ui::Layer* root_layer = Shell::GetRootWindow()->layer(); | 565 ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer(); |
| 566 background_layer_->SetBounds(root_layer->bounds()); | 566 background_layer_->SetBounds(root_layer->bounds()); |
| 567 root_layer->Add(background_layer_.get()); | 567 root_layer->Add(background_layer_.get()); |
| 568 root_layer->StackAtBottom(background_layer_.get()); | 568 root_layer->StackAtBottom(background_layer_.get()); |
| 569 } | 569 } |
| 570 background_layer_->SetVisible(true); | 570 background_layer_->SetVisible(true); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void PowerButtonController::HideBackgroundLayer() { | 573 void PowerButtonController::HideBackgroundLayer() { |
| 574 background_layer_.reset(); | 574 background_layer_.reset(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 } // namespace ash | 577 } // namespace ash |
| OLD | NEW |