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