Bug 1355348 - Factor out method to remove minus sign from property values; r?hiro draft
authorBrian Birtles <birtles@gmail.com>
Wed, 26 Apr 2017 13:00:11 +0900
changeset 569151 4e30878c9fd7ed855faf13a1ddc78fd64aa7f999
parent 569150 54b741e3d664c207718fe4cfdc9907b108daac0d
child 569152 5eafedd33a11c2f19343a2ed7c95258ea351dbd0
push id56073
push userbbirtles@mozilla.com
push dateThu, 27 Apr 2017 02:16:56 +0000
reviewershiro
bugs1355348
milestone55.0a1
Bug 1355348 - Factor out method to remove minus sign from property values; r?hiro This is just a minor refactoring to simplify ValueFromStringHelper before we refactor it further in the next patch (and so we can re-use this definition to produce debug warning for Servo since we don't handle negative values there yet). MozReview-Commit-ID: CfcnI2Be5di
dom/smil/nsSMILCSSValueType.cpp
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -331,49 +331,61 @@ GetPresContextForElement(Element* aElem)
     // and remove anonymous animated content from the document as a result.
     // See bug 534975.
     return nullptr;
   }
   nsIPresShell* shell = doc->GetShell();
   return shell ? shell->GetPresContext() : nullptr;
 }
 
+static const nsDependentSubstring
+GetNonNegativePropValue(const nsAString& aString, nsCSSPropertyID aPropID,
+                        bool& aIsNegative)
+{
+  // If value is negative, we'll strip off the "-" so the CSS parser won't
+  // barf, and then manually make the parsed value negative.
+  // (This is a partial solution to let us accept some otherwise out-of-bounds
+  // CSS values. Bug 501188 will provide a more complete fix.)
+  aIsNegative = false;
+  uint32_t subStringBegin = 0;
+
+  // NOTE: We need to opt-out 'stroke-dasharray' from the negative-number
+  // check.  Its values might look negative (e.g. by starting with "-1"), but
+  // they're more complicated than our simple negation logic here can handle.
+  if (aPropID != eCSSProperty_stroke_dasharray) {
+    int32_t absValuePos = nsSMILParserUtils::CheckForNegativeNumber(aString);
+    if (absValuePos > 0) {
+      aIsNegative = true;
+      subStringBegin = (uint32_t)absValuePos; // Start parsing after '-' sign
+    }
+  }
+
+  return Substring(aString, subStringBegin);
+}
+
 // Helper function to parse a string into a StyleAnimationValue
 static bool
 ValueFromStringHelper(nsCSSPropertyID aPropID,
                       Element* aTargetElement,
                       nsPresContext* aPresContext,
                       const nsAString& aString,
                       StyleAnimationValue& aStyleAnimValue,
                       bool* aIsContextSensitive)
 {
-  // If value is negative, we'll strip off the "-" so the CSS parser won't
-  // barf, and then manually make the parsed value negative.
-  // (This is a partial solution to let us accept some otherwise out-of-bounds
-  // CSS values. Bug 501188 will provide a more complete fix.)
-  bool isNegative = false;
-  uint32_t subStringBegin = 0;
-
-  // NOTE: We need to opt-out 'stroke-dasharray' from the negative-number
-  // check.  Its values might look negative (e.g. by starting with "-1"), but
-  // they're more complicated than our simple negation logic here can handle.
-  if (aPropID != eCSSProperty_stroke_dasharray) {
-    int32_t absValuePos = nsSMILParserUtils::CheckForNegativeNumber(aString);
-    if (absValuePos > 0) {
-      isNegative = true;
-      subStringBegin = (uint32_t)absValuePos; // Start parsing after '-' sign
-    }
-  }
   RefPtr<nsStyleContext> styleContext =
     nsComputedDOMStyle::GetStyleContext(aTargetElement, nullptr,
                                         aPresContext->PresShell());
   if (!styleContext) {
     return false;
   }
-  nsDependentSubstring subString(aString, subStringBegin);
+
+  bool isNegative = false;
+  const nsDependentSubstring subString =
+    GetNonNegativePropValue(aString, aPropID, isNegative);
+
   if (!StyleAnimationValue::ComputeValue(aPropID, aTargetElement, styleContext,
                                          subString, true, aStyleAnimValue,
                                          aIsContextSensitive)) {
     return false;
   }
   if (isNegative) {
     InvertSign(aStyleAnimValue);
   }