Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_WM_TABLET_POWER_BUTTON_CONTROLLER_H_ | |
| 6 #define ASH_WM_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 "ui/events/event_handler.h" | |
| 13 | |
| 14 namespace ash { | |
| 15 | |
| 16 class LockStateController; | |
| 17 | |
| 18 // Handles power button events on convertible/tablet device. This class is | |
| 19 // instantiated and used in PowerButtonController. | |
| 20 class ASH_EXPORT TabletPowerButtonController : public ui::EventHandler { | |
| 21 public: | |
| 22 // Helper class used by tablet power button tests to access internal state. | |
| 23 class ASH_EXPORT TestApi { | |
| 24 public: | |
| 25 explicit TestApi(TabletPowerButtonController* controller); | |
| 26 virtual ~TestApi(); | |
| 27 | |
| 28 // Returns true when |tablet_power_button_timer_| is not timeout. | |
| 29 bool TabletPowerButtonTimerIsRunning() const; | |
| 30 | |
| 31 // Emulates |tablet_power_button_timer_| timeout. | |
| 32 void TriggerTabletPowerButtonTimeout(); | |
| 33 | |
| 34 private: | |
| 35 TabletPowerButtonController* controller_; // Not owned. | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
| 38 }; | |
| 39 | |
| 40 explicit TabletPowerButtonController(LockStateController* controller); | |
| 41 ~TabletPowerButtonController() override; | |
| 42 | |
| 43 // Returns true if power button events should be handled by this class instead | |
| 44 // of PowerButtonController. | |
| 45 bool ShouldHandlePowerButtonEvents() const; | |
|
Qiang(Joe) Xu
2016/11/04 23:18:21
It is the same as "IsTabletModeSupported". Using S
| |
| 46 | |
| 47 void OnPowerButtonEvent(bool down, | |
| 48 const base::TimeTicks& timestamp, | |
| 49 bool brightness_is_zero); | |
| 50 | |
| 51 // ui::EventHandler: | |
| 52 void OnKeyEvent(ui::KeyEvent* event) override; | |
| 53 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 54 | |
| 55 private: | |
| 56 // Set backlights to |forced_off| if needed. | |
| 57 void SetBacklightsForcedOff(bool forced_off); | |
| 58 | |
| 59 // Sends a request to powerd to get the backlights forced off state so that | |
| 60 // |backlights_forced_off_| can be initialized. | |
| 61 void GetInitialBacklightsForcedOff(); | |
| 62 | |
| 63 // Initializes |backlights_forced_off_|. | |
| 64 void OnGotInitialBacklightsForcedOff(bool is_forced_off); | |
| 65 | |
| 66 // Starts |tablet_power_button_timer_| when the power button is pressed while | |
| 67 // in tablet mode. | |
| 68 void StartTabletPowerButtonTimer(); | |
| 69 | |
| 70 // Called by |tablet_power_button_timer_| to start the pre-shutdown animation. | |
| 71 void OnTabletPowerButtonTimeout(); | |
| 72 | |
| 73 // Locks the screen if the "require password to wake from sleep" pref is set | |
| 74 // and locking is possible. | |
| 75 void LockScreenIfRequired(); | |
| 76 | |
| 77 // Returns true if device is a convertible/tablet device or has | |
| 78 // kAshEnableTouchViewTesting in test, otherwise false. | |
| 79 bool IsTabletModeSupported() const; | |
| 80 | |
| 81 // Returns true if device is currently in tablet/maximize mode, otherwise | |
| 82 // false. | |
| 83 bool IsTabletModeActive() const; | |
| 84 | |
| 85 // Current forced-off state of backlights. | |
| 86 bool backlights_forced_off_ = false; | |
| 87 | |
| 88 // True if the screen was off when the power button was pressed. | |
| 89 bool power_button_down_while_screen_off_ = false; | |
| 90 | |
| 91 // Started when the tablet power button is pressed and stopped when it's | |
| 92 // released. Runs OnTabletPowerButtonTimeout() to start shutdown. | |
| 93 base::OneShotTimer tablet_power_button_timer_; | |
| 94 | |
| 95 LockStateController* controller_; // Not owned. | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonController); | |
| 98 }; | |
| 99 | |
| 100 } // namespace ash | |
| 101 | |
| 102 #endif // ASH_WM_TABLET_POWER_BUTTON_CONTROLLER_H_ | |
| OLD | NEW |