Bug 1304886 - Part 2: Factor out TransformFunctionListsMatch. r?boris draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Wed, 16 Nov 2016 20:32:32 +0900
changeset 439607 19dd1af1cbbcc95c046885ce3531219ef93002c3
parent 439606 b69626c2b214005ad953571716b691cfd0fbd9a6
child 439608 c5cf349e36f1f14db4e0244e5519c66013e16050
push id36059
push userhiikezoe@mozilla-japan.org
push dateWed, 16 Nov 2016 11:32:59 +0000
reviewersboris
bugs1304886
milestone53.0a1
Bug 1304886 - Part 2: Factor out TransformFunctionListsMatch. r?boris MozReview-Commit-ID: BhRkF6ClJjv
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -130,16 +130,39 @@ ToPrimitive(nsCSSKeyword aKeyword)
 }
 
 static bool
 TransformFunctionsMatch(nsCSSKeyword func1, nsCSSKeyword func2)
 {
   return ToPrimitive(func1) == ToPrimitive(func2);
 }
 
+static bool
+TransformFunctionListsMatch(const nsCSSValueList *list1,
+                            const nsCSSValueList *list2)
+{
+  const nsCSSValueList *item1 = list1, *item2 = list2;
+  do {
+    nsCSSKeyword func1 = nsStyleTransformMatrix::TransformFunctionOf(
+        item1->mValue.GetArrayValue());
+    nsCSSKeyword func2 = nsStyleTransformMatrix::TransformFunctionOf(
+        item2->mValue.GetArrayValue());
+
+    if (!TransformFunctionsMatch(func1, func2)) {
+      return false;
+    }
+
+    item1 = item1->mNext;
+    item2 = item2->mNext;
+  } while (item1 && item2);
+
+  // Length match?
+  return !item1 && !item2;
+}
+
 static already_AddRefed<nsCSSValue::Array>
 AppendFunction(nsCSSKeyword aTransformFunction)
 {
   uint32_t nargs;
   switch (aTransformFunction) {
     case eCSSKeyword_matrix3d:
       nargs = 16;
       break;
@@ -1514,39 +1537,21 @@ StyleAnimationValue::ComputeDistance(nsC
         // Both none, nothing happens.
         aDistance = 0.0;
       } else if (list1->mValue.GetUnit() == eCSSUnit_None) {
         nsAutoPtr<nsCSSValueList> none(AddTransformLists(0, list2, 0, list2));
         aDistance = ComputeTransformListDistance(none, list2);
       } else if (list2->mValue.GetUnit() == eCSSUnit_None) {
         nsAutoPtr<nsCSSValueList> none(AddTransformLists(0, list1, 0, list1));
         aDistance = ComputeTransformListDistance(list1, none);
+      } else if (TransformFunctionListsMatch(list1, list2)) {
+        aDistance = ComputeTransformListDistance(list1, list2);
       } else {
-        const nsCSSValueList *item1 = list1, *item2 = list2;
-        do {
-          nsCSSKeyword func1 = nsStyleTransformMatrix::TransformFunctionOf(
-            item1->mValue.GetArrayValue());
-          nsCSSKeyword func2 = nsStyleTransformMatrix::TransformFunctionOf(
-            item2->mValue.GetArrayValue());
-          if (!TransformFunctionsMatch(func1, func2)) {
-            break;
-          }
-
-          item1 = item1->mNext;
-          item2 = item2->mNext;
-        } while (item1 && item2);
-
-        if (item1 || item2) {
-          // Either the transform function types don't match or
-          // the lengths don't match.
-          aDistance =
-            ComputeMismatchedTransfromListDistance(list1, list2, aStyleContext);
-        } else {
-          aDistance = ComputeTransformListDistance(list1, list2);
-        }
+        aDistance =
+          ComputeMismatchedTransfromListDistance(list1, list2, aStyleContext);
       }
       return true;
     }
     case eUnit_BackgroundPositionCoord: {
       const nsCSSValueList *position1 = aStartValue.GetCSSValueListValue();
       const nsCSSValueList *position2 = aEndValue.GetCSSValueListValue();
 
       double squareDistance = 0.0;
@@ -3017,45 +3022,20 @@ StyleAnimationValue::AddWeighted(nsCSSPr
             result->mValue.SetNoneValue();
           }
         } else {
           result = AddTransformLists(0, list2, aCoeff2, list2);
         }
       } else {
         if (list2->mValue.GetUnit() == eCSSUnit_None) {
           result = AddTransformLists(0, list1, aCoeff1, list1);
+        } else if (TransformFunctionListsMatch(list1, list2)) {
+          result = AddTransformLists(aCoeff1, list1, aCoeff2, list2);
         } else {
-          bool match = true;
-
-          {
-            const nsCSSValueList *item1 = list1, *item2 = list2;
-            do {
-              nsCSSKeyword func1 = nsStyleTransformMatrix::TransformFunctionOf(
-                                     item1->mValue.GetArrayValue());
-              nsCSSKeyword func2 = nsStyleTransformMatrix::TransformFunctionOf(
-                                     item2->mValue.GetArrayValue());
-
-              if (!TransformFunctionsMatch(func1, func2)) {
-                break;
-              }
-
-              item1 = item1->mNext;
-              item2 = item2->mNext;
-            } while (item1 && item2);
-            if (item1 || item2) {
-              // Either |break| above or length mismatch.
-              match = false;
-            }
-          }
-
-          if (match) {
-            result = AddTransformLists(aCoeff1, list1, aCoeff2, list2);
-          } else {
-            result = AddDifferentTransformLists(aCoeff1, list1, aCoeff2, list2);
-          }
+          result = AddDifferentTransformLists(aCoeff1, list1, aCoeff2, list2);
         }
       }
 
       aResultValue.SetTransformValue(new nsCSSValueSharedList(result.forget()));
       return true;
     }
     case eUnit_BackgroundPositionCoord: {
       const nsCSSValueList *position1 = aValue1.GetCSSValueListValue();