Bug 1346052 - Part 1: Factor out ParseProperty. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 24 Mar 2017 17:35:27 +0800
changeset 571664 f5cea33ade2b6ffe3619fdc2cea9646a43d154c1
parent 571663 98386af3aa2f84b709ec92bfae56456715f8a724
child 571665 49703a8e4b790fb0b8929bf6a02efab874767d9e
push id56881
push userbmo:boris.chiou@gmail.com
push dateWed, 03 May 2017 03:53:29 +0000
bugs1346052
milestone55.0a1
Bug 1346052 - Part 1: Factor out ParseProperty. We can reuse ParseProperty in nsDOMWindowUtils::ComputeAnimationDistance(), so factor out this function. MozReview-Commit-ID: FdXGPxOZf84
dom/animation/KeyframeUtils.cpp
dom/animation/KeyframeUtils.h
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -725,16 +725,31 @@ KeyframeUtils::IsAnimatableProperty(nsCS
     if (nsCSSProps::kAnimTypeTable[*subprop] != eStyleAnimType_None) {
       return true;
     }
   }
 
   return false;
 }
 
+/* static */ already_AddRefed<RawServoDeclarationBlock>
+KeyframeUtils::ParseProperty(nsCSSPropertyID aProperty,
+                             const nsAString& aValue,
+                             nsIDocument* aDocument)
+{
+  MOZ_ASSERT(aDocument);
+
+  NS_ConvertUTF16toUTF8 value(aValue);
+  // FIXME this is using the wrong base uri (bug 1343919)
+  RefPtr<URLExtraData> data = new URLExtraData(aDocument->GetDocumentURI(),
+                                               aDocument->GetDocumentURI(),
+                                               aDocument->NodePrincipal());
+  return Servo_ParseProperty(aProperty, &value, data).Consume();
+}
+
 // ------------------------------------------------------------------
 //
 // Internal helpers
 //
 // ------------------------------------------------------------------
 
 /**
  * Converts a JS object to an IDL sequence<Keyframe>.
@@ -1010,25 +1025,18 @@ MakePropertyValuePair(nsCSSPropertyID aP
                       nsCSSParser& aParser, nsIDocument* aDocument)
 {
   MOZ_ASSERT(aDocument);
   PropertyValuePair result;
 
   result.mProperty = aProperty;
 
   if (aDocument->GetStyleBackendType() == StyleBackendType::Servo) {
-    NS_ConvertUTF16toUTF8 value(aStringValue);
-
-    // FIXME this is using the wrong base uri (bug 1343919)
-    RefPtr<URLExtraData> data = new URLExtraData(aDocument->GetDocumentURI(),
-                                                 aDocument->GetDocumentURI(),
-                                                 aDocument->NodePrincipal());
-
     RefPtr<RawServoDeclarationBlock> servoDeclarationBlock =
-      Servo_ParseProperty(aProperty, &value, data).Consume();
+      KeyframeUtils::ParseProperty(aProperty, aStringValue, aDocument);
 
     if (servoDeclarationBlock) {
       result.mServoDeclarationBlock = servoDeclarationBlock.forget();
     }
     return result;
   }
 
   nsCSSValue value;
--- a/dom/animation/KeyframeUtils.h
+++ b/dom/animation/KeyframeUtils.h
@@ -11,16 +11,17 @@
 #include "js/RootingAPI.h" // For JS::Handle
 #include "mozilla/KeyframeEffectParams.h" // SpacingMode
 
 struct JSContext;
 class JSObject;
 class nsIDocument;
 class nsStyleContext;
 struct ServoComputedValues;
+struct RawServoDeclarationBlock;
 
 namespace mozilla {
 struct AnimationProperty;
 enum class CSSPseudoElementType : uint8_t;
 class ErrorResult;
 struct Keyframe;
 struct PropertyStyleAnimationValuePair;
 struct ServoComputedValuesWithParent;
@@ -156,13 +157,29 @@ public:
   /**
    * Check if the property or, for shorthands, one or more of
    * its subproperties, is animatable.
    *
    * @param aProperty The property to check.
    * @return true if |aProperty| is animatable.
    */
   static bool IsAnimatableProperty(nsCSSPropertyID aProperty);
+
+  /**
+   * Parse a string representing a CSS property value into a
+   * RawServoDeclarationBlock.
+   *
+   * @param aProperty The property to be parsed.
+   * @param aValue The specified value.
+   * @param aDocument The current document.
+   * @return The parsed value as a RawServoDeclarationBlock. We put the value
+   *   in a declaration block since that is how we represent specified values
+   *   in Servo.
+   */
+  static already_AddRefed<RawServoDeclarationBlock> ParseProperty(
+    nsCSSPropertyID aProperty,
+    const nsAString& aValue,
+    nsIDocument* aDocument);
 };
 
 } // namespace mozilla
 
 #endif // mozilla_KeyframeUtils_h