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 25 matching lines...) Expand all Loading... |
36 int LayerAnimator::slow_animation_scale_factor_ = 4; | 36 int LayerAnimator::slow_animation_scale_factor_ = 4; |
37 | 37 |
38 // LayerAnimator public -------------------------------------------------------- | 38 // LayerAnimator public -------------------------------------------------------- |
39 | 39 |
40 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) | 40 LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) |
41 : delegate_(NULL), | 41 : delegate_(NULL), |
42 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), | 42 preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET), |
43 transition_duration_(transition_duration), | 43 transition_duration_(transition_duration), |
44 tween_type_(Tween::LINEAR), | 44 tween_type_(Tween::LINEAR), |
45 is_started_(false), | 45 is_started_(false), |
46 disable_timer_for_test_(false) { | 46 disable_timer_for_test_(false), |
| 47 destroyed_(NULL) { |
47 } | 48 } |
48 | 49 |
49 LayerAnimator::~LayerAnimator() { | 50 LayerAnimator::~LayerAnimator() { |
50 for (size_t i = 0; i < running_animations_.size(); ++i) | 51 for (size_t i = 0; i < running_animations_.size(); ++i) |
51 running_animations_[i].sequence->OnAnimatorDestroyed(); | 52 running_animations_[i].sequence->OnAnimatorDestroyed(); |
52 ClearAnimations(); | 53 ClearAnimations(); |
| 54 if (destroyed_) |
| 55 *destroyed_ = true; |
53 } | 56 } |
54 | 57 |
55 // static | 58 // static |
56 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { | 59 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { |
57 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); | 60 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); |
58 } | 61 } |
59 | 62 |
60 // static | 63 // static |
61 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { | 64 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { |
62 return new LayerAnimator(kDefaultTransitionDuration); | 65 return new LayerAnimator(kDefaultTransitionDuration); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 231 } |
229 return false; | 232 return false; |
230 } | 233 } |
231 | 234 |
232 void LayerAnimator::StopAnimatingProperty( | 235 void LayerAnimator::StopAnimatingProperty( |
233 LayerAnimationElement::AnimatableProperty property) { | 236 LayerAnimationElement::AnimatableProperty property) { |
234 while (true) { | 237 while (true) { |
235 RunningAnimation* running = GetRunningAnimation(property); | 238 RunningAnimation* running = GetRunningAnimation(property); |
236 if (!running) | 239 if (!running) |
237 break; | 240 break; |
238 FinishAnimation(running->sequence); | 241 if (FinishAnimation(running->sequence) == DESTROYED) |
| 242 return; |
239 } | 243 } |
240 } | 244 } |
241 | 245 |
242 void LayerAnimator::StopAnimating() { | 246 void LayerAnimator::StopAnimating() { |
243 while (is_animating()) | 247 while (is_animating()) { |
244 FinishAnimation(running_animations_[0].sequence); | 248 if (FinishAnimation(running_animations_[0].sequence) == DESTROYED) |
| 249 return; |
| 250 } |
245 } | 251 } |
246 | 252 |
247 void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { | 253 void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { |
248 if (!observers_.HasObserver(observer)) | 254 if (!observers_.HasObserver(observer)) |
249 observers_.AddObserver(observer); | 255 observers_.AddObserver(observer); |
250 } | 256 } |
251 | 257 |
252 void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { | 258 void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { |
253 observers_.RemoveObserver(observer); | 259 observers_.RemoveObserver(observer); |
254 // Remove the observer from all sequences as well. | 260 // Remove the observer from all sequences as well. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // animations. | 292 // animations. |
287 RunningAnimations running_animations_copy = running_animations_; | 293 RunningAnimations running_animations_copy = running_animations_; |
288 bool needs_redraw = false; | 294 bool needs_redraw = false; |
289 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 295 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
290 if (!HasAnimation(running_animations_copy[i].sequence)) | 296 if (!HasAnimation(running_animations_copy[i].sequence)) |
291 continue; | 297 continue; |
292 | 298 |
293 base::TimeDelta delta = now - running_animations_copy[i].start_time; | 299 base::TimeDelta delta = now - running_animations_copy[i].start_time; |
294 if (delta >= running_animations_copy[i].sequence->duration() && | 300 if (delta >= running_animations_copy[i].sequence->duration() && |
295 !running_animations_copy[i].sequence->is_cyclic()) { | 301 !running_animations_copy[i].sequence->is_cyclic()) { |
296 FinishAnimation(running_animations_copy[i].sequence); | 302 if (FinishAnimation(running_animations_copy[i].sequence) == DESTROYED) |
| 303 return; |
297 needs_redraw = true; | 304 needs_redraw = true; |
298 } else if (ProgressAnimation(running_animations_copy[i].sequence, delta)) | 305 } else if (ProgressAnimation(running_animations_copy[i].sequence, delta)) { |
299 needs_redraw = true; | 306 needs_redraw = true; |
| 307 } |
300 } | 308 } |
301 | 309 |
302 if (needs_redraw && delegate()) | 310 if (needs_redraw && delegate()) |
303 delegate()->ScheduleDrawForAnimation(); | 311 delegate()->ScheduleDrawForAnimation(); |
304 } | 312 } |
305 | 313 |
306 void LayerAnimator::SetStartTime(base::TimeTicks start_time) { | 314 void LayerAnimator::SetStartTime(base::TimeTicks start_time) { |
307 // Do nothing. | 315 // Do nothing. |
308 } | 316 } |
309 | 317 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if ((*queue_iter) == sequence) { | 357 if ((*queue_iter) == sequence) { |
350 to_return = *queue_iter; | 358 to_return = *queue_iter; |
351 animation_queue_.erase(queue_iter); | 359 animation_queue_.erase(queue_iter); |
352 break; | 360 break; |
353 } | 361 } |
354 } | 362 } |
355 | 363 |
356 return to_return.release(); | 364 return to_return.release(); |
357 } | 365 } |
358 | 366 |
359 void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) { | 367 LayerAnimator::DestroyedType LayerAnimator::FinishAnimation( |
| 368 LayerAnimationSequence* sequence) { |
360 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); | 369 scoped_ptr<LayerAnimationSequence> removed(RemoveAnimation(sequence)); |
361 sequence->Progress(sequence->duration(), delegate()); | 370 { |
| 371 bool destroyed = false; |
| 372 destroyed_ = &destroyed; |
| 373 sequence->Progress(sequence->duration(), delegate()); |
| 374 if (destroyed) |
| 375 return DESTROYED; |
| 376 destroyed_ = NULL; |
| 377 } |
362 ProcessQueue(); | 378 ProcessQueue(); |
363 UpdateAnimationState(); | 379 UpdateAnimationState(); |
| 380 return NOT_DESTROYED; |
364 } | 381 } |
365 | 382 |
366 void LayerAnimator::FinishAnyAnimationWithZeroDuration() { | 383 void LayerAnimator::FinishAnyAnimationWithZeroDuration() { |
367 // Special case: if we've started a 0 duration animation, just finish it now | 384 // Special case: if we've started a 0 duration animation, just finish it now |
368 // and get rid of it. We need to make a copy because Progress may indirectly | 385 // and get rid of it. We need to make a copy because Progress may indirectly |
369 // cause new animations to start running. | 386 // cause new animations to start running. |
370 RunningAnimations running_animations_copy = running_animations_; | 387 RunningAnimations running_animations_copy = running_animations_; |
371 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 388 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
372 if (!HasAnimation(running_animations_copy[i].sequence)) | 389 if (!HasAnimation(running_animations_copy[i].sequence)) |
373 continue; | 390 continue; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 628 } |
612 } | 629 } |
613 sequence->OnScheduled(); | 630 sequence->OnScheduled(); |
614 } | 631 } |
615 | 632 |
616 base::TimeDelta LayerAnimator::GetTransitionDuration() const { | 633 base::TimeDelta LayerAnimator::GetTransitionDuration() const { |
617 return transition_duration_; | 634 return transition_duration_; |
618 } | 635 } |
619 | 636 |
620 } // namespace ui | 637 } // namespace ui |
OLD | NEW |