Index: ash/wm/tablet_power_button_controller.h |
diff --git a/ash/wm/tablet_power_button_controller.h b/ash/wm/tablet_power_button_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1bacce92b65addb8b138edd9e196f312392a8d75 |
--- /dev/null |
+++ b/ash/wm/tablet_power_button_controller.h |
@@ -0,0 +1,102 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef ASH_WM_TABLET_POWER_BUTTON_CONTROLLER_H_ |
+#define ASH_WM_TABLET_POWER_BUTTON_CONTROLLER_H_ |
+ |
+#include "ash/ash_export.h" |
+#include "base/macros.h" |
+#include "base/time/time.h" |
+#include "base/timer/timer.h" |
+#include "ui/events/event_handler.h" |
+ |
+namespace ash { |
+ |
+class LockStateController; |
+ |
+// Handles power button events on convertible/tablet device. This class is |
+// instantiated and used in PowerButtonController. |
+class ASH_EXPORT TabletPowerButtonController : public ui::EventHandler { |
+ public: |
+ // Helper class used by tablet power button tests to access internal state. |
+ class ASH_EXPORT TestApi { |
+ public: |
+ explicit TestApi(TabletPowerButtonController* controller); |
+ virtual ~TestApi(); |
+ |
+ // Returns true when |tablet_power_button_timer_| is not timeout. |
Daniel Erat
2016/11/07 20:54:41
s/is not timeout/is running/
Qiang(Joe) Xu
2016/11/10 22:18:45
Done.
|
+ bool TabletPowerButtonTimerIsRunning() const; |
+ |
+ // Emulates |tablet_power_button_timer_| timeout. |
+ void TriggerTabletPowerButtonTimeout(); |
+ |
+ private: |
+ TabletPowerButtonController* controller_; // Not owned. |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestApi); |
+ }; |
+ |
+ explicit TabletPowerButtonController(LockStateController* controller); |
+ ~TabletPowerButtonController() override; |
+ |
+ // Returns true if power button events should be handled by this class instead |
+ // of PowerButtonController. |
+ bool ShouldHandlePowerButtonEvents() const; |
+ |
+ void OnPowerButtonEvent(bool down, |
+ const base::TimeTicks& timestamp, |
+ bool brightness_is_zero); |
+ |
+ // ui::EventHandler: |
+ void OnKeyEvent(ui::KeyEvent* event) override; |
+ void OnMouseEvent(ui::MouseEvent* event) override; |
+ |
+ private: |
+ // Set backlights to |forced_off| if needed. |
+ void SetBacklightsForcedOff(bool forced_off); |
+ |
+ // Sends a request to powerd to get the backlights forced off state so that |
+ // |backlights_forced_off_| can be initialized. |
+ void GetInitialBacklightsForcedOff(); |
+ |
+ // Initializes |backlights_forced_off_|. |
+ void OnGotInitialBacklightsForcedOff(bool is_forced_off); |
+ |
+ // Starts |tablet_power_button_timer_| when the power button is pressed while |
+ // in tablet mode. |
+ void StartTabletPowerButtonTimer(); |
Daniel Erat
2016/11/07 20:54:41
nit: rename this to match the member's name (see b
Qiang(Joe) Xu
2016/11/10 22:18:45
Done.
|
+ |
+ // Called by |tablet_power_button_timer_| to start the pre-shutdown animation. |
+ void OnTabletPowerButtonTimeout(); |
Daniel Erat
2016/11/07 20:54:41
nit: rename
Qiang(Joe) Xu
2016/11/10 22:18:45
Done.
|
+ |
+ // Locks the screen if the "require password to wake from sleep" pref is set |
+ // and locking is possible. |
+ void LockScreenIfRequired(); |
+ |
+ // Returns true if device is a convertible/tablet device or has |
+ // kAshEnableTouchViewTesting in test, otherwise false. |
+ bool IsTabletModeSupported() const; |
+ |
+ // Returns true if device is currently in tablet/maximize mode, otherwise |
+ // false. |
+ bool IsTabletModeActive() const; |
+ |
+ // Current forced-off state of backlights. |
+ bool backlights_forced_off_ = false; |
+ |
+ // True if the screen was off when the power button was pressed. |
+ bool power_button_down_while_screen_off_ = false; |
Daniel Erat
2016/11/07 20:54:41
i know i suggested this name earlier, but how abou
Qiang(Joe) Xu
2016/11/10 22:18:45
Done.
|
+ |
+ // Started when the tablet power button is pressed and stopped when it's |
+ // released. Runs OnTabletPowerButtonTimeout() to start shutdown. |
+ base::OneShotTimer tablet_power_button_timer_; |
Daniel Erat
2016/11/07 20:54:41
how about renaming this to "shutdown_timer_" now?
Qiang(Joe) Xu
2016/11/10 22:18:45
Done.
|
+ |
+ LockStateController* controller_; // Not owned. |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonController); |
+}; |
+ |
+} // namespace ash |
+ |
+#endif // ASH_WM_TABLET_POWER_BUTTON_CONTROLLER_H_ |