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 #include "ash/wm/session_state_controller_impl2.h" | 5 #include "ash/wm/session_state_controller_impl2.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/wm/session_state_animator.h" | 11 #include "ash/wm/session_state_animator.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/timer.h" |
14 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/compositor/layer_animation_sequence.h" |
| 17 #include "ui/compositor/scoped_layer_animation_settings.h" |
15 #include "ui/views/corewm/compound_event_filter.h" | 18 #include "ui/views/corewm/compound_event_filter.h" |
16 | 19 |
17 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
18 #include "base/chromeos/chromeos_version.h" | 21 #include "base/chromeos/chromeos_version.h" |
19 #endif | 22 #endif |
20 | 23 |
21 namespace ash { | 24 namespace ash { |
22 | 25 |
| 26 namespace { |
| 27 |
| 28 aura::Window* GetBackground() { |
| 29 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 30 return Shell::GetContainer(root_window, |
| 31 internal::kShellWindowId_DesktopBackgroundContainer); |
| 32 } |
| 33 |
| 34 bool IsBackgroundHidden() { |
| 35 return !GetBackground()->IsVisible(); |
| 36 } |
| 37 |
| 38 void ShowBackground() { |
| 39 ui::ScopedLayerAnimationSettings settings( |
| 40 GetBackground()->layer()->GetAnimator()); |
| 41 settings.SetTransitionDuration(base::TimeDelta()); |
| 42 GetBackground()->Show(); |
| 43 } |
| 44 |
| 45 void HideBackground() { |
| 46 ui::ScopedLayerAnimationSettings settings( |
| 47 GetBackground()->layer()->GetAnimator()); |
| 48 settings.SetTransitionDuration(base::TimeDelta()); |
| 49 GetBackground()->Hide(); |
| 50 } |
| 51 |
| 52 // This observer is intended to use in cases when some action has to be taken |
| 53 // once some animation successfully completes (i.e. it was not aborted). |
| 54 // Observer will count a number of sequences it is attached to, and a number of |
| 55 // finished sequences (either Ended or Aborted). Once these two numbers are |
| 56 // equal, observer will delete itself, calling callback passed to constructor if |
| 57 // there were no aborted animations. |
| 58 // This way it can be either used to wait for some animation to be finished in |
| 59 // multiple layers, to wait once a sequence of animations is finished in one |
| 60 // layer or the mixture of both. |
| 61 class AnimationFinishedObserver : public ui::LayerAnimationObserver { |
| 62 public: |
| 63 explicit AnimationFinishedObserver(base::Closure &callback) |
| 64 : callback_(callback), |
| 65 sequences_attached_(0), |
| 66 sequences_completed_(0), |
| 67 paused_(false) { |
| 68 } |
| 69 |
| 70 // Pauses observer: no checks will be made while paused. It can be used when |
| 71 // a sequence has some immediate animations in the beginning. |
| 72 void Pause() { |
| 73 paused_ = true; |
| 74 } |
| 75 |
| 76 // Unpauses observer. It does a check and calls callback if conditions are |
| 77 // met. |
| 78 void Unpause() { |
| 79 if (!paused_) |
| 80 return; |
| 81 paused_ = false; |
| 82 if (sequences_completed_ == sequences_attached_) { |
| 83 callback_.Run(); |
| 84 delete this; |
| 85 } |
| 86 } |
| 87 |
| 88 private: |
| 89 virtual ~AnimationFinishedObserver() { |
| 90 } |
| 91 |
| 92 // LayerAnimationObserver implementation |
| 93 virtual void OnLayerAnimationEnded( |
| 94 ui::LayerAnimationSequence* sequence) OVERRIDE { |
| 95 sequences_completed_++; |
| 96 if ((sequences_completed_ == sequences_attached_) && !paused_) { |
| 97 callback_.Run(); |
| 98 delete this; |
| 99 } |
| 100 } |
| 101 |
| 102 virtual void OnLayerAnimationAborted( |
| 103 ui::LayerAnimationSequence* sequence) OVERRIDE { |
| 104 sequences_completed_++; |
| 105 if ((sequences_completed_ == sequences_attached_) && !paused_) |
| 106 delete this; |
| 107 } |
| 108 |
| 109 virtual void OnLayerAnimationScheduled( |
| 110 ui::LayerAnimationSequence* sequence) OVERRIDE { |
| 111 } |
| 112 |
| 113 virtual void OnAttachedToSequence( |
| 114 ui::LayerAnimationSequence* sequence) OVERRIDE { |
| 115 LayerAnimationObserver::OnAttachedToSequence(sequence); |
| 116 sequences_attached_++; |
| 117 } |
| 118 |
| 119 // Callback to be called. |
| 120 base::Closure callback_; |
| 121 |
| 122 // Number of sequences this observer was attached to. |
| 123 int sequences_attached_; |
| 124 |
| 125 // Number of sequences either ended or aborted. |
| 126 int sequences_completed_; |
| 127 |
| 128 bool paused_; |
| 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(AnimationFinishedObserver); |
| 131 }; |
| 132 |
| 133 } // namespace |
| 134 |
23 SessionStateControllerImpl2::TestApi::TestApi( | 135 SessionStateControllerImpl2::TestApi::TestApi( |
24 SessionStateControllerImpl2* controller) | 136 SessionStateControllerImpl2* controller) |
25 : controller_(controller) { | 137 : controller_(controller) { |
26 } | 138 } |
27 | 139 |
28 SessionStateControllerImpl2::TestApi::~TestApi() { | 140 SessionStateControllerImpl2::TestApi::~TestApi() { |
29 } | 141 } |
30 | 142 |
31 SessionStateControllerImpl2::SessionStateControllerImpl2() | 143 SessionStateControllerImpl2::SessionStateControllerImpl2() |
32 : login_status_(user::LOGGED_IN_NONE), | 144 : login_status_(user::LOGGED_IN_NONE), |
33 system_is_locked_(false), | 145 system_is_locked_(false), |
34 shutting_down_(false), | 146 shutting_down_(false), |
35 shutdown_after_lock_(false) { | 147 shutdown_after_lock_(false), |
| 148 animating_lock_(false), |
| 149 can_cancel_lock_animation_(false) { |
36 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); | 150 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this); |
37 } | 151 } |
38 | 152 |
39 SessionStateControllerImpl2::~SessionStateControllerImpl2() { | 153 SessionStateControllerImpl2::~SessionStateControllerImpl2() { |
40 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); | 154 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this); |
41 } | 155 } |
42 | 156 |
43 void SessionStateControllerImpl2::OnLoginStateChanged( | 157 void SessionStateControllerImpl2::OnLoginStateChanged( |
44 user::LoginStatus status) { | 158 user::LoginStatus status) { |
45 if (status != user::LOGGED_IN_LOCKED) | 159 if (status != user::LOGGED_IN_LOCKED) |
46 login_status_ = status; | 160 login_status_ = status; |
47 system_is_locked_ = (status == user::LOGGED_IN_LOCKED); | 161 system_is_locked_ = (status == user::LOGGED_IN_LOCKED); |
48 } | 162 } |
49 | 163 |
50 void SessionStateControllerImpl2::OnAppTerminating() { | 164 void SessionStateControllerImpl2::OnAppTerminating() { |
51 // If we hear that Chrome is exiting but didn't request it ourselves, all we | 165 // If we hear that Chrome is exiting but didn't request it ourselves, all we |
52 // can really hope for is that we'll have time to clear the screen. | 166 // can really hope for is that we'll have time to clear the screen. |
| 167 // This is also the case when the user signs off. |
53 if (!shutting_down_) { | 168 if (!shutting_down_) { |
54 shutting_down_ = true; | 169 shutting_down_ = true; |
55 Shell* shell = ash::Shell::GetInstance(); | 170 Shell* shell = ash::Shell::GetInstance(); |
56 shell->env_filter()->set_cursor_hidden_by_filter(false); | 171 shell->env_filter()->set_cursor_hidden_by_filter(false); |
57 shell->cursor_manager()->ShowCursor(false); | 172 shell->cursor_manager()->ShowCursor(false); |
58 animator_->StartAnimation( | 173 animator_->StartAnimation( |
59 internal::SessionStateAnimator::kAllContainersMask, | 174 internal::SessionStateAnimator::kAllContainersMask, |
60 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | 175 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, |
61 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | 176 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
62 } | 177 } |
63 } | 178 } |
64 | 179 |
65 void SessionStateControllerImpl2::OnLockStateChanged(bool locked) { | 180 void SessionStateControllerImpl2::OnLockStateChanged(bool locked) { |
66 if (shutting_down_ || (system_is_locked_ == locked)) | 181 if (shutting_down_ || (system_is_locked_ == locked)) |
67 return; | 182 return; |
68 | 183 |
69 system_is_locked_ = locked; | 184 system_is_locked_ = locked; |
70 | 185 |
71 if (locked) { | 186 if (locked) { |
72 base::Callback<void(void)> callback = | 187 StartPostLockAnimation(); |
73 base::Bind(&SessionStateControllerImpl2::OnLockScreenAnimationFinished, | |
74 base::Unretained(this)); | |
75 animator_->StartAnimationWithCallback( | |
76 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
77 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN, | |
78 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | |
79 callback); | |
80 lock_timer_.Stop(); | |
81 lock_fail_timer_.Stop(); | 188 lock_fail_timer_.Stop(); |
82 } else { | 189 } else { |
83 animator_->StartAnimation( | 190 StartUnlockAnimationAfterUIDestroyed(); |
84 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
85 internal::SessionStateAnimator::LAUNCHER, | |
86 internal::SessionStateAnimator::ANIMATION_DROP, | |
87 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); | |
88 } | 191 } |
89 } | 192 } |
90 | 193 |
91 void SessionStateControllerImpl2::SetLockScreenDisplayedCallback( | 194 void SessionStateControllerImpl2::SetLockScreenDisplayedCallback( |
92 base::Closure& callback) { | 195 base::Closure& callback) { |
93 lock_screen_displayed_callback_ = callback; | 196 lock_screen_displayed_callback_ = callback; |
94 } | 197 } |
95 | 198 |
96 void SessionStateControllerImpl2::OnLockScreenAnimationFinished() { | |
97 FOR_EACH_OBSERVER(SessionStateObserver, observers_, | |
98 OnSessionStateEvent( | |
99 SessionStateObserver::EVENT_LOCK_ANIMATION_FINISHED)); | |
100 if (!lock_screen_displayed_callback_.is_null()) { | |
101 lock_screen_displayed_callback_.Run(); | |
102 lock_screen_displayed_callback_.Reset(); | |
103 } | |
104 if (shutdown_after_lock_) { | |
105 shutdown_after_lock_ = false; | |
106 StartLockToShutdownTimer(); | |
107 } | |
108 } | |
109 | |
110 void SessionStateControllerImpl2::OnStartingLock() { | 199 void SessionStateControllerImpl2::OnStartingLock() { |
111 if (shutting_down_ || system_is_locked_) | 200 if (shutting_down_ || system_is_locked_) |
112 return; | 201 return; |
113 | 202 if (animating_lock_) |
114 animator_->StartAnimation( | 203 return; |
115 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 204 StartImmediatePreLockAnimation(); |
116 internal::SessionStateAnimator::LAUNCHER, | |
117 internal::SessionStateAnimator::ANIMATION_LIFT, | |
118 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); | |
119 FOR_EACH_OBSERVER(SessionStateObserver, observers_, | |
120 OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED)); | |
121 // Hide the screen locker containers so we can raise them later. | |
122 animator_->StartAnimation( | |
123 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
124 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, | |
125 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); | |
126 } | 205 } |
127 | 206 |
128 void SessionStateControllerImpl2::StartLockAnimationAndLockImmediately() { | 207 void SessionStateControllerImpl2::StartLockAnimationAndLockImmediately() { |
129 animator_->StartAnimation( | 208 if (animating_lock_) |
130 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 209 return; |
131 internal::SessionStateAnimator::LAUNCHER, | 210 StartImmediatePreLockAnimation(); |
132 internal::SessionStateAnimator::ANIMATION_LIFT, | |
133 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); | |
134 FOR_EACH_OBSERVER(SessionStateObserver, observers_, | |
135 OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED)); | |
136 OnLockTimeout(); | |
137 } | 211 } |
138 | 212 |
139 void SessionStateControllerImpl2::StartLockAnimation(bool shutdown_after_lock) { | 213 void SessionStateControllerImpl2::StartLockAnimation(bool shutdown_after_lock) { |
| 214 if (animating_lock_) |
| 215 return; |
140 shutdown_after_lock_ = shutdown_after_lock; | 216 shutdown_after_lock_ = shutdown_after_lock; |
| 217 can_cancel_lock_animation_ = true; |
141 | 218 |
142 animator_->StartAnimation( | 219 StartCancellablePreLockAnimation(); |
143 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
144 internal::SessionStateAnimator::LAUNCHER, | |
145 internal::SessionStateAnimator::ANIMATION_LIFT, | |
146 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); | |
147 FOR_EACH_OBSERVER(SessionStateObserver, observers_, | |
148 OnSessionStateEvent( | |
149 SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); | |
150 StartLockTimer(); | |
151 } | |
152 | |
153 void SessionStateControllerImpl2::StartShutdownAnimation() { | |
154 animator_->StartGlobalAnimation( | |
155 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, | |
156 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | |
157 StartPreShutdownAnimationTimer(); | |
158 } | 220 } |
159 | 221 |
160 bool SessionStateControllerImpl2::LockRequested() { | 222 bool SessionStateControllerImpl2::LockRequested() { |
161 return lock_fail_timer_.IsRunning(); | 223 return lock_fail_timer_.IsRunning(); |
162 } | 224 } |
163 | 225 |
164 bool SessionStateControllerImpl2::ShutdownRequested() { | 226 bool SessionStateControllerImpl2::ShutdownRequested() { |
165 return shutting_down_; | 227 return shutting_down_; |
166 } | 228 } |
167 | 229 |
168 bool SessionStateControllerImpl2::CanCancelLockAnimation() { | 230 bool SessionStateControllerImpl2::CanCancelLockAnimation() { |
169 return lock_timer_.IsRunning(); | 231 return can_cancel_lock_animation_; |
170 } | 232 } |
171 | 233 |
172 void SessionStateControllerImpl2::CancelLockAnimation() { | 234 void SessionStateControllerImpl2::CancelLockAnimation() { |
173 if (!CanCancelLockAnimation()) | 235 if (!CanCancelLockAnimation()) |
174 return; | 236 return; |
175 shutdown_after_lock_ = false; | 237 shutdown_after_lock_ = false; |
176 animator_->StartAnimation( | 238 animating_lock_ = false; |
177 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 239 CancelPreLockAnimation(); |
178 internal::SessionStateAnimator::LAUNCHER, | |
179 internal::SessionStateAnimator::ANIMATION_DROP, | |
180 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); | |
181 lock_timer_.Stop(); | |
182 } | 240 } |
183 | 241 |
184 bool SessionStateControllerImpl2::CanCancelShutdownAnimation() { | 242 bool SessionStateControllerImpl2::CanCancelShutdownAnimation() { |
185 return pre_shutdown_timer_.IsRunning() || | 243 return pre_shutdown_timer_.IsRunning() || |
186 shutdown_after_lock_ || | 244 shutdown_after_lock_ || |
187 lock_to_shutdown_timer_.IsRunning(); | 245 lock_to_shutdown_timer_.IsRunning(); |
188 } | 246 } |
189 | 247 |
| 248 void SessionStateControllerImpl2::StartShutdownAnimation() { |
| 249 StartCancellableShutdownAnimation(); |
| 250 } |
| 251 |
190 void SessionStateControllerImpl2::CancelShutdownAnimation() { | 252 void SessionStateControllerImpl2::CancelShutdownAnimation() { |
191 if (!CanCancelShutdownAnimation()) | 253 if (!CanCancelShutdownAnimation()) |
192 return; | 254 return; |
193 if (lock_to_shutdown_timer_.IsRunning()) { | 255 if (lock_to_shutdown_timer_.IsRunning()) { |
194 lock_to_shutdown_timer_.Stop(); | 256 lock_to_shutdown_timer_.Stop(); |
195 return; | 257 return; |
196 } | 258 } |
197 if (shutdown_after_lock_) { | 259 if (shutdown_after_lock_) { |
198 shutdown_after_lock_ = false; | 260 shutdown_after_lock_ = false; |
199 return; | 261 return; |
(...skipping 10 matching lines...) Expand all Loading... |
210 } | 272 } |
211 | 273 |
212 void SessionStateControllerImpl2::RequestShutdownImpl() { | 274 void SessionStateControllerImpl2::RequestShutdownImpl() { |
213 DCHECK(!shutting_down_); | 275 DCHECK(!shutting_down_); |
214 shutting_down_ = true; | 276 shutting_down_ = true; |
215 | 277 |
216 Shell* shell = ash::Shell::GetInstance(); | 278 Shell* shell = ash::Shell::GetInstance(); |
217 shell->env_filter()->set_cursor_hidden_by_filter(false); | 279 shell->env_filter()->set_cursor_hidden_by_filter(false); |
218 shell->cursor_manager()->ShowCursor(false); | 280 shell->cursor_manager()->ShowCursor(false); |
219 | 281 |
220 animator_->StartGlobalAnimation( | 282 StartShutdownAnimationImpl(); |
221 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, | |
222 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | |
223 StartRealShutdownTimer(); | |
224 } | 283 } |
225 | 284 |
226 void SessionStateControllerImpl2::OnRootWindowHostCloseRequested( | 285 void SessionStateControllerImpl2::OnRootWindowHostCloseRequested( |
227 const aura::RootWindow*) { | 286 const aura::RootWindow*) { |
228 Shell::GetInstance()->delegate()->Exit(); | 287 Shell::GetInstance()->delegate()->Exit(); |
229 } | 288 } |
230 | 289 |
231 void SessionStateControllerImpl2::StartLockTimer() { | |
232 lock_timer_.Stop(); | |
233 lock_timer_.Start( | |
234 FROM_HERE, | |
235 animator_->GetDuration( | |
236 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE), | |
237 this, &SessionStateControllerImpl2::OnLockTimeout); | |
238 } | |
239 | |
240 void SessionStateControllerImpl2::OnLockTimeout() { | |
241 delegate_->RequestLockScreen(); | |
242 lock_fail_timer_.Start( | |
243 FROM_HERE, | |
244 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | |
245 this, &SessionStateControllerImpl2::OnLockFailTimeout); | |
246 } | |
247 | |
248 void SessionStateControllerImpl2::OnLockFailTimeout() { | 290 void SessionStateControllerImpl2::OnLockFailTimeout() { |
249 DCHECK(!system_is_locked_); | 291 DCHECK(!system_is_locked_); |
250 // Undo lock animation. | 292 // Undo lock animation. |
251 animator_->StartAnimation( | 293 StartUnlockAnimationAfterUIDestroyed(); |
252 internal::SessionStateAnimator::LAUNCHER | | |
253 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | |
254 internal::SessionStateAnimator::ANIMATION_DROP, | |
255 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); | |
256 } | 294 } |
257 | 295 |
258 void SessionStateControllerImpl2::StartLockToShutdownTimer() { | 296 void SessionStateControllerImpl2::StartLockToShutdownTimer() { |
259 shutdown_after_lock_ = false; | 297 shutdown_after_lock_ = false; |
260 lock_to_shutdown_timer_.Stop(); | 298 lock_to_shutdown_timer_.Stop(); |
261 lock_to_shutdown_timer_.Start( | 299 lock_to_shutdown_timer_.Start( |
262 FROM_HERE, | 300 FROM_HERE, |
263 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 301 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
264 this, &SessionStateControllerImpl2::OnLockToShutdownTimeout); | 302 this, &SessionStateControllerImpl2::OnLockToShutdownTimeout); |
265 } | 303 } |
266 | 304 |
267 | |
268 void SessionStateControllerImpl2::OnLockToShutdownTimeout() { | 305 void SessionStateControllerImpl2::OnLockToShutdownTimeout() { |
269 DCHECK(system_is_locked_); | 306 DCHECK(system_is_locked_); |
270 StartShutdownAnimation(); | 307 StartCancellableShutdownAnimation(); |
| 308 } |
| 309 |
| 310 void SessionStateControllerImpl2::StartCancellableShutdownAnimation() { |
| 311 animator_->StartGlobalAnimation( |
| 312 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, |
| 313 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 314 StartPreShutdownAnimationTimer(); |
| 315 } |
| 316 |
| 317 void SessionStateControllerImpl2::StartShutdownAnimationImpl() { |
| 318 animator_->StartGlobalAnimation( |
| 319 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS, |
| 320 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 321 StartRealShutdownTimer(true); |
271 } | 322 } |
272 | 323 |
273 void SessionStateControllerImpl2::StartPreShutdownAnimationTimer() { | 324 void SessionStateControllerImpl2::StartPreShutdownAnimationTimer() { |
274 pre_shutdown_timer_.Stop(); | 325 pre_shutdown_timer_.Stop(); |
275 pre_shutdown_timer_.Start( | 326 pre_shutdown_timer_.Start( |
276 FROM_HERE, | 327 FROM_HERE, |
277 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), | 328 animator_-> |
278 this, &SessionStateControllerImpl2::OnPreShutdownAnimationTimeout); | 329 GetDuration(internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN), |
| 330 this, |
| 331 &SessionStateControllerImpl2::OnPreShutdownAnimationTimeout); |
279 } | 332 } |
280 | 333 |
281 void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() { | 334 void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() { |
282 if (!shutting_down_) | 335 shutting_down_ = true; |
283 RequestShutdownImpl(); | 336 |
| 337 Shell* shell = ash::Shell::GetInstance(); |
| 338 shell->env_filter()->set_cursor_hidden_by_filter(false); |
| 339 shell->cursor_manager()->ShowCursor(false); |
| 340 |
| 341 StartRealShutdownTimer(false); |
284 } | 342 } |
285 | 343 |
286 void SessionStateControllerImpl2::StartRealShutdownTimer() { | 344 void SessionStateControllerImpl2::StartRealShutdownTimer( |
| 345 bool with_animation_time) { |
287 base::TimeDelta duration = | 346 base::TimeDelta duration = |
288 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); | 347 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); |
289 duration += animator_->GetDuration( | 348 if (with_animation_time) { |
290 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); | 349 duration += animator_->GetDuration( |
| 350 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 351 } |
291 real_shutdown_timer_.Start( | 352 real_shutdown_timer_.Start( |
292 FROM_HERE, | 353 FROM_HERE, |
293 duration, | 354 duration, |
294 this, &SessionStateControllerImpl2::OnRealShutdownTimeout); | 355 this, |
| 356 &SessionStateControllerImpl2::OnRealShutdownTimeout); |
295 } | 357 } |
296 | 358 |
297 void SessionStateControllerImpl2::OnRealShutdownTimeout() { | 359 void SessionStateControllerImpl2::OnRealShutdownTimeout() { |
298 DCHECK(shutting_down_); | 360 DCHECK(shutting_down_); |
299 #if defined(OS_CHROMEOS) | 361 #if defined(OS_CHROMEOS) |
300 if (!base::chromeos::IsRunningOnChromeOS()) { | 362 if (!base::chromeos::IsRunningOnChromeOS()) { |
301 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 363 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
302 if (delegate) { | 364 if (delegate) { |
303 delegate->Exit(); | 365 delegate->Exit(); |
304 return; | 366 return; |
305 } | 367 } |
306 } | 368 } |
307 #endif | 369 #endif |
308 delegate_->RequestShutdown(); | 370 delegate_->RequestShutdown(); |
309 } | 371 } |
310 | 372 |
311 void SessionStateControllerImpl2::OnLockScreenHide( | 373 void SessionStateControllerImpl2::OnLockScreenHide( |
312 base::Callback<void(void)>& callback) { | 374 base::Callback<void(void)>& callback) { |
| 375 StartUnlockAnimationBeforeUIDestroyed(callback); |
| 376 } |
| 377 |
| 378 void SessionStateControllerImpl2::LockAnimationCancelled() { |
| 379 can_cancel_lock_animation_ = false; |
| 380 RestoreUnlockedProperties(); |
| 381 } |
| 382 |
| 383 void SessionStateControllerImpl2::PreLockAnimationFinished() { |
| 384 can_cancel_lock_animation_ = false; |
| 385 |
| 386 delegate_->RequestLockScreen(); |
| 387 lock_fail_timer_.Start( |
| 388 FROM_HERE, |
| 389 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), |
| 390 this, |
| 391 &SessionStateControllerImpl2::OnLockFailTimeout); |
| 392 } |
| 393 |
| 394 void SessionStateControllerImpl2::PostLockAnimationFinished() { |
| 395 animating_lock_ = false; |
| 396 |
| 397 FOR_EACH_OBSERVER(SessionStateObserver, observers_, |
| 398 OnSessionStateEvent( |
| 399 SessionStateObserver::EVENT_LOCK_ANIMATION_FINISHED)); |
| 400 if (!lock_screen_displayed_callback_.is_null()) { |
| 401 lock_screen_displayed_callback_.Run(); |
| 402 lock_screen_displayed_callback_.Reset(); |
| 403 } |
| 404 if (shutdown_after_lock_) { |
| 405 shutdown_after_lock_ = false; |
| 406 StartLockToShutdownTimer(); |
| 407 } |
| 408 } |
| 409 |
| 410 void SessionStateControllerImpl2::UnlockAnimationAfterUIDestroyedFinished() { |
| 411 RestoreUnlockedProperties(); |
| 412 } |
| 413 |
| 414 void SessionStateControllerImpl2::StartImmediatePreLockAnimation() { |
| 415 animating_lock_ = true; |
| 416 |
| 417 StoreUnlockedProperties(); |
| 418 |
| 419 base::Closure next_animation_starter = |
| 420 base::Bind(&SessionStateControllerImpl2::PreLockAnimationFinished, |
| 421 base::Unretained(this)); |
| 422 ui::LayerAnimationObserver* observer = |
| 423 new AnimationFinishedObserver(next_animation_starter); |
| 424 |
| 425 animator_->StartAnimationWithObserver( |
| 426 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 427 internal::SessionStateAnimator::ANIMATION_LIFT, |
| 428 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 429 observer); |
| 430 animator_->StartAnimationWithObserver( |
| 431 internal::SessionStateAnimator::LAUNCHER, |
| 432 internal::SessionStateAnimator::ANIMATION_FADE_OUT, |
| 433 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 434 observer); |
| 435 // Hide the screen locker containers so we can raise them later. |
| 436 animator_->StartAnimation( |
| 437 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 438 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, |
| 439 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
| 440 AnimateBackgroundAppearanceIfNecessary( |
| 441 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 442 observer); |
| 443 |
| 444 FOR_EACH_OBSERVER(SessionStateObserver, observers_, |
| 445 OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED)); |
| 446 } |
| 447 |
| 448 void SessionStateControllerImpl2::StartCancellablePreLockAnimation() { |
| 449 animating_lock_ = true; |
| 450 StoreUnlockedProperties(); |
| 451 |
| 452 base::Closure next_animation_starter = |
| 453 base::Bind(&SessionStateControllerImpl2::PreLockAnimationFinished, |
| 454 base::Unretained(this)); |
| 455 AnimationFinishedObserver* observer = |
| 456 new AnimationFinishedObserver(next_animation_starter); |
| 457 |
| 458 observer->Pause(); |
| 459 |
| 460 animator_->StartAnimationWithObserver( |
| 461 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 462 internal::SessionStateAnimator::ANIMATION_LIFT, |
| 463 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, |
| 464 observer); |
| 465 animator_->StartAnimationWithObserver( |
| 466 internal::SessionStateAnimator::LAUNCHER, |
| 467 internal::SessionStateAnimator::ANIMATION_FADE_OUT, |
| 468 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, |
| 469 observer); |
| 470 // Hide the screen locker containers so we can raise them later. |
| 471 animator_->StartAnimation( |
| 472 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 473 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, |
| 474 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
| 475 AnimateBackgroundAppearanceIfNecessary( |
| 476 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, |
| 477 observer); |
| 478 |
| 479 FOR_EACH_OBSERVER(SessionStateObserver, observers_, |
| 480 OnSessionStateEvent( |
| 481 SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED)); |
| 482 observer->Unpause(); |
| 483 } |
| 484 |
| 485 void SessionStateControllerImpl2::CancelPreLockAnimation() { |
| 486 base::Closure next_animation_starter = |
| 487 base::Bind(&SessionStateControllerImpl2::LockAnimationCancelled, |
| 488 base::Unretained(this)); |
| 489 AnimationFinishedObserver* observer = |
| 490 new AnimationFinishedObserver(next_animation_starter); |
| 491 |
| 492 observer->Pause(); |
| 493 |
| 494 animator_->StartAnimationWithObserver( |
| 495 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 496 internal::SessionStateAnimator::ANIMATION_UNDO_LIFT, |
| 497 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 498 observer); |
| 499 animator_->StartAnimationWithObserver( |
| 500 internal::SessionStateAnimator::LAUNCHER, |
| 501 internal::SessionStateAnimator::ANIMATION_FADE_IN, |
| 502 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 503 observer); |
| 504 AnimateBackgroundHidingIfNecessary( |
| 505 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 506 observer); |
| 507 observer->Unpause(); |
| 508 } |
| 509 |
| 510 void SessionStateControllerImpl2::StartPostLockAnimation() { |
| 511 base::Closure next_animation_starter = |
| 512 base::Bind(&SessionStateControllerImpl2::PostLockAnimationFinished, |
| 513 base::Unretained(this)); |
| 514 |
| 515 ui::LayerAnimationObserver* observer = |
| 516 new AnimationFinishedObserver(next_animation_starter); |
| 517 |
| 518 animator_->StartAnimationWithObserver( |
| 519 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 520 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN, |
| 521 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 522 observer); |
| 523 } |
| 524 |
| 525 void SessionStateControllerImpl2::StartUnlockAnimationBeforeUIDestroyed( |
| 526 base::Closure& callback) { |
313 animator_->StartAnimationWithCallback( | 527 animator_->StartAnimationWithCallback( |
314 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 528 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
315 internal::SessionStateAnimator::ANIMATION_LIFT, | 529 internal::SessionStateAnimator::ANIMATION_LIFT, |
316 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, | 530 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
317 callback); | 531 callback); |
318 } | 532 } |
319 | 533 |
| 534 void SessionStateControllerImpl2::StartUnlockAnimationAfterUIDestroyed() { |
| 535 base::Closure next_animation_starter = |
| 536 base::Bind( |
| 537 &SessionStateControllerImpl2::UnlockAnimationAfterUIDestroyedFinished, |
| 538 base::Unretained(this)); |
| 539 |
| 540 ui::LayerAnimationObserver* observer = |
| 541 new AnimationFinishedObserver(next_animation_starter); |
| 542 |
| 543 animator_->StartAnimationWithObserver( |
| 544 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 545 internal::SessionStateAnimator::ANIMATION_DROP, |
| 546 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 547 observer); |
| 548 animator_->StartAnimationWithObserver( |
| 549 internal::SessionStateAnimator::LAUNCHER, |
| 550 internal::SessionStateAnimator::ANIMATION_FADE_IN, |
| 551 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 552 observer); |
| 553 AnimateBackgroundHidingIfNecessary( |
| 554 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, |
| 555 observer); |
| 556 } |
| 557 |
| 558 void SessionStateControllerImpl2::StoreUnlockedProperties() { |
| 559 if (!unlocked_properties_.get()) { |
| 560 unlocked_properties_.reset(new UnlockedStateProperties()); |
| 561 unlocked_properties_->background_is_hidden = IsBackgroundHidden(); |
| 562 } |
| 563 if (unlocked_properties_->background_is_hidden) { |
| 564 // Hide background so that it can be animated later. |
| 565 animator_->StartAnimation( |
| 566 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
| 567 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, |
| 568 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
| 569 ShowBackground(); |
| 570 } |
| 571 } |
| 572 |
| 573 void SessionStateControllerImpl2::RestoreUnlockedProperties() { |
| 574 if (!unlocked_properties_.get()) |
| 575 return; |
| 576 if (unlocked_properties_->background_is_hidden) { |
| 577 HideBackground(); |
| 578 // Restore background visibility. |
| 579 animator_->StartAnimation( |
| 580 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
| 581 internal::SessionStateAnimator::ANIMATION_FADE_IN, |
| 582 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE); |
| 583 } |
| 584 unlocked_properties_.reset(); |
| 585 } |
| 586 |
| 587 void SessionStateControllerImpl2::AnimateBackgroundAppearanceIfNecessary( |
| 588 internal::SessionStateAnimator::AnimationSpeed speed, |
| 589 ui::LayerAnimationObserver* observer) { |
| 590 if (unlocked_properties_.get() && |
| 591 unlocked_properties_->background_is_hidden) { |
| 592 animator_->StartAnimationWithObserver( |
| 593 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
| 594 internal::SessionStateAnimator::ANIMATION_FADE_IN, |
| 595 speed, |
| 596 observer); |
| 597 } |
| 598 } |
| 599 |
| 600 void SessionStateControllerImpl2::AnimateBackgroundHidingIfNecessary( |
| 601 internal::SessionStateAnimator::AnimationSpeed speed, |
| 602 ui::LayerAnimationObserver* observer) { |
| 603 if (unlocked_properties_.get() && |
| 604 unlocked_properties_->background_is_hidden) { |
| 605 animator_->StartAnimationWithObserver( |
| 606 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
| 607 internal::SessionStateAnimator::ANIMATION_FADE_OUT, |
| 608 speed, |
| 609 observer); |
| 610 } |
| 611 } |
| 612 |
320 } // namespace ash | 613 } // namespace ash |
OLD | NEW |