| 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 "ui/compositor/layer_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/base/animation/animation_container.h" | 10 #include "ui/base/animation/animation_container.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 static ui::AnimationContainer* container = NULL; | 31 static ui::AnimationContainer* container = NULL; |
| 32 if (!container) { | 32 if (!container) { |
| 33 container = new AnimationContainer(); | 33 container = new AnimationContainer(); |
| 34 container->AddRef(); | 34 container->AddRef(); |
| 35 } | 35 } |
| 36 return container; | 36 return container; |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 class LayerAnimator::DestroyedTracker |
| 42 : public base::RefCounted<LayerAnimator::DestroyedTracker> { |
| 43 public: |
| 44 DestroyedTracker() : is_alive_(true) {} |
| 45 |
| 46 // Returns true if the animator is still alive. |
| 47 bool is_alive() const { return is_alive_; } |
| 48 |
| 49 // Invoked when the animator is destroyed. |
| 50 void AnimatorDeleted() { |
| 51 DCHECK(is_alive_); |
| 52 is_alive_ = false; |
| 53 } |
| 54 |
| 55 private: |
| 56 friend class base::RefCounted<DestroyedTracker>; |
| 57 |
| 58 ~DestroyedTracker() { |
| 59 DCHECK(!is_alive_); |
| 60 } |
| 61 |
| 62 bool is_alive_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(DestroyedTracker); |
| 65 }; |
| 66 |
| 41 // static | 67 // static |
| 42 bool LayerAnimator::disable_animations_for_test_ = false; | 68 bool LayerAnimator::disable_animations_for_test_ = false; |
| 43 // static | 69 // static |
| 44 bool LayerAnimator::slow_animation_mode_ = false; | 70 bool LayerAnimator::slow_animation_mode_ = false; |
| 45 // static | 71 // static |
| 46 int LayerAnimator::slow_animation_scale_factor_ = 4; | 72 int LayerAnimator::slow_animation_scale_factor_ = 4; |
| 47 | 73 |
| 48 // LayerAnimator public -------------------------------------------------------- | 74 // LayerAnimator public -------------------------------------------------------- |
| 49 | 75 |
| 50 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) | 76 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
| 51 : delegate_(NULL), | 77 : delegate_(NULL), |
| 52 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), | 78 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), |
| 53 transition_duration_(transition_duration), | 79 transition_duration_(transition_duration), |
| 54 tween_type_(Tween::LINEAR), | 80 tween_type_(Tween::LINEAR), |
| 55 is_started_(false), | 81 is_started_(false), |
| 56 disable_timer_for_test_(false) { | 82 disable_timer_for_test_(false), |
| 83 destroyed_tracker_(new DestroyedTracker) { |
| 57 } | 84 } |
| 58 | 85 |
| 59 LayerAnimator::~LayerAnimator() { | 86 LayerAnimator::~LayerAnimator() { |
| 60 for (size_t i = 0; i < running_animations_.size(); ++i) | 87 for (size_t i = 0; i < running_animations_.size(); ++i) |
| 61 running_animations_[i].sequence->OnAnimatorDestroyed(); | 88 running_animations_[i].sequence->OnAnimatorDestroyed(); |
| 62 ClearAnimationsInternal(); | 89 ClearAnimations(); |
| 63 delegate_ = NULL; | 90 destroyed_tracker_->AnimatorDeleted(); |
| 64 } | 91 } |
| 65 | 92 |
| 66 // static | 93 // static |
| 67 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { | 94 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { |
| 68 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); | 95 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); |
| 69 } | 96 } |
| 70 | 97 |
| 71 // static | 98 // static |
| 72 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { | 99 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { |
| 73 return new LayerAnimator(kDefaultTransitionDuration); | 100 return new LayerAnimator(kDefaultTransitionDuration); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 StartAnimation(new LayerAnimationSequence(element.release())); | 179 StartAnimation(new LayerAnimationSequence(element.release())); |
| 153 } | 180 } |
| 154 | 181 |
| 155 float LayerAnimator::GetTargetGrayscale() const { | 182 float LayerAnimator::GetTargetGrayscale() const { |
| 156 LayerAnimationElement::TargetValue target(delegate()); | 183 LayerAnimationElement::TargetValue target(delegate()); |
| 157 GetTargetValue(&target); | 184 GetTargetValue(&target); |
| 158 return target.grayscale; | 185 return target.grayscale; |
| 159 } | 186 } |
| 160 | 187 |
| 161 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { | 188 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
| 189 DCHECK(delegate); |
| 162 delegate_ = delegate; | 190 delegate_ = delegate; |
| 163 } | 191 } |
| 164 | 192 |
| 165 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { | 193 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
| 166 scoped_refptr<LayerAnimator> retain(this); | |
| 167 OnScheduled(animation); | 194 OnScheduled(animation); |
| 168 if (!StartSequenceImmediately(animation)) { | 195 if (!StartSequenceImmediately(animation)) { |
| 169 // Attempt to preempt a running animation. | 196 // Attempt to preempt a running animation. |
| 170 switch (preemption_strategy_) { | 197 switch (preemption_strategy_) { |
| 171 case IMMEDIATELY_SET_NEW_TARGET: | 198 case IMMEDIATELY_SET_NEW_TARGET: |
| 172 ImmediatelySetNewTarget(animation); | 199 ImmediatelySetNewTarget(animation); |
| 173 break; | 200 break; |
| 174 case IMMEDIATELY_ANIMATE_TO_NEW_TARGET: | 201 case IMMEDIATELY_ANIMATE_TO_NEW_TARGET: |
| 175 ImmediatelyAnimateToNewTarget(animation); | 202 ImmediatelyAnimateToNewTarget(animation); |
| 176 break; | 203 break; |
| 177 case ENQUEUE_NEW_ANIMATION: | 204 case ENQUEUE_NEW_ANIMATION: |
| 178 EnqueueNewAnimation(animation); | 205 EnqueueNewAnimation(animation); |
| 179 break; | 206 break; |
| 180 case REPLACE_QUEUED_ANIMATIONS: | 207 case REPLACE_QUEUED_ANIMATIONS: |
| 181 ReplaceQueuedAnimations(animation); | 208 ReplaceQueuedAnimations(animation); |
| 182 break; | 209 break; |
| 183 case BLEND_WITH_CURRENT_ANIMATION: { | 210 case BLEND_WITH_CURRENT_ANIMATION: { |
| 184 // TODO(vollick) Add support for blended sequences and use them here. | 211 // TODO(vollick) Add support for blended sequences and use them here. |
| 185 NOTIMPLEMENTED(); | 212 NOTIMPLEMENTED(); |
| 186 break; | 213 break; |
| 187 } | 214 } |
| 188 } | 215 } |
| 189 } | 216 } |
| 190 FinishAnyAnimationWithZeroDuration(); | 217 FinishAnyAnimationWithZeroDuration(); |
| 191 UpdateAnimationState(); | 218 UpdateAnimationState(); |
| 192 } | 219 } |
| 193 | 220 |
| 194 void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) { | 221 void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) { |
| 195 scoped_refptr<LayerAnimator> retain(this); | |
| 196 OnScheduled(animation); | 222 OnScheduled(animation); |
| 197 if (is_animating()) { | 223 if (is_animating()) { |
| 198 animation_queue_.push_back(make_linked_ptr(animation)); | 224 animation_queue_.push_back(make_linked_ptr(animation)); |
| 199 ProcessQueue(); | 225 ProcessQueue(); |
| 200 } else { | 226 } else { |
| 201 StartSequenceImmediately(animation); | 227 StartSequenceImmediately(animation); |
| 202 } | 228 } |
| 203 UpdateAnimationState(); | 229 UpdateAnimationState(); |
| 204 } | 230 } |
| 205 | 231 |
| 206 void LayerAnimator::ScheduleTogether( | 232 void LayerAnimator::ScheduleTogether( |
| 207 const std::vector<LayerAnimationSequence*>& animations) { | 233 const std::vector<LayerAnimationSequence*>& animations) { |
| 208 scoped_refptr<LayerAnimator> retain(this); | |
| 209 | |
| 210 // Collect all the affected properties. | 234 // Collect all the affected properties. |
| 211 LayerAnimationElement::AnimatableProperties animated_properties; | 235 LayerAnimationElement::AnimatableProperties animated_properties; |
| 212 std::vector<LayerAnimationSequence*>::const_iterator iter; | 236 std::vector<LayerAnimationSequence*>::const_iterator iter; |
| 213 for (iter = animations.begin(); iter != animations.end(); ++iter) { | 237 for (iter = animations.begin(); iter != animations.end(); ++iter) { |
| 214 animated_properties.insert((*iter)->properties().begin(), | 238 animated_properties.insert((*iter)->properties().begin(), |
| 215 (*iter)->properties().end()); | 239 (*iter)->properties().end()); |
| 216 } | 240 } |
| 217 | 241 |
| 218 // Scheduling a zero duration pause that affects all the animated properties | 242 // Scheduling a zero duration pause that affects all the animated properties |
| 219 // will prevent any of the sequences from animating until there are no | 243 // will prevent any of the sequences from animating until there are no |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if ((*queue_iter)->properties().find(property) != | 279 if ((*queue_iter)->properties().find(property) != |
| 256 (*queue_iter)->properties().end()) { | 280 (*queue_iter)->properties().end()) { |
| 257 return true; | 281 return true; |
| 258 } | 282 } |
| 259 } | 283 } |
| 260 return false; | 284 return false; |
| 261 } | 285 } |
| 262 | 286 |
| 263 void LayerAnimator::StopAnimatingProperty( | 287 void LayerAnimator::StopAnimatingProperty( |
| 264 LayerAnimationElement::AnimatableProperty property) { | 288 LayerAnimationElement::AnimatableProperty property) { |
| 265 scoped_refptr<LayerAnimator> retain(this); | |
| 266 while (true) { | 289 while (true) { |
| 267 RunningAnimation* running = GetRunningAnimation(property); | 290 RunningAnimation* running = GetRunningAnimation(property); |
| 268 if (!running) | 291 if (!running) |
| 269 break; | 292 break; |
| 270 FinishAnimation(running->sequence); | 293 if (FinishAnimation(running->sequence) == DESTROYED) |
| 294 return; |
| 271 } | 295 } |
| 272 } | 296 } |
| 273 | 297 |
| 274 void LayerAnimator::StopAnimating() { | 298 void LayerAnimator::StopAnimating() { |
| 275 scoped_refptr<LayerAnimator> retain(this); | 299 while (is_animating()) { |
| 276 while (is_animating()) | 300 if (FinishAnimation(running_animations_[0].sequence) == DESTROYED) |
| 277 FinishAnimation(running_animations_[0].sequence); | 301 return; |
| 302 } |
| 278 } | 303 } |
| 279 | 304 |
| 280 void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { | 305 void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { |
| 281 if (!observers_.HasObserver(observer)) | 306 if (!observers_.HasObserver(observer)) |
| 282 observers_.AddObserver(observer); | 307 observers_.AddObserver(observer); |
| 283 } | 308 } |
| 284 | 309 |
| 285 void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { | 310 void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { |
| 286 observers_.RemoveObserver(observer); | 311 observers_.RemoveObserver(observer); |
| 287 // Remove the observer from all sequences as well. | 312 // Remove the observer from all sequences as well. |
| 288 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 313 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 289 queue_iter != animation_queue_.end(); ++queue_iter) { | 314 queue_iter != animation_queue_.end(); ++queue_iter) { |
| 290 (*queue_iter)->RemoveObserver(observer); | 315 (*queue_iter)->RemoveObserver(observer); |
| 291 } | 316 } |
| 292 } | 317 } |
| 293 | 318 |
| 294 // LayerAnimator protected ----------------------------------------------------- | 319 // LayerAnimator protected ----------------------------------------------------- |
| 295 | 320 |
| 296 void LayerAnimator::ProgressAnimation(LayerAnimationSequence* sequence, | 321 bool LayerAnimator::ProgressAnimation(LayerAnimationSequence* sequence, |
| 297 base::TimeDelta delta) { | 322 base::TimeDelta delta) { |
| 298 if (!delegate()) | 323 return sequence->Progress(delta, delegate()); |
| 299 return; | |
| 300 | |
| 301 sequence->Progress(delta, delegate()); | |
| 302 } | 324 } |
| 303 | 325 |
| 304 | 326 |
| 305 bool LayerAnimator::HasAnimation(LayerAnimationSequence* sequence) const { | 327 bool LayerAnimator::HasAnimation(LayerAnimationSequence* sequence) const { |
| 306 for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); | 328 for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); |
| 307 queue_iter != animation_queue_.end(); ++queue_iter) { | 329 queue_iter != animation_queue_.end(); ++queue_iter) { |
| 308 if ((*queue_iter).get() == sequence) | 330 if ((*queue_iter).get() == sequence) |
| 309 return true; | 331 return true; |
| 310 } | 332 } |
| 311 return false; | 333 return false; |
| 312 } | 334 } |
| 313 | 335 |
| 314 // LayerAnimator private ------------------------------------------------------- | 336 // LayerAnimator private ------------------------------------------------------- |
| 315 | 337 |
| 316 void LayerAnimator::Step(base::TimeTicks now) { | 338 void LayerAnimator::Step(base::TimeTicks now) { |
| 317 TRACE_EVENT0("ui", "LayerAnimator::Step"); | 339 TRACE_EVENT0("ui", "LayerAnimator::Step"); |
| 318 scoped_refptr<LayerAnimator> retain(this); | |
| 319 | 340 |
| 320 last_step_time_ = now; | 341 last_step_time_ = now; |
| 321 | 342 |
| 322 // We need to make a copy of the running animations because progressing them | 343 // We need to make a copy of the running animations because progressing them |
| 323 // and finishing them may indirectly affect the collection of running | 344 // and finishing them may indirectly affect the collection of running |
| 324 // animations. | 345 // animations. |
| 325 RunningAnimations running_animations_copy = running_animations_; | 346 RunningAnimations running_animations_copy = running_animations_; |
| 347 bool needs_redraw = false; |
| 326 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 348 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
| 327 if (!HasAnimation(running_animations_copy[i].sequence)) | 349 if (!HasAnimation(running_animations_copy[i].sequence)) |
| 328 continue; | 350 continue; |
| 329 | 351 |
| 330 base::TimeDelta delta = now - running_animations_copy[i].start_time; | 352 base::TimeDelta delta = now - running_animations_copy[i].start_time; |
| 331 if (delta >= running_animations_copy[i].sequence->duration() && | 353 if (delta >= running_animations_copy[i].sequence->duration() && |
| 332 !running_animations_copy[i].sequence->is_cyclic()) { | 354 !running_animations_copy[i].sequence->is_cyclic()) { |
| 333 FinishAnimation(running_animations_copy[i].sequence); | 355 if (FinishAnimation(running_animations_copy[i].sequence) == DESTROYED) |
| 334 } else | 356 return; |
| 335 ProgressAnimation(running_animations_copy[i].sequence, delta); | 357 needs_redraw = true; |
| 358 } else { |
| 359 scoped_refptr<DestroyedTracker> tracker(destroyed_tracker_); |
| 360 const bool progress_result = |
| 361 ProgressAnimation(running_animations_copy[i].sequence, delta); |
| 362 if (!tracker->is_alive()) |
| 363 return; |
| 364 if (progress_result) |
| 365 needs_redraw = true; |
| 366 } |
| 336 } | 367 } |
| 368 |
| 369 if (needs_redraw && delegate()) |
| 370 delegate()->ScheduleDrawForAnimation(); |
| 337 } | 371 } |
| 338 | 372 |
| 339 void LayerAnimator::SetStartTime(base::TimeTicks start_time) { | 373 void LayerAnimator::SetStartTime(base::TimeTicks start_time) { |
| 340 // Do nothing. | 374 // Do nothing. |
| 341 } | 375 } |
| 342 | 376 |
| 343 base::TimeDelta LayerAnimator::GetTimerInterval() const { | 377 base::TimeDelta LayerAnimator::GetTimerInterval() const { |
| 344 return kTimerInterval; | 378 return kTimerInterval; |
| 345 } | 379 } |
| 346 | 380 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 376 if ((*queue_iter) == sequence) { | 410 if ((*queue_iter) == sequence) { |
| 377 to_return = *queue_iter; | 411 to_return = *queue_iter; |
| 378 animation_queue_.erase(queue_iter); | 412 animation_queue_.erase(queue_iter); |
| 379 break; | 413 break; |
| 380 } | 414 } |
| 381 } | 415 } |
| 382 | 416 |
| 383 return to_return.release(); | 417 return to_return.release(); |
| 384 } | 418 } |
| 385 | 419 |
| 386 void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) { | 420 LayerAnimator::DestroyedType LayerAnimator::FinishAnimation( |
| 387 scoped_refptr<LayerAnimator> retain(this); | 421 LayerAnimationSequence* sequence) { |
| 388 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); | 422 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); |
| 389 if (delegate()) | 423 { |
| 424 scoped_refptr<DestroyedTracker> tracker(destroyed_tracker_); |
| 390 sequence->Progress(sequence->duration(), delegate()); | 425 sequence->Progress(sequence->duration(), delegate()); |
| 426 if (!tracker->is_alive()) |
| 427 return DESTROYED; |
| 428 } |
| 391 ProcessQueue(); | 429 ProcessQueue(); |
| 392 UpdateAnimationState(); | 430 UpdateAnimationState(); |
| 431 return NOT_DESTROYED; |
| 393 } | 432 } |
| 394 | 433 |
| 395 void LayerAnimator::FinishAnyAnimationWithZeroDuration() { | 434 void LayerAnimator::FinishAnyAnimationWithZeroDuration() { |
| 396 scoped_refptr<LayerAnimator> retain(this); | |
| 397 // Special case: if we've started a 0 duration animation, just finish it now | 435 // Special case: if we've started a 0 duration animation, just finish it now |
| 398 // and get rid of it. We need to make a copy because Progress may indirectly | 436 // and get rid of it. We need to make a copy because Progress may indirectly |
| 399 // cause new animations to start running. | 437 // cause new animations to start running. |
| 400 RunningAnimations running_animations_copy = running_animations_; | 438 RunningAnimations running_animations_copy = running_animations_; |
| 401 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 439 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
| 402 if (!HasAnimation(running_animations_copy[i].sequence)) | 440 if (!HasAnimation(running_animations_copy[i].sequence)) |
| 403 continue; | 441 continue; |
| 404 | 442 |
| 405 if (running_animations_copy[i].sequence->duration() == base::TimeDelta()) { | 443 if (running_animations_copy[i].sequence->duration() == base::TimeDelta()) { |
| 406 ProgressAnimation(running_animations_copy[i].sequence, | 444 running_animations_copy[i].sequence->Progress( |
| 407 running_animations_copy[i].sequence->duration()); | 445 running_animations_copy[i].sequence->duration(), delegate()); |
| 408 scoped_ptr<LayerAnimationSequence> removed( | 446 scoped_ptr<LayerAnimationSequence> removed( |
| 409 RemoveAnimation(running_animations_copy[i].sequence)); | 447 RemoveAnimation(running_animations_copy[i].sequence)); |
| 410 } | 448 } |
| 411 } | 449 } |
| 412 ProcessQueue(); | 450 ProcessQueue(); |
| 413 UpdateAnimationState(); | 451 UpdateAnimationState(); |
| 414 } | 452 } |
| 415 | 453 |
| 416 void LayerAnimator::ClearAnimations() { | 454 void LayerAnimator::ClearAnimations() { |
| 417 scoped_refptr<LayerAnimator> retain(this); | 455 // Abort should never affect the set of running animations, but just in case |
| 418 ClearAnimationsInternal(); | 456 // clients are badly behaved, we will use a copy of the running animations. |
| 457 RunningAnimations running_animations_copy = running_animations_; |
| 458 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
| 459 if (!HasAnimation(running_animations_copy[i].sequence)) |
| 460 continue; |
| 461 |
| 462 scoped_ptr<LayerAnimationSequence> removed( |
| 463 RemoveAnimation(running_animations_copy[i].sequence)); |
| 464 if (removed.get()) |
| 465 removed->Abort(); |
| 466 } |
| 467 // This *should* have cleared the list of running animations. |
| 468 DCHECK(running_animations_.empty()); |
| 469 running_animations_.clear(); |
| 470 animation_queue_.clear(); |
| 471 UpdateAnimationState(); |
| 419 } | 472 } |
| 420 | 473 |
| 421 LayerAnimator::RunningAnimation* LayerAnimator::GetRunningAnimation( | 474 LayerAnimator::RunningAnimation* LayerAnimator::GetRunningAnimation( |
| 422 LayerAnimationElement::AnimatableProperty property) { | 475 LayerAnimationElement::AnimatableProperty property) { |
| 423 for (RunningAnimations::iterator iter = running_animations_.begin(); | 476 for (RunningAnimations::iterator iter = running_animations_.begin(); |
| 424 iter != running_animations_.end(); ++iter) { | 477 iter != running_animations_.end(); ++iter) { |
| 425 if ((*iter).sequence->properties().find(property) != | 478 if ((*iter).sequence->properties().find(property) != |
| 426 (*iter).sequence->properties().end()) | 479 (*iter).sequence->properties().end()) |
| 427 return &(*iter); | 480 return &(*iter); |
| 428 } | 481 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 455 if (!HasAnimation(running_animations_copy[i].sequence)) | 508 if (!HasAnimation(running_animations_copy[i].sequence)) |
| 456 continue; | 509 continue; |
| 457 | 510 |
| 458 if (running_animations_copy[i].sequence->HasCommonProperty( | 511 if (running_animations_copy[i].sequence->HasCommonProperty( |
| 459 sequence->properties())) { | 512 sequence->properties())) { |
| 460 scoped_ptr<LayerAnimationSequence> removed( | 513 scoped_ptr<LayerAnimationSequence> removed( |
| 461 RemoveAnimation(running_animations_copy[i].sequence)); | 514 RemoveAnimation(running_animations_copy[i].sequence)); |
| 462 if (abort) | 515 if (abort) |
| 463 running_animations_copy[i].sequence->Abort(); | 516 running_animations_copy[i].sequence->Abort(); |
| 464 else | 517 else |
| 465 ProgressAnimation(running_animations_copy[i].sequence, | 518 running_animations_copy[i].sequence->Progress( |
| 466 running_animations_copy[i].sequence->duration()); | 519 running_animations_copy[i].sequence->duration(), delegate()); |
| 467 } | 520 } |
| 468 } | 521 } |
| 469 | 522 |
| 470 // Same for the queued animations that haven't been started. Again, we'll | 523 // Same for the queued animations that haven't been started. Again, we'll |
| 471 // need to operate on a copy. | 524 // need to operate on a copy. |
| 472 std::vector<LayerAnimationSequence*> sequences; | 525 std::vector<LayerAnimationSequence*> sequences; |
| 473 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); | 526 for (AnimationQueue::iterator queue_iter = animation_queue_.begin(); |
| 474 queue_iter != animation_queue_.end(); ++queue_iter) | 527 queue_iter != animation_queue_.end(); ++queue_iter) |
| 475 sequences.push_back((*queue_iter).get()); | 528 sequences.push_back((*queue_iter).get()); |
| 476 | 529 |
| 477 for (size_t i = 0; i < sequences.size(); ++i) { | 530 for (size_t i = 0; i < sequences.size(); ++i) { |
| 478 if (!HasAnimation(sequences[i])) | 531 if (!HasAnimation(sequences[i])) |
| 479 continue; | 532 continue; |
| 480 | 533 |
| 481 if (sequences[i]->HasCommonProperty(sequence->properties())) { | 534 if (sequences[i]->HasCommonProperty(sequence->properties())) { |
| 482 scoped_ptr<LayerAnimationSequence> removed( | 535 scoped_ptr<LayerAnimationSequence> removed( |
| 483 RemoveAnimation(sequences[i])); | 536 RemoveAnimation(sequences[i])); |
| 484 if (abort) | 537 if (abort) |
| 485 sequences[i]->Abort(); | 538 sequences[i]->Abort(); |
| 486 else | 539 else |
| 487 ProgressAnimation(sequences[i], sequences[i]->duration()); | 540 sequences[i]->Progress(sequences[i]->duration(), delegate()); |
| 488 } | 541 } |
| 489 } | 542 } |
| 490 } | 543 } |
| 491 | 544 |
| 492 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { | 545 void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { |
| 493 // Ensure that sequence is disposed of when this function completes. | 546 // Ensure that sequence is disposed of when this function completes. |
| 494 scoped_ptr<LayerAnimationSequence> to_dispose(sequence); | 547 scoped_ptr<LayerAnimationSequence> to_dispose(sequence); |
| 495 const bool abort = false; | 548 const bool abort = false; |
| 496 RemoveAllAnimationsWithACommonProperty(sequence, abort); | 549 RemoveAllAnimationsWithACommonProperty(sequence, abort); |
| 497 LayerAnimationSequence* removed = RemoveAnimation(sequence); | 550 LayerAnimationSequence* removed = RemoveAnimation(sequence); |
| 498 DCHECK(removed == NULL || removed == sequence); | 551 DCHECK(removed == NULL || removed == sequence); |
| 499 ProgressAnimation(sequence, sequence->duration()); | 552 sequence->Progress(sequence->duration(), delegate()); |
| 500 } | 553 } |
| 501 | 554 |
| 502 void LayerAnimator::ImmediatelyAnimateToNewTarget( | 555 void LayerAnimator::ImmediatelyAnimateToNewTarget( |
| 503 LayerAnimationSequence* sequence) { | 556 LayerAnimationSequence* sequence) { |
| 504 const bool abort = true; | 557 const bool abort = true; |
| 505 RemoveAllAnimationsWithACommonProperty(sequence, abort); | 558 RemoveAllAnimationsWithACommonProperty(sequence, abort); |
| 506 AddToQueueIfNotPresent(sequence); | 559 AddToQueueIfNotPresent(sequence); |
| 507 StartSequenceImmediately(sequence); | 560 StartSequenceImmediately(sequence); |
| 508 } | 561 } |
| 509 | 562 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 sequence->AddObserver(obs); | 685 sequence->AddObserver(obs); |
| 633 } | 686 } |
| 634 } | 687 } |
| 635 sequence->OnScheduled(); | 688 sequence->OnScheduled(); |
| 636 } | 689 } |
| 637 | 690 |
| 638 base::TimeDelta LayerAnimator::GetTransitionDuration() const { | 691 base::TimeDelta LayerAnimator::GetTransitionDuration() const { |
| 639 return transition_duration_; | 692 return transition_duration_; |
| 640 } | 693 } |
| 641 | 694 |
| 642 void LayerAnimator::ClearAnimationsInternal() { | |
| 643 // Abort should never affect the set of running animations, but just in case | |
| 644 // clients are badly behaved, we will use a copy of the running animations. | |
| 645 RunningAnimations running_animations_copy = running_animations_; | |
| 646 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | |
| 647 if (!HasAnimation(running_animations_copy[i].sequence)) | |
| 648 continue; | |
| 649 | |
| 650 scoped_ptr<LayerAnimationSequence> removed( | |
| 651 RemoveAnimation(running_animations_copy[i].sequence)); | |
| 652 if (removed.get()) | |
| 653 removed->Abort(); | |
| 654 } | |
| 655 // This *should* have cleared the list of running animations. | |
| 656 DCHECK(running_animations_.empty()); | |
| 657 running_animations_.clear(); | |
| 658 animation_queue_.clear(); | |
| 659 UpdateAnimationState(); | |
| 660 } | |
| 661 | |
| 662 } // namespace ui | 695 } // namespace ui |
| OLD | NEW |