Bug 1346052 - Part 2: Implement AnimationValue::ComputeDistance. draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 26 Apr 2017 20:05:04 +0800
changeset 571665 49703a8e4b790fb0b8929bf6a02efab874767d9e
parent 571664 f5cea33ade2b6ffe3619fdc2cea9646a43d154c1
child 571666 3e2acc0717322ec6d2c4f5231cd2299da9d1c0fd
push id56881
push userbmo:boris.chiou@gmail.com
push dateWed, 03 May 2017 03:53:29 +0000
bugs1346052
milestone55.0a1
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
layout/style/StyleAnimationValue.cpp
layout/style/StyleAnimationValue.h
--- 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