Bug 1180125 part 4 - Move PseudoTypeAsString to AnimationCollection and reuse; r=dbaron
authorBrian Birtles <birtles@gmail.com>
Wed, 29 Jul 2015 10:57:40 +0900
changeset 288378 50892e26a6ec6469407a654d4f242bafb32a7b95
parent 288377 d9549506b9cffa8337ad44eb32e8fe3105ac1b48
child 288379 e901b139e679c6744e2c6e5c197fda67f74fb9ef
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1180125
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1180125 part 4 - Move PseudoTypeAsString to AnimationCollection and reuse; r=dbaron Prior to this patch, CSSAnimation defined a method for converting an nsCSSPseudoElements::Type to a nsString (but only for the set of pseudo-elements that can have animations). We would like to re-use this when setting up transition events so this patch moves it to AnimationCollection. Re-using this method more widely means we can make a few further simplifications to the code.
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/nsAnimationManager.cpp
layout/style/nsAnimationManager.h
layout/style/nsTransitionManager.cpp
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -715,16 +715,31 @@ AnimationCollection::HasAnimationOfPrope
     if (effect && effect->HasAnimationOfProperty(aProperty) &&
         !effect->IsFinishedTransition()) {
       return true;
     }
   }
   return false;
 }
 
+/*static*/ nsString
+AnimationCollection::PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType)
+{
+  switch (aPseudoType) {
+    case nsCSSPseudoElements::ePseudo_before:
+      return NS_LITERAL_STRING("::before");
+    case nsCSSPseudoElements::ePseudo_after:
+      return NS_LITERAL_STRING("::after");
+    default:
+      MOZ_ASSERT(aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement,
+                 "Unexpected pseudo type");
+      return EmptyString();
+  }
+}
+
 mozilla::dom::Element*
 AnimationCollection::GetElementToRestyle() const
 {
   if (IsForElement()) {
     return mElement;
   }
 
   nsIFrame* primaryFrame = mElement->GetPrimaryFrame();
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -344,42 +344,31 @@ public:
   }
 
   bool IsForAnimations() const {
     return mElementProperty == nsGkAtoms::animationsProperty ||
            mElementProperty == nsGkAtoms::animationsOfBeforeProperty ||
            mElementProperty == nsGkAtoms::animationsOfAfterProperty;
   }
 
-  nsString PseudoElement() const
-  {
-    if (IsForElement()) {
-      return EmptyString();
-    }
-    if (IsForBeforePseudo()) {
-      return NS_LITERAL_STRING("::before");
-    }
-    MOZ_ASSERT(IsForAfterPseudo(),
-               "::before & ::after should be the only pseudo-elements here");
-    return NS_LITERAL_STRING("::after");
-  }
-
   nsCSSPseudoElements::Type PseudoElementType() const
   {
     if (IsForElement()) {
       return nsCSSPseudoElements::ePseudo_NotPseudoElement;
     }
     if (IsForBeforePseudo()) {
       return nsCSSPseudoElements::ePseudo_before;
     }
     MOZ_ASSERT(IsForAfterPseudo(),
                "::before & ::after should be the only pseudo-elements here");
     return nsCSSPseudoElements::ePseudo_after;
   }
 
+  static nsString PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType);
+
   dom::Element* GetElementToRestyle() const;
 
   void PostRestyleForAnimation(nsPresContext *aPresContext) {
     dom::Element* element = GetElementToRestyle();
     if (element) {
       nsRestyleHint hint = IsForTransitions() ? eRestyle_CSSTransitions
                                               : eRestyle_CSSAnimations;
       aPresContext->PresShell()->RestyleForAnimation(element, hint);
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -247,17 +247,17 @@ CSSAnimation::QueueEvents()
   } else if (skippedActivePhase) {
     // First notifying for start of 0th iteration by appending an
     // 'animationstart':
     StickyTimeDuration elapsedTime =
       std::min(StickyTimeDuration(mEffect->InitialAdvance()),
                computedTiming.mActiveDuration);
     manager->QueueEvent(
       AnimationEventInfo(owningElement, mAnimationName, NS_ANIMATION_START,
-                         elapsedTime, PseudoTypeAsString(owningPseudoType)));
+                         elapsedTime, owningPseudoType));
     // Then have the shared code below append an 'animationend':
     message = NS_ANIMATION_END;
   } else {
     return; // No events need to be sent
   }
 
   StickyTimeDuration elapsedTime;
 
@@ -269,43 +269,30 @@ CSSAnimation::QueueEvents()
                                               mEffect->InitialAdvance()));
   } else {
     MOZ_ASSERT(message == NS_ANIMATION_END);
     elapsedTime = computedTiming.mActiveDuration;
   }
 
   manager->QueueEvent(
     AnimationEventInfo(owningElement, mAnimationName, message, elapsedTime,
-                       PseudoTypeAsString(owningPseudoType)));
+                       owningPseudoType));
 }
 
 CommonAnimationManager*
 CSSAnimation::GetAnimationManager() const
 {
   nsPresContext* context = GetPresContext();
   if (!context) {
     return nullptr;
   }
 
   return context->AnimationManager();
 }
 
