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

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: nits 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
« no previous file with comments | « ash/wm/lock_state_controller_unittest.cc ('k') | ash/wm/power_button_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory>
9
8 #include "ash/ash_export.h" 10 #include "ash/ash_export.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/time/time.h" 12 #include "base/time/time.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 {
30 class PowerButtonControllerTest;
31 }
32
33 class LockStateController; 31 class LockStateController;
32 #if defined(OS_CHROMEOS)
33 class TabletPowerButtonController;
34 #endif
34 35
35 // Handles power & lock button events which may result in the locking or 36 // 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 37 // shutting down of the system as well as taking screen shots while in maximize
37 // mode. 38 // mode.
38 class ASH_EXPORT PowerButtonController 39 class ASH_EXPORT PowerButtonController
39 : public ui::EventHandler 40 : public ui::EventHandler
40 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes 41 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes
41 // cross-platform. 42 // cross-platform.
42 #if defined(OS_CHROMEOS) 43 #if defined(OS_CHROMEOS)
43 , 44 ,
44 public ui::DisplayConfigurator::Observer, 45 public ui::DisplayConfigurator::Observer,
45 public chromeos::PowerManagerClient::Observer 46 public chromeos::PowerManagerClient::Observer
46 #endif 47 #endif
47 { 48 {
48 public: 49 public:
49 explicit PowerButtonController(LockStateController* controller); 50 explicit PowerButtonController(LockStateController* controller);
50 ~PowerButtonController() override; 51 ~PowerButtonController() override;
51 52
52 void set_has_legacy_power_button_for_test(bool legacy) { 53 void set_has_legacy_power_button_for_test(bool legacy) {
53 has_legacy_power_button_ = legacy; 54 has_legacy_power_button_ = legacy;
54 } 55 }
55 56
56 void set_enable_quick_lock_for_test(bool enable_quick_lock) {
57 enable_quick_lock_ = enable_quick_lock;
58 }
59
60 // Called when the current screen brightness changes. 57 // Called when the current screen brightness changes.
61 void OnScreenBrightnessChanged(double percent); 58 void OnScreenBrightnessChanged(double percent);
62 59
63 // Called when the power or lock buttons are pressed or released. 60 // Called when the power or lock buttons are pressed or released.
64 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); 61 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
65 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); 62 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp);
66 63
67 // ui::EventHandler: 64 // ui::EventHandler:
68 void OnKeyEvent(ui::KeyEvent* event) override; 65 void OnKeyEvent(ui::KeyEvent* event) override;
69 66
70 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
71 // Overriden from ui::DisplayConfigurator::Observer: 68 // Overriden from ui::DisplayConfigurator::Observer:
72 void OnDisplayModeChanged( 69 void OnDisplayModeChanged(
73 const ui::DisplayConfigurator::DisplayStateList& outputs) override; 70 const ui::DisplayConfigurator::DisplayStateList& outputs) override;
74 71
75 // Overridden from chromeos::PowerManagerClient::Observer: 72 // Overridden from chromeos::PowerManagerClient::Observer:
76 void PowerButtonEventReceived(bool down, 73 void PowerButtonEventReceived(bool down,
77 const base::TimeTicks& timestamp) override; 74 const base::TimeTicks& timestamp) override;
75
76 TabletPowerButtonController* tablet_power_button_controller_for_test() {
77 return tablet_controller_.get();
78 }
78 #endif 79 #endif
79 80
80 private: 81 private:
81 friend class test::PowerButtonControllerTest;
82
83 // Are the power or lock buttons currently held? 82 // Are the power or lock buttons currently held?
84 bool power_button_down_; 83 bool power_button_down_;
85 bool lock_button_down_; 84 bool lock_button_down_;
86 85
87 // True when the volume down button is being held down. 86 // True when the volume down button is being held down.
88 bool volume_down_pressed_; 87 bool volume_down_pressed_;
89 88
90 #if defined(OS_CHROMEOS) 89 #if defined(OS_CHROMEOS)
91 // Volume to be restored after a screenshot is taken by pressing the power 90 // Volume to be restored after a screenshot is taken by pressing the power
92 // button while holding VKEY_VOLUME_DOWN. 91 // button while holding VKEY_VOLUME_DOWN.
93 int volume_percent_before_screenshot_; 92 int volume_percent_before_screenshot_;
94 #endif 93 #endif
95 94
96 // Has the screen brightness been reduced to 0%? 95 // Has the screen brightness been reduced to 0%?
97 bool brightness_is_zero_; 96 bool brightness_is_zero_;
98 97
99 // True if an internal display is off while an external display is on (e.g. 98 // True if an internal display is off while an external display is on (e.g.
100 // for Chrome OS's docked mode, where a Chromebook's lid is closed while an 99 // for Chrome OS's docked mode, where a Chromebook's lid is closed while an
101 // external display is connected). 100 // external display is connected).
102 bool internal_display_off_and_external_display_on_; 101 bool internal_display_off_and_external_display_on_;
103 102
104 // Was a command-line switch set telling us that we're running on hardware 103 // Was a command-line switch set telling us that we're running on hardware
105 // that misreports power button releases? 104 // that misreports power button releases?
106 bool has_legacy_power_button_; 105 bool has_legacy_power_button_;
107 106
108 // Enables quick, non-cancellable locking of the screen when in maximize mode. 107 LockStateController* lock_state_controller_; // Not owned.
109 bool enable_quick_lock_;
110 108
111 LockStateController* controller_; // Not owned. 109 #if defined(OS_CHROMEOS)
110 // Handles events for convertible/tablet devices.
111 std::unique_ptr<TabletPowerButtonController> tablet_controller_;
112 #endif
112 113
113 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); 114 DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
114 }; 115 };
115 116
116 } // namespace ash 117 } // namespace ash
117 118
118 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ 119 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ash/wm/lock_state_controller_unittest.cc ('k') | ash/wm/power_button_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698