Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: ash/wm/session_state_controller_impl2.cc

Issue 11453012: Fix black background when locking with fullscreen window: (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rename undo/stop to cancel Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 have to be taken
Daniel Erat 2012/12/13 21:47:33 nit: s/have/has/
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 was no aborted animations.
Daniel Erat 2012/12/13 21:47:33 nit: s/was/were/
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 // sequence have some immediate animations in the beginning.
Daniel Erat 2012/12/13 21:47:33 nit: s/sequence have/a sequence has/
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 a case when user signs off.
Daniel Erat 2012/12/13 21:47:33 nit: "... also the case when the user ..."
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
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_->
329 GetDuration(internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN),
Daniel Erat 2012/12/13 21:47:33 nit: change this to: animator_->GetDuration(
278 this, &SessionStateControllerImpl2::OnPreShutdownAnimationTimeout); 330 this, &SessionStateControllerImpl2::OnPreShutdownAnimationTimeout);
279 } 331 }
280 332
281 void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() { 333 void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() {
282 if (!shutting_down_) 334 shutting_down_ = true;
283 RequestShutdownImpl(); 335
336 Shell* shell = ash::Shell::GetInstance();
337 shell->env_filter()->set_cursor_hidden_by_filter(false);
338 shell->cursor_manager()->ShowCursor(false);
339
340 StartRealShutdownTimer(false);
284 } 341 }
285 342
286 void SessionStateControllerImpl2::StartRealShutdownTimer() { 343
344 void SessionStateControllerImpl2::StartRealShutdownTimer(bool animation_time) {
Daniel Erat 2012/12/13 21:47:33 nit: s/animation_time/with_animation_time/ to matc
287 base::TimeDelta duration = 345 base::TimeDelta duration =
288 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs); 346 base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs);
289 duration += animator_->GetDuration( 347 if (animation_time) {
290 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 348 duration += animator_->GetDuration(
349 internal::SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
350 }
291 real_shutdown_timer_.Start( 351 real_shutdown_timer_.Start(
292 FROM_HERE, 352 FROM_HERE,
293 duration, 353 duration,
294 this, &SessionStateControllerImpl2::OnRealShutdownTimeout); 354 this, &SessionStateControllerImpl2::OnRealShutdownTimeout);
295 } 355 }
296 356
297 void SessionStateControllerImpl2::OnRealShutdownTimeout() { 357 void SessionStateControllerImpl2::OnRealShutdownTimeout() {
298 DCHECK(shutting_down_); 358 DCHECK(shutting_down_);
299 #if defined(OS_CHROMEOS) 359 #if defined(OS_CHROMEOS)
300 if (!base::chromeos::IsRunningOnChromeOS()) { 360 if (!base::chromeos::IsRunningOnChromeOS()) {
301 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 361 ShellDelegate* delegate = Shell::GetInstance()->delegate();
302 if (delegate) { 362 if (delegate) {
303 delegate->Exit(); 363 delegate->Exit();
304 return; 364 return;
305 } 365 }
306 } 366 }
307 #endif 367 #endif
308 delegate_->RequestShutdown(); 368 delegate_->RequestShutdown();
309 } 369 }
310 370
311 void SessionStateControllerImpl2::OnLockScreenHide( 371 void SessionStateControllerImpl2::OnLockScreenHide(
312 base::Callback<void(void)>& callback) { 372 base::Callback<void(void)>& callback) {
373 StartUnlockAnimationBeforeUIDestroyed(callback);
374 }
375
376 void SessionStateControllerImpl2::LockAnimationCancelled() {
377 can_cancel_lock_animation_ = false;
378 RestoreUnlockedProperties();
379 }
380
381 void SessionStateControllerImpl2::PreLockAnimationFinished() {
382 can_cancel_lock_animation_ = false;
383
384 delegate_->RequestLockScreen();
385 lock_fail_timer_.Start(
386 FROM_HERE,
387 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs),
388 this, &SessionStateControllerImpl2::OnLockFailTimeout);
389 }
390
391 void SessionStateControllerImpl2::PostLockAnimationFinished() {
392 animating_lock_ = false;
393
394 FOR_EACH_OBSERVER(SessionStateObserver, observers_,
395 OnSessionStateEvent(
396 SessionStateObserver::EVENT_LOCK_ANIMATION_FINISHED));
397 if (!lock_screen_displayed_callback_.is_null()) {
398 lock_screen_displayed_callback_.Run();
399 lock_screen_displayed_callback_.Reset();
400 }
401 if (shutdown_after_lock_) {
402 shutdown_after_lock_ = false;
403 StartLockToShutdownTimer();
404 }
405 }
406
407 void SessionStateControllerImpl2::UnlockAnimationAfterUIDestroyedFinished() {
408 RestoreUnlockedProperties();
409 }
410
411 void SessionStateControllerImpl2::StartImmediatePreLockAnimation() {
412 animating_lock_ = true;
413
414 StoreUnlockedProperties();
415
416 base::Closure next_animation_starter =
417 base::Bind(&SessionStateControllerImpl2::PreLockAnimationFinished,
418 base::Unretained(this));
419 ui::LayerAnimationObserver* observer =
420 new AnimationFinishedObserver(next_animation_starter);
421
422 animator_->StartAnimationWithObserver(
423 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
424 internal::SessionStateAnimator::ANIMATION_LIFT,
425 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
426 observer);
427
Daniel Erat 2012/12/13 21:47:33 nit: delete extra blank lines between these functi
428 animator_->StartAnimationWithObserver(
429 internal::SessionStateAnimator::LAUNCHER,
430 internal::SessionStateAnimator::ANIMATION_FADE_OUT,
431 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
432 observer);
433
434 // Hide the screen locker containers so we can raise them later.
435 animator_->StartAnimation(
436 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
437 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
438 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
439
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
Daniel Erat 2012/12/13 21:47:33 nit: delete extra blank line
466 animator_->StartAnimationWithObserver(
467 internal::SessionStateAnimator::LAUNCHER,
468 internal::SessionStateAnimator::ANIMATION_FADE_OUT,
469 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE,
470 observer);
471
472 // Hide the screen locker containers so we can raise them later.
473 animator_->StartAnimation(
474 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
475 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
476 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
477
Daniel Erat 2012/12/13 21:47:33 nit: delete blank line
478 AnimateBackgroundAppearanceIfNecessary(
479 internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE,
480 observer);
481
482 FOR_EACH_OBSERVER(SessionStateObserver, observers_,
483 OnSessionStateEvent(
484 SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED));
485 observer->Unpause();
486 }
487
488 void SessionStateControllerImpl2::CancelPreLockAnimation() {
489 base::Closure next_animation_starter =
490 base::Bind(&SessionStateControllerImpl2::LockAnimationCancelled,
491 base::Unretained(this));
492 AnimationFinishedObserver* observer =
493 new AnimationFinishedObserver(next_animation_starter);
494
495 observer->Pause();
496
497 animator_->StartAnimationWithObserver(
498 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
499 internal::SessionStateAnimator::ANIMATION_UNDO_LIFT,
500 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
501 observer);
502
Daniel Erat 2012/12/13 21:47:33 nit: delete blank lines
503 animator_->StartAnimationWithObserver(
504 internal::SessionStateAnimator::LAUNCHER,
505 internal::SessionStateAnimator::ANIMATION_FADE_IN,
506 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
507 observer);
508
509 AnimateBackgroundHidingIfNecessary(
510 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
511 observer);
512 observer->Unpause();
513 }
514
515 void SessionStateControllerImpl2::StartPostLockAnimation() {
516 base::Closure next_animation_starter =
517 base::Bind(&SessionStateControllerImpl2::PostLockAnimationFinished,
518 base::Unretained(this));
519
Daniel Erat 2012/12/13 21:47:33 nit: delete blank lines
520 ui::LayerAnimationObserver* observer =
521 new AnimationFinishedObserver(next_animation_starter);
522
523 animator_->StartAnimationWithObserver(
524 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
525 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN,
526 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
527 observer);
528 }
529
530 void SessionStateControllerImpl2::StartUnlockAnimationBeforeUIDestroyed(
531 base::Closure& callback) {
313 animator_->StartAnimationWithCallback( 532 animator_->StartAnimationWithCallback(
314 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, 533 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
315 internal::SessionStateAnimator::ANIMATION_LIFT, 534 internal::SessionStateAnimator::ANIMATION_LIFT,
316 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 535 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
317 callback); 536 callback);
318 } 537 }
319 538
539 void SessionStateControllerImpl2::StartUnlockAnimationAfterUIDestroyed() {
540 base::Closure next_animation_starter =
541 base::Bind(
542 &SessionStateControllerImpl2::UnlockAnimationAfterUIDestroyedFinished,
543 base::Unretained(this));
544
Daniel Erat 2012/12/13 21:47:33 nit: delete blank lines
545 ui::LayerAnimationObserver* observer =
546 new AnimationFinishedObserver(next_animation_starter);
547
548 animator_->StartAnimationWithObserver(
549 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
550 internal::SessionStateAnimator::ANIMATION_DROP,
551 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
552 observer);
553
554 animator_->StartAnimationWithObserver(
555 internal::SessionStateAnimator::LAUNCHER,
556 internal::SessionStateAnimator::ANIMATION_FADE_IN,
557 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
558 observer);
559
560 AnimateBackgroundHidingIfNecessary(
561 internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS,
562 observer);
563 }
564
565 void SessionStateControllerImpl2::StoreUnlockedProperties() {
566 if (!unlocked_properties_.get()) {
567 unlocked_properties_.reset(new UnlockedStateProperties());
568 unlocked_properties_->background_is_hidden = IsBackgroundHidden();
569 }
570 if (unlocked_properties_->background_is_hidden) {
571 // Hide background so that it can be animated later.
572 animator_->StartAnimation(
573 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
574 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY,
575 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
576 ShowBackground();
577 }
578 }
579
580 void SessionStateControllerImpl2::RestoreUnlockedProperties() {
581 if (!unlocked_properties_.get())
582 return;
583 if (unlocked_properties_->background_is_hidden) {
584 HideBackground();
585 // Restore background visibility.
586 animator_->StartAnimation(
587 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
588 internal::SessionStateAnimator::ANIMATION_FADE_IN,
589 internal::SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
590 }
591 unlocked_properties_.reset();
592 }
593
594 void SessionStateControllerImpl2::AnimateBackgroundAppearanceIfNecessary(
595 internal::SessionStateAnimator::AnimationSpeed speed,
596 ui::LayerAnimationObserver* observer) {
597 if (unlocked_properties_.get() &&
598 unlocked_properties_->background_is_hidden) {
599 animator_->StartAnimationWithObserver(
600 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
601 internal::SessionStateAnimator::ANIMATION_FADE_IN,
602 speed,
603 observer);
604 }
605 }
606
607 void SessionStateControllerImpl2::AnimateBackgroundHidingIfNecessary(
608 internal::SessionStateAnimator::AnimationSpeed speed,
609 ui::LayerAnimationObserver* observer) {
610 if (unlocked_properties_.get() &&
611 unlocked_properties_->background_is_hidden) {
612 animator_->StartAnimationWithObserver(
613 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
614 internal::SessionStateAnimator::ANIMATION_FADE_OUT,
615 speed,
616 observer);
617 }
618 }
619
320 } // namespace ash 620 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698