Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 5 #ifndef ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
| 6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "base/timer/timer.h" | |
| 11 #include "ui/events/event_handler.h" | 12 #include "ui/events/event_handler.h" |
| 12 | 13 |
| 13 #if defined(OS_CHROMEOS) | 14 #if defined(OS_CHROMEOS) |
| 14 #include "chromeos/dbus/power_manager_client.h" | 15 #include "chromeos/dbus/power_manager_client.h" |
| 15 #include "ui/display/chromeos/display_configurator.h" | 16 #include "ui/display/chromeos/display_configurator.h" |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 namespace gfx { | 19 namespace gfx { |
| 19 class Rect; | 20 class Rect; |
| 20 class Size; | 21 class Size; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace ui { | 24 namespace ui { |
| 24 class Layer; | 25 class Layer; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace ash { | 28 namespace ash { |
| 28 | 29 |
| 29 namespace test { | |
| 30 class PowerButtonControllerTest; | |
| 31 } | |
| 32 | |
| 33 class LockStateController; | 30 class LockStateController; |
| 34 | 31 |
| 35 // Handles power & lock button events which may result in the locking or | 32 // Handles power & lock button events which may result in the locking or |
| 36 // shutting down of the system as well as taking screen shots while in maximize | 33 // shutting down of the system as well as taking screen shots while in maximize |
| 37 // mode. | 34 // mode. |
| 38 class ASH_EXPORT PowerButtonController | 35 class ASH_EXPORT PowerButtonController |
| 39 : public ui::EventHandler | 36 : public ui::EventHandler |
| 40 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes | 37 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes |
| 41 // cross-platform. | 38 // cross-platform. |
| 42 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 43 , | 40 , |
| 44 public ui::DisplayConfigurator::Observer, | 41 public ui::DisplayConfigurator::Observer, |
| 45 public chromeos::PowerManagerClient::Observer | 42 public chromeos::PowerManagerClient::Observer |
| 46 #endif | 43 #endif |
| 47 { | 44 { |
| 48 public: | 45 public: |
| 46 // Helper class used by tablet power button tests to access internal state. | |
| 47 class ASH_EXPORT TestApi { | |
| 48 public: | |
| 49 explicit TestApi(PowerButtonController* controller); | |
| 50 virtual ~TestApi(); | |
| 51 | |
| 52 bool TabletPowerButtonTimerIsRunning() const; | |
|
Daniel Erat
2016/11/04 20:18:34
nit: add comments to both of these documenting wha
Qiang(Joe) Xu
2016/11/04 23:18:21
Done.
| |
| 53 | |
| 54 void TriggerTabletPowerButtonTimeout(); | |
| 55 | |
| 56 private: | |
| 57 PowerButtonController* controller_; // Not owned. | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
| 60 }; | |
| 61 | |
| 49 explicit PowerButtonController(LockStateController* controller); | 62 explicit PowerButtonController(LockStateController* controller); |
| 50 ~PowerButtonController() override; | 63 ~PowerButtonController() override; |
| 51 | 64 |
| 52 void set_has_legacy_power_button_for_test(bool legacy) { | 65 void set_has_legacy_power_button_for_test(bool legacy) { |
| 53 has_legacy_power_button_ = legacy; | 66 has_legacy_power_button_ = legacy; |
| 54 } | 67 } |
| 55 | 68 |
| 56 void set_enable_quick_lock_for_test(bool enable_quick_lock) { | 69 void set_enable_quick_lock_for_test(bool enable_quick_lock) { |
| 57 enable_quick_lock_ = enable_quick_lock; | 70 enable_quick_lock_ = enable_quick_lock; |
| 58 } | 71 } |
| 59 | 72 |
| 60 // Called when the current screen brightness changes. | 73 // Called when the current screen brightness changes. |
| 61 void OnScreenBrightnessChanged(double percent); | 74 void OnScreenBrightnessChanged(double percent); |
| 62 | 75 |
| 63 // Called when the power or lock buttons are pressed or released. | 76 // Called when the power or lock buttons are pressed or released. |
| 64 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 77 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 65 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 78 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 66 | 79 |
| 67 // ui::EventHandler: | 80 // ui::EventHandler: |
| 68 void OnKeyEvent(ui::KeyEvent* event) override; | 81 void OnKeyEvent(ui::KeyEvent* event) override; |
| 82 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 69 | 83 |
| 70 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
| 71 // Overriden from ui::DisplayConfigurator::Observer: | 85 // Overriden from ui::DisplayConfigurator::Observer: |
| 72 void OnDisplayModeChanged( | 86 void OnDisplayModeChanged( |
| 73 const ui::DisplayConfigurator::DisplayStateList& outputs) override; | 87 const ui::DisplayConfigurator::DisplayStateList& outputs) override; |
| 74 | 88 |
| 75 // Overridden from chromeos::PowerManagerClient::Observer: | 89 // Overridden from chromeos::PowerManagerClient::Observer: |
| 76 void PowerButtonEventReceived(bool down, | 90 void PowerButtonEventReceived(bool down, |
| 77 const base::TimeTicks& timestamp) override; | 91 const base::TimeTicks& timestamp) override; |
| 78 #endif | 92 #endif |
| 79 | 93 |
| 80 private: | 94 private: |
| 81 friend class test::PowerButtonControllerTest; | 95 // Called by OnPowerButtonEvent on convertible/tablet devices. |
| 96 void OnTabletPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | |
| 97 | |
| 98 // Set backlights to |forced_off| if needed. | |
| 99 void SetBacklightsForcedOff(bool forced_off); | |
| 100 | |
| 101 // Sends a request to powerd to get the backlights forced off state so that | |
| 102 // |backlights_forced_off_| can be initialized. | |
| 103 void GetInitialBacklightsForcedOff(); | |
| 104 | |
| 105 // Initializes |backlights_forced_off_|. | |
| 106 void OnGotInitialBacklightsForcedOff(bool is_forced_off); | |
| 107 | |
| 108 // Starts |tablet_power_button_timer_| when the power button is pressed while | |
| 109 // in tablet mode. | |
| 110 void StartTabletPowerButtonTimer(); | |
| 111 | |
| 112 // Called by |tablet_power_button_timer_| to start the pre-shutdown animation. | |
| 113 void OnTabletPowerButtonTimeout(); | |
| 114 | |
| 115 // Locks the screen if the "require password to wake from sleep" pref is set | |
| 116 // and locking is possible. | |
| 117 void LockScreenIfRequired(); | |
| 118 | |
| 119 // Returns true if device is a convertible/tablet device or has | |
| 120 // kAshEnableTouchViewTesting in test, otherwise false. | |
| 121 bool IsTabletModeSupported() const; | |
| 122 | |
| 123 // Returns true if device is currently in tablet/maximize mode, otherwise | |
| 124 // false. | |
| 125 bool IsTabletModeActive() const; | |
| 82 | 126 |
| 83 // Are the power or lock buttons currently held? | 127 // Are the power or lock buttons currently held? |
| 84 bool power_button_down_; | 128 bool power_button_down_; |
| 85 bool lock_button_down_; | 129 bool lock_button_down_; |
| 86 | 130 |
| 87 // True when the volume down button is being held down. | 131 // True when the volume down button is being held down. |
| 88 bool volume_down_pressed_; | 132 bool volume_down_pressed_; |
| 89 | 133 |
| 90 #if defined(OS_CHROMEOS) | 134 #if defined(OS_CHROMEOS) |
| 91 // Volume to be restored after a screenshot is taken by pressing the power | 135 // Volume to be restored after a screenshot is taken by pressing the power |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 103 | 147 |
| 104 // Was a command-line switch set telling us that we're running on hardware | 148 // Was a command-line switch set telling us that we're running on hardware |
| 105 // that misreports power button releases? | 149 // that misreports power button releases? |
| 106 bool has_legacy_power_button_; | 150 bool has_legacy_power_button_; |
| 107 | 151 |
| 108 // Enables quick, non-cancellable locking of the screen when in maximize mode. | 152 // Enables quick, non-cancellable locking of the screen when in maximize mode. |
| 109 bool enable_quick_lock_; | 153 bool enable_quick_lock_; |
| 110 | 154 |
| 111 LockStateController* controller_; // Not owned. | 155 LockStateController* controller_; // Not owned. |
| 112 | 156 |
| 157 // True if the screen was off when the power button was pressed. | |
| 158 bool power_button_down_while_screen_off_; | |
| 159 | |
| 160 // Current forced-off state of backlights. | |
| 161 bool backlights_forced_off_; | |
| 162 | |
| 163 // Started when the tablet power button is pressed and stopped when it's | |
| 164 // released. Runs OnTabletPowerButtonTimeout() to start shutdown. | |
| 165 base::OneShotTimer tablet_power_button_timer_; | |
| 166 | |
| 113 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 167 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
| 114 }; | 168 }; |
| 115 | 169 |
| 116 } // namespace ash | 170 } // namespace ash |
| 117 | 171 |
| 118 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 172 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
| OLD | NEW |