Commit 1e39dd5b authored by Min Chen's avatar Min Chen Committed by Commit Bot

Cancel the ongoing animation for repeat power button releases.

Should cancel the stated showing menu animation for repeat power button
releases. Otherwise, the ongoing animation will run the callback function
SetShowMenuAnimationDone to start |pre_shutdown_timer_|
OnImplicitAnimationFinished after release the power button. This will lead
to device power off.

Bug: 831915
Change-Id: I07753f4156dfc7ba299c37f8fd7a7551d5ec858a
Reviewed-on: https://chromium-review.googlesource.com/1009485Reviewed-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@{#550509}
parent cd44c762
...@@ -176,6 +176,8 @@ void PowerButtonController::OnPowerButtonEvent( ...@@ -176,6 +176,8 @@ void PowerButtonController::OnPowerButtonEvent(
if (lock_button_down_) if (lock_button_down_)
return; return;
// TODO(minch): move the LEGACY logic out as a separate function
// OnLegacyPowerButtonEvent.
if (button_type_ == ButtonType::LEGACY) { if (button_type_ == ButtonType::LEGACY) {
// Avoid starting the lock/shutdown sequence if the power button is pressed // Avoid starting the lock/shutdown sequence if the power button is pressed
// while the screen is off (http://crbug.com/128451), unless an external // while the screen is off (http://crbug.com/128451), unless an external
...@@ -248,6 +250,14 @@ void PowerButtonController::OnPowerButtonEvent( ...@@ -248,6 +250,14 @@ void PowerButtonController::OnPowerButtonEvent(
power_button_menu_timer_.Stop(); power_button_menu_timer_.Stop();
pre_shutdown_timer_.Stop(); pre_shutdown_timer_.Stop();
// Cancel the menu animation if it's still ongoing when the button is
// released on a clamshell device.
if (!ShouldTurnScreenOffForTap() && IsMenuOpened() &&
!show_menu_animation_done_) {
static_cast<PowerButtonMenuScreenView*>(menu_widget_->GetContentsView())
->ScheduleShowHideAnimation(false);
}
// Ignore the event if it comes too soon after the last one. // Ignore the event if it comes too soon after the last one.
if (timestamp - previous_up_time <= kIgnoreRepeatedButtonUpDelay) if (timestamp - previous_up_time <= kIgnoreRepeatedButtonUpDelay)
return; return;
...@@ -257,14 +267,6 @@ void PowerButtonController::OnPowerButtonEvent( ...@@ -257,14 +267,6 @@ void PowerButtonController::OnPowerButtonEvent(
display_controller_->SetBacklightsForcedOff(true); display_controller_->SetBacklightsForcedOff(true);
LockScreenIfRequired(); LockScreenIfRequired();
} }
// Cancel the menu animation if it's still ongoing when the button is
// released on a clamshell device.
if (!ShouldTurnScreenOffForTap() && IsMenuOpened() &&
!show_menu_animation_done_) {
static_cast<PowerButtonMenuScreenView*>(menu_widget_->GetContentsView())
->ScheduleShowHideAnimation(false);
}
} }
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "chromeos/dbus/fake_power_manager_client.h" #include "chromeos/dbus/fake_power_manager_client.h"
#include "chromeos/dbus/fake_session_manager_client.h" #include "chromeos/dbus/fake_session_manager_client.h"
#include "chromeos/dbus/power_manager/suspend.pb.h" #include "chromeos/dbus/power_manager/suspend.pb.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/test/display_manager_test_api.h" #include "ui/display/test/display_manager_test_api.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
...@@ -612,6 +613,28 @@ TEST_F(PowerButtonControllerTest, IgnoreRepeatedPowerButtonReleases) { ...@@ -612,6 +613,28 @@ TEST_F(PowerButtonControllerTest, IgnoreRepeatedPowerButtonReleases) {
EXPECT_TRUE(power_manager_client_->backlights_forced_off()); EXPECT_TRUE(power_manager_client_->backlights_forced_off());
} }
// Tests that repeated power button releases of clamshell should cancel the
// ongoing showing menu animation.
TEST_F(PowerButtonControllerTest,
ClamshellRepeatedPowerButtonReleasesCancelledAnimation) {
InitPowerButtonControllerMembers(PowerManagerClient::TabletMode::UNSUPPORTED);
// Enable animations so that we can make sure that they occur.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
PressPowerButton();
ReleasePowerButton();
EXPECT_FALSE(power_button_test_api_->IsMenuOpened());
tick_clock_.Advance(base::TimeDelta::FromMilliseconds(200));
PressPowerButton();
ReleasePowerButton();
// Showing menu animation should be cancelled and menu is not shown.
EXPECT_FALSE(power_button_test_api_->IsMenuOpened());
EXPECT_FALSE(power_button_test_api_->PreShutdownTimerIsRunning());
}
// Tests that lid closed/open events stop forcing off backlights. // Tests that lid closed/open events stop forcing off backlights.
TEST_F(PowerButtonControllerTest, LidEventsStopForcingOff) { TEST_F(PowerButtonControllerTest, LidEventsStopForcingOff) {
// Pressing/releasing power button to set backlights forced off. // Pressing/releasing power button to set backlights forced off.
......
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