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

Side by Side Diff: ash/system/chromeos/power/tablet_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/BUILD.gn ('k') | ash/system/chromeos/power/tablet_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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
7
8 #include <memory>
9
10 #include "ash/ash_export.h"
11 #include "base/macros.h"
12 #include "base/time/tick_clock.h"
13 #include "base/time/time.h"
14 #include "base/timer/timer.h"
15 #include "chromeos/dbus/power_manager_client.h"
16 #include "ui/events/devices/input_device_event_observer.h"
17 #include "ui/events/event_handler.h"
18
19 namespace ash {
20
21 class LockStateController;
22
23 // Handles power button events on convertible/tablet device. This class is
24 // instantiated and used in PowerButtonController.
25 class ASH_EXPORT TabletPowerButtonController
26 : public chromeos::PowerManagerClient::Observer,
27 public ui::EventHandler,
28 public ui::InputDeviceEventObserver {
29 public:
30 // Helper class used by tablet power button tests to access internal state.
31 class ASH_EXPORT TestApi {
32 public:
33 explicit TestApi(TabletPowerButtonController* controller);
34 ~TestApi();
35
36 // Returns true when |shutdown_timer_| is running.
37 bool ShutdownTimerIsRunning() const;
38
39 // Emulates |shutdown_timer_| timeout.
40 void TriggerShutdownTimeout();
41
42 private:
43 TabletPowerButtonController* controller_; // Not owned.
44
45 DISALLOW_COPY_AND_ASSIGN(TestApi);
46 };
47
48 explicit TabletPowerButtonController(LockStateController* controller);
49 ~TabletPowerButtonController() override;
50
51 // Returns true if power button events should be handled by this class instead
52 // of PowerButtonController.
53 bool ShouldHandlePowerButtonEvents() const;
54
55 // Handles a power button event.
56 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
57
58 // Overridden from chromeos::PowerManagerClient::Observer:
59 void PowerManagerRestarted() override;
60 void BrightnessChanged(int level, bool user_initiated) override;
61 void SuspendDone(const base::TimeDelta& sleep_duration) override;
62
63 // Overridden from ui::EventHandler:
64 void OnKeyEvent(ui::KeyEvent* event) override;
65 void OnMouseEvent(ui::MouseEvent* event) override;
66
67 // Overridden from ui::InputDeviceObserver:
68 void OnStylusStateChanged(ui::StylusState state) override;
69
70 // Overrides the tick clock used by |this| for testing.
71 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
72
73 private:
74 // Set backlights to |forced_off| if they aren't already.
75 void SetBacklightsForcedOff(bool forced_off);
76
77 // Sends a request to powerd to get the backlights forced off state so that
78 // |backlights_forced_off_| can be initialized.
79 void GetInitialBacklightsForcedOff();
80
81 // Initializes |backlights_forced_off_|.
82 void OnGotInitialBacklightsForcedOff(bool is_forced_off);
83
84 // Starts |shutdown_timer_| when the power button is pressed while in
85 // tablet mode.
86 void StartShutdownTimer();
87
88 // Called by |shutdown_timer_| to start the pre-shutdown animation.
89 void OnShutdownTimeout();
90
91 // Locks the screen if the "require password to wake from sleep" pref is set
92 // and locking is possible.
93 void LockScreenIfRequired();
94
95 // True if the brightness level is currently set to off.
96 bool brightness_level_is_zero_ = false;
97
98 // Current forced-off state of backlights.
99 bool backlights_forced_off_ = false;
100
101 // True if the screen was off when the power button was pressed.
102 bool screen_off_when_power_button_down_ = false;
103
104 // Time source for performed action times.
105 std::unique_ptr<base::TickClock> tick_clock_;
106
107 // Saves the most recent timestamp that powerd is resuming from suspend,
108 // updated in SuspendDone().
109 base::TimeTicks last_resume_time_;
110
111 // Started when the tablet power button is pressed and stopped when it's
112 // released. Runs OnShutdownTimeout() to start shutdown.
113 base::OneShotTimer shutdown_timer_;
114
115 LockStateController* controller_; // Not owned.
116
117 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonController);
118 };
119
120 } // namespace ash
121
122 #endif // ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ash/BUILD.gn ('k') | ash/system/chromeos/power/tablet_power_button_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698