Bug 1754897 - Part 7: Factor out the check of PseudoStyleType for animations. r=emilio

It seems we use it frequently, so move it to AnimationUtils.h.

Differential Revision: https://phabricator.services.mozilla.com/D147774
This commit is contained in:
Boris Chiou 2022-06-13 20:26:47 +00:00
Родитель 80e27fb970
Коммит c34416388a
5 изменённых файлов: 21 добавлений и 30 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#ifndef mozilla_dom_AnimationUtils_h
#define mozilla_dom_AnimationUtils_h
#include "mozilla/PseudoStyleType.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/Nullable.h"
#include "nsRFPService.h"
@ -18,7 +19,6 @@ struct JSContext;
namespace mozilla {
enum class PseudoStyleType : uint8_t;
class ComputedTimingFunction;
class EffectSet;
@ -84,6 +84,16 @@ class AnimationUtils {
*/
static bool HasCurrentTransitions(const dom::Element* aElement,
PseudoStyleType aPseudoType);
/**
* Returns true if this pseudo style type is supported by animations.
* Note: This doesn't include PseudoStyleType::NotPseudo.
*/
static bool IsSupportedPseudoForAnimations(PseudoStyleType aType) {
// FIXME: Bug 1615469: Support first-line and first-letter for Animation.
return aType == PseudoStyleType::before ||
aType == PseudoStyleType::after || aType == PseudoStyleType::marker;
}
};
} // namespace mozilla

Просмотреть файл

@ -21,9 +21,7 @@ CSSPseudoElement::CSSPseudoElement(dom::Element* aElement,
PseudoStyleType aType)
: mOriginatingElement(aElement), mPseudoType(aType) {
MOZ_ASSERT(aElement);
MOZ_ASSERT(aType == PseudoStyleType::after ||
aType == PseudoStyleType::before ||
aType == PseudoStyleType::marker,
MOZ_ASSERT(AnimationUtils::IsSupportedPseudoForAnimations(aType),
"Unexpected Pseudo Type");
}

Просмотреть файл

@ -345,9 +345,7 @@ void EffectCompositor::ClearRestyleRequestsFor(Element* aElement) {
elementsToRestyle.Remove(beforePseudoKey);
elementsToRestyle.Remove(afterPseudoKey);
elementsToRestyle.Remove(markerPseudoKey);
} else if (pseudoType == PseudoStyleType::before ||
pseudoType == PseudoStyleType::after ||
pseudoType == PseudoStyleType::marker) {
} else if (AnimationUtils::IsSupportedPseudoForAnimations(pseudoType)) {
Element* parentElement = aElement->GetParentElement();
MOZ_ASSERT(parentElement);
PseudoElementHashEntry::KeyType key = {parentElement, pseudoType};
@ -614,9 +612,7 @@ EffectCompositor::GetAnimationElementAndPseudoForFrame(const nsIFrame* aFrame) {
PseudoStyleType pseudoType = aFrame->Style()->GetPseudoType();
if (pseudoType != PseudoStyleType::NotPseudo &&
pseudoType != PseudoStyleType::before &&
pseudoType != PseudoStyleType::after &&
pseudoType != PseudoStyleType::marker) {
!AnimationUtils::IsSupportedPseudoForAnimations(pseudoType)) {
return result;
}
@ -625,9 +621,7 @@ EffectCompositor::GetAnimationElementAndPseudoForFrame(const nsIFrame* aFrame) {
return result;
}
if (pseudoType == PseudoStyleType::before ||
pseudoType == PseudoStyleType::after ||
pseudoType == PseudoStyleType::marker) {
if (AnimationUtils::IsSupportedPseudoForAnimations(pseudoType)) {
content = content->GetParent();
if (!content) {
return result;

Просмотреть файл

@ -743,12 +743,6 @@ void KeyframeEffect::ResetPartialPrerendered() {
}
}
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());
@ -794,7 +788,7 @@ static KeyframeEffectParams KeyframeEffectParamsFromUnion(
}
result.mPseudoType = *pseudoType;
if (!IsSupportedPseudoForWebAnimation(result.mPseudoType)) {
if (!AnimationUtils::IsSupportedPseudoForAnimations(result.mPseudoType)) {
// Per the spec, we throw SyntaxError for unsupported pseudos.
aRv.ThrowSyntaxError(
nsPrintfCString("'%s' is an unsupported pseudo-element.",
@ -1103,7 +1097,7 @@ void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement,
return;
}
if (!IsSupportedPseudoForWebAnimation(*pseudoType)) {
if (!AnimationUtils::IsSupportedPseudoForAnimations(*pseudoType)) {
// Per the spec, we throw SyntaxError for unsupported pseudos.
aRv.ThrowSyntaxError(
nsPrintfCString("'%s' is an unsupported pseudo-element.",

Просмотреть файл

@ -1825,9 +1825,7 @@ nsresult Element::BindToTree(BindContext& aContext, nsINode& aParent) {
if (aParent.IsInUncomposedDoc() && MayHaveAnimations()) {
PseudoStyleType pseudoType = GetPseudoElementType();
if ((pseudoType == PseudoStyleType::NotPseudo ||
pseudoType == PseudoStyleType::before ||
pseudoType == PseudoStyleType::after ||
pseudoType == PseudoStyleType::marker) &&
AnimationUtils::IsSupportedPseudoForAnimations(pseudoType)) &&
EffectSet::GetEffectSet(this, pseudoType)) {
if (nsPresContext* presContext = aContext.OwnerDoc().GetPresContext()) {
presContext->EffectCompositor()->RequestRestyle(
@ -3663,9 +3661,8 @@ void Element::GetAnimationsWithoutFlush(
return;
}
if (!aOptions.mSubtree || pseudoType == PseudoStyleType::before ||
pseudoType == PseudoStyleType::after ||
pseudoType == PseudoStyleType::marker) {
if (!aOptions.mSubtree ||
AnimationUtils::IsSupportedPseudoForAnimations(pseudoType)) {
GetAnimationsUnsorted(elem, pseudoType, aAnimations);
} else {
for (nsIContent* node = this; node; node = node->GetNextNode(this)) {
@ -3691,9 +3688,7 @@ void Element::GetAnimationsUnsorted(Element* aElement,
PseudoStyleType aPseudoType,
nsTArray<RefPtr<Animation>>& aAnimations) {
MOZ_ASSERT(aPseudoType == PseudoStyleType::NotPseudo ||
aPseudoType == PseudoStyleType::after ||
aPseudoType == PseudoStyleType::before ||
aPseudoType == PseudoStyleType::marker,
AnimationUtils::IsSupportedPseudoForAnimations(aPseudoType),
"Unsupported pseudo type");
MOZ_ASSERT(aElement, "Null element");