Bug 1216843 - Part 10: Implement box-shadow/text-shadow color accumulation. r?dholbert draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Mon, 12 Sep 2016 14:34:28 +0900
changeset 412523 193383caab19f3360260f440cccf38d7930e282f
parent 412522 318a219764d02abb08cb2c607cf984ec4efa2007
child 412524 22a7cb11611d4717f9326b3c74babaffbc058b3c
push id29192
push userbmo:hiikezoe@mozilla-japan.org
push dateMon, 12 Sep 2016 05:39:50 +0000
reviewersdholbert
bugs1216843
milestone51.0a1
Bug 1216843 - Part 10: Implement box-shadow/text-shadow color accumulation. r?dholbert MozReview-Commit-ID: CkKOaDN6SPo
layout/style/StyleAnimationValue.cpp
testing/web-platform/meta/web-animations/interfaces/KeyframeEffect/iterationComposite.html.ini
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -1290,17 +1290,18 @@ AppendToCSSValueList(UniquePtr<nsCSSValu
     *aTail = aHead.get();
   } else {
     (*aTail) = (*aTail)->mNext = aValueToAppend.release();
   }
 }
 
 static UniquePtr<nsCSSValueList>
 AddWeightedShadowItems(double aCoeff1, const nsCSSValue &aValue1,
-                       double aCoeff2, const nsCSSValue &aValue2)
+                       double aCoeff2, const nsCSSValue &aValue2,
+                       ColorAdditionType aColorAdditionType)
 {
   // X, Y, Radius, Spread, Color, Inset
   MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Array,
              "wrong unit");
   MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Array,
              "wrong unit");
   nsCSSValue::Array *array1 = aValue1.GetArrayValue();
   nsCSSValue::Array *array2 = aValue2.GetArrayValue();
@@ -1327,17 +1328,17 @@ AddWeightedShadowItems(double aCoeff1, c
     return nullptr;
   }
 
   if (color1.GetUnit() != eCSSUnit_Null) {
     if (aCoeff2 == 0.0 && aCoeff1 != 1.0) {
       DiluteColor(color1, aCoeff1, resultArray->Item(4));
     } else {
       AddWeightedColors(aCoeff1, color1, aCoeff2, color2,
-                        ColorAdditionType::Clamped,
+                        aColorAdditionType,
                         resultArray->Item(4));
     }
   }
 
   MOZ_ASSERT(inset1 == inset2, "should match");
   resultArray->Item(5) = inset1;
 
   auto resultItem = MakeUnique<nsCSSValueList>();
@@ -1870,18 +1871,21 @@ AddFilterFunctionImpl(double aCoeff1, co
                        aCoeff2, funcArg2,
                        resultArg);
       break;
     case eCSSKeyword_drop_shadow: {
       MOZ_ASSERT(!funcArg1.GetListValue()->mNext &&
                  !funcArg2.GetListValue()->mNext,
                  "drop-shadow filter func doesn't support lists");
       UniquePtr<nsCSSValueList> shadowValue =
-        AddWeightedShadowItems(aCoeff1, funcArg1.GetListValue()->mValue,
-                               aCoeff2, funcArg2.GetListValue()->mValue);
+        AddWeightedShadowItems(aCoeff1,
+                               funcArg1.GetListValue()->mValue,
+                               aCoeff2,
+                               funcArg2.GetListValue()->mValue,
+                               ColorAdditionType::Clamped);
       if (!shadowValue) {
         return false;
       }
       resultArg.AdoptListValue(Move(shadowValue));
       break;
     }
     default:
       MOZ_ASSERT(false, "unknown filter function");
@@ -2367,29 +2371,33 @@ 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)
+AddWeightedShadowList(double aCoeff1,
+                      const nsCSSValueList* aShadow1,
+                      double aCoeff2,
+                      const nsCSSValueList* aShadow2,
+                      ColorAdditionType aColorAdditionType)
 {
   // 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);
+                             aCoeff2, aShadow2->mValue,
+                             aColorAdditionType);
     if (!shadowValue) {
       return nullptr;
     }
     aShadow1 = aShadow1->mNext;
     aShadow2 = aShadow2->mNext;
     AppendToCSSValueList(result, Move(shadowValue), &tail);
   }
   if (aShadow1 || aShadow2) {
@@ -2404,17 +2412,18 @@ AddWeightedShadowList(double aCoeff1, co
     }
 
     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);
+                               0.0, longShadow->mValue,
+                               aColorAdditionType);
       if (!shadowValue) {
         return nullptr;
       }
 
       longShadow = longShadow->mNext;
       AppendToCSSValueList(result, Move(shadowValue), &tail);
     }
   }
@@ -2715,18 +2724,21 @@ StyleAnimationValue::AddWeighted(nsCSSPr
       }
 
       aResultValue.SetAndAdoptCSSValueListValue(result.forget(),
                                                 eUnit_Dasharray);
       return true;
     }
     case eUnit_Shadow: {
       UniquePtr<nsCSSValueList> result =
-        AddWeightedShadowList(aCoeff1, aValue1.GetCSSValueListValue(),
-                              aCoeff2, aValue2.GetCSSValueListValue());
+        AddWeightedShadowList(aCoeff1,
+                              aValue1.GetCSSValueListValue(),
+                              aCoeff2,
+                              aValue2.GetCSSValueListValue(),
+                              ColorAdditionType::Clamped);
       if (!result) {
         return false;
       }
       aResultValue.SetAndAdoptCSSValueListValue(result.release(), eUnit_Shadow);
       return true;
     }
     case eUnit_Shape: {
       RefPtr<nsCSSValue::Array> result =
@@ -2886,18 +2898,28 @@ StyleAnimationValue::Accumulate(nsCSSPro
                                 StyleAnimationValue& aDest,
                                 const StyleAnimationValue& aValueToAccumulate,
                                 uint64_t aCount)
 {
   Unit commonUnit =
     GetCommonUnit(aProperty, aDest.GetUnit(), aValueToAccumulate.GetUnit());
   switch (commonUnit) {
     // FIXME: implement them!
-    //case eUnit_Shadow:
     //case eUnit_Filter:
+    case eUnit_Shadow: {
+      UniquePtr<nsCSSValueList> result =
+        AddWeightedShadowList(1.0, aDest.GetCSSValueListValue(),
+                              aCount, aValueToAccumulate.GetCSSValueListValue(),
+                              ColorAdditionType::Unclamped);
+      if (!result) {
+        return false;
+      }
+      aDest.SetAndAdoptCSSValueListValue(result.release(), eUnit_Shadow);
+      return true;
+    }
     case eUnit_Color: {
       auto resultColor = MakeUnique<nsCSSValue>();
       AddWeightedColors(1.0,
                         *aDest.GetCSSValueValue(),
                         aCount,
                         *aValueToAccumulate.GetCSSValueValue(),
                         ColorAdditionType::Unclamped,
                         *resultColor);
--- a/testing/web-platform/meta/web-animations/interfaces/KeyframeEffect/iterationComposite.html.ini
+++ b/testing/web-platform/meta/web-animations/interfaces/KeyframeEffect/iterationComposite.html.ini
@@ -1,8 +1,5 @@
 [iterationComposite.html]
   type: testharness
   [iterationComposite of filter drop-shadow animation]
     expected: FAIL
 
-  [iterationComposite of box-shadow animation]
-    expected: FAIL
-