diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 17:30:25 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 17:30:25 +0000 |
commit | b44c414b41f42be1f6256a4d35278b7be5a57230 (patch) | |
tree | 472c4f0f46a8c420c5f782ae22dac5b4a5331615 | |
parent | 1d0475b98ca8a71b9d5ddf7361900d2c5d955cf8 (diff) | |
download | chromium_src-b44c414b41f42be1f6256a4d35278b7be5a57230.zip chromium_src-b44c414b41f42be1f6256a4d35278b7be5a57230.tar.gz chromium_src-b44c414b41f42be1f6256a4d35278b7be5a57230.tar.bz2 |
chromeos: Ignore power button presses when screen is off.
Make PowerButtonController ignore power button events when
the screen is turned off -- if the user hits the power
button to turn the screen back on, we don't want to lock or
shutdown if they hold it a bit too long.
BUG=128451
TEST=added, also did manual testing
Review URL: https://chromiumcodereview.appspot.com/10382211
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137679 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/wm/power_button_controller.cc | 10 | ||||
-rw-r--r-- | ash/wm/power_button_controller.h | 6 | ||||
-rw-r--r-- | ash/wm/power_button_controller_unittest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/chromeos/power/brightness_observer.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/power/brightness_observer.h | 4 |
5 files changed, 39 insertions, 2 deletions
diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc index 22fd150..1905219 100644 --- a/ash/wm/power_button_controller.cc +++ b/ash/wm/power_button_controller.cc @@ -285,6 +285,7 @@ PowerButtonController::PowerButtonController() unlocked_login_status_(user::LOGGED_IN_NONE), power_button_down_(false), lock_button_down_(false), + screen_is_off_(false), shutting_down_(false), has_legacy_power_button_( CommandLine::ForCurrentProcess()->HasSwitch( @@ -345,6 +346,10 @@ void PowerButtonController::OnLockStateChanged(bool locked) { } } +void PowerButtonController::OnScreenBrightnessChanged(double percent) { + screen_is_off_ = percent <= 0.001; +} + void PowerButtonController::OnStartingLock() { if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) return; @@ -368,6 +373,11 @@ void PowerButtonController::OnPowerButtonEvent( if (shutting_down_) return; + // Avoid starting the lock/shutdown sequence if the power button is pressed + // while the screen is off (http://crbug.com/128451). + if (screen_is_off_) + return; + if (has_legacy_power_button_) { // If power button releases won't get reported correctly because we're not // running on official hardware, just lock the screen or shut down diff --git a/ash/wm/power_button_controller.h b/ash/wm/power_button_controller.h index 40719d8..efe5f53 100644 --- a/ash/wm/power_button_controller.h +++ b/ash/wm/power_button_controller.h @@ -142,6 +142,9 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, has_legacy_power_button_ = legacy; } + // Called when the current screen brightness changes. + void OnScreenBrightnessChanged(double percent); + // Called when Chrome gets a request to display the lock screen. void OnStartingLock(); @@ -203,6 +206,9 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, bool power_button_down_; bool lock_button_down_; + // Is the screen currently turned off? + bool screen_is_off_; + // Are we in the process of shutting the machine down? bool shutting_down_; diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc index 81a5830..3a326fa 100644 --- a/ash/wm/power_button_controller_unittest.cc +++ b/ash/wm/power_button_controller_unittest.cc @@ -539,5 +539,22 @@ TEST_F(PowerButtonControllerTest, ResizeBackgroundLayer) { test_api_->GetBackgroundLayerBounds().ToString()); } +// Test that we ignore power button presses when the screen is turned off. +TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + + // When the screen brightness is at 0%, we shouldn't do anything in response + // to power button presses. + controller_->OnScreenBrightnessChanged(0.0); + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); + EXPECT_FALSE(test_api_->lock_timer_is_running()); + + // After increasing the brightness to 10%, we should start the timer like + // usual. + controller_->OnScreenBrightnessChanged(10.0); + controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); + EXPECT_TRUE(test_api_->lock_timer_is_running()); +} + } // namespace test } // namespace ash diff --git a/chrome/browser/chromeos/power/brightness_observer.cc b/chrome/browser/chromeos/power/brightness_observer.cc index cd4e4a5..cbf5119 100644 --- a/chrome/browser/chromeos/power/brightness_observer.cc +++ b/chrome/browser/chromeos/power/brightness_observer.cc @@ -4,6 +4,8 @@ #include "chrome/browser/chromeos/power/brightness_observer.h" +#include "ash/shell.h" +#include "ash/wm/power_button_controller.h" #include "chrome/browser/extensions/system/system_api.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -19,6 +21,8 @@ BrightnessObserver::~BrightnessObserver() { void BrightnessObserver::BrightnessChanged(int level, bool user_initiated) { extensions::DispatchBrightnessChangedEvent(level, user_initiated); + ash::Shell::GetInstance()->power_button_controller()-> + OnScreenBrightnessChanged(static_cast<double>(level)); } } // namespace chromeos diff --git a/chrome/browser/chromeos/power/brightness_observer.h b/chrome/browser/chromeos/power/brightness_observer.h index 46f78e3..5ab9389 100644 --- a/chrome/browser/chromeos/power/brightness_observer.h +++ b/chrome/browser/chromeos/power/brightness_observer.h @@ -12,8 +12,8 @@ namespace chromeos { -// This observer displays a bubble at the bottom of the screen showing the -// current brightness level whenever the user changes it. +// This observer listens for changes to the screen brightness and notifies +// extensions and ash::PowerButtonController about them. class BrightnessObserver : public PowerManagerClient::Observer { public: // This class registers/unregisters itself as an observer in ctor/dtor. |