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

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

Powered by Google App Engine
This is Rietveld 408576698