Bug 1390352 - Make Servo_AnimationValues_ComputeDistance return negative value instead of 0.0 when the function fails to distinguish its failure. r?hiro draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Tue, 22 Aug 2017 03:37:35 +0900
changeset 650091 9d02adc7d37e12496f30005e96601d63caf2bea7
parent 650090 9aad032830363df4625cf13a6f74b07d728532d5
child 727297 2b48d0e3e62377be306f76e7b35301538846602a
push id75266
push usermantaroh@gmail.com
push dateMon, 21 Aug 2017 18:39:16 +0000
reviewershiro
bugs1390352
milestone57.0a1
Bug 1390352 - Make Servo_AnimationValues_ComputeDistance return negative value instead of 0.0 when the function fails to distinguish its failure. r?hiro We need to check the return value of Servo_AnimationValues_ComputeDistance in order to check whether we support the specified paced animation value. Current servo returns 0.0 when failed computing distance, so servo doesn't distinguish its failure. This patch makes Servo_AnimationValue_ComputeDistance return a negative value when the function fails. MozReview-Commit-ID: 43Q4gu4xwHc
dom/smil/nsSMILCSSValueType.cpp
layout/style/StyleAnimationValue.cpp
servo/ports/geckolib/glue.rs
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -451,16 +451,20 @@ ComputeDistanceForServo(const ValueWrapp
       aFromWrapper ? &aFromWrapper->mServoValues[0] : nullptr;
     const RefPtr<RawServoAnimationValue>* toValue = &aToWrapper.mServoValues[0];
     RefPtr<RawServoAnimationValue> zeroValueStorage;
     if (!FinalizeServoAnimationValues(fromValue, toValue, zeroValueStorage)) {
       return NS_ERROR_FAILURE;
     }
 
     double distance = Servo_AnimationValues_ComputeDistance(*fromValue, *toValue);
+    if (distance < 0.0) {
+      return NS_ERROR_FAILURE;
+    }
+
     if (len == 1) {
       aDistance = distance;
       return NS_OK;
     }
     squareDistance += distance * distance;
   }
 
   aDistance = sqrt(squareDistance);
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -5395,21 +5395,24 @@ AnimationValue::ComputeDistance(nsCSSPro
     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");
 
+  double distance= 0.0;
   if (mServo) {
-    return Servo_AnimationValues_ComputeDistance(mServo, aOther.mServo);
+    distance = Servo_AnimationValues_ComputeDistance(mServo, aOther.mServo);
+    return distance < 0.0
+           ? 0.0
+           : distance;
   }
 
-  double distance = 0.0;
   return StyleAnimationValue::ComputeDistance(aProperty,
                                               mGecko,
                                               aOther.mGecko,
                                               aStyleContext->AsGecko(),
                                               distance)
          ? distance
          : 0.0;
 }
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -378,17 +378,17 @@ pub extern "C" fn Servo_AnimationValues_
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_AnimationValues_ComputeDistance(from: RawServoAnimationValueBorrowed,
                                                         to: RawServoAnimationValueBorrowed)
                                                         -> f64 {
     let from_value = AnimationValue::as_arc(&from);
     let to_value = AnimationValue::as_arc(&to);
-    from_value.compute_squared_distance(to_value).map(|d| d.sqrt()).unwrap_or(0.0)
+    from_value.compute_squared_distance(to_value).map(|d| d.sqrt()).unwrap_or(-1.0)
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_AnimationCompose(raw_value_map: RawServoAnimationValueMapBorrowedMut,
                                          base_values: RawServoAnimationValueTableBorrowed,
                                          css_property: nsCSSPropertyID,
                                          segment: RawGeckoAnimationPropertySegmentBorrowed,
                                          last_segment: RawGeckoAnimationPropertySegmentBorrowed,