Bug 1286151 - Part 7: Make ComputeShapeDistance return the status. draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 17 Nov 2016 11:52:41 +0800
changeset 440287 aecf790c508447a618239987ae8dc4b4cb6353f3
parent 440282 9fb7c03261094c573859566e3c14282916bef364
child 537345 3856a4ebb895d01a1b5f09164a25d8130c808ea7
push id36194
push userbmo:boris.chiou@gmail.com
push dateThu, 17 Nov 2016 07:59:41 +0000
bugs1286151
milestone52.0a1
Bug 1286151 - Part 7: Make ComputeShapeDistance return the status. We should follow the rules used by other types - return false if computing the distance is failed. So make ComputeShapeDistance and return the status and let the last argument be the output distance. MozReview-Commit-ID: CFoQhgyqILB
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -942,27 +942,28 @@ enum class Restrictions {
 };
 
 static already_AddRefed<nsCSSValue::Array>
 AddShapeFunction(nsCSSPropertyID aProperty,
                  double aCoeff1, const nsCSSValue::Array* aArray1,
                  double aCoeff2, const nsCSSValue::Array* aArray2,
                  Restrictions aRestriction = Restrictions::Enable);
 
-static double
+static bool
 ComputeShapeDistance(nsCSSPropertyID aProperty,
                      const nsCSSValue::Array* aArray1,
-                     const nsCSSValue::Array* aArray2)
+                     const nsCSSValue::Array* aArray2,
+                     double& aDistance)
 {
   // Use AddShapeFunction to get the difference between two shape functions.
   RefPtr<nsCSSValue::Array> diffShape =
     AddShapeFunction(aProperty, 1.0, aArray2, -1.0, aArray1,
                      Restrictions::Disable);
   if (!diffShape) {
-    return 0.0;
+    return false;
   }
 
   // A helper function to convert a calc() diff value into a double distance.
   auto pixelCalcDistance = [](const PixelCalcValue& aValue) {
     MOZ_ASSERT(aValue.mHasPercent || aValue.mPercent == 0.0f,
              "can't have a nonzero percentage part without having percentages");
     return aValue.mLength * aValue.mLength + aValue.mPercent * aValue.mPercent;
   };
@@ -1014,17 +1015,18 @@ ComputeShapeDistance(nsCSSPropertyID aPr
         squareDistance += pixelCalcDistance(ExtractCalcValue(pair.mXValue)) +
                           pixelCalcDistance(ExtractCalcValue(pair.mYValue));
       }
       break;
     }
     default:
       MOZ_ASSERT_UNREACHABLE("Unknown shape type");
   }
-  return sqrt(squareDistance);
+  aDistance = sqrt(squareDistance);
+  return true;
 }
 
 static nsCSSValueList*
 AddTransformLists(double aCoeff1, const nsCSSValueList* aList1,
                   double aCoeff2, const nsCSSValueList* aList2);
 
 static double
 ComputeTransform2DMatrixDistance(const Matrix& aMatrix1,
@@ -1658,20 +1660,20 @@ StyleAnimationValue::ComputeDistance(nsC
       const nsCSSValueList *shadow1 = normValue1.GetCSSValueListValue();
       const nsCSSValueList *shadow2 = normValue2.GetCSSValueListValue();
       if (!ComputeShadowDistance(shadow1, shadow2, aDistance)) {
         NS_ERROR("Can not compute shadow distance!");
       }
       return true;
     }
     case eUnit_Shape:
-      aDistance = ComputeShapeDistance(aProperty,
-                                       aStartValue.GetCSSValueArrayValue(),
-                                       aEndValue.GetCSSValueArrayValue());
-      return true;
+      return ComputeShapeDistance(aProperty,
+                                  aStartValue.GetCSSValueArrayValue(),
+                                  aEndValue.GetCSSValueArrayValue(),
+                                  aDistance);
 
     case eUnit_Filter:
       return ComputeFilterListDistance(aStartValue.GetCSSValueListValue(),
                                        aEndValue.GetCSSValueListValue(),
                                        aDistance);
 
     case eUnit_Transform: {
       // FIXME: We don't have an official spec to define the distance of