| 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_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Fills |containers| with the containers described by |container_mask|. | 162 // Fills |containers| with the containers described by |container_mask|. |
| 163 void GetContainers(int container_mask, aura::Window::Windows* containers) { | 163 void GetContainers(int container_mask, aura::Window::Windows* containers) { |
| 164 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 164 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 165 containers->clear(); | 165 containers->clear(); |
| 166 | 166 |
| 167 if (container_mask & PowerButtonController::DESKTOP_BACKGROUND) { | 167 if (container_mask & PowerButtonController::DESKTOP_BACKGROUND) { |
| 168 containers->push_back(Shell::GetContainer( | 168 containers->push_back(Shell::GetContainer( |
| 169 root_window, | 169 root_window, |
| 170 internal::kShellWindowId_DesktopBackgroundContainer)); | 170 internal::kShellWindowId_DesktopBackgroundContainer)); |
| 171 } | 171 } |
| 172 if (container_mask & PowerButtonController::NON_LOCK_SCREEN_CONTAINERS) { | 172 if (container_mask & PowerButtonController::LAUNCHER) { |
| 173 containers->push_back(Shell::GetContainer( | 173 containers->push_back(Shell::GetContainer( |
| 174 root_window, | 174 root_window, |
| 175 internal::kShellWindowId_NonLockScreenContainersContainer)); | 175 internal::kShellWindowId_LauncherContainer)); |
| 176 } |
| 177 if (container_mask & PowerButtonController::NON_LOCK_SCREEN_CONTAINERS) { |
| 178 // TODO(antrim): Figure out a way to eliminate a need to exclude launcher |
| 179 // in such way. |
| 180 aura::Window* non_lock_screen_containers = Shell::GetContainer( |
| 181 root_window, |
| 182 internal::kShellWindowId_NonLockScreenContainersContainer); |
| 183 aura::Window::Windows children = non_lock_screen_containers->children(); |
| 184 |
| 185 for (aura::Window::Windows::const_iterator it = children.begin(); |
| 186 it != children.end(); ++it) { |
| 187 aura::Window* window = *it; |
| 188 if (window->id() == internal::kShellWindowId_LauncherContainer) |
| 189 continue; |
| 190 containers->push_back(window); |
| 191 } |
| 176 } | 192 } |
| 177 if (container_mask & PowerButtonController::LOCK_SCREEN_BACKGROUND) { | 193 if (container_mask & PowerButtonController::LOCK_SCREEN_BACKGROUND) { |
| 178 containers->push_back(Shell::GetContainer( | 194 containers->push_back(Shell::GetContainer( |
| 179 root_window, | 195 root_window, |
| 180 internal::kShellWindowId_LockScreenBackgroundContainer)); | 196 internal::kShellWindowId_LockScreenBackgroundContainer)); |
| 181 } | 197 } |
| 182 if (container_mask & PowerButtonController::LOCK_SCREEN_CONTAINERS) { | 198 if (container_mask & PowerButtonController::LOCK_SCREEN_CONTAINERS) { |
| 183 containers->push_back(Shell::GetContainer( | 199 containers->push_back(Shell::GetContainer( |
| 184 root_window, | 200 root_window, |
| 185 internal::kShellWindowId_LockScreenContainersContainer)); | 201 internal::kShellWindowId_LockScreenContainersContainer)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 292 } |
| 277 | 293 |
| 278 gfx::Rect PowerButtonController::TestApi::GetBlackLayerBounds() const { | 294 gfx::Rect PowerButtonController::TestApi::GetBlackLayerBounds() const { |
| 279 ui::Layer* layer = controller_->black_layer_.get(); | 295 ui::Layer* layer = controller_->black_layer_.get(); |
| 280 return layer ? layer->bounds() : gfx::Rect(); | 296 return layer ? layer->bounds() : gfx::Rect(); |
| 281 } | 297 } |
| 282 | 298 |
| 283 // static | 299 // static |
| 284 int PowerButtonController::GetAllContainersMask() { | 300 int PowerButtonController::GetAllContainersMask() { |
| 285 return PowerButtonController::DESKTOP_BACKGROUND | | 301 return PowerButtonController::DESKTOP_BACKGROUND | |
| 302 PowerButtonController::LAUNCHER | |
| 286 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS | | 303 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS | |
| 287 GetAllLockScreenContainersMask(); | 304 GetAllLockScreenContainersMask(); |
| 288 } | 305 } |
| 289 | 306 |
| 290 // static | 307 // static |
| 291 int PowerButtonController::GetAllLockScreenContainersMask() { | 308 int PowerButtonController::GetAllLockScreenContainersMask() { |
| 292 return PowerButtonController::LOCK_SCREEN_BACKGROUND | | 309 return PowerButtonController::LOCK_SCREEN_BACKGROUND | |
| 293 PowerButtonController::LOCK_SCREEN_CONTAINERS | | 310 PowerButtonController::LOCK_SCREEN_CONTAINERS | |
| 294 PowerButtonController::LOCK_SCREEN_RELATED_CONTAINERS; | 311 PowerButtonController::LOCK_SCREEN_RELATED_CONTAINERS; |
| 295 } | 312 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 lock_fail_timer_.Stop(); | 363 lock_fail_timer_.Stop(); |
| 347 | 364 |
| 348 if (!has_legacy_power_button_ && power_button_down_) { | 365 if (!has_legacy_power_button_ && power_button_down_) { |
| 349 lock_to_shutdown_timer_.Stop(); | 366 lock_to_shutdown_timer_.Stop(); |
| 350 lock_to_shutdown_timer_.Start( | 367 lock_to_shutdown_timer_.Start( |
| 351 FROM_HERE, | 368 FROM_HERE, |
| 352 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 369 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
| 353 this, &PowerButtonController::OnLockToShutdownTimeout); | 370 this, &PowerButtonController::OnLockToShutdownTimeout); |
| 354 } | 371 } |
| 355 } else { | 372 } else { |
| 356 StartAnimation(DESKTOP_BACKGROUND | NON_LOCK_SCREEN_CONTAINERS, | 373 StartAnimation(DESKTOP_BACKGROUND | LAUNCHER | NON_LOCK_SCREEN_CONTAINERS, |
| 357 ANIMATION_RESTORE); | 374 ANIMATION_RESTORE); |
| 358 HideBlackLayer(); | 375 HideBlackLayer(); |
| 359 } | 376 } |
| 360 } | 377 } |
| 361 | 378 |
| 362 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 379 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
| 363 screen_is_off_ = percent <= 0.001; | 380 screen_is_off_ = percent <= 0.001; |
| 364 } | 381 } |
| 365 | 382 |
| 366 void PowerButtonController::OnStartingLock() { | 383 void PowerButtonController::OnStartingLock() { |
| 367 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) | 384 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) |
| 368 return; | 385 return; |
| 369 | 386 |
| 370 // Ensure that the black layer is visible -- if the screen was locked via | 387 // Ensure that the black layer is visible -- if the screen was locked via |
| 371 // the wrench menu, we won't have already shown the black background | 388 // the wrench menu, we won't have already shown the black background |
| 372 // as part of the slow-close animation. | 389 // as part of the slow-close animation. |
| 373 ShowBlackLayer(); | 390 ShowBlackLayer(); |
| 374 | 391 |
| 392 StartAnimation(LAUNCHER, ANIMATION_HIDE); |
| 393 |
| 375 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_FAST_CLOSE); | 394 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_FAST_CLOSE); |
| 376 | 395 |
| 377 // Hide the screen locker containers so we can make them fade in later. | 396 // Hide the screen locker containers so we can make them fade in later. |
| 378 StartAnimation(LOCK_SCREEN_CONTAINERS, ANIMATION_HIDE); | 397 StartAnimation(LOCK_SCREEN_CONTAINERS, ANIMATION_HIDE); |
| 379 } | 398 } |
| 380 | 399 |
| 381 void PowerButtonController::OnPowerButtonEvent( | 400 void PowerButtonController::OnPowerButtonEvent( |
| 382 bool down, const base::TimeTicks& timestamp) { | 401 bool down, const base::TimeTicks& timestamp) { |
| 383 power_button_down_ = down; | 402 power_button_down_ = down; |
| 384 | 403 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 delegate_->RequestLockScreen(); | 522 delegate_->RequestLockScreen(); |
| 504 lock_fail_timer_.Start( | 523 lock_fail_timer_.Start( |
| 505 FROM_HERE, | 524 FROM_HERE, |
| 506 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | 525 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), |
| 507 this, &PowerButtonController::OnLockFailTimeout); | 526 this, &PowerButtonController::OnLockFailTimeout); |
| 508 } | 527 } |
| 509 | 528 |
| 510 void PowerButtonController::OnLockFailTimeout() { | 529 void PowerButtonController::OnLockFailTimeout() { |
| 511 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); | 530 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); |
| 512 LOG(ERROR) << "Screen lock request timed out"; | 531 LOG(ERROR) << "Screen lock request timed out"; |
| 513 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_RESTORE); | 532 StartAnimation(LAUNCHER | NON_LOCK_SCREEN_CONTAINERS, ANIMATION_RESTORE); |
| 514 HideBlackLayer(); | 533 HideBlackLayer(); |
| 515 } | 534 } |
| 516 | 535 |
| 517 void PowerButtonController::OnLockToShutdownTimeout() { | 536 void PowerButtonController::OnLockToShutdownTimeout() { |
| 518 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); | 537 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); |
| 519 StartShutdownTimer(); | 538 StartShutdownTimer(); |
| 520 } | 539 } |
| 521 | 540 |
| 522 void PowerButtonController::OnShutdownTimeout() { | 541 void PowerButtonController::OnShutdownTimeout() { |
| 523 if (!shutting_down_) | 542 if (!shutting_down_) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 553 shutting_down_ = true; | 572 shutting_down_ = true; |
| 554 | 573 |
| 555 Shell* shell = ash::Shell::GetInstance(); | 574 Shell* shell = ash::Shell::GetInstance(); |
| 556 shell->cursor_manager()->ShowCursor(false); | 575 shell->cursor_manager()->ShowCursor(false); |
| 557 | 576 |
| 558 ShowBlackLayer(); | 577 ShowBlackLayer(); |
| 559 if (login_status_ != user::LOGGED_IN_NONE) { | 578 if (login_status_ != user::LOGGED_IN_NONE) { |
| 560 // Hide the other containers before starting the animation. | 579 // Hide the other containers before starting the animation. |
| 561 // ANIMATION_FAST_CLOSE will make the screen locker windows partially | 580 // ANIMATION_FAST_CLOSE will make the screen locker windows partially |
| 562 // transparent, and we don't want the other windows to show through. | 581 // transparent, and we don't want the other windows to show through. |
| 563 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_HIDE); | 582 StartAnimation(LAUNCHER | NON_LOCK_SCREEN_CONTAINERS, ANIMATION_HIDE); |
| 564 StartAnimation(GetAllLockScreenContainersMask(), ANIMATION_FAST_CLOSE); | 583 StartAnimation(GetAllLockScreenContainersMask(), ANIMATION_FAST_CLOSE); |
| 565 } else { | 584 } else { |
| 566 StartAnimation(GetAllContainersMask(), ANIMATION_FAST_CLOSE); | 585 StartAnimation(GetAllContainersMask(), ANIMATION_FAST_CLOSE); |
| 567 } | 586 } |
| 568 | 587 |
| 569 real_shutdown_timer_.Start( | 588 real_shutdown_timer_.Start( |
| 570 FROM_HERE, | 589 FROM_HERE, |
| 571 base::TimeDelta::FromMilliseconds( | 590 base::TimeDelta::FromMilliseconds( |
| 572 kFastCloseAnimMs + kShutdownRequestDelayMs), | 591 kFastCloseAnimMs + kShutdownRequestDelayMs), |
| 573 this, &PowerButtonController::OnRealShutdownTimeout); | 592 this, &PowerButtonController::OnRealShutdownTimeout); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 587 root_layer->StackAtBottom(black_layer_.get()); | 606 root_layer->StackAtBottom(black_layer_.get()); |
| 588 } | 607 } |
| 589 black_layer_->SetVisible(true); | 608 black_layer_->SetVisible(true); |
| 590 } | 609 } |
| 591 | 610 |
| 592 void PowerButtonController::HideBlackLayer() { | 611 void PowerButtonController::HideBlackLayer() { |
| 593 black_layer_.reset(); | 612 black_layer_.reset(); |
| 594 } | 613 } |
| 595 | 614 |
| 596 } // namespace ash | 615 } // namespace ash |
| OLD | NEW |