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