Bug 1216843 - Part 9: Factor out AddWeightedShadowList. r?dholbert draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 09 Aug 2016 11:20:08 +0900
changeset 398377 0594fb3a3f4bc8e456aacbd2e1a52004ed836ed1
parent 398376 96de3817a84ab7167dcc4557939c476b46a814d6
child 398378 3263bae26fa07a676f40a86b53bb7ab7e07dba33
push id25511
push userbmo:hiikezoe@mozilla-japan.org
push dateTue, 09 Aug 2016 02:33:32 +0000
reviewersdholbert
bugs1216843
milestone51.0a1
Bug 1216843 - Part 9: Factor out AddWeightedShadowList. r?dholbert MozReview-Commit-ID: GbxOTRWVB9M
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -2304,16 +2304,80 @@ AddPositionCoords(double aCoeff1, const 
    */
   const nsCSSValue& v1 = posArray1->Item(1);
   const nsCSSValue& v2 = posArray2->Item(1);
   nsCSSValue& vr = resultPosArray->Item(1);
   AddCSSValueCanonicalCalc(aCoeff1, v1,
                            aCoeff2, v2, vr);
 }
 
+static UniquePtr<nsCSSValueList>
+AddWeightedShadowList(double aCoeff1, const nsCSSValueList* aShadow1,
+                      double aCoeff2, const nsCSSValueList* aShadow2)
+{
+  // This is implemented according to:
+  // http://dev.w3.org/csswg/css3-transitions/#animation-of-property-types-
+  // and the third item in the summary of:
+  // http://lists.w3.org/Archives/Public/www-style/2009Jul/0050.html
+  UniquePtr<nsCSSValueList> result;
+  nsCSSValueList* tail = nullptr;
+  while (aShadow1 && aShadow2) {
+    UniquePtr<nsCSSValueList> shadowValue =
+      AddWeightedShadowItems(aCoeff1, aShadow1->mValue,
+                             aCoeff2, aShadow2->mValue);
+    if (!shadowValue) {
+      return nullptr;
+    }
+    aShadow1 = aShadow1->mNext;
+    aShadow2 = aShadow2->mNext;
+    // Append the result.
+    if (!tail) {
+      result = Move(shadowValue);
+      tail = result.get();
+    } else {
+      tail->mNext = shadowValue.release();
+      tail = tail->mNext;
+    }
+  }
+  if (aShadow1 || aShadow2) {
+    const nsCSSValueList *longShadow;
+    double longCoeff;
+    if (aShadow1) {
+      longShadow = aShadow1;
+      longCoeff = aCoeff1;
+    } else {
+      longShadow = aShadow2;
+      longCoeff = aCoeff2;
+    }
+
+    while (longShadow) {
+      // Passing coefficients that add to less than 1 produces the
+      // desired result of interpolating "0 0 0 transparent" with
+      // the current shadow.
+      UniquePtr<nsCSSValueList> shadowValue =
+        AddWeightedShadowItems(longCoeff, longShadow->mValue,
+                               0.0, longShadow->mValue);
+      if (!shadowValue) {
+        return nullptr;
+      }
+
+      longShadow = longShadow->mNext;
+      // Append the result.
+      if (!tail) {
+        result = Move(shadowValue);
+        tail = result.get();
+      } else {
+        tail->mNext = shadowValue.release();
+        tail = tail->mNext;
+      }
+    }
+  }
+  return result;
+}
+
 bool
 StyleAnimationValue::AddWeighted(nsCSSProperty aProperty,
                                  double aCoeff1,
                                  const StyleAnimationValue& aValue1,
                                  double aCoeff2,
                                  const StyleAnimationValue& aValue2,
                                  StyleAnimationValue& aResultValue)
 {
@@ -2592,74 +2656,21 @@ StyleAnimationValue::AddWeighted(nsCSSPr
         }
       }
 
       aResultValue.SetAndAdoptCSSValueListValue(result.forget(),
                                                 eUnit_Dasharray);
       return true;
     }
     case eUnit_Shadow: {
-      // This is implemented according to:
-      // http://dev.w3.org/csswg/css3-transitions/#animation-of-property-types-
-      // and the third item in the summary of:
-      // http://lists.w3.org/Archives/Public/www-style/2009Jul/0050.html
-      const nsCSSValueList *shadow1 = aValue1.GetCSSValueListValue();
-      const nsCSSValueList *shadow2 = aValue2.GetCSSValueListValue();
-      UniquePtr<nsCSSValueList> result;
-      nsCSSValueList* tail = nullptr;
-      while (shadow1 && shadow2) {
-        UniquePtr<nsCSSValueList> shadowValue =
-          AddWeightedShadowItems(aCoeff1, shadow1->mValue,
-                                 aCoeff2, shadow2->mValue);
-        if (!shadowValue) {
-          return false;
-        }
-        shadow1 = shadow1->mNext;
-        shadow2 = shadow2->mNext;
-        // Append the result.
-        if (!tail) {
-          result = Move(shadowValue);
-          tail = result.get();
-        } else {
-          tail->mNext = shadowValue.release();
-          tail = tail->mNext;
-        }
-      }
-      if (shadow1 || shadow2) {
-        const nsCSSValueList *longShadow;
-        double longCoeff;
-        if (shadow1) {
-          longShadow = shadow1;
-          longCoeff = aCoeff1;
-        } else {
-          longShadow = shadow2;
-          longCoeff = aCoeff2;
-        }
-
-        while (longShadow) {
-          // Passing coefficients that add to less than 1 produces the
-          // desired result of interpolating "0 0 0 transparent" with
-          // the current shadow.
-          UniquePtr<nsCSSValueList> shadowValue =
-            AddWeightedShadowItems(longCoeff, longShadow->mValue,
-                                   0.0, longShadow->mValue);
-          if (!shadowValue) {
-            return false;
-          }
-
-          longShadow = longShadow->mNext;
-          // Append the result.
-          if (!tail) {
-            result = Move(shadowValue);
-            tail = result.get();
-          } else {
-            tail->mNext = shadowValue.release();
-            tail = tail->mNext;
-          }
-        }
+      UniquePtr<nsCSSValueList> result =
+        AddWeightedShadowList(aCoeff1, aValue1.GetCSSValueListValue(),
+                              aCoeff2, aValue2.GetCSSValueListValue());
+      if (!result) {
+        return false;
       }
       aResultValue.SetAndAdoptCSSValueListValue(result.release(), eUnit_Shadow);
       return true;
     }
     case eUnit_Shape: {
       RefPtr<nsCSSValue::Array> result =
         AddShapeFunction(aProperty,
                          aCoeff1, aValue1.GetCSSValueArrayValue(),