Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: ash/wm/power_button_controller.h

Issue 2474913004: Tablet-like power button behavior on Convertible/Tablet ChromeOS devices (Closed)
Patch Set: based on Daniel's comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 tablet_pre_start_shutdown_animation_timer_is_running() const {
Daniel Erat 2016/11/04 16:12:52 neither of these are trivial getters or setters, s
Qiang(Joe) Xu 2016/11/04 19:29:51 Done.
53 return controller_->tablet_pre_start_shutdown_animation_timer_
54 .IsRunning();
55 }
56
57 void trigger_tablet_pre_start_shutdown_animation_timeout() {
58 controller_->OnTabletPreStartShutdownAnimationTimeout();
59 controller_->tablet_pre_start_shutdown_animation_timer_.Stop();
60 }
61
62 private:
63 PowerButtonController* controller_; // Not owned.
64
65 DISALLOW_COPY_AND_ASSIGN(TestApi);
66 };
67
49 explicit PowerButtonController(LockStateController* controller); 68 explicit PowerButtonController(LockStateController* controller);
50 ~PowerButtonController() override; 69 ~PowerButtonController() override;
51 70
52 void set_has_legacy_power_button_for_test(bool legacy) { 71 void set_has_legacy_power_button_for_test(bool legacy) {
53 has_legacy_power_button_ = legacy; 72 has_legacy_power_button_ = legacy;
54 } 73 }
55 74
56 void set_enable_quick_lock_for_test(bool enable_quick_lock) { 75 void set_enable_quick_lock_for_test(bool enable_quick_lock) {
57 enable_quick_lock_ = enable_quick_lock; 76 enable_quick_lock_ = enable_quick_lock;
58 } 77 }
59 78
60 // Called when the current screen brightness changes. 79 // Called when the current screen brightness changes.
61 void OnScreenBrightnessChanged(double percent); 80 void OnScreenBrightnessChanged(double percent);
62 81
63 // Called when the power or lock buttons are pressed or released. 82 // Called when the power or lock buttons are pressed or released.
64 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); 83 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
65 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); 84 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp);
66 85
67 // ui::EventHandler: 86 // ui::EventHandler:
68 void OnKeyEvent(ui::KeyEvent* event) override; 87 void OnKeyEvent(ui::KeyEvent* event) override;
88 void OnMouseEvent(ui::MouseEvent* event) override;
69 89
70 #if defined(OS_CHROMEOS) 90 #if defined(OS_CHROMEOS)
71 // Overriden from ui::DisplayConfigurator::Observer: 91 // Overriden from ui::DisplayConfigurator::Observer:
72 void OnDisplayModeChanged( 92 void OnDisplayModeChanged(
73 const ui::DisplayConfigurator::DisplayStateList& outputs) override; 93 const ui::DisplayConfigurator::DisplayStateList& outputs) override;
74 94
75 // Overridden from chromeos::PowerManagerClient::Observer: 95 // Overridden from chromeos::PowerManagerClient::Observer:
76 void PowerButtonEventReceived(bool down, 96 void PowerButtonEventReceived(bool down,
77 const base::TimeTicks& timestamp) override; 97 const base::TimeTicks& timestamp) override;
78 #endif 98 #endif
79 99
80 private: 100 private:
81 friend class test::PowerButtonControllerTest; 101 // Called by OnPowerButtonEvent on convertible/tablet devices.
102 void OnTabletPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
103
104 // Set backlights to |forced_off| if needed.
105 void SetBacklightsForcedOff(bool forced_off);
106
107 // Sends a request to get the backlights forced off state so that
Daniel Erat 2016/11/04 16:12:52 nit: "... a request to powerd to get ..."
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
108 // |backlights_forced_off_| can be initialized.
109 void GetInitialBacklightsForcedOff();
110
111 // Initializes |backlights_forced_off_|.
112 void HandleInitialBacklightsForcedOff(bool is_forced_off);
Daniel Erat 2016/11/04 16:12:52 nit: OnGotInitialBacklightsForcedOff for consisten
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
113
114 // When power button is pressed, spin a 1s timer before starting shutdown
115 // white animation managed by |controller_|.
Daniel Erat 2016/11/04 16:12:52 // Starts |tablet_power_button_timer_| when the po
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
116 void StartTabletPreStartShutdownAnimationTimer();
117
118 // When this timer times out, starting shutdown white animation managed
119 // by |controller_|.
Daniel Erat 2016/11/04 16:12:52 // Called by |tablet_power_button_timer_| to start
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
120 void OnTabletPreStartShutdownAnimationTimeout();
121
122 // If user has "require password to wake from sleep" pref set in profile,
123 // setting backlights forced off should be accompanied with locking screen.
Daniel Erat 2016/11/04 16:12:52 // Locks the screen if the "require password to wa
Qiang(Joe) Xu 2016/11/04 19:29:51 Done.
124 void LockScreenIfRequired();
125
126 // Returns true if device is a convertible/tablet device or has
127 // kAshEnableTouchViewTesting in test, otherwise false.
128 bool IsTabletModeSupported() const;
129
130 // Returns true if device works in tablet/maximize mode, otherwise false.
Daniel Erat 2016/11/04 16:12:52 s/if device works in/if device is currently in/
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
131 bool IsTabletModeActive() const;
132
133 // The one sec timer to wait for tablet power button released. If it is
Daniel Erat 2016/11/04 16:12:52 nit: mind moving this down to the bottom instead o
Qiang(Joe) Xu 2016/11/04 19:29:51 Done.
134 // timeout, |controller_| will start shutdown white animation.
135 base::OneShotTimer tablet_pre_start_shutdown_animation_timer_;
Daniel Erat 2016/11/04 16:12:52 maybe just call this tablet_power_button_timer_? i
Qiang(Joe) Xu 2016/11/04 19:29:52 OK. I agree with this change.
82 136
83 // Are the power or lock buttons currently held? 137 // Are the power or lock buttons currently held?
84 bool power_button_down_; 138 bool power_button_down_;
85 bool lock_button_down_; 139 bool lock_button_down_;
86 140
87 // True when the volume down button is being held down. 141 // True when the volume down button is being held down.
88 bool volume_down_pressed_; 142 bool volume_down_pressed_;
89 143
90 #if defined(OS_CHROMEOS) 144 #if defined(OS_CHROMEOS)
91 // Volume to be restored after a screenshot is taken by pressing the power 145 // Volume to be restored after a screenshot is taken by pressing the power
(...skipping 11 matching lines...) Expand all
103 157
104 // Was a command-line switch set telling us that we're running on hardware 158 // Was a command-line switch set telling us that we're running on hardware
105 // that misreports power button releases? 159 // that misreports power button releases?
106 bool has_legacy_power_button_; 160 bool has_legacy_power_button_;
107 161
108 // Enables quick, non-cancellable locking of the screen when in maximize mode. 162 // Enables quick, non-cancellable locking of the screen when in maximize mode.
109 bool enable_quick_lock_; 163 bool enable_quick_lock_;
110 164
111 LockStateController* controller_; // Not owned. 165 LockStateController* controller_; // Not owned.
112 166
167 // To differentiate a power button pressed is taking on while screen is off
168 // or not.
Daniel Erat 2016/11/04 16:12:52 // True if the screen was off when the power butto
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
169 bool power_button_down_while_screen_off_;
170
171 // Saving backlights forced off state, so that it doesn't need to bother
172 // calling GetBacklightsForcedOff method.
Daniel Erat 2016/11/04 16:12:52 // Current forced-off state of backlights.
Qiang(Joe) Xu 2016/11/04 19:29:52 Done.
173 bool backlights_forced_off_;
174
113 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); 175 DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
114 }; 176 };
115 177
116 } // namespace ash 178 } // namespace ash
117 179
118 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ 180 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698