Bug 1610981 - Eliminate usage of CSSPseudoElement from KeyframeEffect. r=birtles,smaug

Replace ElementOrCSSPseudoElement with Element and add PseudoElement (which is
a DOMString) into KeyframeAnimationOptions and KeyframeEffect.

Differential Revision: https://phabricator.services.mozilla.com/D62667
This commit is contained in:
Boris Chiou committed 2020-02-18 20:44:14 +00:00
1 parent 1b91bf4b41
commit 1377970ec8
31 files changed
+242 -315

No files matched your search

+6 -4
View File
@@ -110,7 +110,7 @@ var AnimationPlayerActor = protocol.ActorClassWithSpec(animationPlayerSpec, {
},
get isPseudoElement() {
return !!this.player.effect.target.element;
return !!this.player.effect.pseudoElement;
},
get node() {
@@ -118,9 +118,11 @@ var AnimationPlayerActor = protocol.ActorClassWithSpec(animationPlayerSpec, {
return this.player.effect.target;
}
const pseudo = this.player.effect.target;
const treeWalker = this.walker.getDocumentWalker(pseudo.element);
return pseudo.type === "::before"
const originatingElem = this.player.effect.target;
const treeWalker = this.walker.getDocumentWalker(originatingElem);
// FIXME: Bug 1615473: It's possible to use ::before, ::after, ::marker,
// ::first-line, or ::first-letter pseudo selector.
return this.player.effect.pseudoElement === "::before"
? treeWalker.firstChild()
: treeWalker.lastChild();
},
+23 -21
View File
@@ -62,13 +62,13 @@ class MOZ_RAII AutoMutationBatchForAnimation {
explicit AutoMutationBatchForAnimation(
const Animation& aAnimation MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
Maybe<NonOwningAnimationTarget> target = aAnimation.GetTargetForAnimation();
NonOwningAnimationTarget target = aAnimation.GetTargetForAnimation();
if (!target) {
return;
}
// For mutation observers, we use the OwnerDoc.
mAutoBatch.emplace(target->mElement->OwnerDoc());
mAutoBatch.emplace(target.mElement->OwnerDoc());
}
private:
@@ -83,12 +83,13 @@ class MOZ_RAII AutoMutationBatchForAnimation {
//
// ---------------------------------------------------------------------------
Maybe<NonOwningAnimationTarget> Animation::GetTargetForAnimation() const {
NonOwningAnimationTarget Animation::GetTargetForAnimation() const {
AnimationEffect* effect = GetEffect();
NonOwningAnimationTarget target;
if (!effect || !effect->AsKeyframeEffect()) {
return Nothing();
return target;
}
return effect->AsKeyframeEffect()->GetTarget();
return effect->AsKeyframeEffect()->GetAnimationTarget();
}
/* static */
@@ -641,18 +642,18 @@ void Animation::CommitStyles(ErrorResult& aRv) {
return;
}
Maybe<NonOwningAnimationTarget> target = keyframeEffect->GetTarget();
NonOwningAnimationTarget target = keyframeEffect->GetAnimationTarget();
if (!target) {
return;
}
if (target->mPseudoType != PseudoStyleType::NotPseudo) {
if (target.mPseudoType != PseudoStyleType::NotPseudo) {
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
return;
}
// Check it is an element with a style attribute
nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(target->mElement);
nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(target.mElement);
if (!styledElement) {
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
return;
@@ -660,16 +661,16 @@ void Animation::CommitStyles(ErrorResult& aRv) {
// Flush style before checking if the target element is rendered since the
// result could depend on pending style changes.
if (Document* doc = target->mElement->GetComposedDoc()) {
if (Document* doc = target.mElement->GetComposedDoc()) {
doc->FlushPendingNotifications(FlushType::Style);
}
if (!target->mElement->IsRendered()) {
if (!target.mElement->IsRendered()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsPresContext* presContext =
nsContentUtils::GetContextForContent(target->mElement);
nsContentUtils::GetContextForContent(target.mElement);
if (!presContext) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
@@ -688,11 +689,11 @@ void Animation::CommitStyles(ErrorResult& aRv) {
// Start the update now so that the old rule doesn't get used
// between when we mutate the declaration and when we set the new
// rule.
mozAutoDocUpdate autoUpdate(target->mElement->OwnerDoc(), true);
mozAutoDocUpdate autoUpdate(target.mElement->OwnerDoc(), true);
// Get the inline style to append to
RefPtr<DeclarationBlock> declarationBlock;
if (auto* existing = target->mElement->GetInlineStyleDeclaration()) {
if (auto* existing = target.mElement->GetInlineStyleDeclaration()) {
declarationBlock = existing->EnsureMutable();
} else {
declarationBlock = new DeclarationBlock();
@@ -702,7 +703,7 @@ void Animation::CommitStyles(ErrorResult& aRv) {
// Prepare the callback
MutationClosureData closureData;
closureData.mClosure = nsDOMCSSAttributeDeclaration::MutationClosureFunction;
closureData.mElement = target->mElement;
closureData.mElement = target.mElement;
DeclarationBlockMutationClosure beforeChangeClosure = {
nsDOMCSSAttributeDeclaration::MutationClosureFunction,
&closureData,
@@ -726,7 +727,7 @@ void Animation::CommitStyles(ErrorResult& aRv) {
}
// Update inline style declaration
target->mElement->SetInlineStyleDeclaration(*declarationBlock, closureData);
target.mElement->SetInlineStyleDeclaration(*declarationBlock, closureData);
}
// ---------------------------------------------------------------------------
@@ -1052,7 +1053,7 @@ bool Animation::IsReplaceable() const {
// We should only replace animations with a target element (since otherwise
// what other effects would we consider when determining if they are covered
// or not?).
if (!GetEffect()->AsKeyframeEffect()->GetTarget()) {
if (!GetEffect()->AsKeyframeEffect()->GetAnimationTarget()) {
return false;
}
@@ -1071,15 +1072,16 @@ void Animation::ScheduleReplacementCheck() {
// If IsReplaceable() is true, the following should also hold
MOZ_ASSERT(GetEffect());
MOZ_ASSERT(GetEffect()->AsKeyframeEffect());
MOZ_ASSERT(GetEffect()->AsKeyframeEffect()->GetTarget());
Maybe<NonOwningAnimationTarget> target =
GetEffect()->AsKeyframeEffect()->GetTarget();
NonOwningAnimationTarget target =
GetEffect()->AsKeyframeEffect()->GetAnimationTarget();
MOZ_ASSERT(target);
nsPresContext* presContext =
nsContentUtils::GetContextForContent(target->mElement);
nsContentUtils::GetContextForContent(target.mElement);
if (presContext) {
presContext->EffectCompositor()->NoteElementForReducing(*target);
presContext->EffectCompositor()->NoteElementForReducing(target);
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ class Animation : public DOMEventTargetHelper,
* Utility function to get the target (pseudo-)element associated with an
* animation.
*/
Maybe<NonOwningAnimationTarget> GetTargetForAnimation() const;
NonOwningAnimationTarget GetTargetForAnimation() const;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
+2 -2
View File
@@ -73,8 +73,8 @@ void AnimationEffect::SetSpecifiedTiming(TimingParams&& aTiming) {
if (mAnimation) {
Maybe<nsAutoAnimationMutationBatch> mb;
if (AsKeyframeEffect() && AsKeyframeEffect()->GetTarget()) {
mb.emplace(AsKeyframeEffect()->GetTarget()->mElement->OwnerDoc());
if (AsKeyframeEffect() && AsKeyframeEffect()->GetAnimationTarget()) {
mb.emplace(AsKeyframeEffect()->GetAnimationTarget().mElement->OwnerDoc());
}
mAnimation->NotifyEffectTimingUpdated();
+6
View File
@@ -53,6 +53,12 @@ struct NonOwningAnimationTarget {
return mElement == aOther.mElement && mPseudoType == aOther.mPseudoType;
}
NonOwningAnimationTarget& operator=(const OwningAnimationTarget& aOther) {
mElement = aOther.mElement;
mPseudoType = aOther.mPseudoType;
return *this;
}
explicit operator bool() const { return !!mElement; }
// mElement represents the parent element of a pseudo-element, not the
-25
View File
@@ -45,31 +45,6 @@ JSObject* CSSPseudoElement::WrapObject(JSContext* aCx,
return CSSPseudoElement_Binding::Wrap(aCx, this, aGivenProto);
}
void CSSPseudoElement::GetAnimations(const GetAnimationsOptions& aOptions,
nsTArray<RefPtr<Animation>>& aRetVal) {
Document* doc = mOriginatingElement->GetComposedDoc();
if (doc) {
// We don't need to explicitly flush throttled animations here, since
// updating the animation style of (pseudo-)elements will never affect the
// set of running animations and it's only the set of running animations
// that is important here.
doc->FlushPendingNotifications(
ChangesToFlush(FlushType::Style, false /* flush animations */));
}
Element::GetAnimationsUnsorted(mOriginatingElement, mPseudoType, aRetVal);
aRetVal.Sort(AnimationPtrComparator<RefPtr<Animation>>());
}
already_AddRefed<Animation> CSSPseudoElement::Animate(
JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError) {
Nullable<ElementOrCSSPseudoElement> target;
target.SetValue().SetAsCSSPseudoElement() = this;
return Element::Animate(target, aContext, aKeyframes, aOptions, aError);
}
/* static */
already_AddRefed<CSSPseudoElement> CSSPseudoElement::GetCSSPseudoElement(
dom::Element* aElement, PseudoStyleType aType) {
-7
View File
@@ -54,13 +54,6 @@ class CSSPseudoElement final : public nsWrapperCache {
return retVal.forget();
}
void GetAnimations(const GetAnimationsOptions& aOptions,
nsTArray<RefPtr<Animation>>& aRetVal);
already_AddRefed<Animation> Animate(
JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError);
// Given an element:pseudoType pair, returns the CSSPseudoElement stored as a
// property on |aElement|. If there is no CSSPseudoElement for the specified
// pseudo-type on element, a new CSSPseudoElement will be created and stored
+13 -7
View File
@@ -271,6 +271,12 @@ void EffectCompositor::PostRestyleForAnimation(dom::Element* aElement,
return;
}
// FIXME: Bug 1615083 KeyframeEffect::SetTarget() and
// KeyframeEffect::SetPseudoElement() may set a non-existing pseudo element,
// and we still have to update its style, based on the wpt. However, we don't
// have the generated element here, so we failed the wpt.
//
// See wpt for more info: web-animations/interfaces/KeyframeEffect/target.html
dom::Element* element = GetElementToRestyle(aElement, aPseudoType);
if (!element) {
return;
@@ -474,14 +480,14 @@ bool EffectCompositor::ComposeServoAnimationRuleForEffect(
MOZ_ASSERT(mPresContext && mPresContext->IsDynamic(),
"Should not be in print preview");
Maybe<NonOwningAnimationTarget> target = aEffect.GetTarget();
NonOwningAnimationTarget target = aEffect.GetAnimationTarget();
if (!target) {
return false;
}
// Don't try to compose animations for elements in documents without a pres
// shell (e.g. XMLHttpRequest documents).
if (!nsContentUtils::GetPresShellForContent(target->mElement)) {
if (!nsContentUtils::GetPresShellForContent(target.mElement)) {
return false;
}
@@ -489,10 +495,10 @@ bool EffectCompositor::ComposeServoAnimationRuleForEffect(
// where the cascade results are updated in the pre-traversal as needed.
// This function, however, is only called when committing styles so we
// need to ensure the cascade results are up-to-date manually.
MaybeUpdateCascadeResults(target->mElement, target->mPseudoType);
MaybeUpdateCascadeResults(target.mElement, target.mPseudoType);
EffectSet* effectSet =
EffectSet::GetEffectSet(target->mElement, target->mPseudoType);
EffectSet::GetEffectSet(target.mElement, target.mPseudoType);
// Get a list of effects sorted by composite order up to and including
// |aEffect|, even if it is not in the EffectSet.
@@ -512,9 +518,9 @@ bool EffectCompositor::ComposeServoAnimationRuleForEffect(
ComposeSortedEffects(sortedEffectList, effectSet, aCascadeLevel,
aAnimationValues);
MOZ_ASSERT(effectSet ==
EffectSet::GetEffectSet(target->mElement, target->mPseudoType),
"EffectSet should not change while composing style");
MOZ_ASSERT(
effectSet == EffectSet::GetEffectSet(target.mElement, target.mPseudoType),
"EffectSet should not change while composing style");
return true;
}
+95 -89
View File
@@ -10,7 +10,6 @@
#include "mozilla/dom/Animation.h"
#include "mozilla/dom/KeyframeAnimationOptionsBinding.h"
// For UnrestrictedDoubleOrKeyframeAnimationOptions;
#include "mozilla/dom/CSSPseudoElement.h"
#include "mozilla/dom/KeyframeEffectBinding.h"
#include "mozilla/dom/MutationObservers.h"
#include "mozilla/AnimationUtils.h"
@@ -652,6 +651,12 @@ void KeyframeEffect::ResetIsRunningOnCompositor() {
}
}
static bool IsSupportedPseudoForWebAnimation(PseudoStyleType aType) {
// FIXME: Bug 1615469: Support first-line and first-letter for Web Animation.
return aType == PseudoStyleType::before || aType == PseudoStyleType::after ||
aType == PseudoStyleType::marker;
}
static const KeyframeEffectOptions& KeyframeEffectOptionsFromUnion(
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions) {
MOZ_ASSERT(aOptions.IsKeyframeEffectOptions());
@@ -666,7 +671,7 @@ static const KeyframeEffectOptions& KeyframeEffectOptionsFromUnion(
template <class OptionsType>
static KeyframeEffectParams KeyframeEffectParamsFromUnion(
const OptionsType& aOptions, CallerType aCallerType) {
const OptionsType& aOptions, CallerType aCallerType, ErrorResult& aRv) {
KeyframeEffectParams result;
if (aOptions.IsUnrestrictedDouble() ||
// Ignore iterationComposite and composite if the corresponding pref is
@@ -679,37 +684,33 @@ static KeyframeEffectParams KeyframeEffectParamsFromUnion(
KeyframeEffectOptionsFromUnion(aOptions);
result.mIterationComposite = options.mIterationComposite;
result.mComposite = options.mComposite;
return result;
}
/* static */
OwningAnimationTarget KeyframeEffect::ConvertTarget(
const Nullable<ElementOrCSSPseudoElement>& aTarget) {
// Return value optimization.
OwningAnimationTarget result;
if (aTarget.IsNull()) {
result.mPseudoType = PseudoStyleType::NotPseudo;
if (DOMStringIsNull(options.mPseudoElement)) {
return result;
}
const ElementOrCSSPseudoElement& target = aTarget.Value();
MOZ_ASSERT(target.IsElement() || target.IsCSSPseudoElement(),
"Uninitialized target");
if (target.IsElement()) {
result.mElement = &target.GetAsElement();
} else {
result.mElement = target.GetAsCSSPseudoElement().Element();
result.mPseudoType = target.GetAsCSSPseudoElement().GetType();
RefPtr<nsAtom> pseudoAtom =
nsCSSPseudoElements::GetPseudoAtom(options.mPseudoElement);
if (!pseudoAtom) {
aRv.ThrowTypeError<MSG_INVALID_PSEUDO_SELECTOR>(options.mPseudoElement);
return result;
}
result.mPseudoType = nsCSSPseudoElements::GetPseudoType(
pseudoAtom, CSSEnabledState::ForAllContent);
if (!IsSupportedPseudoForWebAnimation(result.mPseudoType)) {
aRv.ThrowTypeError<MSG_UNSUPPORTED_PSEUDO_SELECTOR>(options.mPseudoElement);
}
return result;
}
template <class OptionsType>
/* static */
already_AddRefed<KeyframeEffect> KeyframeEffect::ConstructKeyframeEffect(
const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
const GlobalObject& aGlobal, Element* aTarget,
JS::Handle<JSObject*> aKeyframes, const OptionsType& aOptions,
ErrorResult& aRv) {
// We should get the document from `aGlobal` instead of the current Realm
@@ -727,17 +728,22 @@ already_AddRefed<KeyframeEffect> KeyframeEffect::ConstructKeyframeEffect(
return nullptr;
}
KeyframeEffectParams effectOptions =
KeyframeEffectParamsFromUnion(aOptions, aGlobal.CallerType(), aRv);
// An invalid Pseudo-element aborts all further steps.
if (aRv.Failed()) {
return nullptr;
}
TimingParams timingParams =
TimingParams::FromOptionsUnion(aOptions, doc, aRv);
if (aRv.Failed()) {
return nullptr;
}
KeyframeEffectParams effectOptions =
KeyframeEffectParamsFromUnion(aOptions, aGlobal.CallerType());
RefPtr<KeyframeEffect> effect = new KeyframeEffect(
doc, ConvertTarget(aTarget), std::move(timingParams), effectOptions);
doc, OwningAnimationTarget(aTarget, effectOptions.mPseudoType),
std::move(timingParams), effectOptions);
effect->SetKeyframes(aGlobal.Context(), aKeyframes, aRv);
if (aRv.Failed()) {
@@ -788,6 +794,50 @@ static void EnumerateContinuationsOrIBSplitSiblings(nsIFrame* aFrame,
}
}
void KeyframeEffect::UpdateTarget(Element* aElement,
PseudoStyleType aPseudoType) {
OwningAnimationTarget newTarget(aElement, aPseudoType);
if (mTarget == newTarget) {
// Assign the same target, skip it.
return;
}
if (mTarget) {
UnregisterTarget();
ResetIsRunningOnCompositor();
RequestRestyle(EffectCompositor::RestyleType::Layer);
nsAutoAnimationMutationBatch mb(mTarget.mElement->OwnerDoc());
if (mAnimation) {
MutationObservers::NotifyAnimationRemoved(mAnimation);
}
}
mTarget = newTarget;
if (mTarget) {
UpdateTargetRegistration();
RefPtr<ComputedStyle> computedStyle = GetTargetComputedStyle(Flush::None);
if (computedStyle) {
UpdateProperties(computedStyle);
}
RequestRestyle(EffectCompositor::RestyleType::Layer);
nsAutoAnimationMutationBatch mb(mTarget.mElement->OwnerDoc());
if (mAnimation) {
MutationObservers::NotifyAnimationAdded(mAnimation);
mAnimation->ReschedulePendingTasks();
}
}
if (mAnimation) {
mAnimation->NotifyEffectTargetUpdated();
}
}
void KeyframeEffect::UpdateTargetRegistration() {
if (!mTarget) {
return;
@@ -896,8 +946,7 @@ void DumpAnimationProperties(
/* static */
already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
const GlobalObject& aGlobal, Element* aTarget,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
ErrorResult& aRv) {
@@ -906,8 +955,7 @@ already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
/* static */
already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
const GlobalObject& aGlobal, Element* aTarget,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aRv) {
@@ -947,73 +995,31 @@ already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(
return effect.forget();
}
void KeyframeEffect::GetTarget(
Nullable<OwningElementOrCSSPseudoElement>& aRv) const {
if (!mTarget) {
aRv.SetNull();
void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement,
ErrorResult& aRv) {
PseudoStyleType pseudoType = PseudoStyleType::NotPseudo;
if (DOMStringIsNull(aPseudoElement)) {
UpdateTarget(mTarget.mElement, pseudoType);
return;
}
switch (mTarget.mPseudoType) {
case PseudoStyleType::before:
case PseudoStyleType::after:
case PseudoStyleType::marker:
aRv.SetValue().SetAsCSSPseudoElement() =
CSSPseudoElement::GetCSSPseudoElement(mTarget.mElement,
mTarget.mPseudoType);
break;
case PseudoStyleType::NotPseudo:
aRv.SetValue().SetAsElement() = mTarget.mElement;
break;
default:
MOZ_ASSERT_UNREACHABLE("Animation of unsupported pseudo-type");
aRv.SetNull();
}
}
void KeyframeEffect::SetTarget(
const Nullable<ElementOrCSSPseudoElement>& aTarget) {
OwningAnimationTarget newTarget = ConvertTarget(aTarget);
if (mTarget == newTarget) {
// Assign the same target, skip it.
// Note: GetPseudoAtom() also returns nullptr for the null string,
// so we handle null case before this.
RefPtr<nsAtom> pseudoAtom =
nsCSSPseudoElements::GetPseudoAtom(aPseudoElement);
if (!pseudoAtom) {
aRv.ThrowTypeError<MSG_INVALID_PSEUDO_SELECTOR>(aPseudoElement);
return;
}
if (mTarget) {
UnregisterTarget();
ResetIsRunningOnCompositor();
RequestRestyle(EffectCompositor::RestyleType::Layer);
nsAutoAnimationMutationBatch mb(mTarget.mElement->OwnerDoc());
if (mAnimation) {
MutationObservers::NotifyAnimationRemoved(mAnimation);
}
pseudoType = nsCSSPseudoElements::GetPseudoType(
pseudoAtom, CSSEnabledState::ForAllContent);
if (!IsSupportedPseudoForWebAnimation(pseudoType)) {
aRv.ThrowTypeError<MSG_UNSUPPORTED_PSEUDO_SELECTOR>(aPseudoElement);
return;
}
mTarget = newTarget;
if (mTarget) {
UpdateTargetRegistration();
RefPtr<ComputedStyle> computedStyle = GetTargetComputedStyle(Flush::None);
if (computedStyle) {
UpdateProperties(computedStyle);
}
RequestRestyle(EffectCompositor::RestyleType::Layer);
nsAutoAnimationMutationBatch mb(mTarget.mElement->OwnerDoc());
if (mAnimation) {
MutationObservers::NotifyAnimationAdded(mAnimation);
mAnimation->ReschedulePendingTasks();
}
}
if (mAnimation) {
mAnimation->NotifyEffectTargetUpdated();
}
UpdateTarget(mTarget.mElement, pseudoType);
}
static void CreatePropertyValue(
+26 -22
View File
@@ -39,7 +39,6 @@ class nsIFrame;
namespace mozilla {
class AnimValuesStyleRule;
enum class PseudoStyleType : uint8_t;
class ErrorResult;
struct AnimationRule;
struct TimingParams;
@@ -48,9 +47,7 @@ class ComputedStyle;
class PresShell;
namespace dom {
class ElementOrCSSPseudoElement;
class GlobalObject;
class OwningElementOrCSSPseudoElement;
class UnrestrictedDoubleOrKeyframeAnimationOptions;
class UnrestrictedDoubleOrKeyframeEffectOptions;
enum class IterationCompositeOperation : uint8_t;
@@ -127,8 +124,7 @@ class KeyframeEffect : public AnimationEffect {
// KeyframeEffect interface
static already_AddRefed<KeyframeEffect> Constructor(
const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
const GlobalObject& aGlobal, Element* aTarget,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
ErrorResult& aRv);
@@ -140,26 +136,35 @@ class KeyframeEffect : public AnimationEffect {
// for use with for Animatable.animate.
// Not exposed to content.
static already_AddRefed<KeyframeEffect> Constructor(
const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
const GlobalObject& aGlobal, Element* aTarget,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aRv);
void GetTarget(Nullable<OwningElementOrCSSPseudoElement>& aRv) const;
Maybe<NonOwningAnimationTarget> GetTarget() const {
Maybe<NonOwningAnimationTarget> result;
if (mTarget) {
result.emplace(mTarget);
}
return result;
already_AddRefed<Element> GetTarget() const {
RefPtr<Element> ret = mTarget.mElement;
return ret.forget();
}
// This method calls GetTargetComputedStyle which is not safe to use when
NonOwningAnimationTarget GetAnimationTarget() const {
return NonOwningAnimationTarget(mTarget.mElement, mTarget.mPseudoType);
}
void GetPseudoElement(nsAString& aRetVal) const {
if (mTarget.mPseudoType == PseudoStyleType::NotPseudo) {
SetDOMStringToNull(aRetVal);
return;
}
aRetVal = nsCSSPseudoElements::PseudoTypeAsString(mTarget.mPseudoType);
}
// These two setters call 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);
void SetTarget(Element* aTarget) {
UpdateTarget(aTarget, mTarget.mPseudoType);
}
void SetPseudoElement(const nsAString& aPseudoElement, ErrorResult& aRv);
void GetKeyframes(JSContext*& aCx, nsTArray<JSObject*>& aResult,
ErrorResult& aRv) const;
@@ -278,7 +283,7 @@ class KeyframeEffect : public AnimationEffect {
AnimationPerformanceWarning::Type& aPerformanceWarning /* out */) const;
bool HasGeometricProperties() const;
bool AffectsGeometry() const override {
return GetTarget() && HasGeometricProperties();
return mTarget && HasGeometricProperties();
}
Document* GetRenderedDocument() const;
@@ -345,13 +350,9 @@ class KeyframeEffect : public AnimationEffect {
protected:
~KeyframeEffect() override = default;
static OwningAnimationTarget ConvertTarget(
const Nullable<ElementOrCSSPseudoElement>& aTarget);
template <class OptionsType>
static already_AddRefed<KeyframeEffect> ConstructKeyframeEffect(
const GlobalObject& aGlobal,
const Nullable<ElementOrCSSPseudoElement>& aTarget,
const GlobalObject& aGlobal, Element* aTarget,
JS::Handle<JSObject*> aKeyframes, const OptionsType& aOptions,
ErrorResult& aRv);
@@ -360,6 +361,9 @@ class KeyframeEffect : public AnimationEffect {
// needed.
nsTArray<AnimationProperty> BuildProperties(const ComputedStyle* aStyle);
// Helper for SetTarget() and SetPseudoElement().
void UpdateTarget(Element* aElement, PseudoStyleType aPseudoType);
// This effect is registered with its target element so long as:
//
// (a) It has a target element, and
+2
View File
@@ -8,6 +8,7 @@
#define mozilla_KeyframeEffectParams_h
#include "mozilla/dom/KeyframeEffectBinding.h" // IterationCompositeOperation
#include "mozilla/PseudoStyleType.h" // PseudoStyleType
namespace mozilla {
@@ -15,6 +16,7 @@ struct KeyframeEffectParams {
dom::IterationCompositeOperation mIterationComposite =
dom::IterationCompositeOperation::Replace;
dom::CompositeOperation mComposite = dom::CompositeOperation::Replace;
PseudoStyleType mPseudoType = PseudoStyleType::NotPseudo;
};
} // namespace mozilla
@@ -502,13 +502,14 @@ promise_test(t => {
var childBAnimations = childB.getAnimations();
var divBeforeAnimations =
docAnims.filter(x => (x.effect.target.element == div &&
x.effect.target.type == "::before"));
docAnims.filter(x => (x.effect.target == div &&
x.effect.pseudoElement == "::before"));
var divAfterAnimations =
docAnims.filter(x => (x.effect.target.element == div &&
x.effect.target.type == "::after"));
docAnims.filter(x => (x.effect.target == div &&
x.effect.pseudoElement == "::after"));
var childBPseudoAnimations =
docAnims.filter(x => x.effect.target.element == childB);
docAnims.filter(x => (x.effect.target == childB &&
x.effect.pseudoElement == "::before"));
var seekRecords;
// The order in which we get the corresponding records is currently
@@ -74,21 +74,6 @@ function assert_equals_records(actual, expected, desc) {
}
}
// Create a pseudo element
function createPseudo(test, element, type) {
addStyle(test, { '@keyframes anim': '',
['.pseudo::' + type]: 'animation: anim 10s; ' +
'content: \'\';' });
element.classList.add('pseudo');
var anims = document.getAnimations();
assert_true(anims.length >= 1);
var anim = anims[anims.length - 1];
assert_equals(anim.effect.target.element, element);
assert_equals(anim.effect.target.type, '::' + type);
anim.cancel();
return anim.effect.target;
}
function runTest() {
[ { subtree: false },
{ subtree: true }
@@ -1518,10 +1503,11 @@ function runTest() {
test(t => {
var div = addDiv(t);
var pseudoTarget = createPseudo(t, div, 'before');
var observer = setupSynchronousObserver(t, div, true);
var anim = pseudoTarget.animate({ opacity: [ 0, 1 ] }, 200 * MS_PER_SEC);
var anim = div.animate({ opacity: [ 0, 1 ] },
{ duration: 200 * MS_PER_SEC,
pseudoElement: '::before' });
assert_equals_records(observer.takeRecords(),
[{ added: [anim], changed: [], removed: [] }],
@@ -1561,13 +1547,13 @@ function runTest() {
test(t => {
var div = addDiv(t);
var pseudoTarget = createPseudo(t, div, 'before');
var observer = setupSynchronousObserver(t, div, false);
var anim = div.animate({ opacity: [ 0, 1 ] },
{ duration: 100 * MS_PER_SEC });
var pAnim = pseudoTarget.animate({ opacity: [ 0, 1 ] },
{ duration: 100 * MS_PER_SEC });
var pAnim = div.animate({ opacity: [ 0, 1 ] },
{ duration: 100 * MS_PER_SEC,
pseudoElement: "::before" });
assert_equals_records(observer.takeRecords(),
[{ added: [anim], changed: [], removed: [] }],
@@ -15,11 +15,6 @@ test(t => {
}, 'Document.getAnimations() is not available when getAnimations pref is'
+ ' disabled');
test(t => {
assert_false('CSSPseudoElement' in window);
}, 'CSSPseudoElement interface is not available when getAnimations pref is'
+ ' disabled');
done();
</script>
</body>
+4 -26
View File
@@ -3245,29 +3245,7 @@ already_AddRefed<Animation> Element::Animate(
JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError) {
Nullable<ElementOrCSSPseudoElement> target;
target.SetValue().SetAsElement() = this;
return Animate(target, aContext, aKeyframes, aOptions, aError);
}
/* static */
already_AddRefed<Animation> Element::Animate(
const Nullable<ElementOrCSSPseudoElement>& aTarget, JSContext* aContext,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError) {
MOZ_ASSERT(!aTarget.IsNull() && (aTarget.Value().IsElement() ||
aTarget.Value().IsCSSPseudoElement()),
"aTarget should be initialized");
RefPtr<Element> referenceElement;
if (aTarget.Value().IsElement()) {
referenceElement = &aTarget.Value().GetAsElement();
} else {
referenceElement = aTarget.Value().GetAsCSSPseudoElement().Element();
}
nsCOMPtr<nsIGlobalObject> ownerGlobal = referenceElement->GetOwnerGlobal();
nsCOMPtr<nsIGlobalObject> ownerGlobal = GetOwnerGlobal();
if (!ownerGlobal) {
aError.Throw(NS_ERROR_FAILURE);
return nullptr;
@@ -3279,8 +3257,8 @@ already_AddRefed<Animation> Element::Animate(
// convention and needs to be called in caller's compartment.
// This should match to RunConstructorInCallerCompartment attribute in
// KeyframeEffect.webidl.
RefPtr<KeyframeEffect> effect = KeyframeEffect::Constructor(
global, aTarget, aKeyframes, aOptions, aError);
RefPtr<KeyframeEffect> effect =
KeyframeEffect::Constructor(global, this, aKeyframes, aOptions, aError);
if (aError.Failed()) {
return nullptr;
}
@@ -3289,7 +3267,7 @@ already_AddRefed<Animation> Element::Animate(
// needs to be called in the target element's realm.
JSAutoRealm ar(aContext, global.Get());
AnimationTimeline* timeline = referenceElement->OwnerDoc()->Timeline();
AnimationTimeline* timeline = OwnerDoc()->Timeline();
RefPtr<Animation> animation = Animation::Constructor(
global, effect, Optional<AnimationTimeline*>(timeline), aError);
if (aError.Failed()) {
-8
View File
@@ -1310,14 +1310,6 @@ class Element : public FragmentOrElement {
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError);
// A helper method that factors out the common functionality needed by
// Element::Animate and CSSPseudoElement::Animate
static already_AddRefed<Animation> Animate(
const Nullable<ElementOrCSSPseudoElement>& aTarget, JSContext* aContext,
JS::Handle<JSObject*> aKeyframes,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aError);
enum class Flush { Yes, No };
MOZ_CAN_RUN_SCRIPT
+3 -3
View File
@@ -222,16 +222,16 @@ void MutationObservers::NotifyAnimationMutated(
dom::Animation* aAnimation, AnimationMutationType aMutatedType) {
MOZ_ASSERT(aAnimation);
Maybe<NonOwningAnimationTarget> target = aAnimation->GetTargetForAnimation();
NonOwningAnimationTarget target = aAnimation->GetTargetForAnimation();
if (!target) {
return;
}
// A pseudo element and its parent element use the same owner doc.
Document* doc = target->mElement->OwnerDoc();
Document* doc = target.mElement->OwnerDoc();
if (doc->MayHaveAnimationObservers()) {
// we use the its parent element as the subject in DOM Mutation Observer.
Element* elem = target->mElement;
Element* elem = target.mElement;
switch (aMutatedType) {
case AnimationMutationType::Added:
IMPL_ANIMATION_NOTIFICATION(AnimationAdded, elem, (aAnimation));
+4 -4
View File
@@ -353,20 +353,20 @@ void nsAnimationReceiver::RecordAnimationMutation(
return;
}
Maybe<NonOwningAnimationTarget> animationTarget = keyframeEffect->GetTarget();
NonOwningAnimationTarget animationTarget =
keyframeEffect->GetAnimationTarget();
if (!animationTarget) {
return;
}
Element* elem = animationTarget->mElement;
Element* elem = animationTarget.mElement;
if (!Animations() || !(Subtree() || elem == Target()) ||
elem->ChromeOnlyAccess()) {
return;
}
// Record animations targeting to a pseudo element only when subtree is true.
if (animationTarget->mPseudoType != PseudoStyleType::NotPseudo &&
!Subtree()) {
if (animationTarget.mPseudoType != PseudoStyleType::NotPseudo && !Subtree()) {
return;
}
+2
View File
@@ -83,6 +83,8 @@ MSG_DEF(MSG_CACHE_ADD_FAILED_RESPONSE, 4, true, JSEXN_TYPEERR, "{0}Cache got {1}
MSG_DEF(MSG_SW_UPDATE_BAD_REGISTRATION, 3, true, JSEXN_TYPEERR, "{0}Failed to update the ServiceWorker for scope {1} because the registration has been {2} since the update was scheduled.")
MSG_DEF(MSG_INVALID_DURATION_ERROR, 2, true, JSEXN_TYPEERR, "{0}Invalid duration '{1}'.")
MSG_DEF(MSG_INVALID_EASING_ERROR, 2, true, JSEXN_TYPEERR, "{0}Invalid easing '{1}'.")
MSG_DEF(MSG_INVALID_PSEUDO_SELECTOR, 2, true, JSEXN_TYPEERR, "{0}Invalid pseudo-selector '{1}'")
MSG_DEF(MSG_UNSUPPORTED_PSEUDO_SELECTOR, 2, true, JSEXN_TYPEERR, "{0}Unsupported pseudo-selector '{1}'")
MSG_DEF(MSG_TOKENLIST_NO_SUPPORTED_TOKENS, 3, true, JSEXN_TYPEERR, "{0}{1} attribute of <{2}> does not define any supported tokens")
MSG_DEF(MSG_TIME_VALUE_OUT_OF_RANGE, 2, true, JSEXN_TYPEERR, "{0}{1} is outside the supported range for time values.")
MSG_DEF(MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN, 2, true, JSEXN_TYPEERR, "{0}Request mode '{1}' was used, but request cache mode 'only-if-cached' can only be used with request mode 'same-origin'.")
-3
View File
@@ -16,6 +16,3 @@ interface CSSPseudoElement {
readonly attribute DOMString type;
readonly attribute Element element;
};
// https://drafts.csswg.org/web-animations/#extensions-to-the-pseudoelement-interface
CSSPseudoElement includes Animatable;
+4 -2
View File
@@ -18,6 +18,7 @@ enum IterationCompositeOperation {
dictionary KeyframeEffectOptions : EffectTiming {
IterationCompositeOperation iterationComposite = "replace";
CompositeOperation composite = "replace";
DOMString? pseudoElement = null;
};
// KeyframeEffect should run in the caller's compartment to do custom
@@ -27,13 +28,14 @@ dictionary KeyframeEffectOptions : EffectTiming {
Exposed=Window]
interface KeyframeEffect : AnimationEffect {
[Throws]
constructor((Element or CSSPseudoElement)? target,
constructor(Element? target,
object? keyframes,
optional (unrestricted double or KeyframeEffectOptions) options = {});
[Throws]
constructor(KeyframeEffect source);
attribute (Element or CSSPseudoElement)? target;
attribute Element? target;
[SetterThrows] attribute DOMString? pseudoElement;
[Pref="dom.animations-api.compositing.enabled"]
attribute IterationCompositeOperation iterationComposite;
[Pref="dom.animations-api.compositing.enabled"]
@@ -1,4 +0,0 @@
[Document-getAnimations.tentative.html]
[CSS Animations targetting (pseudo-)elements should have correct order after sorting]
expected: FAIL
@@ -1,7 +0,0 @@
[Element-getAnimations.tentative.html]
[{ subtree: true } on a leaf element returns the element's animations and its pseudo-elements' animations]
expected: FAIL
[{ subtree: true } on an element with a child returns animations from the element, its pseudo-elements, its child and its child pseudo-elements]
expected: FAIL
@@ -1,4 +0,0 @@
[Document-getAnimations.tentative.html]
[CSS Transitions targetting (pseudo-)elements should have correct order after sorting]
expected: FAIL
@@ -2,9 +2,3 @@
[Animation interface: attribute timeline]
expected: FAIL
[KeyframeEffect interface: attribute pseudoElement]
expected: FAIL
[KeyframeEffect interface: new KeyframeEffect(null, null) must inherit property "pseudoElement" with the proper type]
expected: FAIL
@@ -8,15 +8,11 @@
[Element.animate() accepts a two property (one shorthand and one of its shorthand components) two value property-indexed keyframes specification]
expected: FAIL
[animate() with pseudoElement parameter creates an Animation object for ::first-line]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615469
[animate() with pseudoElement an Animation object targeting the correct pseudo-element for ::first-line]
expected: FAIL
[animate() with pseudoElement an Animation object targeting the correct pseudo-element for ::marker]
expected: FAIL
[animate() with pseudoElement without content creates an Animation object targeting the correct pseudo-element]
expected: FAIL
[animate() with pseudoElement an Animation object targeting the correct pseudo-element]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615469
@@ -1,10 +1,4 @@
[commitStyles.html]
[Throws if the target element is a pseudo element]
expected: FAIL
[Checks the pseudo element condition before the not rendered condition]
expected: FAIL
[Commits custom variables]
expected: FAIL
@@ -1,4 +0,0 @@
[style-change-events.html]
[All property keys are recognized]
expected: FAIL
@@ -1,37 +1,25 @@
[target.html]
[Change target from null to an existing pseudoElement setting pseudoElement first.]
expected: FAIL
[Change target from an existing to a different non-existing pseudo-element by setting pseudoElement.]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615083
[Change target from null to a non-existing pseudoElement setting target first.]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615083
[Change target from an existing to a different non-existing pseudo-element by setting target.]
expected: FAIL
[Change target from an existing to a different existing pseudo-element by setting target.]
expected: FAIL
[Change target from a non-existing to a different existing pseudo-element by setting target.]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615083
[Change target from a non-existing to a different non-existing pseudo-element by setting target.]
expected: FAIL
[Change target from a non-existing to a different existing pseudo-element by setting pseudoElement.]
expected: FAIL
[Change target from null to an existing pseudoElement setting target first.]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615083
[Change target from null to a non-existing pseudoElement setting pseudoElement first.]
expected: FAIL
[Change target from an existing to a different existing pseudo-element by setting pseudoElement.]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615083
[Change target from a non-existing to a different non-existing pseudo-element by setting pseudoElement.]
expected: FAIL
bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1615083
@@ -265,7 +265,7 @@ test(t => {
getComputedStyle(div,"::marker").content; // Sync style
const anim = div.animate(null, {pseudoElement: '::marker'});
assert_class_string(anim, 'Animation', 'The returned object is an Animation for ::marker');
}, 'animate() with pseudoElement parameter creates an Animation object for ::marker');
}, 'animate() with pseudoElement parameter creates an Animation object for ::marker');
test(t => {
const div = createDiv(t);
@@ -273,7 +273,7 @@ test(t => {
div.textContent = 'foo';
const anim = div.animate(null, {pseudoElement: '::first-line'});
assert_class_string(anim, 'Animation', 'The returned object is an Animation for ::first-line');
}, 'animate() with pseudoElement parameter creates an Animation object for ::first-line');
}, 'animate() with pseudoElement parameter creates an Animation object for ::first-line');
test(t => {
const div = createDiv(t);
@@ -318,5 +318,19 @@ test(t => {
}, 'animate() with pseudoElement an Animation object targeting ' +
'the correct pseudo-element for ::first-line');
for (const pseudo of [
'',
'before',
'::abc',
'::placeholder',
]) {
test(t => {
const div = createDiv(t);
assert_throws_js(TypeError, () => {
div.animate(null, {pseudoElement: pseudo});
});
}, `animate() with the invalid pseudoElement '${pseudo}' throws a TypeError`);
}
</script>
</body>
@@ -255,7 +255,18 @@ for (const hasContent of [true, false]){
}
}
for (const pseudo of [
'',
'before',
'::abc',
'::placeholder',
]) {
test(t => {
const effect = new KeyframeEffect(null, gKeyFrames, 100 * MS_PER_SEC);
assert_throws_js(TypeError, () => effect.pseudoElement = pseudo );
}, `Changing pseudoElement to invalid pseudo-selector '${pseudo}' throws a ` +
`TypeError`);
}
</script>
</body>