Bug 1174575 - Part 4: Support CSSPseudoElement for TimingParams. r=birtles
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 05 Feb 2016 19:11:00 +0100
changeset 283635 b8a9555e8d4db68318dfcccafb49e9db14af4f67
parent 283634 db640b0bb03575bffca6721d204957c4b84b349a
child 283636 989f065259c4318ab6684d876204a4db67e58a46
push id17536
push usercbook@mozilla.com
push dateWed, 10 Feb 2016 13:30:18 +0000
treeherderfx-team@31150215eedf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1174575
milestone47.0a1
Bug 1174575 - Part 4: Support CSSPseudoElement for TimingParams. r=birtles
dom/animation/AnimationEffectTimingReadOnly.cpp
--- a/dom/animation/AnimationEffectTimingReadOnly.cpp
+++ b/dom/animation/AnimationEffectTimingReadOnly.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/AnimationEffectTimingReadOnly.h"
 
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/dom/AnimatableBinding.h"
 #include "mozilla/dom/AnimationEffectTimingReadOnlyBinding.h"
+#include "mozilla/dom/CSSPseudoElement.h"
 #include "mozilla/dom/KeyframeEffectBinding.h"
 
 namespace mozilla {
 
 TimingParams::TimingParams(const dom::AnimationEffectTimingProperties& aRhs,
                            const dom::Element* aTarget)
   : mDuration(aRhs.mDuration)
   , mDelay(TimeDuration::FromMilliseconds(aRhs.mDelay))
@@ -55,23 +56,32 @@ template <class OptionsType>
 static TimingParams
 TimingParamsFromOptionsUnion(
   const OptionsType& aOptions,
   const Nullable<dom::ElementOrCSSPseudoElement>& aTarget)
 {
   if (aOptions.IsUnrestrictedDouble()) {
     return TimingParams(aOptions.GetAsUnrestrictedDouble());
   } else {
-    // FIXME: Bug 1241784: Implement CSSPsuedoElement::Animate() and let
-    // this function handle CSSPseudoElement properly.
-    MOZ_ASSERT(aTarget.IsNull() ||
-               (!aTarget.IsNull() && aTarget.Value().IsElement()),
-               "CSSPseudoElement is not supported here");
-    return TimingParams(GetTimingProperties(aOptions),
-                        &aTarget.Value().GetAsElement());
+    // If aTarget is a pseudo element, we pass its parent element because
+    // TimingParams only needs its owner doc to parse easing and both pseudo
+    // element and its parent element should have the same owner doc.
+    // Bug 1246320: Avoid passing the element for parsing the timing function
+    RefPtr<dom::Element> targetElement;
+    if (!aTarget.IsNull()) {
+      const dom::ElementOrCSSPseudoElement& target = aTarget.Value();
+      MOZ_ASSERT(target.IsElement() || target.IsCSSPseudoElement(),
+                 "Uninitialized target");
+      if (target.IsElement()) {
+        targetElement = &target.GetAsElement();
+      } else {
+        targetElement = target.GetAsCSSPseudoElement().ParentElement();
+      }
+    }
+    return TimingParams(GetTimingProperties(aOptions), targetElement);
   }
 }
 
 /* static */ TimingParams
 TimingParams::FromOptionsUnion(
   const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
   const Nullable<dom::ElementOrCSSPseudoElement>& aTarget)
 {