Chromium Code Reviews| Index: ui/gfx/compositor/layer_animator.cc |
| diff --git a/ui/gfx/compositor/layer_animator.cc b/ui/gfx/compositor/layer_animator.cc |
| index 8004c5cdea2d08439903dcbcbde340f8e4605d5b..f845874a67623b95d3fe2f900fc3ca64f22e8104 100644 |
| --- a/ui/gfx/compositor/layer_animator.cc |
| +++ b/ui/gfx/compositor/layer_animator.cc |
| @@ -7,10 +7,12 @@ |
| #include "base/debug/trace_event.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
|
sky
2011/10/27 19:29:19
don't need this since in header.
|
| #include "ui/base/animation/animation_container.h" |
| #include "ui/gfx/compositor/compositor.h" |
| #include "ui/gfx/compositor/layer.h" |
| -#include "ui/gfx/compositor/layer_animator_delegate.h" |
| +#include "ui/gfx/compositor/layer_animation_delegate.h" |
| +#include "ui/gfx/compositor/layer_animation_observer.h" |
| #include "ui/gfx/compositor/layer_animation_sequence.h" |
| namespace ui { |
| @@ -55,8 +57,9 @@ void LayerAnimator::SetTransform(const Transform& transform) { |
| if (transition_duration_ == base::TimeDelta()) |
| delegate_->SetTransformFromAnimation(transform); |
| else |
| - StartAnimationElement(LayerAnimationElement::CreateTransformElement( |
| - transform, transition_duration_)); |
| + StartAnimation(new LayerAnimationSequence( |
| + LayerAnimationElement::CreateTransformElement( |
| + transform, transition_duration_))); |
| } |
| Transform LayerAnimator::GetTargetTransform() const { |
| @@ -69,8 +72,9 @@ void LayerAnimator::SetBounds(const gfx::Rect& bounds) { |
| if (transition_duration_ == base::TimeDelta()) |
| delegate_->SetBoundsFromAnimation(bounds); |
| else |
| - StartAnimationElement(LayerAnimationElement::CreateBoundsElement( |
| - bounds, transition_duration_)); |
| + StartAnimation(new LayerAnimationSequence( |
| + LayerAnimationElement::CreateBoundsElement( |
| + bounds, transition_duration_))); |
| } |
| gfx::Rect LayerAnimator::GetTargetBounds() const { |
| @@ -83,8 +87,9 @@ void LayerAnimator::SetOpacity(float opacity) { |
| if (transition_duration_ == base::TimeDelta()) |
| delegate_->SetOpacityFromAnimation(opacity); |
| else |
| - StartAnimationElement(LayerAnimationElement::CreateOpacityElement( |
| - opacity, transition_duration_)); |
| + StartAnimation(new LayerAnimationSequence( |
| + LayerAnimationElement::CreateOpacityElement( |
| + opacity, transition_duration_))); |
| } |
| float LayerAnimator::GetTargetOpacity() const { |
| @@ -93,12 +98,13 @@ float LayerAnimator::GetTargetOpacity() const { |
| return target.opacity; |
| } |
| -void LayerAnimator::SetDelegate(LayerAnimatorDelegate* delegate) { |
| +void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
| DCHECK(delegate); |
| delegate_ = delegate; |
| } |
| void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
| + AddObserversToSequence(animation); |
| if (!StartSequenceImmediately(animation)) { |
| // Attempt to preempt a running animation. |
| switch (preemption_strategy_) { |
| @@ -126,6 +132,7 @@ void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
| } |
| void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) { |
| + AddObserversToSequence(animation); |
| if (is_animating()) { |
| animation_queue_.push_back(make_linked_ptr(animation)); |
| ProcessQueue(); |
| @@ -162,22 +169,6 @@ void LayerAnimator::ScheduleTogether( |
| UpdateAnimationState(); |
| } |
| -void LayerAnimator::StartAnimationElement(LayerAnimationElement* animation) { |
| - StartAnimation(new LayerAnimationSequence(animation)); |
| -} |
| - |
| -void LayerAnimator::ScheduleAnimationElement(LayerAnimationElement* animation) { |
| - ScheduleAnimation(new LayerAnimationSequence(animation)); |
| -} |
| - |
| -void LayerAnimator::ScheduleElementsTogether( |
| - const std::vector<LayerAnimationElement*>& animations) { |
| - std::vector<LayerAnimationSequence*> sequences; |
| - for (size_t i = 0; i < animations.size(); ++i) |
| - sequences.push_back(new LayerAnimationSequence(animations[i])); |
| - ScheduleTogether(sequences); |
| -} |
| - |
| void LayerAnimator::StopAnimatingProperty( |
| LayerAnimationElement::AnimatableProperty property) { |
| while (true) { |
| @@ -193,6 +184,15 @@ void LayerAnimator::StopAnimating() { |
| FinishAnimation(running_animations_[0].sequence); |
| } |
| +void LayerAnimator::AddObserver(LayerAnimationObserver* observer) { |
| + if (!observers_.HasObserver(observer)) |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void LayerAnimator::RemoveObserver(LayerAnimationObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| LayerAnimator::ScopedSettings::ScopedSettings(LayerAnimator* animator) |
| : animator_(animator), |
| old_transition_duration_(animator->transition_duration_) { |
| @@ -201,6 +201,14 @@ LayerAnimator::ScopedSettings::ScopedSettings(LayerAnimator* animator) |
| LayerAnimator::ScopedSettings::~ScopedSettings() { |
| animator_->transition_duration_ = old_transition_duration_; |
| + for (size_t i = 0; i < observers_.size(); ++i) |
| + animator_->RemoveObserver(observers_[i]); |
| +} |
| + |
| +void LayerAnimator::ScopedSettings::AddObserver( |
| + LayerAnimationObserver* observer) { |
| + observers_.push_back(observer); |
| + animator_->AddObserver(observer); |
|
sky
2011/10/27 19:29:19
I believe this means the observer is notified of e
|
| } |
| void LayerAnimator::ScopedSettings::SetTransitionDuration( |
| @@ -277,7 +285,7 @@ void LayerAnimator::RemoveAnimation(LayerAnimationSequence* sequence) { |
| void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) { |
| sequence->Progress(sequence->duration(), delegate()); |
| - delegate()->OnLayerAnimationEnded(sequence); |
| + NotifyAnimationEnded(sequence); |
| RemoveAnimation(sequence); |
| ProcessQueue(); |
| UpdateAnimationState(); |
| @@ -293,7 +301,7 @@ void LayerAnimator::FinishAnyAnimationWithZeroDuration() { |
| if (running_animations_[i].sequence->duration() == base::TimeDelta()) { |
| running_animations_[i].sequence->Progress( |
| running_animations_[i].sequence->duration(), delegate()); |
| - delegate()->OnLayerAnimationEnded(running_animations_[i].sequence); |
| + NotifyAnimationEnded(running_animations_[i].sequence); |
|
sky
2011/10/27 19:29:19
Can't progress recognize it's at the end and notif
|
| RemoveAnimation(running_animations_[i].sequence); |
| } else { |
| ++i; |
| @@ -356,7 +364,7 @@ void LayerAnimator::RemoveAllAnimationsWithACommonProperty( |
| } else { |
| running_animations_[i].sequence->Progress( |
| running_animations_[i].sequence->duration(), delegate()); |
| - delegate()->OnLayerAnimationEnded(running_animations_[i].sequence); |
| + NotifyAnimationEnded(running_animations_[i].sequence); |
| } |
| RemoveAnimation(running_animations_[i].sequence); |
| } else { |
| @@ -384,7 +392,7 @@ void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) { |
| const bool abort = false; |
| RemoveAllAnimationsWithACommonProperty(sequence, abort); |
| sequence->Progress(sequence->duration(), delegate()); |
| - delegate()->OnLayerAnimationEnded(sequence); |
| + NotifyAnimationEnded(sequence); |
| RemoveAnimation(sequence); |
| } |
| @@ -500,4 +508,17 @@ void LayerAnimator::GetTargetValue( |
| } |
| } |
| +void LayerAnimator::NotifyAnimationEnded(LayerAnimationSequence* sequence) { |
| + sequence->NotifyEnded(); |
| +} |
| + |
| +void LayerAnimator::AddObserversToSequence(LayerAnimationSequence* sequence) { |
| + if (observers_.might_have_observers()) { |
| + ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); |
| + LayerAnimationObserver* obs; |
| + while ((obs = it.GetNext()) != NULL) |
| + sequence->AddObserver(obs); |
| + } |
| +} |
| + |
| } // namespace ui |