Skip to content

Commit ad7ddfe

Browse files
Min ChenMin Chen
Min Chen
authored and
Min Chen
committed
[Merge to M67]Cancel the ongoing animation for repeat power button releases.
[email protected] 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. (cherry picked from commit 1e39dd5) Bug: 831915 Change-Id: I07753f4156dfc7ba299c37f8fd7a7551d5ec858a Reviewed-on: https://chromium-review.googlesource.com/1009485 Reviewed-by: Dan Erat <[email protected]> Reviewed-by: Qiang Xu <[email protected]> Commit-Queue: Min Chen <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#550509} Reviewed-on: https://chromium-review.googlesource.com/1015419 Reviewed-by: Min Chen <[email protected]> Cr-Commit-Position: refs/branch-heads/3396@{#51} Cr-Branched-From: 9ef2aa8-refs/heads/master@{#550428}
1 parent aeff192 commit ad7ddfe

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

ash/system/power/power_button_controller.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ void PowerButtonController::OnPowerButtonEvent(
176176
if (lock_button_down_)
177177
return;
178178

179+
// TODO(minch): move the LEGACY logic out as a separate function
180+
// OnLegacyPowerButtonEvent.
179181
if (button_type_ == ButtonType::LEGACY) {
180182
// Avoid starting the lock/shutdown sequence if the power button is pressed
181183
// while the screen is off (http://crbug.com/128451), unless an external
@@ -248,6 +250,14 @@ void PowerButtonController::OnPowerButtonEvent(
248250
power_button_menu_timer_.Stop();
249251
pre_shutdown_timer_.Stop();
250252

253+
// Cancel the menu animation if it's still ongoing when the button is
254+
// released on a clamshell device.
255+
if (!ShouldTurnScreenOffForTap() && IsMenuOpened() &&
256+
!show_menu_animation_done_) {
257+
static_cast<PowerButtonMenuScreenView*>(menu_widget_->GetContentsView())
258+
->ScheduleShowHideAnimation(false);
259+
}
260+
251261
// Ignore the event if it comes too soon after the last one.
252262
if (timestamp - previous_up_time <= kIgnoreRepeatedButtonUpDelay)
253263
return;
@@ -257,14 +267,6 @@ void PowerButtonController::OnPowerButtonEvent(
257267
display_controller_->SetBacklightsForcedOff(true);
258268
LockScreenIfRequired();
259269
}
260-
261-
// Cancel the menu animation if it's still ongoing when the button is
262-
// released on a clamshell device.
263-
if (!ShouldTurnScreenOffForTap() && IsMenuOpened() &&
264-
!show_menu_animation_done_) {
265-
static_cast<PowerButtonMenuScreenView*>(menu_widget_->GetContentsView())
266-
->ScheduleShowHideAnimation(false);
267-
}
268270
}
269271
}
270272

ash/system/power/power_button_controller_unittest.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "chromeos/dbus/fake_power_manager_client.h"
3333
#include "chromeos/dbus/fake_session_manager_client.h"
3434
#include "chromeos/dbus/power_manager/suspend.pb.h"
35+
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
3536
#include "ui/display/test/display_manager_test_api.h"
3637
#include "ui/events/event.h"
3738
#include "ui/events/test/event_generator.h"
@@ -612,6 +613,28 @@ TEST_F(PowerButtonControllerTest, IgnoreRepeatedPowerButtonReleases) {
612613
EXPECT_TRUE(power_manager_client_->backlights_forced_off());
613614
}
614615

616+
// Tests that repeated power button releases of clamshell should cancel the
617+
// ongoing showing menu animation.
618+
TEST_F(PowerButtonControllerTest,
619+
ClamshellRepeatedPowerButtonReleasesCancelledAnimation) {
620+
InitPowerButtonControllerMembers(PowerManagerClient::TabletMode::UNSUPPORTED);
621+
622+
// Enable animations so that we can make sure that they occur.
623+
ui::ScopedAnimationDurationScaleMode regular_animations(
624+
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
625+
626+
PressPowerButton();
627+
ReleasePowerButton();
628+
EXPECT_FALSE(power_button_test_api_->IsMenuOpened());
629+
630+
tick_clock_.Advance(base::TimeDelta::FromMilliseconds(200));
631+
PressPowerButton();
632+
ReleasePowerButton();
633+
// Showing menu animation should be cancelled and menu is not shown.
634+
EXPECT_FALSE(power_button_test_api_->IsMenuOpened());
635+
EXPECT_FALSE(power_button_test_api_->PreShutdownTimerIsRunning());
636+
}
637+
615638
// Tests that lid closed/open events stop forcing off backlights.
616639
TEST_F(PowerButtonControllerTest, LidEventsStopForcingOff) {
617640
// Pressing/releasing power button to set backlights forced off.

0 commit comments

Comments
 (0)