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/callback.h" | |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/timer/timer.h" | |
11 #include "ui/events/event_handler.h" | 13 #include "ui/events/event_handler.h" |
12 | 14 |
13 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
14 #include "chromeos/dbus/power_manager_client.h" | 16 #include "chromeos/dbus/power_manager_client.h" |
15 #include "ui/display/chromeos/display_configurator.h" | 17 #include "ui/display/chromeos/display_configurator.h" |
16 #endif | 18 #endif |
17 | 19 |
18 namespace gfx { | 20 namespace gfx { |
19 class Rect; | 21 class Rect; |
20 class Size; | 22 class Size; |
21 } | 23 } |
22 | 24 |
23 namespace ui { | 25 namespace ui { |
24 class Layer; | 26 class Layer; |
25 } | 27 } |
26 | 28 |
27 namespace ash { | 29 namespace ash { |
28 | 30 |
29 namespace test { | 31 class LockStateController; |
30 class PowerButtonControllerTest; | |
31 } | |
32 | 32 |
33 class LockStateController; | 33 // Tablet power state delegate to handle environment specific work. |
34 class ASH_EXPORT TabletPowerStateDelegate { | |
35 public: | |
36 TabletPowerStateDelegate() {} | |
37 virtual ~TabletPowerStateDelegate() {} | |
38 | |
39 virtual void SetBacklightsForcedOff(bool forced_off) = 0; | |
40 | |
41 virtual void GetBacklightsForcedOff( | |
42 const base::Callback<void(bool)>& callback) = 0; | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(TabletPowerStateDelegate); | |
46 }; | |
34 | 47 |
35 // Handles power & lock button events which may result in the locking or | 48 // 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 | 49 // shutting down of the system as well as taking screen shots while in maximize |
37 // mode. | 50 // mode. |
38 class ASH_EXPORT PowerButtonController | 51 class ASH_EXPORT PowerButtonController |
39 : public ui::EventHandler | 52 : public ui::EventHandler |
40 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes | 53 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes |
41 // cross-platform. | 54 // cross-platform. |
42 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
43 , | 56 , |
44 public ui::DisplayConfigurator::Observer, | 57 public ui::DisplayConfigurator::Observer, |
45 public chromeos::PowerManagerClient::Observer | 58 public chromeos::PowerManagerClient::Observer |
46 #endif | 59 #endif |
47 { | 60 { |
48 public: | 61 public: |
62 // Helper class used by tablet power button tests to access internal state. | |
63 class ASH_EXPORT TestApi { | |
64 public: | |
65 explicit TestApi(PowerButtonController* controller); | |
66 virtual ~TestApi(); | |
67 | |
68 bool tablet_pre_start_shutdown_animation_timer_is_running() const { | |
69 return controller_->tablet_pre_start_shutdown_animation_timer_ | |
70 .IsRunning(); | |
71 } | |
72 | |
73 void trigger_tablet_pre_start_shutdown_animation_timeout() { | |
74 controller_->OnTabletPreStartShutdownAnimationTimeout(); | |
75 controller_->tablet_pre_start_shutdown_animation_timer_.Stop(); | |
76 } | |
77 | |
78 private: | |
79 PowerButtonController* controller_; // Not owned. | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
82 }; | |
83 | |
49 explicit PowerButtonController(LockStateController* controller); | 84 explicit PowerButtonController(LockStateController* controller); |
50 ~PowerButtonController() override; | 85 ~PowerButtonController() override; |
51 | 86 |
52 void set_has_legacy_power_button_for_test(bool legacy) { | 87 void set_has_legacy_power_button_for_test(bool legacy) { |
53 has_legacy_power_button_ = legacy; | 88 has_legacy_power_button_ = legacy; |
54 } | 89 } |
55 | 90 |
56 void set_enable_quick_lock_for_test(bool enable_quick_lock) { | 91 void set_enable_quick_lock_for_test(bool enable_quick_lock) { |
57 enable_quick_lock_ = enable_quick_lock; | 92 enable_quick_lock_ = enable_quick_lock; |
58 } | 93 } |
59 | 94 |
60 // Called when the current screen brightness changes. | 95 // Called when the current screen brightness changes. |
61 void OnScreenBrightnessChanged(double percent); | 96 void OnScreenBrightnessChanged(double percent); |
62 | 97 |
63 // Called when the power or lock buttons are pressed or released. | 98 // Called when the power or lock buttons are pressed or released. |
64 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 99 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
65 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 100 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
66 | 101 |
67 // ui::EventHandler: | 102 // ui::EventHandler: |
68 void OnKeyEvent(ui::KeyEvent* event) override; | 103 void OnKeyEvent(ui::KeyEvent* event) override; |
104 void OnMouseEvent(ui::MouseEvent* event) override; | |
69 | 105 |
70 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
71 // Overriden from ui::DisplayConfigurator::Observer: | 107 // Overriden from ui::DisplayConfigurator::Observer: |
72 void OnDisplayModeChanged( | 108 void OnDisplayModeChanged( |
73 const ui::DisplayConfigurator::DisplayStateList& outputs) override; | 109 const ui::DisplayConfigurator::DisplayStateList& outputs) override; |
74 | 110 |
75 // Overridden from chromeos::PowerManagerClient::Observer: | 111 // Overridden from chromeos::PowerManagerClient::Observer: |
76 void PowerButtonEventReceived(bool down, | 112 void PowerButtonEventReceived(bool down, |
77 const base::TimeTicks& timestamp) override; | 113 const base::TimeTicks& timestamp) override; |
78 #endif | 114 #endif |
79 | 115 |
80 private: | 116 private: |
81 friend class test::PowerButtonControllerTest; | 117 // A helper method to be called on convertible/tablet device. |
Daniel Erat
2016/11/03 21:28:08
nit: // Called by OnPowerButtonEvent on convertibl
Qiang(Joe) Xu
2016/11/04 01:14:04
Done.
| |
118 void OnTabletPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | |
119 | |
120 // |tablet_power_state_delegate_| will set backlights to |forced_off| | |
121 // if needed. | |
122 void SetBacklightsForcedOff(bool forced_off); | |
123 | |
124 // Sends a request to get the backlights forced off state so that | |
125 // |backlights_forced_off_| can be initialized. | |
126 void GetInitialBacklightsForcedOff(); | |
127 | |
128 // Updates |backlights_forced_off_| requested by | |
129 // GetInitialBacklightsForcedOff, if |is_forced_off|, then set backlights | |
130 // forced off to false. | |
131 void HandleInitialBacklightsForcedOff(bool is_forced_off); | |
132 | |
133 // When power button is pressed, spin a 1s timer before starting shutdown | |
134 // white animation managed by |controller_|. | |
135 void StartTabletPreStartShutdownAnimationTimer(); | |
136 | |
137 // When this timer times out, starting shutdown white animation managed | |
138 // by |controller_|. | |
139 void OnTabletPreStartShutdownAnimationTimeout(); | |
140 | |
141 // If user has "require password to wake from sleep" pref set in profile, | |
142 // setting backlights forced off should be accompanied with locking screen. | |
143 void LockScreenIfRequired(); | |
144 | |
145 // Allow KeyEvent/MouseEvent wake convertible device when it is working on | |
146 // laptop mode. | |
147 void WakeOnLaptopMode(); | |
148 | |
149 // Return true (need taking screenshot operation) when |power_button_pressed| | |
150 // is true, otherwise false. | |
151 bool MaybeTakeScreenshot(bool power_button_pressed); | |
Daniel Erat
2016/11/03 21:28:08
"MaybeTakeScreenshot" suggests that this method mi
Qiang(Joe) Xu
2016/11/04 01:14:04
Done.
| |
152 | |
153 // The one sec timer to wait for tablet power button released. If it is | |
154 // timeout, |controller_| will start shutdown white animation. | |
155 base::OneShotTimer tablet_pre_start_shutdown_animation_timer_; | |
82 | 156 |
83 // Are the power or lock buttons currently held? | 157 // Are the power or lock buttons currently held? |
84 bool power_button_down_; | 158 bool power_button_down_; |
85 bool lock_button_down_; | 159 bool lock_button_down_; |
86 | 160 |
87 // True when the volume down button is being held down. | 161 // True when the volume down button is being held down. |
88 bool volume_down_pressed_; | 162 bool volume_down_pressed_; |
89 | 163 |
90 #if defined(OS_CHROMEOS) | 164 #if defined(OS_CHROMEOS) |
91 // Volume to be restored after a screenshot is taken by pressing the power | 165 // Volume to be restored after a screenshot is taken by pressing the power |
(...skipping 11 matching lines...) Expand all Loading... | |
103 | 177 |
104 // Was a command-line switch set telling us that we're running on hardware | 178 // Was a command-line switch set telling us that we're running on hardware |
105 // that misreports power button releases? | 179 // that misreports power button releases? |
106 bool has_legacy_power_button_; | 180 bool has_legacy_power_button_; |
107 | 181 |
108 // Enables quick, non-cancellable locking of the screen when in maximize mode. | 182 // Enables quick, non-cancellable locking of the screen when in maximize mode. |
109 bool enable_quick_lock_; | 183 bool enable_quick_lock_; |
110 | 184 |
111 LockStateController* controller_; // Not owned. | 185 LockStateController* controller_; // Not owned. |
112 | 186 |
187 // To differentiate a power button pressed is taking on screen off or not. | |
188 bool pressed_on_screen_off_; | |
Daniel Erat
2016/11/03 21:28:08
this name is a bit vague. how about "power_button_
Qiang(Joe) Xu
2016/11/04 01:14:04
Done.
| |
189 | |
190 // Saving backlights forced off state, so that it doesn't need to bother | |
191 // calling GetBacklightsForcedOff method. | |
192 bool backlights_forced_off_; | |
193 | |
194 // TabletPowerStateDelegate object, currently supported on ChromeOS only, for | |
195 // other environments, it is nullptr. | |
196 std::unique_ptr<TabletPowerStateDelegate> tablet_power_state_delegate_; | |
197 | |
113 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 198 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
114 }; | 199 }; |
115 | 200 |
116 } // namespace ash | 201 } // namespace ash |
117 | 202 |
118 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 203 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
OLD | NEW |