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

Side by Side Diff: ash/system/chromeos/power/tablet_power_button_controller.h

Issue 2474913004: Tablet-like power button behavior on Convertible/Tablet ChromeOS devices (Closed)
Patch Set: cr and additional changes 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
(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 "ash/ash_export.h"
9 #include "base/macros.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
12 #include "chromeos/dbus/power_manager_client.h"
13 #include "ui/events/devices/input_device_event_observer.h"
14 #include "ui/events/event_handler.h"
15
16 namespace ash {
17
18 class LockStateController;
19
20 // Handles power button events on convertible/tablet device. This class is
21 // instantiated and used in PowerButtonController.
22 class ASH_EXPORT TabletPowerButtonController
23 : public chromeos::PowerManagerClient::Observer,
24 public ui::EventHandler,
25 public ui::InputDeviceEventObserver {
26 public:
27 // Helper class used by tablet power button tests to access internal state.
28 class ASH_EXPORT TestApi {
29 public:
30 explicit TestApi(TabletPowerButtonController* controller);
31 virtual ~TestApi();
Daniel Erat 2016/11/10 22:48:55 this doesn't need to be virtual
Qiang(Joe) Xu 2016/11/11 04:39:23 Done.
32
33 // Returns true when |shutdown_timer_| is running.
34 bool ShutdownTimerIsRunning() const;
35
36 // Emulates |shutdown_timer_| timeout.
37 void TriggerShutdownTimeout();
38
39 private:
40 TabletPowerButtonController* controller_; // Not owned.
41
42 DISALLOW_COPY_AND_ASSIGN(TestApi);
43 };
44
45 explicit TabletPowerButtonController(LockStateController* controller);
46 ~TabletPowerButtonController() override;
47
48 static TabletPowerButtonController* GetInstance();
Daniel Erat 2016/11/10 22:48:55 if at all possible, please don't introduce new sin
Qiang(Joe) Xu 2016/11/11 04:39:23 I see. I make TabletPowerButtonController belongs
49
50 // Returns true if power button events should be handled by this class instead
51 // of PowerButtonController.
52 bool ShouldHandlePowerButtonEvents() const;
53
54 // Handles a power button event.
55 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
56
57 // Overriden from chromeos::PowerManagerClient::Observer:
58 void PowerManagerRestarted() override;
59 void BrightnessChanged(int level, bool user_initiated) override;
60 void SuspendDone(const base::TimeDelta& sleep_duration) override;
61
62 // Overriden from ui::EventHandler:
63 void OnKeyEvent(ui::KeyEvent* event) override;
64 void OnMouseEvent(ui::MouseEvent* event) override;
65
66 // Overriden from ui::InputDeviceObserver:
67 void OnStylusStateChanged(ui::StylusState state) override;
68
69 private:
70 // Set backlights to |forced_off| if needed.
Daniel Erat 2016/11/10 22:48:55 nit: s/if needed/if they aren't already/
Qiang(Joe) Xu 2016/11/11 04:39:23 Done.
71 void SetBacklightsForcedOff(bool forced_off);
72
73 // Sends a request to powerd to get the backlights forced off state so that
74 // |backlights_forced_off_| can be initialized.
75 void GetInitialBacklightsForcedOff();
76
77 // Initializes |backlights_forced_off_|.
78 void OnGotInitialBacklightsForcedOff(bool is_forced_off);
79
80 // Starts |shutdown_timer_| when the power button is pressed while in
81 // tablet mode.
82 void StartShutdownTimer();
83
84 // Called by |shutdown_timer_| to start the pre-shutdown animation.
85 void OnShutdownTimeout();
86
87 // Locks the screen if the "require password to wake from sleep" pref is set
88 // and locking is possible.
89 void LockScreenIfRequired();
90
91 // True if the brightness level is currently set to off.
92 bool brightness_level_is_zero_ = false;
93
94 // Current forced-off state of backlights.
95 bool backlights_forced_off_ = false;
96
97 // True if the screen was off when the power button was pressed.
98 bool screen_off_when_power_button_down_ = false;
99
100 // Saves the most recent timestamp that powerd is resuming from suspend,
101 // updated in SuspendDone().
102 base::TimeTicks last_resume_time_;
103
104 // Started when the tablet power button is pressed and stopped when it's
105 // released. Runs OnShutdownTimeout() to start shutdown.
106 base::OneShotTimer shutdown_timer_;
107
108 LockStateController* controller_; // Not owned.
109
110 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonController);
111 };
112
113 } // namespace ash
114
115 #endif // ASH_SYSTEM_CHROMEOS_POWER_TABLET_POWER_BUTTON_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698