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