Bug 1246320 part 2 - Pass document to ParseEasing draft
authorBrian Birtles <birtles@gmail.com>
Fri, 11 Mar 2016 17:21:03 +0900
changeset 339653 afa5dc066f473ab18bb6b01461ab0300f0b1f205
parent 339652 51864a04dbcef0205a4173e0c00fc088dc063a53
child 339654 5f7e7aca8414be32c10a0b233a486565a4b99b2a
push id12784
push userbbirtles@mozilla.com
push dateFri, 11 Mar 2016 23:06:50 +0000
bugs1246320
milestone48.0a1
Bug 1246320 part 2 - Pass document to ParseEasing MozReview-Commit-ID: KWW53htO0Jj
dom/animation/AnimationUtils.cpp
dom/animation/AnimationUtils.h
dom/animation/KeyframeEffect.cpp
dom/animation/TimingParams.cpp
--- a/dom/animation/AnimationUtils.cpp
+++ b/dom/animation/AnimationUtils.cpp
@@ -10,18 +10,17 @@
 #include "nsDebug.h"
 #include "nsIAtom.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsGlobalWindow.h"
 #include "nsString.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ComputedTimingFunction.h" // ComputedTimingFunction
-#include "mozilla/dom/Element.h" // For dom::Element
-#include "xpcpublic.h" // For xpc::CurrentWindowOrNull
+#include "xpcpublic.h" // For xpc::NativeGlobal
 
 namespace mozilla {
 
 /* static */ void
 AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage,
                                          const nsIContent* aContent)
 {
   if (aContent) {
@@ -36,32 +35,28 @@ AnimationUtils::LogAsyncAnimationFailure
     }
     aMessage.Append(']');
   }
   aMessage.Append('\n');
   printf_stderr("%s", aMessage.get());
 }
 
 /* static */ Maybe<ComputedTimingFunction>
-AnimationUtils::ParseEasing(const dom::Element* aTarget,
-                            const nsAString& aEasing)
+AnimationUtils::ParseEasing(const nsAString& aEasing,
+                            nsIDocument* aDocument)
 {
-  if (!aTarget) {
-    return Nothing();
-  }
-
-  nsIDocument* doc = aTarget->OwnerDoc();
+  MOZ_ASSERT(aDocument);
 
   nsCSSValue value;
   nsCSSParser parser;
   parser.ParseLonghandProperty(eCSSProperty_animation_timing_function,
                                aEasing,
-                               doc->GetDocumentURI(),
-                               doc->GetDocumentURI(),
-                               doc->NodePrincipal(),
+                               aDocument->GetDocumentURI(),
+                               aDocument->GetDocumentURI(),
+                               aDocument->NodePrincipal(),
                                value);
 
   switch (value.GetUnit()) {
     case eCSSUnit_List: {
       const nsCSSValueList* list = value.GetListValue();
       if (list->mNext) {
         // don't support a list of timing functions
         break;
--- a/dom/animation/AnimationUtils.h
+++ b/dom/animation/AnimationUtils.h
@@ -14,20 +14,16 @@
 class nsIContent;
 class nsIDocument;
 struct JSContext;
 
 namespace mozilla {
 
 class ComputedTimingFunction;
 
-namespace dom {
-class Element;
-}
-
 class AnimationUtils
 {
 public:
   static dom::Nullable<double>
   TimeDurationToDouble(const dom::Nullable<TimeDuration>& aTime)
   {
     dom::Nullable<double> result;
 
@@ -54,17 +50,17 @@ public:
                                        const nsIContent* aContent = nullptr);
 
   /**
    * Parses a CSS <single-transition-timing-function> value from
    * aEasing into a ComputedTimingFunction.  If parsing fails, Nothing() will
    * be returned.
    */
   static Maybe<ComputedTimingFunction>
-  ParseEasing(const dom::Element* aTarget, const nsAString& aEasing);
+  ParseEasing(const nsAString& aEasing, nsIDocument* aDocument);
 
   /**
    * Get the document from the JS context to use when parsing CSS properties.
    */
   static nsIDocument*
   GetCurrentRealmDocument(JSContext* aCx);
 };
 
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -1282,20 +1282,19 @@ GenerateValueEntries(Element* aTarget,
                      ErrorResult& aRv)
 {
   nsCSSPropertySet properties;              // All properties encountered.
   nsCSSPropertySet propertiesWithFromValue; // Those with a defined 0% value.
   nsCSSPropertySet propertiesWithToValue;   // Those with a defined 100% value.
 
   for (OffsetIndexedKeyframe& keyframe : aKeyframes) {
     float offset = float(keyframe.mKeyframeDict.mOffset.Value());
-    // ParseEasing uses element's owner doc, so if it is a pseudo element,
-    // we use its parent element's owner doc.
     Maybe<ComputedTimingFunction> easing =
-      AnimationUtils::ParseEasing(aTarget, keyframe.mKeyframeDict.mEasing);
+      AnimationUtils::ParseEasing(keyframe.mKeyframeDict.mEasing,
+                                  aTarget->OwnerDoc());
     // We ignore keyframe.mKeyframeDict.mComposite since we don't support
     // composite modes on keyframes yet.
 
     // keyframe.mPropertyValuePairs is currently sorted by CSS property IDL
     // name, since that was the order we read the properties from the JS
     // object.  Re-sort the list so that longhand properties appear before
     // shorthands, and with shorthands all appearing in increasing order of
     // number of components.  For two longhand properties, or two shorthands
@@ -1549,20 +1548,18 @@ BuildAnimationPropertyListFromPropertyIn
   // get its explicit dictionary members.
   binding_detail::FastPropertyIndexedKeyframes keyframes;
   if (!keyframes.Init(aCx, aValue, "PropertyIndexedKeyframes argument",
                       false)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
-  // ParseEasing uses element's owner doc, so if it is a pseudo element,
-  // we use its parent element's owner doc.
   Maybe<ComputedTimingFunction> easing =
-    AnimationUtils::ParseEasing(aTarget, keyframes.mEasing);
+    AnimationUtils::ParseEasing(keyframes.mEasing, aTarget->OwnerDoc());
 
   // We ignore easing.mComposite since we don't support composite modes on
   // keyframes yet.
 
   // Get all the property--value-list pairs off the object.
   JS::Rooted<JSObject*> object(aCx, &aValue.toObject());
   nsTArray<PropertyValuesPair> propertyValuesPairs;
   if (!GetPropertyValuesPairs(aCx, object, ListAllowance::eAllow,
--- a/dom/animation/TimingParams.cpp
+++ b/dom/animation/TimingParams.cpp
@@ -72,17 +72,17 @@ TimingParamsFromOptionsUnion(
     result.mDuration = duration;
     result.mDelay = TimeDuration::FromMilliseconds(timing.mDelay);
     result.mEndDelay = TimeDuration::FromMilliseconds(timing.mEndDelay);
     result.mIterations = timing.mIterations;
     result.mIterationStart = timing.mIterationStart;
     result.mDirection = timing.mDirection;
     result.mFill = timing.mFill;
     result.mFunction =
-      AnimationUtils::ParseEasing(targetElement, timing.mEasing);
+      AnimationUtils::ParseEasing(timing.mEasing, targetElement->OwnerDoc());
   }
   return result;
 }
 
 /* static */ TimingParams
 TimingParams::FromOptionsUnion(
   const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
   const Nullable<dom::ElementOrCSSPseudoElement>& aTarget,