Bug 1341372 - Part 4: Add a utility method to get AnimationCollection by Element and nsIAtom. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 14 Apr 2017 10:17:43 +0800
changeset 563575 7e4a8bc1159720cef16f0a377e71ae4def039099
parent 563574 4c5042d1a0a6209f62e2eda99c9317c5da0f75ed
child 563576 4168e45f82fb2aa1826eebff8e6b18db6f39dfb5
push id54353
push userbmo:boris.chiou@gmail.com
push dateMon, 17 Apr 2017 09:07:14 +0000
bugs1341372
milestone55.0a1
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
layout/style/AnimationCollection.cpp
layout/style/AnimationCollection.h
layout/style/ServoBindings.cpp
--- 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;
 }