Index: ui/compositor/layer.cc |
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc |
index ca3ff288ee293a43b49d39bee0f6f97311e6a0cd..d3585595473c887cf9e8a4487f2415ec7e92407b 100644 |
--- a/ui/compositor/layer.cc |
+++ b/ui/compositor/layer.cc |
@@ -142,10 +142,15 @@ void Layer::SetCompositor(Compositor* compositor) { |
DCHECK(!compositor || !compositor_); |
DCHECK(!compositor || compositor->root_layer() == this); |
DCHECK(!parent_); |
+ if (compositor_) { |
+ RemoveAnimatorsInTreeFromCollection( |
+ compositor_->layer_animator_collection()); |
+ } |
compositor_ = compositor; |
if (compositor) { |
OnDeviceScaleFactorChanged(compositor->device_scale_factor()); |
SendPendingThreadedAnimations(); |
+ AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection()); |
} |
} |
@@ -159,15 +164,20 @@ void Layer::Add(Layer* child) { |
child->OnDeviceScaleFactorChanged(device_scale_factor_); |
if (GetCompositor()) |
child->SendPendingThreadedAnimations(); |
+ LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
+ if (collection) |
+ child->AddAnimatorsInTreeToCollection(collection); |
} |
void Layer::Remove(Layer* child) { |
+ LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
+ if (collection) |
+ child->RemoveAnimatorsInTreeFromCollection(collection); |
ajuma
2014/06/02 14:53:22
This should be moved to after the StopAnimatingPro
sadrul
2014/06/02 17:53:44
Done.
|
// Current bounds are used to calculate offsets when layers are reparented. |
// Stop (and complete) an ongoing animation to update the bounds immediately. |
- if (child->GetAnimator()) { |
- child->GetAnimator()->StopAnimatingProperty( |
- ui::LayerAnimationElement::BOUNDS); |
- } |
+ LayerAnimator* child_animator = child->animator_; |
+ if (child_animator) |
+ child_animator->StopAnimatingProperty(ui::LayerAnimationElement::BOUNDS); |
std::vector<Layer*>::iterator i = |
std::find(children_.begin(), children_.end(), child); |
DCHECK(i != children_.end()); |
@@ -873,6 +883,11 @@ void Layer::RemoveThreadedAnimation(int animation_id) { |
pending_threaded_animations_.end()); |
} |
+LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { |
+ Compositor* compositor = GetCompositor(); |
+ return compositor ? compositor->layer_animator_collection() : NULL; |
+} |
+ |
void Layer::SendPendingThreadedAnimations() { |
for (cc::ScopedPtrVector<cc::Animation>::iterator it = |
pending_threaded_animations_.begin(); |
@@ -930,4 +945,32 @@ void Layer::RecomputePosition() { |
cc_layer_->SetPosition(gfx::PointF(bounds_.x(), bounds_.y())); |
} |
+void Layer::AddAnimatorsInTreeToCollection( |
+ LayerAnimatorCollection* collection) { |
+ DCHECK(collection); |
+ if (IsAnimating()) |
+ collection->StartAnimator(animator_.get()); |
ajuma
2014/06/02 14:53:22
LayerAnimator::is_started_ will have a stale value
sadrul
2014/06/02 17:53:44
Done.
|
+ std::for_each( |
+ children_.begin(), |
+ children_.end(), |
+ std::bind2nd(std::mem_fun(&Layer::AddAnimatorsInTreeToCollection), |
+ collection)); |
+} |
+ |
+void Layer::RemoveAnimatorsInTreeFromCollection( |
+ LayerAnimatorCollection* collection) { |
+ DCHECK(collection); |
+ if (IsAnimating()) |
+ collection->StopAnimator(animator_.get()); |
+ std::for_each( |
+ children_.begin(), |
+ children_.end(), |
+ std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
+ collection)); |
+} |
+ |
+bool Layer::IsAnimating() const { |
+ return animator_ && animator_->is_animating(); |
+} |
+ |
} // namespace ui |