Bug 1346052 - Part 2: Implement AnimationValue::ComputeDistance.
We will use this API to compute the distance between two AnimationValues
in the patch series.
MozReview-Commit-ID: 2Tw9xumuz45
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -5269,8 +5269,36 @@ AnimationValue::IsInterpolableWith(nsCSS
}
// If this is ever a performance problem, we could add a
// StyleAnimationValue::IsInterpolatable method, but it seems fine for now.
StyleAnimationValue dummy;
return StyleAnimationValue::Interpolate(
aProperty, mGecko, aToValue.mGecko, 0.5, dummy);
}
+
+double
+AnimationValue::ComputeDistance(nsCSSPropertyID aProperty,
+ const AnimationValue& aOther,
+ nsStyleContext* aStyleContext) const
+{
+ if (IsNull() || aOther.IsNull()) {
+ return 0.0;
+ }
+
+ MOZ_ASSERT(!mServo != mGecko.IsNull());
+ MOZ_ASSERT(mGecko.IsNull() == aOther.mGecko.IsNull() &&
+ !mServo == !aOther.mServo,
+ "Animation values should have the same style engine");
+
+ if (mServo) {
+ return Servo_AnimationValues_ComputeDistance(mServo, aOther.mServo);
+ }
+
+ double distance = 0.0;
+ return StyleAnimationValue::ComputeDistance(aProperty,
+ mGecko,
+ aOther.mGecko,
+ aStyleContext,
+ distance)
+ ? distance
+ : 0.0;
+}
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -597,16 +597,23 @@ struct AnimationValue
// Uncompute this AnimationValue and then serialize it.
void SerializeSpecifiedValue(nsCSSPropertyID aProperty,
nsAString& aString) const;
// Check if |*this| and |aToValue| can be interpolated.
bool IsInterpolableWith(nsCSSPropertyID aProperty,
const AnimationValue& aToValue) const;
+
+ // Compute the distance between *this and aOther.
+ // If |aStyleContext| is nullptr, we will return 0.0 if we have mismatched
+ // transform lists.
+ double ComputeDistance(nsCSSPropertyID aProperty,
+ const AnimationValue& aOther,
+ nsStyleContext* aStyleContext) const;
};
struct PropertyStyleAnimationValuePair
{
nsCSSPropertyID mProperty;
AnimationValue mValue;
};
} // namespace mozilla