Bug 1346052 - Part 1: Factor out ParseProperty.
We can reuse ParseProperty in nsDOMWindowUtils::ComputeAnimationDistance(),
so factor out this function.
MozReview-Commit-ID: FdXGPxOZf84
--- 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