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 "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 private: | 36 private: |
37 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); | 37 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate); |
38 }; | 38 }; |
39 | 39 |
40 // Displays onscreen animations and locks or suspends the system in response to | 40 // Displays onscreen animations and locks or suspends the system in response to |
41 // the power button being pressed or released. | 41 // the power button being pressed or released. |
42 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, | 42 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, |
43 public ShellObserver { | 43 public ShellObserver { |
44 public: | 44 public: |
45 // Animations that can be applied to groups of containers. | 45 // Animations that can be applied to groups of containers. |
46 // Exposed here for TestApi::ContainerGroupIsAnimated(). | 46 // Exposed here for TestApi::ContainersAreAnimated(). |
47 enum AnimationType { | 47 enum AnimationType { |
48 ANIMATION_SLOW_CLOSE = 0, | 48 ANIMATION_SLOW_CLOSE = 0, |
49 ANIMATION_UNDO_SLOW_CLOSE, | 49 ANIMATION_UNDO_SLOW_CLOSE, |
50 ANIMATION_FAST_CLOSE, | 50 ANIMATION_FAST_CLOSE, |
51 ANIMATION_FADE_IN, | 51 ANIMATION_FADE_IN, |
52 ANIMATION_HIDE, | 52 ANIMATION_HIDE, |
53 ANIMATION_RESTORE, | 53 ANIMATION_RESTORE, |
54 }; | 54 }; |
55 | 55 |
56 // Groups of containers that can be animated. | 56 // Specific containers or groups of containers that can be animated. |
57 // Exposed here for TestApi::ContainerGroupIsAnimated(). | 57 // Exposed here for TestApi::ContainersAreAnimated(). |
58 enum ContainerGroup { | 58 enum Container { |
59 ALL_CONTAINERS = 0, | 59 DESKTOP_BACKGROUND = 1 << 0, |
60 SCREEN_LOCKER_CONTAINERS, | 60 |
61 SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 61 // All user session related containers including system background but |
62 ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 62 // not including desktop background (wallpaper). |
| 63 NON_LOCK_SCREEN_CONTAINERS = 1 << 1, |
| 64 |
| 65 // Desktop wallpaper is moved to this layer when screen is locked. |
| 66 // This layer is excluded from lock animation so that wallpaper stays as is, |
| 67 // user session windows are hidden and lock UI is shown on top of it. |
| 68 // This layer is included in shutdown animation. |
| 69 LOCK_SCREEN_BACKGROUND = 1 << 2, |
| 70 |
| 71 // Lock screen and lock screen modal containers. |
| 72 LOCK_SCREEN_CONTAINERS = 1 << 3, |
| 73 |
| 74 // Multiple system layers belong here like status, menu, tooltip |
| 75 // and overlay layers. |
| 76 LOCK_SCREEN_RELATED_CONTAINERS = 1 << 4, |
63 }; | 77 }; |
64 | 78 |
65 // Helper class used by tests to access internal state. | 79 // Helper class used by tests to access internal state. |
66 class ASH_EXPORT TestApi { | 80 class ASH_EXPORT TestApi { |
67 public: | 81 public: |
68 explicit TestApi(PowerButtonController* controller) | 82 explicit TestApi(PowerButtonController* controller) |
69 : controller_(controller) {} | 83 : controller_(controller) {} |
70 | 84 |
71 bool lock_timer_is_running() const { | 85 bool lock_timer_is_running() const { |
72 return controller_->lock_timer_.IsRunning(); | 86 return controller_->lock_timer_.IsRunning(); |
73 } | 87 } |
74 bool lock_fail_timer_is_running() const { | 88 bool lock_fail_timer_is_running() const { |
75 return controller_->lock_fail_timer_.IsRunning(); | 89 return controller_->lock_fail_timer_.IsRunning(); |
76 } | 90 } |
77 bool lock_to_shutdown_timer_is_running() const { | 91 bool lock_to_shutdown_timer_is_running() const { |
78 return controller_->lock_to_shutdown_timer_.IsRunning(); | 92 return controller_->lock_to_shutdown_timer_.IsRunning(); |
79 } | 93 } |
80 bool shutdown_timer_is_running() const { | 94 bool shutdown_timer_is_running() const { |
81 return controller_->shutdown_timer_.IsRunning(); | 95 return controller_->shutdown_timer_.IsRunning(); |
82 } | 96 } |
83 bool real_shutdown_timer_is_running() const { | 97 bool real_shutdown_timer_is_running() const { |
84 return controller_->real_shutdown_timer_.IsRunning(); | 98 return controller_->real_shutdown_timer_.IsRunning(); |
85 } | 99 } |
86 bool hide_background_layer_timer_is_running() const { | 100 bool hide_black_layer_timer_is_running() const { |
87 return controller_->hide_background_layer_timer_.IsRunning(); | 101 return controller_->hide_black_layer_timer_.IsRunning(); |
88 } | 102 } |
89 | 103 |
90 void trigger_lock_timeout() { | 104 void trigger_lock_timeout() { |
91 controller_->OnLockTimeout(); | 105 controller_->OnLockTimeout(); |
92 controller_->lock_timer_.Stop(); | 106 controller_->lock_timer_.Stop(); |
93 } | 107 } |
94 void trigger_lock_fail_timeout() { | 108 void trigger_lock_fail_timeout() { |
95 controller_->OnLockFailTimeout(); | 109 controller_->OnLockFailTimeout(); |
96 controller_->lock_fail_timer_.Stop(); | 110 controller_->lock_fail_timer_.Stop(); |
97 } | 111 } |
98 void trigger_lock_to_shutdown_timeout() { | 112 void trigger_lock_to_shutdown_timeout() { |
99 controller_->OnLockToShutdownTimeout(); | 113 controller_->OnLockToShutdownTimeout(); |
100 controller_->lock_to_shutdown_timer_.Stop(); | 114 controller_->lock_to_shutdown_timer_.Stop(); |
101 } | 115 } |
102 void trigger_shutdown_timeout() { | 116 void trigger_shutdown_timeout() { |
103 controller_->OnShutdownTimeout(); | 117 controller_->OnShutdownTimeout(); |
104 controller_->shutdown_timer_.Stop(); | 118 controller_->shutdown_timer_.Stop(); |
105 } | 119 } |
106 void trigger_real_shutdown_timeout() { | 120 void trigger_real_shutdown_timeout() { |
107 controller_->OnRealShutdownTimeout(); | 121 controller_->OnRealShutdownTimeout(); |
108 controller_->real_shutdown_timer_.Stop(); | 122 controller_->real_shutdown_timer_.Stop(); |
109 } | 123 } |
110 void trigger_hide_background_layer_timeout() { | 124 void trigger_hide_black_layer_timeout() { |
111 controller_->HideBackgroundLayer(); | 125 controller_->HideBlackLayer(); |
112 controller_->hide_background_layer_timer_.Stop(); | 126 controller_->hide_black_layer_timer_.Stop(); |
113 } | 127 } |
114 | 128 |
115 // Returns true if the given set of containers was last animated with | 129 // Returns true if containers of a given |container_mask| |
116 // |type| (probably; the analysis is fairly ad-hoc). | 130 // were last animated with |type| (probably; the analysis is fairly ad-hoc). |
117 bool ContainerGroupIsAnimated(ContainerGroup group, | 131 // |container_mask| is a bitfield of a Container. |
118 AnimationType type) const; | 132 bool ContainersAreAnimated(int container_mask, AnimationType type) const; |
119 | 133 |
120 // Returns true if |background_layer_| is non-NULL and visible. | 134 // Returns true if |black_layer_| is non-NULL and visible. |
121 bool BackgroundLayerIsVisible() const; | 135 bool BlackLayerIsVisible() const; |
122 | 136 |
123 // Returns |background_layer_|'s bounds, or an empty rect if the layer is | 137 // Returns |black_layer_|'s bounds, or an empty rect if the layer is |
124 // NULL. | 138 // NULL. |
125 gfx::Rect GetBackgroundLayerBounds() const; | 139 gfx::Rect GetBlackLayerBounds() const; |
126 | 140 |
127 private: | 141 private: |
128 PowerButtonController* controller_; // not owned | 142 PowerButtonController* controller_; // not owned |
129 | 143 |
130 DISALLOW_COPY_AND_ASSIGN(TestApi); | 144 DISALLOW_COPY_AND_ASSIGN(TestApi); |
131 }; | 145 }; |
132 | 146 |
| 147 // Helper method that returns a bitfield mask of all containers. |
| 148 static int GetAllContainersMask(); |
| 149 |
| 150 // Helper method that returns a bitfield mask including LOCK_SCREEN_WALLPAPER, |
| 151 // LOCK_SCREEN_CONTAINERS, and LOCK_SCREEN_RELATED_CONTAINERS. |
| 152 static int GetAllLockScreenContainersMask(); |
| 153 |
133 PowerButtonController(); | 154 PowerButtonController(); |
134 virtual ~PowerButtonController(); | 155 virtual ~PowerButtonController(); |
135 | 156 |
136 void set_delegate(PowerButtonControllerDelegate* delegate) { | 157 void set_delegate(PowerButtonControllerDelegate* delegate) { |
137 delegate_.reset(delegate); | 158 delegate_.reset(delegate); |
138 } | 159 } |
139 | 160 |
140 void set_has_legacy_power_button_for_test(bool legacy) { | 161 void set_has_legacy_power_button_for_test(bool legacy) { |
141 has_legacy_power_button_ = legacy; | 162 has_legacy_power_button_ = legacy; |
142 } | 163 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Requests that the machine be shut down. | 204 // Requests that the machine be shut down. |
184 void OnRealShutdownTimeout(); | 205 void OnRealShutdownTimeout(); |
185 | 206 |
186 // Puts us into the pre-lock or pre-shutdown state. | 207 // Puts us into the pre-lock or pre-shutdown state. |
187 void StartLockTimer(); | 208 void StartLockTimer(); |
188 void StartShutdownTimer(); | 209 void StartShutdownTimer(); |
189 | 210 |
190 // Displays the shutdown animation and starts |real_shutdown_timer_|. | 211 // Displays the shutdown animation and starts |real_shutdown_timer_|. |
191 void StartShutdownAnimationAndRequestShutdown(); | 212 void StartShutdownAnimationAndRequestShutdown(); |
192 | 213 |
193 // Shows or hides |background_layer_|. The show method creates and | 214 // Shows or hides |black_layer_|. The show method creates and |
194 // initializes the layer if it doesn't already exist. | 215 // initializes the layer if it doesn't already exist. |
195 void ShowBackgroundLayer(); | 216 void ShowBlackLayer(); |
196 void HideBackgroundLayer(); | 217 void HideBlackLayer(); |
197 | 218 |
198 scoped_ptr<PowerButtonControllerDelegate> delegate_; | 219 scoped_ptr<PowerButtonControllerDelegate> delegate_; |
199 | 220 |
200 // The current login status. | 221 // The current login status. |
201 user::LoginStatus login_status_; | 222 user::LoginStatus login_status_; |
202 | 223 |
203 // Original login status during locked. LOGGED_IN_NONE if it's not locked. | 224 // Original login status during locked. LOGGED_IN_NONE if it's not locked. |
204 user::LoginStatus unlocked_login_status_; | 225 user::LoginStatus unlocked_login_status_; |
205 | 226 |
206 // Are the power or lock buttons currently held? | 227 // Are the power or lock buttons currently held? |
207 bool power_button_down_; | 228 bool power_button_down_; |
208 bool lock_button_down_; | 229 bool lock_button_down_; |
209 | 230 |
210 // Is the screen currently turned off? | 231 // Is the screen currently turned off? |
211 bool screen_is_off_; | 232 bool screen_is_off_; |
212 | 233 |
213 // Are we in the process of shutting the machine down? | 234 // Are we in the process of shutting the machine down? |
214 bool shutting_down_; | 235 bool shutting_down_; |
215 | 236 |
216 // Should we start |shutdown_timer_| when we receive notification that the | |
217 // screen has been locked? | |
218 bool should_start_shutdown_timer_after_lock_; | |
219 | |
220 // Was a command-line switch set telling us that we're running on hardware | 237 // Was a command-line switch set telling us that we're running on hardware |
221 // that misreports power button releases? | 238 // that misreports power button releases? |
222 bool has_legacy_power_button_; | 239 bool has_legacy_power_button_; |
223 | 240 |
224 // Layer that's stacked under all of the root window's children to provide a | 241 // 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. | 242 // 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 | 243 // TODO(derat): Remove this in favor of having the compositor only clear the |
227 // viewport when there are regions not covered by a layer: | 244 // viewport when there are regions not covered by a layer: |
228 // http://crbug.com/113445 | 245 // http://crbug.com/113445 |
229 scoped_ptr<ui::Layer> background_layer_; | 246 scoped_ptr<ui::Layer> black_layer_; |
230 | 247 |
231 // Started when the user first presses the power button while in a | 248 // 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 | 249 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the |
233 // screen. | 250 // screen. |
234 base::OneShotTimer<PowerButtonController> lock_timer_; | 251 base::OneShotTimer<PowerButtonController> lock_timer_; |
235 | 252 |
236 // Started when we request that the screen be locked. When it fires, we | 253 // Started when we request that the screen be locked. When it fires, we |
237 // assume that our request got dropped. | 254 // assume that our request got dropped. |
238 base::OneShotTimer<PowerButtonController> lock_fail_timer_; | 255 base::OneShotTimer<PowerButtonController> lock_fail_timer_; |
239 | 256 |
240 // Started when the screen is locked while the power button is held. Adds a | 257 // 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 | 258 // delay between the appearance of the lock screen and the beginning of the |
242 // pre-shutdown animation. | 259 // pre-shutdown animation. |
243 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; | 260 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_; |
244 | 261 |
245 // Started when we begin displaying the pre-shutdown animation. When it | 262 // Started when we begin displaying the pre-shutdown animation. When it |
246 // fires, we start the shutdown animation and get ready to request shutdown. | 263 // fires, we start the shutdown animation and get ready to request shutdown. |
247 base::OneShotTimer<PowerButtonController> shutdown_timer_; | 264 base::OneShotTimer<PowerButtonController> shutdown_timer_; |
248 | 265 |
249 // Started when we display the shutdown animation. When it fires, we actually | 266 // Started when we display the shutdown animation. When it fires, we actually |
250 // request shutdown. Gives the animation time to complete before Chrome, X, | 267 // request shutdown. Gives the animation time to complete before Chrome, X, |
251 // etc. are shut down. | 268 // etc. are shut down. |
252 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; | 269 base::OneShotTimer<PowerButtonController> real_shutdown_timer_; |
253 | 270 |
254 // Started when we abort the pre-lock state. When it fires, we hide | 271 // Started when we abort the pre-lock state. When it fires, we hide |
255 // |background_layer_|, as the desktop background is now covering the whole | 272 // |black_layer_|, as the desktop background is now covering the whole |
256 // screen. | 273 // screen. |
257 base::OneShotTimer<PowerButtonController> hide_background_layer_timer_; | 274 base::OneShotTimer<PowerButtonController> hide_black_layer_timer_; |
258 | 275 |
259 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); | 276 DISALLOW_COPY_AND_ASSIGN(PowerButtonController); |
260 }; | 277 }; |
261 | 278 |
262 } // namespace ash | 279 } // namespace ash |
263 | 280 |
264 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ | 281 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_ |
OLD | NEW |