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