Bug 1315874 - Add a method to nsSMILCSSValueType that takes a StyleAnimationValue; r=dholbert
authorBrian Birtles <birtles@gmail.com>
Thu, 30 Mar 2017 16:53:15 +0900
changeset 351511 1f233c0466f62f140f03b68fca7714f216baa63b
parent 351510 09d2b2c67b7fe274ab094d7b623ec19e544959b1
child 351512 cf852fc7100f938b0e3038d86acf04544065445a
push id31611
push usercbook@mozilla.com
push dateThu, 06 Apr 2017 10:51:05 +0000
treeherdermozilla-central@950612071c4e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1315874
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/smil/nsSMILCSSValueType.cpp
dom/smil/nsSMILCSSValueType.h
--- 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.