Commit 760ef910 authored by Min Chen's avatar Min Chen Committed by Commit Bot

ash: Create OnLegacyPowerButtonBehavior in PowerButtonController.

Bug: 799524
Change-Id: If76472261a452021e0bc883a89d944d87e26dabc
Reviewed-on: https://chromium-review.googlesource.com/1013291Reviewed-by: default avatarDan Erat <derat@chromium.org>
Reviewed-by: default avatarQiang Xu <warx@google.com>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551159}
parent 6c74cdcf
......@@ -175,28 +175,18 @@ void PowerButtonController::OnPreShutdownTimeout() {
->FocusPowerOffButton();
}
void PowerButtonController::OnPowerButtonEvent(
bool down,
const base::TimeTicks& timestamp) {
power_button_down_ = down;
// Ignore power button if lock button is being pressed.
if (lock_button_down_)
return;
// TODO(minch): move the LEGACY logic out as a separate function
// OnLegacyPowerButtonEvent.
if (button_type_ == ButtonType::LEGACY) {
void PowerButtonController::OnLegacyPowerButtonEvent(bool down) {
// Avoid starting the lock/shutdown sequence if the power button is pressed
// while the screen is off (http://crbug.com/128451), unless an external
// display is still on (http://crosbug.com/p/24912).
if (brightness_is_zero_ && !internal_display_off_and_external_display_on_)
return;
if (!down)
return;
// If power button releases won't get reported correctly because we're not
// running on official hardware, just lock the screen or shut down
// immediately.
if (down) {
const SessionController* const session_controller =
Shell::Get()->session_controller();
if (session_controller->CanLockScreen() &&
......@@ -206,10 +196,11 @@ void PowerButtonController::OnPowerButtonEvent(
} else {
lock_state_controller_->RequestShutdown(ShutdownReason::POWER_BUTTON);
}
}
return;
}
}
void PowerButtonController::OnPowerButtonEvent(
bool down,
const base::TimeTicks& timestamp) {
if (down) {
force_off_on_button_up_ = false;
if (ShouldTurnScreenOffForTap()) {
......@@ -364,7 +355,13 @@ void PowerButtonController::PowerButtonEventReceived(
return;
}
OnPowerButtonEvent(down, timestamp);
power_button_down_ = down;
// Ignore power button if lock button is being pressed.
if (lock_button_down_)
return;
button_type_ == ButtonType::LEGACY ? OnLegacyPowerButtonEvent(down)
: OnPowerButtonEvent(down, timestamp);
}
void PowerButtonController::SuspendImminent(
......
......@@ -92,7 +92,14 @@ class ASH_EXPORT PowerButtonController
BacklightsForcedOffSetter* backlights_forced_off_setter);
~PowerButtonController() override;
// Handles power button behavior.
// Handles events from "legacy" ACPI power buttons. On devices with these
// buttons (typically Chromeboxes), button releases are misreported
// immediately after button presses, regardless of how long the button
// is actually held.
void OnLegacyPowerButtonEvent(bool down);
// Handles events from "normal" power buttons where button presses and
// releases are both reported accurately.
void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
// Handles lock button behavior.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment