Chromium Code Reviews| Index: ash/system/chromeos/power/tablet_power_button_controller.cc |
| diff --git a/ash/system/chromeos/power/tablet_power_button_controller.cc b/ash/system/chromeos/power/tablet_power_button_controller.cc |
| index cb316de4c38c476672dec7963eefd3946c0c7ac4..d5c4413705fbddb293ca8f483d3ff440ae6086fc 100644 |
| --- a/ash/system/chromeos/power/tablet_power_button_controller.cc |
| +++ b/ash/system/chromeos/power/tablet_power_button_controller.cc |
| @@ -35,6 +35,10 @@ constexpr int kShutdownWhenScreenOffTimeoutMs = 2000; |
| // ignored. |
| constexpr int kIgnorePowerButtonAfterResumeMs = 2000; |
| +// Amount of time since last power button released that power button released |
| +// event for forcing off needs to be ignored. |
| +constexpr int kIgnoreReleasedAfterLastOneMs = 500; |
|
Daniel Erat
2017/01/30 17:55:00
nit: kIgnoreRepeatedButtonUpMs or something simila
Qiang(Joe) Xu
2017/01/30 19:35:43
done, thanks!
|
| + |
| // Returns true if device is a convertible/tablet device, otherwise false. |
| bool IsTabletModeSupported() { |
| MaximizeModeController* maximize_mode_controller = |
| @@ -73,6 +77,7 @@ TabletPowerButtonController::TabletPowerButtonController( |
| LockStateController* controller) |
| : tick_clock_(new base::DefaultTickClock()), |
| last_resume_time_(base::TimeTicks()), |
| + last_released_time_(base::TimeTicks()), |
|
Daniel Erat
2017/01/30 17:55:00
i don't think you need to initialize this member a
Qiang(Joe) Xu
2017/01/30 19:35:44
Done.
|
| force_off_on_button_up_(true), |
| controller_(controller), |
| weak_ptr_factory_(this) { |
| @@ -119,6 +124,20 @@ void TabletPowerButtonController::OnPowerButtonEvent( |
| SetDisplayForcedOff(false); |
| StartShutdownTimer(); |
| } else { |
| + // When power button is released, cancel shutdown animation whenever it is |
| + // still cancellable. |
| + if (controller_->CanCancelShutdownAnimation()) |
| + controller_->CancelShutdownAnimation(); |
| + |
|
Daniel Erat
2017/01/30 17:55:00
might be a little cleaner to do something like thi
Qiang(Joe) Xu
2017/01/30 19:35:43
Done.
|
| + // Drop the very adjacent power button released event for forcing off. |
|
Daniel Erat
2017/01/30 17:55:00
maybe:
// Ignore the event if it comes too soon
Qiang(Joe) Xu
2017/01/30 19:35:43
Done.
|
| + if (timestamp - last_released_time_ <= |
| + base::TimeDelta::FromMilliseconds(kIgnoreReleasedAfterLastOneMs)) { |
| + last_released_time_ = tick_clock_->NowTicks(); |
| + shutdown_timer_.Stop(); |
| + return; |
| + } |
| + last_released_time_ = tick_clock_->NowTicks(); |
| + |
| if (shutdown_timer_.IsRunning()) { |
| shutdown_timer_.Stop(); |
| if (!screen_off_when_power_button_down_ && force_off_on_button_up_) { |
| @@ -126,11 +145,6 @@ void TabletPowerButtonController::OnPowerButtonEvent( |
| LockScreenIfRequired(); |
| } |
| } |
| - |
| - // When power button is released, cancel shutdown animation whenever it is |
| - // still cancellable. |
| - if (controller_->CanCancelShutdownAnimation()) |
| - controller_->CancelShutdownAnimation(); |
| } |
| } |