Bug 1450526 - Part 2: Expose the generated pseudo element itself in KeyframeEffect. r?birtles draft
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 15 May 2018 13:18:31 +0900
changeset 795155 a7395d4dc3f5bbb07da8912823bc13980ce1fdf9
parent 795154 f8501564d18828ce33a32c27bcfda721175a2883
child 795156 9e66ca4b2ecd4065e827e49a052170a8ee851423
push id109876
push userbmo:dakatsuka@mozilla.com
push dateTue, 15 May 2018 04:33:34 +0000
reviewersbirtles
bugs1450526
milestone62.0a1
Bug 1450526 - Part 2: Expose the generated pseudo element itself in KeyframeEffect. r?birtles The animation inspector so far, retrieved the pseudo element which is actually displaying not CSSPseudoElement using DocumentWalker[1], kept the reference, had used that. However, if the pseudo element was re-generated, the reference will be invalid. So as to resolve this, though retrieve the pseudo element if needed, using DocumentWalker takes high cost. Therefor, add a method which get pseudo element directly into KeyframeEfect, use this instead. [1] https://searchfox.org/mozilla-central/source/devtools/server/actors/inspector/document-walker.js MozReview-Commit-ID: oj8UEmkICB
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
dom/webidl/KeyframeEffect.webidl
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -955,16 +955,35 @@ KeyframeEffect::SetTarget(const Nullable
 
     nsAutoAnimationMutationBatch mb(mTarget->mElement->OwnerDoc());
     if (mAnimation) {
       nsNodeUtils::AnimationAdded(mAnimation);
     }
   }
 }
 
+Element*
+KeyframeEffect::GetPseudoTarget() const
+{
+  if (!mTarget) {
+    return nullptr;
+  }
+  switch (mTarget->mPseudoType) {
+    case CSSPseudoElementType::before:
+      return nsLayoutUtils::GetBeforePseudo(mTarget->mElement);
+    case CSSPseudoElementType::after:
+      return nsLayoutUtils::GetAfterPseudo(mTarget->mElement);
+    case CSSPseudoElementType::NotPseudo:
+      return nullptr;
+    default:
+      NS_NOTREACHED("Animation of unsupported pseudo-type");
+      return nullptr;
+  }
+}
+
 static void
 CreatePropertyValue(nsCSSPropertyID aProperty,
                     float aOffset,
                     const Maybe<ComputedTimingFunction>& aTimingFunction,
                     const AnimationValue& aValue,
                     dom::CompositeOperation aComposite,
                     AnimationPropertyValueDetails& aResult)
 {
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -163,16 +163,18 @@ public:
   }
   // This method calls GetTargetComputedStyle which is not safe to use when
   // we are in the middle of updating style. If we need to use this when
   // updating style, we should pass the ComputedStyle into this method and use
   // that to update the properties rather than calling
   // GetComputedStyle.
   void SetTarget(const Nullable<ElementOrCSSPseudoElement>& aTarget);
 
+  Element* GetPseudoTarget() const;
+
   void GetKeyframes(JSContext*& aCx,
                     nsTArray<JSObject*>& aResult,
                     ErrorResult& aRv);
   void GetProperties(nsTArray<AnimationPropertyDetails>& aProperties,
                      ErrorResult& aRv) const;
 
   // aCallerType is not used in the getter so we supply a default value so that
   // internal users don't need to specify this value.
--- a/dom/webidl/KeyframeEffect.webidl
+++ b/dom/webidl/KeyframeEffect.webidl
@@ -49,9 +49,10 @@ dictionary AnimationPropertyDetails {
   required DOMString                               property;
   required boolean                                 runningOnCompositor;
            DOMString                               warning;
   required sequence<AnimationPropertyValueDetails> values;
 };
 
 partial interface KeyframeEffect {
   [ChromeOnly, Throws] sequence<AnimationPropertyDetails> getProperties();
+  [ChromeOnly] readonly attribute Element? pseudoTarget;
 };