Bug 1341372 - Part 4: Add a utility method to get AnimationCollection by Element and nsIAtom.
We need a utility method to get the AnimationCollection by dom::Element
and the pseudo element tag.
MozReview-Commit-ID: KCOY6EKFFX5
--- a/layout/style/AnimationCollection.cpp
+++ b/layout/style/AnimationCollection.cpp
@@ -56,16 +56,35 @@ AnimationCollection<AnimationType>::GetA
return
static_cast<AnimationCollection<AnimationType>*>(aElement->
GetProperty(propName));
}
template <class AnimationType>
/* static */ AnimationCollection<AnimationType>*
AnimationCollection<AnimationType>::GetAnimationCollection(
+ const dom::Element *aElement,
+ nsIAtom* aPseudoTagOrNull)
+{
+ MOZ_ASSERT(!aPseudoTagOrNull ||
+ aPseudoTagOrNull == nsCSSPseudoElements::before ||
+ aPseudoTagOrNull == nsCSSPseudoElements::after);
+
+ CSSPseudoElementType pseudoType = CSSPseudoElementType::NotPseudo;
+ if (aPseudoTagOrNull) {
+ pseudoType = aPseudoTagOrNull == nsCSSPseudoElements::before
+ ? CSSPseudoElementType::before
+ : CSSPseudoElementType::after;
+ }
+ return GetAnimationCollection(aElement, pseudoType);
+}
+
+template <class AnimationType>
+/* static */ AnimationCollection<AnimationType>*
+AnimationCollection<AnimationType>::GetAnimationCollection(
const nsIFrame* aFrame)
{
Maybe<NonOwningAnimationTarget> pseudoElement =
EffectCompositor::GetAnimationElementAndPseudoForFrame(aFrame);
if (!pseudoElement) {
return nullptr;
}
--- a/layout/style/AnimationCollection.h
+++ b/layout/style/AnimationCollection.h
@@ -65,16 +65,22 @@ public:
void *aPropertyValue, void *aData);
// Get the collection of animations for the given |aElement| and
// |aPseudoType|.
static AnimationCollection<AnimationType>*
GetAnimationCollection(const dom::Element* aElement,
CSSPseudoElementType aPseudoType);
+ // Get the collection of animations for the given |aElement| and
+ // |aPseudoTagOrNull|.
+ static AnimationCollection<AnimationType>*
+ GetAnimationCollection(const dom::Element* aElement,
+ nsIAtom* aPseudoTagOrNull);
+
// Given the frame |aFrame| with possibly animated content, finds its
// associated collection of animations. If |aFrame| is a generated content
// frame, this function may examine the parent frame to search for such
// animations.
static AnimationCollection<AnimationType>* GetAnimationCollection(
const nsIFrame* aFrame);
// Get the collection of animations for the given |aElement| and
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -508,81 +508,53 @@ Gecko_ElementHasAnimations(RawGeckoEleme
return !!EffectSet::GetEffectSet(aElement, pseudoType);
}
bool
Gecko_ElementHasCSSAnimations(RawGeckoElementBorrowed aElement,
nsIAtom* aPseudoTagOrNull)
{
- MOZ_ASSERT(!aPseudoTagOrNull ||
- aPseudoTagOrNull == nsCSSPseudoElements::before ||
- aPseudoTagOrNull == nsCSSPseudoElements::after);
-
- CSSPseudoElementType pseudoType =
- nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
- CSSEnabledState::eForAllContent);
nsAnimationManager::CSSAnimationCollection* collection =
nsAnimationManager::CSSAnimationCollection
- ::GetAnimationCollection(aElement, pseudoType);
+ ::GetAnimationCollection(aElement, aPseudoTagOrNull);
return collection && !collection->mAnimations.IsEmpty();
}
bool
Gecko_ElementHasCSSTransitions(RawGeckoElementBorrowed aElement,
nsIAtom* aPseudoTagOrNull)
{
- MOZ_ASSERT(!aPseudoTagOrNull ||
- aPseudoTagOrNull == nsCSSPseudoElements::before ||
- aPseudoTagOrNull == nsCSSPseudoElements::after);
-
- CSSPseudoElementType pseudoType =
- nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
- CSSEnabledState::eForAllContent);
nsTransitionManager::CSSTransitionCollection* collection =
nsTransitionManager::CSSTransitionCollection
- ::GetAnimationCollection(aElement, pseudoType);
+ ::GetAnimationCollection(aElement, aPseudoTagOrNull);
return collection && !collection->mAnimations.IsEmpty();
}
size_t
Gecko_ElementTransitions_Length(RawGeckoElementBorrowed aElement,
nsIAtom* aPseudoTagOrNull)
{
- MOZ_ASSERT(!aPseudoTagOrNull ||
- aPseudoTagOrNull == nsCSSPseudoElements::before ||
- aPseudoTagOrNull == nsCSSPseudoElements::after);
-
- CSSPseudoElementType pseudoType =
- nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
- CSSEnabledState::eForAllContent);
nsTransitionManager::CSSTransitionCollection* collection =
nsTransitionManager::CSSTransitionCollection
- ::GetAnimationCollection(aElement, pseudoType);
+ ::GetAnimationCollection(aElement, aPseudoTagOrNull);
return collection ? collection->mAnimations.Length() : 0;
}
static CSSTransition*
GetCurrentTransitionAt(RawGeckoElementBorrowed aElement,
nsIAtom* aPseudoTagOrNull,
size_t aIndex)
{
- MOZ_ASSERT(!aPseudoTagOrNull ||
- aPseudoTagOrNull == nsCSSPseudoElements::before ||
- aPseudoTagOrNull == nsCSSPseudoElements::after);
-
- CSSPseudoElementType pseudoType =
- nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
- CSSEnabledState::eForAllContent);
nsTransitionManager::CSSTransitionCollection* collection =
nsTransitionManager::CSSTransitionCollection
- ::GetAnimationCollection(aElement, pseudoType);
+ ::GetAnimationCollection(aElement, aPseudoTagOrNull);
if (!collection) {
return nullptr;
}
nsTArray<RefPtr<CSSTransition>>& transitions = collection->mAnimations;
return aIndex < transitions.Length()
? transitions[aIndex].get()
: nullptr;
}