Bug 1315874 - Add a method to nsSMILCSSValueType that takes a StyleAnimationValue; r?dholbert
In a subsequent patch we will extract a StyleAnimationValue from an
nsStyleContext. Rather than serializing it and then re-parsing it into
a StyleAnimationValue, this patch adds a method to directly accept
a StyleAnimationValue since that is what nsSMILCSSValueType stores internally
anyway.
MozReview-Commit-ID: KBaLYAzAlWZ
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -413,16 +413,44 @@ nsSMILCSSValueType::ValueFromString(nsCS
if (ValueFromStringHelper(aPropID, aTargetElement, presContext,
aString, parsedValue, aIsContextSensitive)) {
sSingleton.Init(aValue);
aValue.mU.mPtr = new ValueWrapper(aPropID, parsedValue);
}
}
// static
+nsSMILValue
+nsSMILCSSValueType::ValueFromAnimationValue(nsCSSPropertyID aPropID,
+ Element* aTargetElement,
+ const StyleAnimationValue& aValue)
+{
+ nsSMILValue result;
+
+ nsIDocument* doc = aTargetElement->GetUncomposedDoc();
+ // We'd like to avoid serializing |aValue| if possible, and since the
+ // string passed to CSPAllowsInlineStyle is only used for reporting violations
+ // and an intermediate CSS value is not likely to be particularly useful
+ // in that case, we just use a generic placeholder string instead.
+ static const nsLiteralString kPlaceholderText =
+ NS_LITERAL_STRING("[SVG animation of CSS]");
+ if (doc && !nsStyleUtil::CSPAllowsInlineStyle(nullptr,
+ doc->NodePrincipal(),
+ doc->GetDocumentURI(),
+ 0, kPlaceholderText, nullptr)) {
+ return result;
+ }
+
+ sSingleton.Init(result);
+ result.mU.mPtr = new ValueWrapper(aPropID, aValue);
+
+ return result;
+}
+
+// static
bool
nsSMILCSSValueType::ValueToString(const nsSMILValue& aValue,
nsAString& aString)
{
MOZ_ASSERT(aValue.mType == &nsSMILCSSValueType::sSingleton,
"Unexpected SMIL value type");
const ValueWrapper* wrapper = ExtractValueWrapper(aValue);
return !wrapper ||
--- a/dom/smil/nsSMILCSSValueType.h
+++ b/dom/smil/nsSMILCSSValueType.h
@@ -11,28 +11,30 @@
#include "nsISMILType.h"
#include "nsCSSPropertyID.h"
#include "mozilla/Attributes.h"
class nsAString;
namespace mozilla {
+class StyleAnimationValue;
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
/*
* nsSMILCSSValueType: Represents a SMIL-animated CSS value.
*/
class nsSMILCSSValueType : public nsISMILType
{
public:
typedef mozilla::dom::Element Element;
+ typedef mozilla::StyleAnimationValue StyleAnimationValue;
// Singleton for nsSMILValue objects to hold onto.
static nsSMILCSSValueType sSingleton;
protected:
// nsISMILType Methods
// -------------------
virtual void Init(nsSMILValue& aValue) const override;
@@ -80,16 +82,31 @@ public:
*/
static void ValueFromString(nsCSSPropertyID aPropID,
Element* aTargetElement,
const nsAString& aString,
nsSMILValue& aValue,
bool* aIsContextSensitive);
/**
+ * Creates an nsSMILValue to wrap the given animation value.
+ *
+ * @param aPropID The property that |aValue| corresponds to.
+ * @param aTargetElement The target element to which the animation value
+ * applies.
+ * @param aValue The animation value to use.
+ * @return A new nsSMILValue. On failure, returns an
+ * nsSMILValue with the null type (i.e. rv.IsNull()
+ * returns true).
+ */
+ static nsSMILValue ValueFromAnimationValue(nsCSSPropertyID aPropID,
+ Element* aTargetElement,
+ const StyleAnimationValue& aValue);
+
+ /**
* Creates a string representation of the given nsSMILValue.
*
* Note: aValue is expected to be of this type (that is, it's expected to
* have been initialized by nsSMILCSSValueType::sSingleton). If aValue is a
* freshly-initialized value, this method will succeed, though the resulting
* string will be empty.
*
* @param aValue The nsSMILValue to be converted into a string.