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

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

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