Bug 1286150 - Part 5: Implement shape distance for inset. draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 27 Oct 2016 15:34:06 +0800
changeset 432448 f07174c769032586fb9fc4e3d8139dbf320fa259
parent 432447 2051f0acf3b94428ead256b58aaadfe4d1fa2054
child 432449 25ba32f1abf7b387df6b64244ae8afdd0c5ad47d
push id34315
push userbmo:boris.chiou@gmail.com
push dateWed, 02 Nov 2016 03:24:03 +0000
bugs1286150
milestone52.0a1
Bug 1286150 - Part 5: Implement shape distance for inset. MozReview-Commit-ID: 4C2uZp9qM3D
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -790,21 +790,34 @@ ComputeShapeDistance(nsCSSPropertyID aPr
       const nsCSSValuePairList* list = func->Item(2).GetPairListValue();
       do {
         squareDistance += pixelCalcDistance(ExtractCalcValue(list->mXValue)) +
                           pixelCalcDistance(ExtractCalcValue(list->mYValue));
         list = list->mNext;
       } while (list);
       break;
     }
-    case eCSSKeyword_inset:
-      // TODO: will be fixed in the later patch.
-      MOZ_ASSERT(false);
+    case eCSSKeyword_inset: {
+      // Items 1-4 are respectively the top, right, bottom and left offsets
+      // from the reference box.
+      for (size_t i = 1; i <= 4; ++i) {
+        const nsCSSValue& value = func->Item(i);
+        squareDistance += pixelCalcDistance(ExtractCalcValue(value));
+      }
+      // Item 5 contains the radii of the rounded corners for the inset
+      // rectangle.
+      const nsCSSValue::Array* array = func->Item(5).GetArrayValue();
+      const size_t len = array->Count();
+      for (size_t i = 0; i < len; ++i) {
+        const nsCSSValuePair& pair = array->Item(i).GetPairValue();
+        squareDistance += pixelCalcDistance(ExtractCalcValue(pair.mXValue)) +
+                          pixelCalcDistance(ExtractCalcValue(pair.mYValue));
+      }
       break;
-
+    }
     default:
       MOZ_ASSERT_UNREACHABLE("Unknown shape type");
   }
   return sqrt(squareDistance);
 }
 
 static nsCSSValueList*
 AddTransformLists(double aCoeff1, const nsCSSValueList* aList1,