-/* static */ nsString
-CSSAnimation::PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType)
-{
-  switch (aPseudoType) {
-    case nsCSSPseudoElements::ePseudo_before:
-      return NS_LITERAL_STRING("::before");
-    case nsCSSPseudoElements::ePseudo_after:
-      return NS_LITERAL_STRING("::after");
-    default:
-      return EmptyString();
-  }
-}
-
 ////////////////////////// nsAnimationManager ////////////////////////////
 
 NS_IMPL_CYCLE_COLLECTION(nsAnimationManager, mEventDispatcher)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAnimationManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAnimationManager)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsAnimationManager)
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -27,23 +27,23 @@ class Promise;
 struct AnimationEventInfo {
   nsRefPtr<mozilla::dom::Element> mElement;
   mozilla::InternalAnimationEvent mEvent;
 
   AnimationEventInfo(mozilla::dom::Element *aElement,
                      const nsSubstring& aAnimationName,
                      uint32_t aMessage,
                      const mozilla::StickyTimeDuration& aElapsedTime,
-                     const nsAString& aPseudoElement)
+                     nsCSSPseudoElements::Type aPseudoType)
     : mElement(aElement), mEvent(true, aMessage)
   {
     // XXX Looks like nobody initialize WidgetEvent::time
     mEvent.animationName = aAnimationName;
     mEvent.elapsedTime = aElapsedTime.ToSeconds();
-    mEvent.pseudoElement = aPseudoElement;
+    mEvent.pseudoElement = AnimationCollection::PseudoTypeAsString(aPseudoType);
   }
 
   // InternalAnimationEvent doesn't support copy-construction, so we need
   // to ourselves in order to work with nsTArray
   AnimationEventInfo(const AnimationEventInfo &aOther)
     : mElement(aOther.mElement), mEvent(true, aOther.mEvent.message)
   {
     mEvent.AssignAnimationEventData(aOther.mEvent, false);
@@ -160,18 +160,16 @@ protected:
   {
     MOZ_ASSERT(!mOwningElement.IsSet(), "Owning element should be cleared "
                                         "before a CSS animation is destroyed");
   }
   virtual CommonAnimationManager* GetAnimationManager() const override;
 
   void QueueEvents();
 
-  static nsString PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType);
-
   nsString mAnimationName;
 
   // The (pseudo-)element whose computed animation-name refers to this
   // animation (if any).
   OwningElementRef mOwningElement;
 
   // When combining animation-play-state with play() / pause() the following
   // behavior applies:
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -847,25 +847,26 @@ nsTransitionManager::SizeOfIncludingThis
   return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
 struct TransitionEventInfo {
   nsCOMPtr<nsIContent> mElement;
   InternalTransitionEvent mEvent;
 
   TransitionEventInfo(nsIContent *aElement, nsCSSProperty aProperty,
-                      TimeDuration aDuration, const nsAString& aPseudoElement)
+                      TimeDuration aDuration,
+                      nsCSSPseudoElements::Type aPseudoType)
     : mElement(aElement)
     , mEvent(true, NS_TRANSITION_END)
   {
     // XXX Looks like nobody initialize WidgetEvent::time
     mEvent.propertyName =
       NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aProperty));
     mEvent.elapsedTime = aDuration.ToSeconds();
-    mEvent.pseudoElement = aPseudoElement;
+    mEvent.pseudoElement = AnimationCollection::PseudoTypeAsString(aPseudoType);
   }
 
   // InternalTransitionEvent doesn't support copy-construction, so we need
   // to ourselves in order to work with nsTArray
   TransitionEventInfo(const TransitionEventInfo &aOther)
     : mElement(aOther.mElement)
     , mEvent(true, NS_TRANSITION_END)
   {
@@ -935,18 +936,17 @@ nsTransitionManager::FlushTransitions(Fl
             anim->GetEffect()->GetComputedTiming();
           if (computedTiming.mPhase == ComputedTiming::AnimationPhase_After) {
             nsCSSProperty prop =
               anim->GetEffect()->AsTransition()->TransitionProperty();
             TimeDuration duration =
               anim->GetEffect()->Timing().mIterationDuration;
             events.AppendElement(
               TransitionEventInfo(collection->mElement, prop,
-                                  duration,
-                                  collection->PseudoElement()));
+                                  duration, collection->PseudoElementType()));
 
             // Leave this transition in the list for one more refresh
             // cycle, since we haven't yet processed its style change, and
             // if we also have (already, or will have from processing
             // transitionend events or other refresh driver notifications)
             // a non-animation style change that would affect it, we need
             // to know not to start a new transition for the transition
             // from the almost-completed value to the final value.