| 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/accelerators/accelerator_controller.h" |
| 9 #include "ash/accelerators/accelerator_table.h" |
| 8 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 9 #include "ash/wm/session_state_animator.h" | 11 #include "ash/wm/session_state_animator.h" |
| 10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "ui/base/accelerators/accelerator.h" |
| 11 | 14 |
| 12 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
| 13 #include "ui/display/chromeos/display_configurator.h" | 16 #include "ui/display/chromeos/display_configurator.h" |
| 14 #endif | 17 #endif |
| 15 | 18 |
| 16 namespace gfx { | 19 namespace gfx { |
| 17 class Rect; | 20 class Rect; |
| 18 class Size; | 21 class Size; |
| 19 } | 22 } |
| 20 | 23 |
| 21 namespace ui { | 24 namespace ui { |
| 22 class Layer; | 25 class Layer; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace ash { | 28 namespace ash { |
| 26 | 29 |
| 27 namespace test { | 30 namespace test { |
| 28 class PowerButtonControllerTest; | 31 class PowerButtonControllerTest; |
| 29 } | 32 } |
| 30 | 33 |
| 31 class LockStateController; | 34 class LockStateController; |
| 32 | 35 |
| 33 // Displays onscreen animations and locks or suspends the system in response to | 36 // Handles power & lock button events which may result in the locking or |
| 34 // the power button being pressed or released. | 37 // shutting down of the system as well as taking screen shots. |
| 35 class ASH_EXPORT PowerButtonController | 38 class ASH_EXPORT PowerButtonController |
| 39 : ui::EventHandler |
| 36 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes | 40 // TODO(derat): Remove these ifdefs after DisplayConfigurator becomes |
| 37 // cross-platform. | 41 // cross-platform. |
| 38 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
| 39 : public ui::DisplayConfigurator::Observer | 43 , public ui::DisplayConfigurator::Observer |
| 40 #endif | 44 #endif |
| 41 { | 45 { |
| 42 public: | 46 public: |
| 43 explicit PowerButtonController(LockStateController* controller); | 47 explicit PowerButtonController(LockStateController* controller); |
| 44 virtual ~PowerButtonController(); | 48 virtual ~PowerButtonController(); |
| 45 | 49 |
| 46 void set_has_legacy_power_button_for_test(bool legacy) { | 50 void set_has_legacy_power_button_for_test(bool legacy) { |
| 47 has_legacy_power_button_ = legacy; | 51 has_legacy_power_button_ = legacy; |
| 48 } | 52 } |
| 49 | 53 |
| 54 void set_enable_quick_lock_for_test(bool enable_quick_lock) { |
| 55 enable_quick_lock_ = enable_quick_lock; |
| 56 } |
| 57 |
| 50 // Called when the current screen brightness changes. | 58 // Called when the current screen brightness changes. |
| 51 void OnScreenBrightnessChanged(double percent); | 59 void OnScreenBrightnessChanged(double percent); |
| 52 | 60 |
| 53 // Called when the power or lock buttons are pressed or released. | 61 // Called when the power or lock buttons are pressed or released. |
| 54 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 62 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 55 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 63 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 56 | 64 |
| 65 // ui::EventHandler: |
| 66 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 67 |
| 57 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
| 58 // Overriden from ui::DisplayConfigurator::Observer: | 69 // Overriden from ui::DisplayConfigurator::Observer: |
| 59 virtual void OnDisplayModeChanged( | 70 virtual void OnDisplayModeChanged( |
| 60 const ui::DisplayConfigurator::DisplayStateList& outputs) OVERRIDE; | 71 const ui::DisplayConfigurator::DisplayStateList& outputs) OVERRIDE; |
| 61 #endif | 72 #endif |
| 62 | 73 |
| 63 private: | 74 private: |
| 64 friend class test::PowerButtonControllerTest; | 75 friend class test::PowerButtonControllerTest; |
| 65 | 76 |
| 66 // Are the power or lock buttons currently held? | 77 // Are the power or lock buttons currently held? |
| 67 bool power_button_down_; | 78 bool power_button_down_; |
| 68 bool lock_button_down_; | 79 bool lock_button_down_; |
| 69 | 80 |
| 81 // True when the volume down button is being held down. |
| 82 bool volume_down_pressed_; |
| 83 |
| 70 // Has the screen brightness been reduced to 0%? | 84 // Has the screen brightness been reduced to 0%? |
| 71 bool brightness_is_zero_; | 85 bool brightness_is_zero_; |
| 72 | 86 |
| 73 // True if an internal display is off while an external display is on (e.g. | 87 // True if an internal display is off while an external display is on (e.g. |
| 74 // for Chrome OS's docked mode, where a Chromebook's lid is closed while an | 88 // for Chrome OS's docked mode, where a Chromebook's lid is closed while an |
| 75 // external display is connected). | 89 // external display is connected). |
| 76 bool internal_display_off_and_external_display_on_; | 90 bool internal_display_off_and_external_display_on_; |
| 77 | 91 |
| 78 // Was a command-line switch set telling us that we're running on hardware | 92 // Was a command-line switch set telling us that we're running on hardware |
| 79 // that misreports power button releases? | 93 // that misreports power button releases? |
| 80 bool has_legacy_power_button_; | 94 bool has_legacy_power_button_; |
| 81 | 95 |
| 82 LockStateController* controller_; // Not owned. | 96 // Enables quick, non-cancellable locking of the screen when in maximize mode. |
| 97 bool enable_quick_lock_; |
| 98 |
| 99 LockStateController* controller_; // Not owned. |
| 83 | 100 |
| 84 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 101 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
| 85 }; | 102 }; |
| 86 | 103 |
| 87 } // namespace ash | 104 } // namespace ash |
| 88 | 105 |
| 89 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 106 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
| OLD | NEW |