Bug 1273042 - Part 1: Use StyleContext()->GetPseudoType() to obtain CSSPseudoElementType for the nsIFrame. r?birtles
Before this patch, we could't use EffectSet::GetEffectSet(nsIFrame*) until
the target content associated with the nsIFrame has a primary frame since
nsLayoutUtils::GetStyleFrame(nsIContent*) needs the primary frame.
In this patch, StyleContext()->GetPseudoType() is used for obtaining
CSSPseudoElementType instread of content->NodeInfo()->NameAtom().
As a result, we don't need to care about whether the content has a
primary frame or not.
MozReview-Commit-ID: 3JiUfr5hZb6
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -514,45 +514,36 @@ EffectCompositor::UpdateCascadeResults(E
}
/* static */ Maybe<NonOwningAnimationTarget>
EffectCompositor::GetAnimationElementAndPseudoForFrame(const nsIFrame* aFrame)
{
// Always return the same object to benefit from return-value optimization.
Maybe<NonOwningAnimationTarget> result;
+ CSSPseudoElementType pseudoType =
+ aFrame->StyleContext()->GetPseudoType();
+
+ if (pseudoType != CSSPseudoElementType::NotPseudo &&
+ pseudoType != CSSPseudoElementType::before &&
+ pseudoType != CSSPseudoElementType::after) {
+ return result;
+ }
+
nsIContent* content = aFrame->GetContent();
if (!content) {
return result;
}
- CSSPseudoElementType pseudoType = CSSPseudoElementType::NotPseudo;
-
- if (aFrame->IsGeneratedContentFrame()) {
- nsIFrame* parent = aFrame->GetParent();
- if (parent->IsGeneratedContentFrame()) {
- return result;
- }
- nsIAtom* name = content->NodeInfo()->NameAtom();
- if (name == nsGkAtoms::mozgeneratedcontentbefore) {
- pseudoType = CSSPseudoElementType::before;
- } else if (name == nsGkAtoms::mozgeneratedcontentafter) {
- pseudoType = CSSPseudoElementType::after;
- } else {
- return result;
- }
+ if (pseudoType == CSSPseudoElementType::before ||
+ pseudoType == CSSPseudoElementType::after) {
content = content->GetParent();
if (!content) {
return result;
}
- } else {
- if (nsLayoutUtils::GetStyleFrame(content) != aFrame) {
- // The effects associated with an element are for its primary frame.
- return result;
- }
}
if (!content->IsElement()) {
return result;
}
result.emplace(content->AsElement(), pseudoType);
--- a/dom/animation/EffectSet.cpp
+++ b/dom/animation/EffectSet.cpp
@@ -44,52 +44,28 @@ EffectSet::GetEffectSet(dom::Element* aE
{
nsIAtom* propName = GetEffectSetPropertyAtom(aPseudoType);
return static_cast<EffectSet*>(aElement->GetProperty(propName));
}
/* static */ EffectSet*
EffectSet::GetEffectSet(const nsIFrame* aFrame)
{
- nsIContent* content = aFrame->GetContent();
- if (!content) {
+ Maybe<NonOwningAnimationTarget> target =
+ EffectCompositor::GetAnimationElementAndPseudoForFrame(aFrame);
+
+ if (!target) {
return nullptr;
}
- nsIAtom* propName;
- if (aFrame->IsGeneratedContentFrame()) {
- nsIFrame* parent = aFrame->GetParent();
- if (parent->IsGeneratedContentFrame()) {
- return nullptr;
- }
- nsIAtom* name = content->NodeInfo()->NameAtom();
- if (name == nsGkAtoms::mozgeneratedcontentbefore) {
- propName = nsGkAtoms::animationEffectsForBeforeProperty;
- } else if (name == nsGkAtoms::mozgeneratedcontentafter) {
- propName = nsGkAtoms::animationEffectsForAfterProperty;
- } else {
- return nullptr;
- }
- content = content->GetParent();
- if (!content) {
- return nullptr;
- }
- } else {
- if (nsLayoutUtils::GetStyleFrame(content) != aFrame) {
- // The effects associated with an element are for its primary frame.
- return nullptr;
- }
- propName = nsGkAtoms::animationEffectsProperty;
- }
-
- if (!content->MayHaveAnimations()) {
+ if (!target->mElement->MayHaveAnimations()) {
return nullptr;
}
- return static_cast<EffectSet*>(content->GetProperty(propName));
+ return GetEffectSet(target->mElement, target->mPseudoType);
}
/* static */ EffectSet*
EffectSet::GetOrCreateEffectSet(dom::Element* aElement,
CSSPseudoElementType aPseudoType)
{
EffectSet* effectSet = GetEffectSet(aElement, aPseudoType);
if (effectSet) {