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