Bug 1289049 Part 2 - Extract a helper function ExtractComputedValueFromShapeSource(). draft
authorTing-Yu Lin <tlin@mozilla.com>
Tue, 19 Sep 2017 17:20:14 +0800
changeset 667507 721ad98c70d8c29a31717088ec2cd11184a3f683
parent 667506 7f524ba25d035b5c3e0252467f1eee2601dd0bc9
child 667508 9fbda6227187fdd4fe11f562d483ad37c500dfb6
push id80736
push userbmo:tlin@mozilla.com
push dateWed, 20 Sep 2017 06:30:49 +0000
bugs1289049
milestone57.0a1
Bug 1289049 Part 2 - Extract a helper function ExtractComputedValueFromShapeSource(). MozReview-Commit-ID: IhHaKhQTWbo
layout/style/StyleAnimationValue.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -4235,16 +4235,45 @@ StyleShapeSourceToCSSArray(const StyleSh
     default:
       MOZ_ASSERT_UNREACHABLE("Unknown shape type");
       return false;
   }
   aResult->Item(1).SetEnumValue(aShapeSource.GetReferenceBox());
   return true;
 }
 
+static bool
+ExtractComputedValueFromShapeSource(const StyleShapeSource& aShapeSource,
+                                    StyleAnimationValue& aComputedValue)
+{
+  const StyleShapeSourceType type = aShapeSource.GetType();
+
+  if (type == StyleShapeSourceType::URL) {
+    auto result = MakeUnique<nsCSSValue>();
+    result->SetURLValue(aShapeSource.GetURL());
+    aComputedValue.SetAndAdoptCSSValueValue(result.release(),
+                                            StyleAnimationValue::eUnit_URL);
+  } else if (type == StyleShapeSourceType::Box) {
+    aComputedValue.SetEnumValue(aShapeSource.GetReferenceBox());
+  } else if (type == StyleShapeSourceType::Shape) {
+    RefPtr<nsCSSValue::Array> result = nsCSSValue::Array::Create(2);
+    if (!StyleShapeSourceToCSSArray(aShapeSource, result)) {
+      return false;
+    }
+    aComputedValue.SetCSSValueArrayValue(result,
+                                         StyleAnimationValue::eUnit_Shape);
+
+  } else {
+    MOZ_ASSERT(type == StyleShapeSourceType::None, "unknown type");
+    aComputedValue.SetNoneValue();
+  }
+
+  return true;
+}
+
 static void
 SetFallbackValue(nsCSSValuePair* aPair, const nsStyleSVGPaint& aPaint)
 {
   if (aPaint.GetFallbackType() == eStyleSVGFallbackType_Color) {
     aPair->mYValue.SetColorValue(aPaint.GetFallbackColor());
   } else {
     aPair->mYValue.SetNoneValue();
   }
@@ -4544,35 +4573,19 @@ StyleAnimationValue::ExtractComputedValu
           ExtractImageLayerSizePairList(layers, aComputedValue);
           break;
         }
 #endif
 
         case eCSSProperty_clip_path: {
           const nsStyleSVGReset* svgReset =
             static_cast<const nsStyleSVGReset*>(styleStruct);
-          const StyleShapeSource& clipPath = svgReset->mClipPath;
-          const StyleShapeSourceType type = clipPath.GetType();
-
-          if (type == StyleShapeSourceType::URL) {
-            auto result = MakeUnique<nsCSSValue>();
-            result->SetURLValue(clipPath.GetURL());
-            aComputedValue.SetAndAdoptCSSValueValue(result.release(), eUnit_URL);
-          } else if (type == StyleShapeSourceType::Box) {
-            aComputedValue.SetEnumValue(clipPath.GetReferenceBox());
-          } else if (type == StyleShapeSourceType::Shape) {
-            RefPtr<nsCSSValue::Array> result = nsCSSValue::Array::Create(2);
-            if (!StyleShapeSourceToCSSArray(clipPath, result)) {
-              return false;
-            }
-            aComputedValue.SetCSSValueArrayValue(result, eUnit_Shape);
-
-          } else {
-            MOZ_ASSERT(type == StyleShapeSourceType::None, "unknown type");
-            aComputedValue.SetNoneValue();
+          if (!ExtractComputedValueFromShapeSource(svgReset->mClipPath,
+                                                   aComputedValue)) {
+            return false;
           }
           break;
         }
 
         case eCSSProperty_filter: {
           const nsStyleEffects* effects =
             static_cast<const nsStyleEffects*>(styleStruct);
           const nsTArray<nsStyleFilter>& filters = effects->mFilters;