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