Bug 1340322 - Part 7: SetKeyframes depends on sources, (i.e. nsStyleContext or ServoComputedValues). r?birtles
MozReview-Commit-ID: 47GaZDIdhV3
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -464,16 +464,19 @@ protected:
mCollection->mAnimations.SwapElements(mNewAnimations);
// Cancel removed animations
for (size_t newAnimIdx = mNewAnimations.Length(); newAnimIdx-- != 0; ) {
mNewAnimations[newAnimIdx]->CancelFromStyle();
}
}
+ virtual void SetKeyframes(KeyframeEffectReadOnly& aEffect,
+ nsTArray<Keyframe>&& aKeyframes) = 0;
+
nsAnimationManager* mManager;
RefPtr<dom::Element> mTarget;
CSSPseudoElementType mPseudoType;
RefPtr<dom::DocumentTimeline> mTimeline;
// Existing collection, nullptr if the target element has no animations.
nsAnimationManager::CSSAnimationCollection* mCollection;
OwningCSSAnimationPtrArray mNewAnimations;
};
@@ -490,16 +493,23 @@ public:
nsAnimationManager::CSSAnimationCollection* aCollection)
: CSSAnimationBuilder(aAnimationManager, aTarget, aPseudoType, aCollection)
, mComputedValues(aComputedValues)
, mParentComputedValues(aParentComputedValues)
{
MOZ_ASSERT(aComputedValues);
}
+protected:
+ void SetKeyframes(KeyframeEffectReadOnly& aEffect,
+ nsTArray<Keyframe>&& aKeyframes) override
+ {
+ aEffect.SetKeyframes(Move(aKeyframes),
+ { mComputedValues, mParentComputedValues });
+ }
private:
const ServoComputedValues* mComputedValues;
const ServoComputedValues* mParentComputedValues;
};
class MOZ_STACK_CLASS GeckoCSSAnimationBuilder final
: public CSSAnimationBuilder {
public:
@@ -512,16 +522,24 @@ public:
: CSSAnimationBuilder(aAnimationManager, aTarget, aPseudoType, aCollection)
, mStyleContext(aStyleContext)
{
MOZ_ASSERT(aStyleContext);
}
void BuildAnimations();
+
+protected:
+ void SetKeyframes(KeyframeEffectReadOnly& aEffect,
+ nsTArray<Keyframe>&& aKeyframes) override
+ {
+ aEffect.SetKeyframes(Move(aKeyframes), mStyleContext);
+ }
+
private:
// Returns a new animation set up with given StyleAnimation.
// Or returns an existing animation matching StyleAnimation's name updated
// with the new StyleAnimation.
already_AddRefed<CSSAnimation> Build(const StyleAnimation& aSrc);
void
UpdateOldAnimationPropertiesWithNew(CSSAnimation& aOld,
@@ -577,17 +595,17 @@ GeckoCSSAnimationBuilder::UpdateOldAnima
// identity (and any expando properties attached to it).
if (aOld.GetEffect()) {
dom::AnimationEffectReadOnly* oldEffect = aOld.GetEffect();
animationChanged = oldEffect->SpecifiedTiming() != aNewTiming;
oldEffect->SetSpecifiedTiming(aNewTiming);
KeyframeEffectReadOnly* oldKeyframeEffect = oldEffect->AsKeyframeEffect();
if (oldKeyframeEffect) {
- oldKeyframeEffect->SetKeyframes(Move(aNewKeyframes), mStyleContext);
+ SetKeyframes(*oldKeyframeEffect, Move(aNewKeyframes));
}
}
// Handle changes in play state. If the animation is idle, however,
// changes to animation-play-state should *not* restart it.
if (aOld.PlayState() != AnimationPlayState::Idle) {
// CSSAnimation takes care of override behavior so that,
// for example, if the author has called pause(), that will
@@ -670,17 +688,17 @@ GeckoCSSAnimationBuilder::Build(const St
Maybe<OwningAnimationTarget> target;
target.emplace(mTarget, mPseudoType);
KeyframeEffectParams effectOptions;
RefPtr<KeyframeEffectReadOnly> effect =
new KeyframeEffectReadOnly(mManager->PresContext()->Document(),
target, timing,
effectOptions);
- effect->SetKeyframes(Move(keyframes), mStyleContext);
+ SetKeyframes(*effect, Move(keyframes));
RefPtr<CSSAnimation> animation =
new CSSAnimation(mManager->PresContext()->Document()->GetScopeObject(),
aSrc.GetName());
animation->SetOwningElement(
OwningElementRef(*mTarget, mPseudoType));
animation->SetTimelineNoUpdate(mTimeline);