| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/chromeos/power/tablet_power_button_controller.h" | 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shell_delegate.h" | 9 #include "ash/common/shell_delegate.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // TODO(derat): This is currently set to a high value to work around delays in | 28 // TODO(derat): This is currently set to a high value to work around delays in |
| 29 // powerd's reports of button-up events when the preceding button-down event | 29 // powerd's reports of button-up events when the preceding button-down event |
| 30 // turns the display on. Set it to a lower value once powerd no longer blocks on | 30 // turns the display on. Set it to a lower value once powerd no longer blocks on |
| 31 // asking Chrome to turn the display on: http://crbug.com/685734 | 31 // asking Chrome to turn the display on: http://crbug.com/685734 |
| 32 constexpr int kShutdownWhenScreenOffTimeoutMs = 2000; | 32 constexpr int kShutdownWhenScreenOffTimeoutMs = 2000; |
| 33 | 33 |
| 34 // Amount of time since last SuspendDone() that power button event needs to be | 34 // Amount of time since last SuspendDone() that power button event needs to be |
| 35 // ignored. | 35 // ignored. |
| 36 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; | 36 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; |
| 37 | 37 |
| 38 // Ignore button-up events occurring within this many milliseconds of the |
| 39 // previous button-up event. This prevents us from falling behind if the power |
| 40 // button is pressed repeatedly. |
| 41 constexpr int kIgnoreRepeatedButtonUpMs = 500; |
| 42 |
| 38 // Returns true if device is a convertible/tablet device, otherwise false. | 43 // Returns true if device is a convertible/tablet device, otherwise false. |
| 39 bool IsTabletModeSupported() { | 44 bool IsTabletModeSupported() { |
| 40 MaximizeModeController* maximize_mode_controller = | 45 MaximizeModeController* maximize_mode_controller = |
| 41 WmShell::Get()->maximize_mode_controller(); | 46 WmShell::Get()->maximize_mode_controller(); |
| 42 return maximize_mode_controller && | 47 return maximize_mode_controller && |
| 43 maximize_mode_controller->CanEnterMaximizeMode(); | 48 maximize_mode_controller->CanEnterMaximizeMode(); |
| 44 } | 49 } |
| 45 | 50 |
| 46 // Returns true if device is currently in tablet/maximize mode, otherwise false. | 51 // Returns true if device is currently in tablet/maximize mode, otherwise false. |
| 47 bool IsTabletModeActive() { | 52 bool IsTabletModeActive() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 65 | 70 |
| 66 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { | 71 void TabletPowerButtonController::TestApi::TriggerShutdownTimeout() { |
| 67 DCHECK(ShutdownTimerIsRunning()); | 72 DCHECK(ShutdownTimerIsRunning()); |
| 68 controller_->OnShutdownTimeout(); | 73 controller_->OnShutdownTimeout(); |
| 69 controller_->shutdown_timer_.Stop(); | 74 controller_->shutdown_timer_.Stop(); |
| 70 } | 75 } |
| 71 | 76 |
| 72 TabletPowerButtonController::TabletPowerButtonController( | 77 TabletPowerButtonController::TabletPowerButtonController( |
| 73 LockStateController* controller) | 78 LockStateController* controller) |
| 74 : tick_clock_(new base::DefaultTickClock()), | 79 : tick_clock_(new base::DefaultTickClock()), |
| 75 last_resume_time_(base::TimeTicks()), | |
| 76 force_off_on_button_up_(true), | 80 force_off_on_button_up_(true), |
| 77 controller_(controller), | 81 controller_(controller), |
| 78 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
| 79 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 83 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 80 this); | 84 this); |
| 81 WmShell::Get()->AddShellObserver(this); | 85 WmShell::Get()->AddShellObserver(this); |
| 82 // TODO(mash): Provide a way for this class to observe stylus events: | 86 // TODO(mash): Provide a way for this class to observe stylus events: |
| 83 // http://crbug.com/682460 | 87 // http://crbug.com/682460 |
| 84 if (ui::InputDeviceManager::HasInstance()) | 88 if (ui::InputDeviceManager::HasInstance()) |
| 85 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 89 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 112 // that woke the system. Avoid forcing off display just after resuming to | 116 // that woke the system. Avoid forcing off display just after resuming to |
| 113 // ensure that we don't turn the display off in response to the events. | 117 // ensure that we don't turn the display off in response to the events. |
| 114 if (timestamp - last_resume_time_ <= | 118 if (timestamp - last_resume_time_ <= |
| 115 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { | 119 base::TimeDelta::FromMilliseconds(kIgnorePowerButtonAfterResumeMs)) { |
| 116 force_off_on_button_up_ = false; | 120 force_off_on_button_up_ = false; |
| 117 } | 121 } |
| 118 screen_off_when_power_button_down_ = brightness_level_is_zero_; | 122 screen_off_when_power_button_down_ = brightness_level_is_zero_; |
| 119 SetDisplayForcedOff(false); | 123 SetDisplayForcedOff(false); |
| 120 StartShutdownTimer(); | 124 StartShutdownTimer(); |
| 121 } else { | 125 } else { |
| 126 // When power button is released, cancel shutdown animation whenever it is |
| 127 // still cancellable. |
| 128 if (controller_->CanCancelShutdownAnimation()) |
| 129 controller_->CancelShutdownAnimation(); |
| 130 |
| 131 const base::TimeTicks previous_up_time = last_button_up_time_; |
| 132 last_button_up_time_ = tick_clock_->NowTicks(); |
| 133 // Ignore the event if it comes too soon after the last one. |
| 134 if (timestamp - previous_up_time <= |
| 135 base::TimeDelta::FromMilliseconds(kIgnoreRepeatedButtonUpMs)) { |
| 136 shutdown_timer_.Stop(); |
| 137 return; |
| 138 } |
| 139 |
| 122 if (shutdown_timer_.IsRunning()) { | 140 if (shutdown_timer_.IsRunning()) { |
| 123 shutdown_timer_.Stop(); | 141 shutdown_timer_.Stop(); |
| 124 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { | 142 if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { |
| 125 SetDisplayForcedOff(true); | 143 SetDisplayForcedOff(true); |
| 126 LockScreenIfRequired(); | 144 LockScreenIfRequired(); |
| 127 } | 145 } |
| 128 } | 146 } |
| 129 | |
| 130 // When power button is released, cancel shutdown animation whenever it is | |
| 131 // still cancellable. | |
| 132 if (controller_->CanCancelShutdownAnimation()) | |
| 133 controller_->CancelShutdownAnimation(); | |
| 134 } | 147 } |
| 135 } | 148 } |
| 136 | 149 |
| 137 void TabletPowerButtonController::PowerManagerRestarted() { | 150 void TabletPowerButtonController::PowerManagerRestarted() { |
| 138 chromeos::DBusThreadManager::Get() | 151 chromeos::DBusThreadManager::Get() |
| 139 ->GetPowerManagerClient() | 152 ->GetPowerManagerClient() |
| 140 ->SetBacklightsForcedOff(backlights_forced_off_); | 153 ->SetBacklightsForcedOff(backlights_forced_off_); |
| 141 } | 154 } |
| 142 | 155 |
| 143 void TabletPowerButtonController::BrightnessChanged(int level, | 156 void TabletPowerButtonController::BrightnessChanged(int level, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 WmShell::Get()->GetSessionStateDelegate(); | 256 WmShell::Get()->GetSessionStateDelegate(); |
| 244 if (session_state_delegate->ShouldLockScreenAutomatically() && | 257 if (session_state_delegate->ShouldLockScreenAutomatically() && |
| 245 session_state_delegate->CanLockScreen() && | 258 session_state_delegate->CanLockScreen() && |
| 246 !session_state_delegate->IsUserSessionBlocked() && | 259 !session_state_delegate->IsUserSessionBlocked() && |
| 247 !controller_->LockRequested()) { | 260 !controller_->LockRequested()) { |
| 248 session_state_delegate->LockScreen(); | 261 session_state_delegate->LockScreen(); |
| 249 } | 262 } |
| 250 } | 263 } |
| 251 | 264 |
| 252 } // namespace ash | 265 } // namespace ash |
| OLD | NEW |