Bug 1338927 - Part 6: Templatize SetKeyframes(). r?birtles
We have SetKeyframes(nsStyleContext*) for the same reason
of UpdateProperties(nsStyleContext*).
MozReview-Commit-ID: 7WjMU66MzpU
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -185,33 +185,57 @@ KeyframeEffectReadOnly::SetKeyframes(JSC
RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
SetKeyframes(Move(keyframes), styleContext);
}
void
KeyframeEffectReadOnly::SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
nsStyleContext* aStyleContext)
{
+ DoSetKeyframes(Move(aKeyframes), Move(aStyleContext));
+}
+
+void
+KeyframeEffectReadOnly::SetKeyframes(
+ nsTArray<Keyframe>&& aKeyframes,
+ const ServoComputedStyleValues& aServoValues)
+{
+ DoSetKeyframes(Move(aKeyframes), aServoValues);
+}
+
+template<typename StyleType>
+void
+KeyframeEffectReadOnly::DoSetKeyframes(nsTArray<Keyframe>&& aKeyframes,
+ StyleType&& aStyle)
+{
+ static_assert(IsSame<StyleType, nsStyleContext*>::value ||
+ IsSame<StyleType, const ServoComputedStyleValues&>::value,
+ "StyleType should be nsStyleContext* or "
+ "const ServoComputedStyleValues&");
+
if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) {
return;
}
mKeyframes = Move(aKeyframes);
// Apply distribute spacing irrespective of the spacing mode. We will apply
// the specified spacing mode when we generate computed animation property
// values from the keyframes since both operations require a style context
// and need to be performed whenever the style context changes.
KeyframeUtils::ApplyDistributeSpacing(mKeyframes);
if (mAnimation && mAnimation->IsRelevant()) {
nsNodeUtils::AnimationChanged(mAnimation);
}
- if (aStyleContext) {
- UpdateProperties(aStyleContext);
+ // We need to call UpdateProperties() if the StyleType is
+ // 'const ServoComputedStyleValues&' (i.e. not a pointer) or nsStyleContext*
+ // is not nullptr.
+ if (!IsPointer<StyleType>::value || aStyle) {
+ UpdateProperties(aStyle);
MaybeUpdateFrameForCompositor();
}
}
const AnimationProperty*
KeyframeEffectReadOnly::GetEffectiveAnimationOfProperty(
nsCSSPropertyID aProperty) const
{
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -198,16 +198,18 @@ public:
void NotifyAnimationTimingUpdated();
void SetAnimation(Animation* aAnimation) override;
void SetKeyframes(JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
ErrorResult& aRv);
void SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
nsStyleContext* aStyleContext);
+ void SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
+ const ServoComputedStyleValues& aServoValues);
// Returns true if the effect includes |aProperty| regardless of whether the
// property is overridden by !important rule.
bool HasAnimationOfProperty(nsCSSPropertyID aProperty) const;
// GetEffectiveAnimationOfProperty returns AnimationProperty corresponding
// to a given CSS property if the effect includes the property and the
// property is not overridden by !important rules.
@@ -429,16 +431,19 @@ protected:
// least one animation value that is composited with the underlying value
// (i.e. it uses the additive or accumulate composite mode).
nsDataHashtable<nsUint32HashKey, StyleAnimationValue> mBaseStyleValues;
private:
nsChangeHint mCumulativeChangeHint;
template<typename StyleType>
+ void DoSetKeyframes(nsTArray<Keyframe>&& aKeyframes, StyleType&& aStyle);
+
+ template<typename StyleType>
void DoUpdateProperties(StyleType&& aStyle);
nsIFrame* GetAnimationFrame() const;
bool CanThrottle() const;
bool CanThrottleTransformChanges(nsIFrame& aFrame) const;
// Returns true if the computedTiming has changed since the last