Chromium Code Reviews| 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( |
| 118 AnimationType type) const; | 103 SessionStateAnimator::ContainerGroup group, |
| 104 SessionStateAnimator::AnimationType type) const { | |
| 105 return animator_api_->ContainerGroupIsAnimated(group, type); | |
| 106 } | |
| 119 | 107 |
| 120 // Returns true if |background_layer_| is non-NULL and visible. | 108 // Returns true if |background_layer_| is non-NULL and visible. |
| 121 bool BackgroundLayerIsVisible() const; | 109 bool BackgroundLayerIsVisible() const { |
| 110 return animator_api_->BackgroundLayerIsVisible(); | |
| 111 } | |
| 122 | 112 |
| 123 // Returns |background_layer_|'s bounds, or an empty rect if the layer is | 113 // Returns |background_layer_|'s bounds, or an empty rect if the layer is |
| 124 // NULL. | 114 // NULL. |
| 125 gfx::Rect GetBackgroundLayerBounds() const; | 115 gfx::Rect GetBackgroundLayerBounds() const { |
| 116 return animator_api_->GetBackgroundLayerBounds(); | |
| 117 } | |
| 126 | 118 |
| 127 private: | 119 private: |
| 128 PowerButtonController* controller_; // not owned | 120 PowerButtonController* controller_; // not owned |
| 121 SessionStateAnimator::TestApi* animator_api_; // owned | |
|
Daniel Erat
2012/08/31 17:02:12
any reason not to use scoped_ptr instead?
Denis Kuznetsov (DE-MUC)
2012/09/28 11:52:43
Done.
| |
| 129 | 122 |
| 130 DISALLOW_COPY_AND_ASSIGN(TestApi); | 123 DISALLOW_COPY_AND_ASSIGN(TestApi); |
| 131 }; | 124 }; |
| 132 | 125 |
| 133 PowerButtonController(); | 126 PowerButtonController(); |
| 134 virtual ~PowerButtonController(); | 127 virtual ~PowerButtonController(); |
| 135 | 128 |
| 136 void set_delegate(PowerButtonControllerDelegate* delegate) { | 129 void set_delegate(PowerButtonControllerDelegate* delegate) { |
| 137 delegate_.reset(delegate); | 130 delegate_.reset(delegate); |
| 138 } | 131 } |
| 139 | 132 |
| 140 void set_has_legacy_power_button_for_test(bool legacy) { | 133 void set_has_legacy_power_button_for_test(bool legacy) { |
| 141 has_legacy_power_button_ = legacy; | 134 has_legacy_power_button_ = legacy; |
| 142 } | 135 } |
| 143 | 136 |
| 144 // Called when the current screen brightness changes. | 137 // Called when the current screen brightness changes. |
| 145 void OnScreenBrightnessChanged(double percent); | 138 void OnScreenBrightnessChanged(double percent); |
| 146 | 139 |
| 147 // Called when Chrome gets a request to display the lock screen. | 140 // Called when Chrome gets a request to display the lock screen. |
| 148 void OnStartingLock(); | 141 void OnStartingLock(); |
| 149 | 142 |
| 150 // Called when the power or lock buttons are pressed or released. | 143 // Called when the power or lock buttons are pressed or released. |
| 151 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 144 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 152 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); | 145 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 153 | 146 |
| 154 // Displays the shutdown animation and requests shutdown when it's done. | 147 // Displays the shutdown animation and requests shutdown when it's done. |
| 155 void RequestShutdown(); | 148 void RequestShutdown(); |
| 156 | 149 |
| 157 // aura::RootWindowObserver overrides: | 150 // aura::RootWindowObserver overrides: |
| 158 virtual void OnRootWindowResized(const aura::RootWindow* root, | |
| 159 const gfx::Size& old_size) OVERRIDE; | |
| 160 virtual void OnRootWindowHostCloseRequested( | 151 virtual void OnRootWindowHostCloseRequested( |
| 161 const aura::RootWindow* root) OVERRIDE; | 152 const aura::RootWindow* root) OVERRIDE; |
| 162 | 153 |
| 163 // ShellObserver overrides: | 154 // ShellObserver overrides: |
| 164 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; | 155 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; |
| 165 virtual void OnAppTerminating() OVERRIDE; | 156 virtual void OnAppTerminating() OVERRIDE; |
| 166 virtual void OnLockStateChanged(bool locked) OVERRIDE; | 157 virtual void OnLockStateChanged(bool locked) OVERRIDE; |
| 167 | 158 |
| 168 private: | 159 private: |
| 169 bool LoggedInAsNonGuest() const; | 160 bool LoggedInAsNonGuest() const; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 183 // Requests that the machine be shut down. | 174 // Requests that the machine be shut down. |
| 184 void OnRealShutdownTimeout(); | 175 void OnRealShutdownTimeout(); |
| 185 | 176 |
| 186 // Puts us into the pre-lock or pre-shutdown state. | 177 // Puts us into the pre-lock or pre-shutdown state. |
| 187 void StartLockTimer(); | 178 void StartLockTimer(); |
| 188 void StartShutdownTimer(); | 179 void StartShutdownTimer(); |
| 189 | 180 |
| 190 // Displays the shutdown animation and starts |real_shutdown_timer_|. | 181 // Displays the shutdown animation and starts |real_shutdown_timer_|. |
| 191 void StartShutdownAnimationAndRequestShutdown(); | 182 void StartShutdownAnimationAndRequestShutdown(); |
| 192 | 183 |
| 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_; | 184 scoped_ptr<PowerButtonControllerDelegate> delegate_; |
| 199 | 185 |
| 200 // The current login status. | 186 // The current login status. |
| 201 user::LoginStatus login_status_; | 187 user::LoginStatus login_status_; |
| 202 | 188 |
| 203 // Original login status during locked. LOGGED_IN_NONE if it's not locked. | 189 // Original login status during locked. LOGGED_IN_NONE if it's not locked. |
| 204 user::LoginStatus unlocked_login_status_; | 190 user::LoginStatus unlocked_login_status_; |
| 205 | 191 |
| 206 // Are the power or lock buttons currently held? | 192 // Are the power or lock buttons currently held? |
| 207 bool power_button_down_; | 193 bool power_button_down_; |
| 208 bool lock_button_down_; | 194 bool lock_button_down_; |
| 209 | 195 |
| 210 // Is the screen currently turned off? | 196 // Is the screen currently turned off? |
| 211 bool screen_is_off_; | 197 bool screen_is_off_; |
| 212 | 198 |
| 213 // Are we in the process of shutting the machine down? | 199 // Are we in the process of shutting the machine down? |
| 214 bool shutting_down_; | 200 bool shutting_down_; |
| 215 | 201 |
| 216 // Should we start |shutdown_timer_| when we receive notification that the | 202 // Should we start |shutdown_timer_| when we receive notification that the |
| 217 // screen has been locked? | 203 // screen has been locked? |
| 218 bool should_start_shutdown_timer_after_lock_; | 204 bool should_start_shutdown_timer_after_lock_; |
| 219 | 205 |
| 220 // Was a command-line switch set telling us that we're running on hardware | 206 // Was a command-line switch set telling us that we're running on hardware |
| 221 // that misreports power button releases? | 207 // that misreports power button releases? |
| 222 bool has_legacy_power_button_; | 208 bool has_legacy_power_button_; |
| 223 | 209 |
| 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 | 210 // 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 | 211 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the |
| 233 // screen. | 212 // screen. |
| 234 base::OneShotTimer<PowerButtonController> lock_timer_; | 213 base::OneShotTimer<PowerButtonController> lock_timer_; |
| 235 | 214 |
| 236 // Started when we request that the screen be locked. When it fires, we | 215 // Started when we request that the screen be locked. When it fires, we |
| 237 // assume that our request got dropped. | 216 // assume that our request got dropped. |
| 238 base::OneShotTimer<PowerButtonController> lock_fail_timer_; | 217 base::OneShotTimer<PowerButtonController> lock_fail_timer_; |
| 239 | 218 |
| 240 // Started when the screen is locked while the power button is held. Adds a | 219 // 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 | 220 // delay between the appearance of the lock screen and the beginning of the |
| 242 // pre-shutdown animation. | 221 // pre-shutdown animation. |
| 243 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; | 222 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; |
| 244 | 223 |
| 245 // Started when we begin displaying the pre-shutdown animation. When it | 224 // Started when we begin displaying the pre-shutdown animation. When it |
| 246 // fires, we start the shutdown animation and get ready to request shutdown. | 225 // fires, we start the shutdown animation and get ready to request shutdown. |
| 247 base::OneShotTimer<PowerButtonController> shutdown_timer_; | 226 base::OneShotTimer<PowerButtonController> shutdown_timer_; |
| 248 | 227 |
| 249 // Started when we display the shutdown animation. When it fires, we actually | 228 // Started when we display the shutdown animation. When it fires, we actually |
| 250 // request shutdown. Gives the animation time to complete before Chrome, X, | 229 // request shutdown. Gives the animation time to complete before Chrome, X, |
| 251 // etc. are shut down. | 230 // etc. are shut down. |
| 252 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; | 231 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; |
| 253 | 232 |
| 254 // Started when we abort the pre-lock state. When it fires, we hide | 233 SessionStateAnimator* animator_; |
|
Daniel Erat
2012/08/31 17:02:12
use scoped_ptr. in general, please use it every t
Denis Kuznetsov (DE-MUC)
2012/09/28 11:52:43
Done.
| |
| 255 // |background_layer_|, as the desktop background is now covering the whole | |
| 256 // screen. | |
| 257 base::OneShotTimer<PowerButtonController> hide_background_layer_timer_; | |
| 258 | 234 |
| 259 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 235 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
| 260 }; | 236 }; |
| 261 | 237 |
| 262 } // namespace ash | 238 } // namespace ash |
| 263 | 239 |
| 264 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 240 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
| OLD | NEW |