Bug 1216843 - Part 9: Factor out AddWeightedShadowList. r?dholbert draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Mon, 12 Sep 2016 14:34:28 +0900
changeset 412522 318a219764d02abb08cb2c607cf984ec4efa2007
parent 412521 162147b9270f422cff4522d1680b830119c4852c
child 412523 193383caab19f3360260f440cccf38d7930e282f
push id29192
push userbmo:hiikezoe@mozilla-japan.org
push dateMon, 12 Sep 2016 05:39:50 +0000
reviewersdholbert
bugs1216843
milestone51.0a1
Bug 1216843 - Part 9: Factor out AddWeightedShadowList. r?dholbert MozReview-Commit-ID: Fm6RDSUwYpU
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -2366,16 +2366,66 @@ 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;
+    AppendToCSSValueList(result, Move(shadowValue), &tail);
+  }
+  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;
+      AppendToCSSValueList(result, Move(shadowValue), &tail);
+    }
+  }
+  return result;
+}
+
 bool
 StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty,
                                  double aCoeff1,
                                  const StyleAnimationValue& aValue1,
                                  double aCoeff2,
                                  const StyleAnimationValue& aValue2,
                                  StyleAnimationValue& aResultValue)
 {
@@ -2664,60 +2714,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;
-        AppendToCSSValueList(result, Move(shadowValue), &tail);
-      }
-      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;
-          AppendToCSSValueList(result, Move(shadowValue), &tail);
-        }
+      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(),