| 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/session_state_delegate.h" | |
| 9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/session_state_animator.h" | 11 #include "ash/wm/session_state_animator.h" |
| 12 #include "ash/wm/session_state_controller.h" | 12 #include "ash/wm/session_state_controller.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/views/corewm/compound_event_filter.h" | 15 #include "ui/views/corewm/compound_event_filter.h" |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 | 18 |
| 19 PowerButtonController::PowerButtonController(SessionStateController* controller) | 19 PowerButtonController::PowerButtonController(SessionStateController* controller) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 power_button_down_ = down; | 38 power_button_down_ = down; |
| 39 | 39 |
| 40 if (controller_->ShutdownRequested()) | 40 if (controller_->ShutdownRequested()) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 // Avoid starting the lock/shutdown sequence if the power button is pressed | 43 // Avoid starting the lock/shutdown sequence if the power button is pressed |
| 44 // while the screen is off (http://crbug.com/128451). | 44 // while the screen is off (http://crbug.com/128451). |
| 45 if (screen_is_off_) | 45 if (screen_is_off_) |
| 46 return; | 46 return; |
| 47 | 47 |
| 48 const SessionStateDelegate* session_state_delegate = | 48 Shell* shell = Shell::GetInstance(); |
| 49 Shell::GetInstance()->session_state_delegate(); | |
| 50 if (has_legacy_power_button_) { | 49 if (has_legacy_power_button_) { |
| 51 // If power button releases won't get reported correctly because we're not | 50 // If power button releases won't get reported correctly because we're not |
| 52 // running on official hardware, just lock the screen or shut down | 51 // running on official hardware, just lock the screen or shut down |
| 53 // immediately. | 52 // immediately. |
| 54 if (down) { | 53 if (down) { |
| 55 if (session_state_delegate->CanLockScreen() && | 54 if (shell->CanLockScreen() && !shell->IsScreenLocked() && |
| 56 !session_state_delegate->IsScreenLocked() && | |
| 57 !controller_->LockRequested()) { | 55 !controller_->LockRequested()) { |
| 58 controller_->StartLockAnimationAndLockImmediately(); | 56 controller_->StartLockAnimationAndLockImmediately(); |
| 59 } else { | 57 } else { |
| 60 controller_->RequestShutdown(); | 58 controller_->RequestShutdown(); |
| 61 } | 59 } |
| 62 } | 60 } |
| 63 } else { // !has_legacy_power_button_ | 61 } else { // !has_legacy_power_button_ |
| 64 if (down) { | 62 if (down) { |
| 65 // If we already have a pending request to lock the screen, wait. | 63 // If we already have a pending request to lock the screen, wait. |
| 66 if (controller_->LockRequested()) | 64 if (controller_->LockRequested()) |
| 67 return; | 65 return; |
| 68 | 66 |
| 69 if (session_state_delegate->CanLockScreen() && | 67 if (shell->CanLockScreen() && !shell->IsScreenLocked()) |
| 70 !session_state_delegate->IsScreenLocked()) { | |
| 71 controller_->StartLockAnimation(true); | 68 controller_->StartLockAnimation(true); |
| 72 } else { | 69 else |
| 73 controller_->StartShutdownAnimation(); | 70 controller_->StartShutdownAnimation(); |
| 74 } | |
| 75 } else { // Button is up. | 71 } else { // Button is up. |
| 76 if (controller_->CanCancelLockAnimation()) | 72 if (controller_->CanCancelLockAnimation()) |
| 77 controller_->CancelLockAnimation(); | 73 controller_->CancelLockAnimation(); |
| 78 else if (controller_->CanCancelShutdownAnimation()) | 74 else if (controller_->CanCancelShutdownAnimation()) |
| 79 controller_->CancelShutdownAnimation(); | 75 controller_->CancelShutdownAnimation(); |
| 80 } | 76 } |
| 81 } | 77 } |
| 82 } | 78 } |
| 83 | 79 |
| 84 void PowerButtonController::OnLockButtonEvent( | 80 void PowerButtonController::OnLockButtonEvent( |
| 85 bool down, const base::TimeTicks& timestamp) { | 81 bool down, const base::TimeTicks& timestamp) { |
| 86 lock_button_down_ = down; | 82 lock_button_down_ = down; |
| 87 | 83 |
| 88 const SessionStateDelegate* session_state_delegate = | 84 Shell* shell = Shell::GetInstance(); |
| 89 Shell::GetInstance()->session_state_delegate(); | 85 if (!shell->CanLockScreen() || shell->IsScreenLocked() || |
| 90 if (!session_state_delegate->CanLockScreen() || | 86 controller_->LockRequested() || controller_->ShutdownRequested()) { |
| 91 session_state_delegate->IsScreenLocked() || | |
| 92 controller_->LockRequested() || | |
| 93 controller_->ShutdownRequested()) { | |
| 94 return; | 87 return; |
| 95 } | 88 } |
| 96 | 89 |
| 97 // Give the power button precedence over the lock button (we don't expect both | 90 // Give the power button precedence over the lock button (we don't expect both |
| 98 // buttons to be present, so this is just making sure that we don't do | 91 // buttons to be present, so this is just making sure that we don't do |
| 99 // something completely stupid if that assumption changes later). | 92 // something completely stupid if that assumption changes later). |
| 100 if (power_button_down_) | 93 if (power_button_down_) |
| 101 return; | 94 return; |
| 102 | 95 |
| 103 if (down) | 96 if (down) |
| 104 controller_->StartLockAnimation(false); | 97 controller_->StartLockAnimation(false); |
| 105 else | 98 else |
| 106 controller_->CancelLockAnimation(); | 99 controller_->CancelLockAnimation(); |
| 107 } | 100 } |
| 108 | 101 |
| 109 } // namespace ash | 102 } // namespace ash |
| OLD | NEW |