| 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/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
| 10 #include "ash/wm/session_state_animator.h" |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time.h" | 13 #include "base/time.h" |
| 13 #include "base/timer.h" | 14 #include "base/timer.h" |
| 14 #include "ui/aura/root_window_observer.h" | 15 #include "ui/aura/root_window_observer.h" |
| 15 | 16 |
| 16 namespace gfx { | 17 namespace gfx { |
| 17 class Rect; | 18 class Rect; |
| 18 class Size; | 19 class Size; |
| 19 } | 20 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); | 38 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // Displays onscreen animations and locks or suspends the system in response to | 41 // Displays onscreen animations and locks or suspends the system in response to |
| 41 // the power button being pressed or released. | 42 // the power button being pressed or released. |
| 42 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, | 43 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, |
| 43 public ShellObserver { | 44 public ShellObserver { |
| 44 public: | 45 public: |
| 45 // Animations that can be applied to groups of containers. | |
| 46 // Exposed here for TestApi::ContainerGroupIsAnimated(). | |
| 47 enum AnimationType { | |
| 48 ANIMATION_SLOW_CLOSE = 0, | |
| 49 ANIMATION_UNDO_SLOW_CLOSE, | |
| 50 ANIMATION_FAST_CLOSE, | |
| 51 ANIMATION_FADE_IN, | |
| 52 ANIMATION_HIDE, | |
| 53 ANIMATION_RESTORE, | |
| 54 }; | |
| 55 | |
| 56 // Groups of containers that can be animated. | |
| 57 // Exposed here for TestApi::ContainerGroupIsAnimated(). | |
| 58 enum ContainerGroup { | |
| 59 ALL_CONTAINERS = 0, | |
| 60 SCREEN_LOCKER_CONTAINERS, | |
| 61 SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 62 ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 63 }; | |
| 64 | |
| 65 // Helper class used by tests to access internal state. | 46 // Helper class used by tests to access internal state. |
| 66 class ASH_EXPORT TestApi { | 47 class ASH_EXPORT TestApi { |
| 67 public: | 48 public: |
| 68 explicit TestApi(PowerButtonController* controller) | 49 explicit TestApi(PowerButtonController* controller) |
| 69 : controller_(controller) {} | 50 : controller_(controller), |
| 51 animator_api_(new SessionStateAnimator::TestApi( |
| 52 controller->animator_)) {} |
| 53 virtual ~TestApi() { |
| 54 delete animator_api_; |
| 55 } |
| 70 | 56 |
| 71 bool lock_timer_is_running() const { | 57 bool lock_timer_is_running() const { |
| 72 return controller_->lock_timer_.IsRunning(); | 58 return controller_->lock_timer_.IsRunning(); |
| 73 } | 59 } |
| 74 bool lock_fail_timer_is_running() const { | 60 bool lock_fail_timer_is_running() const { |
| 75 return controller_->lock_fail_timer_.IsRunning(); | 61 return controller_->lock_fail_timer_.IsRunning(); |
| 76 } | 62 } |
| 77 bool lock_to_shutdown_timer_is_running() const { | 63 bool lock_to_shutdown_timer_is_running() const { |
| 78 return controller_->lock_to_shutdown_timer_.IsRunning(); | 64 return controller_->lock_to_shutdown_timer_.IsRunning(); |
| 79 } | 65 } |
| 80 bool shutdown_timer_is_running() const { | 66 bool shutdown_timer_is_running() const { |
| 81 return controller_->shutdown_timer_.IsRunning(); | 67 return controller_->shutdown_timer_.IsRunning(); |
| 82 } | 68 } |
| 83 bool real_shutdown_timer_is_running() const { | 69 bool real_shutdown_timer_is_running() const { |
| 84 return controller_->real_shutdown_timer_.IsRunning(); | 70 return controller_->real_shutdown_timer_.IsRunning(); |
| 85 } | 71 } |
| 86 bool hide_background_layer_timer_is_running() const { | 72 bool hide_background_layer_timer_is_running() const { |
| 87 return controller_->hide_background_layer_timer_.IsRunning(); | 73 return animator_api_->hide_background_layer_timer_is_running(); |
| 88 } | 74 } |
| 89 | 75 |
| 90 void trigger_lock_timeout() { | 76 void trigger_lock_timeout() { |
| 91 controller_->OnLockTimeout(); | 77 controller_->OnLockTimeout(); |
| 92 controller_->lock_timer_.Stop(); | 78 controller_->lock_timer_.Stop(); |
| 93 } | 79 } |
| 94 void trigger_lock_fail_timeout() { | 80 void trigger_lock_fail_timeout() { |
| 95 controller_->OnLockFailTimeout(); | 81 controller_->OnLockFailTimeout(); |
| 96 controller_->lock_fail_timer_.Stop(); | 82 controller_->lock_fail_timer_.Stop(); |
| 97 } | 83 } |
| 98 void trigger_lock_to_shutdown_timeout() { | 84 void trigger_lock_to_shutdown_timeout() { |
| 99 controller_->OnLockToShutdownTimeout(); | 85 controller_->OnLockToShutdownTimeout(); |
| 100 controller_->lock_to_shutdown_timer_.Stop(); | 86 controller_->lock_to_shutdown_timer_.Stop(); |
| 101 } | 87 } |
| 102 void trigger_shutdown_timeout() { | 88 void trigger_shutdown_timeout() { |
| 103 controller_->OnShutdownTimeout(); | 89 controller_->OnShutdownTimeout(); |
| 104 controller_->shutdown_timer_.Stop(); | 90 controller_->shutdown_timer_.Stop(); |
| 105 } | 91 } |
| 106 void trigger_real_shutdown_timeout() { | 92 void trigger_real_shutdown_timeout() { |
| 107 controller_->OnRealShutdownTimeout(); | 93 controller_->OnRealShutdownTimeout(); |
| 108 controller_->real_shutdown_timer_.Stop(); | 94 controller_->real_shutdown_timer_.Stop(); |
| 109 } | 95 } |
| 110 void trigger_hide_background_layer_timeout() { | 96 void trigger_hide_background_layer_timeout() { |
| 111 controller_->HideBackgroundLayer(); | 97 animator_api_->trigger_hide_background_layer_timeout(); |
| 112 controller_->hide_background_layer_timer_.Stop(); | |
| 113 } | 98 } |
| 114 | 99 |
| 115 // Returns true if the given set of containers was last animated with | 100 // Returns true if the given set of containers was last animated with |
| 116 // |type| (probably; the analysis is fairly ad-hoc). | 101 // |type| (probably; the analysis is fairly ad-hoc). |
| 117 bool ContainerGroupIsAnimated(ContainerGroup group, | 102 bool ContainerGroupIsAnimated(AnimationContainerGroup group, |
| 118 AnimationType type) const; | 103 SessionStateAnimationType type) const { |
| 104 return animator_api_->ContainerGroupIsAnimated(group, type); |
| 105 } |
| 119 | 106 |
| 120 // Returns true if |background_layer_| is non-NULL and visible. | 107 // Returns true if |background_layer_| is non-NULL and visible. |
| 121 bool BackgroundLayerIsVisible() const; | 108 bool BackgroundLayerIsVisible() const { |
| 109 return animator_api_->BackgroundLayerIsVisible(); |
| 110 } |
| 122 | 111 |
| 123 // Returns |background_layer_|'s bounds, or an empty rect if the layer is | 112 // Returns |background_layer_|'s bounds, or an empty rect if the layer is |
| 124 // NULL. | 113 // NULL. |
| 125 gfx::Rect GetBackgroundLayerBounds() const; | 114 gfx::Rect GetBackgroundLayerBounds() const { |
| 115 return animator_api_->GetBackgroundLayerBounds(); |
| 116 } |
| 126 | 117 |
| 127 private: | 118 private: |
| 128 PowerButtonController* controller_; // not owned | 119 PowerButtonController* controller_; // not owned |
| 120 SessionStateAnimator::TestApi* animator_api_; // owned |
| 129 | 121 |
| 130 DISALLOW_COPY_AND_ASSIGN(TestApi); | 122 DISALLOW_COPY_AND_ASSIGN(TestApi); |
| 131 }; | 123 }; |
| 132 | 124 |
| 133 PowerButtonController(); | 125 PowerButtonController(); |
| 134 virtual ~PowerButtonController(); | 126 virtual ~PowerButtonController(); |
| 135 | 127 |
| 136 void set_delegate(PowerButtonControllerDelegate* delegate) { | 128 void set_delegate(PowerButtonControllerDelegate* delegate) { |
| 137 delegate_.reset(delegate); | 129 delegate_.reset(delegate); |
| 138 } | 130 } |
| 139 | 131 |
| 140 void set_has_legacy_power_button_for_test(bool legacy) { | 132 void set_has_legacy_power_button_for_test(bool legacy) { |
| 141 has_legacy_power_button_ = legacy; | 133 has_legacy_power_button_ = legacy; |
| 142 } | 134 } |
| 143 | 135 |
| 144 // Called when the current screen brightness changes. | 136 // Called when the current screen brightness changes. |
| 145 void OnScreenBrightnessChanged(double percent); | 137 void OnScreenBrightnessChanged(double percent); |
| 146 | 138 |
| 147 // Called when Chrome gets a request to display the lock screen. | 139 // Called when Chrome gets a request to display the lock screen. |
| 148 void OnStartingLock(); | 140 void OnStartingLock(); |
| 149 | 141 |
| 150 // Called when the power or lock buttons are pressed or released. | 142 // Called when the power or lock buttons are pressed or released. |
| 151 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 143 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 152 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 144 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 153 | 145 |
| 154 // Displays the shutdown animation and requests shutdown when it's done. | 146 // Displays the shutdown animation and requests shutdown when it's done. |
| 155 void RequestShutdown(); | 147 void RequestShutdown(); |
| 156 | 148 |
| 157 // aura::RootWindowObserver overrides: | 149 // aura::RootWindowObserver overrides: |
| 158 virtual void OnRootWindowResized(const aura::RootWindow* root, | |
| 159 const gfx::Size& old_size) OVERRIDE; | |
| 160 virtual void OnRootWindowHostCloseRequested( | 150 virtual void OnRootWindowHostCloseRequested( |
| 161 const aura::RootWindow* root) OVERRIDE; | 151 const aura::RootWindow* root) OVERRIDE; |
| 162 | 152 |
| 163 // ShellObserver overrides: | 153 // ShellObserver overrides: |
| 164 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | 154 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; |
| 165 virtual void OnAppTerminating() OVERRIDE; | 155 virtual void OnAppTerminating() OVERRIDE; |
| 166 virtual void OnLockStateChanged(bool locked) OVERRIDE; | 156 virtual void OnLockStateChanged(bool locked) OVERRIDE; |
| 167 | 157 |
| 168 private: | 158 private: |
| 169 bool LoggedInAsNonGuest() const; | 159 bool LoggedInAsNonGuest() const; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 183 // Requests that the machine be shut down. | 173 // Requests that the machine be shut down. |
| 184 void OnRealShutdownTimeout(); | 174 void OnRealShutdownTimeout(); |
| 185 | 175 |
| 186 // Puts us into the pre-lock or pre-shutdown state. | 176 // Puts us into the pre-lock or pre-shutdown state. |
| 187 void StartLockTimer(); | 177 void StartLockTimer(); |
| 188 void StartShutdownTimer(); | 178 void StartShutdownTimer(); |
| 189 | 179 |
| 190 // Displays the shutdown animation and starts |real_shutdown_timer_|. | 180 // Displays the shutdown animation and starts |real_shutdown_timer_|. |
| 191 void StartShutdownAnimationAndRequestShutdown(); | 181 void StartShutdownAnimationAndRequestShutdown(); |
| 192 | 182 |
| 193 // Shows or hides |background_layer_|. The show method creates and | |
| 194 // initializes the layer if it doesn't already exist. | |
| 195 void ShowBackgroundLayer(); | |
| 196 void HideBackgroundLayer(); | |
| 197 | |
| 198 scoped_ptr<PowerButtonControllerDelegate> delegate_; | 183 scoped_ptr<PowerButtonControllerDelegate> delegate_; |
| 199 | 184 |
| 200 // The current login status. | 185 // The current login status. |
| 201 user::LoginStatus login_status_; | 186 user::LoginStatus login_status_; |
| 202 | 187 |
| 203 // Original login status during locked. LOGGED_IN_NONE if it's not locked. | 188 // Original login status during locked. LOGGED_IN_NONE if it's not locked. |
| 204 user::LoginStatus unlocked_login_status_; | 189 user::LoginStatus unlocked_login_status_; |
| 205 | 190 |
| 206 // Are the power or lock buttons currently held? | 191 // Are the power or lock buttons currently held? |
| 207 bool power_button_down_; | 192 bool power_button_down_; |
| 208 bool lock_button_down_; | 193 bool lock_button_down_; |
| 209 | 194 |
| 210 // Is the screen currently turned off? | 195 // Is the screen currently turned off? |
| 211 bool screen_is_off_; | 196 bool screen_is_off_; |
| 212 | 197 |
| 213 // Are we in the process of shutting the machine down? | 198 // Are we in the process of shutting the machine down? |
| 214 bool shutting_down_; | 199 bool shutting_down_; |
| 215 | 200 |
| 216 // Should we start |shutdown_timer_| when we receive notification that the | 201 // Should we start |shutdown_timer_| when we receive notification that the |
| 217 // screen has been locked? | 202 // screen has been locked? |
| 218 bool should_start_shutdown_timer_after_lock_; | 203 bool should_start_shutdown_timer_after_lock_; |
| 219 | 204 |
| 220 // Was a command-line switch set telling us that we're running on hardware | 205 // Was a command-line switch set telling us that we're running on hardware |
| 221 // that misreports power button releases? | 206 // that misreports power button releases? |
| 222 bool has_legacy_power_button_; | 207 bool has_legacy_power_button_; |
| 223 | 208 |
| 224 // Layer that's stacked under all of the root window's children to provide a | |
| 225 // black background when we're scaling all of the other windows down. | |
| 226 // TODO(derat): Remove this in favor of having the compositor only clear the | |
| 227 // viewport when there are regions not covered by a layer: | |
| 228 // http://crbug.com/113445 | |
| 229 scoped_ptr<ui::Layer> background_layer_; | |
| 230 | |
| 231 // Started when the user first presses the power button while in a | 209 // Started when the user first presses the power button while in a |
| 232 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the | 210 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the |
| 233 // screen. | 211 // screen. |
| 234 base::OneShotTimer<PowerButtonController> lock_timer_; | 212 base::OneShotTimer<PowerButtonController> lock_timer_; |
| 235 | 213 |
| 236 // Started when we request that the screen be locked. When it fires, we | 214 // Started when we request that the screen be locked. When it fires, we |
| 237 // assume that our request got dropped. | 215 // assume that our request got dropped. |
| 238 base::OneShotTimer<PowerButtonController> lock_fail_timer_; | 216 base::OneShotTimer<PowerButtonController> lock_fail_timer_; |
| 239 | 217 |
| 240 // Started when the screen is locked while the power button is held. Adds a | 218 // Started when the screen is locked while the power button is held. Adds a |
| 241 // delay between the appearance of the lock screen and the beginning of the | 219 // delay between the appearance of the lock screen and the beginning of the |
| 242 // pre-shutdown animation. | 220 // pre-shutdown animation. |
| 243 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; | 221 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; |
| 244 | 222 |
| 245 // Started when we begin displaying the pre-shutdown animation. When it | 223 // Started when we begin displaying the pre-shutdown animation. When it |
| 246 // fires, we start the shutdown animation and get ready to request shutdown. | 224 // fires, we start the shutdown animation and get ready to request shutdown. |
| 247 base::OneShotTimer<PowerButtonController> shutdown_timer_; | 225 base::OneShotTimer<PowerButtonController> shutdown_timer_; |
| 248 | 226 |
| 249 // Started when we display the shutdown animation. When it fires, we actually | 227 // Started when we display the shutdown animation. When it fires, we actually |
| 250 // request shutdown. Gives the animation time to complete before Chrome, X, | 228 // request shutdown. Gives the animation time to complete before Chrome, X, |
| 251 // etc. are shut down. | 229 // etc. are shut down. |
| 252 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; | 230 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; |
| 253 | 231 |
| 254 // Started when we abort the pre-lock state. When it fires, we hide | 232 SessionStateAnimator* animator_; |
| 255 // |background_layer_|, as the desktop background is now covering the whole | |
| 256 // screen. | |
| 257 base::OneShotTimer<PowerButtonController> hide_background_layer_timer_; | |
| 258 | 233 |
| 259 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 234 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
| 260 }; | 235 }; |
| 261 | 236 |
| 262 } // namespace ash | 237 } // namespace ash |
| 263 | 238 |
| 264 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 239 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
| OLD | NEW |