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
--- 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;
};