Bug 1180125 part 6 - Use DelayedEventDispatcher in nsTransitionManager; r=dbaron
authorBrian Birtles <birtles@gmail.com>
Wed, 29 Jul 2015 10:57:40 +0900
changeset 288380 0162e758928d832be2fab18a113d41e8e2d9ad6f
parent 288379 e901b139e679c6744e2c6e5c197fda67f74fb9ef
child 288381 c9a55501a48fa4d022403a912e0770f1a2461ac1
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 6 - Use DelayedEventDispatcher in nsTransitionManager; r=dbaron This simply uses the DelayedEventDispatcher in place of the previous array of TransitionEventInfo objects. Doing the actual delayed dispatch is performed in a separate patch.
layout/style/nsTransitionManager.cpp
layout/style/nsTransitionManager.h
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -169,17 +169,25 @@ CSSTransition::HasLowerCompositeOrderTha
 
   // 5. (Same transition generation): Sort by transition property
   return nsCSSProps::GetStringValue(TransitionProperty()) <
          nsCSSProps::GetStringValue(otherTransition->TransitionProperty());
 }
 
 ////////////////////////// nsTransitionManager ////////////////////////////
 
-NS_IMPL_ISUPPORTS(nsTransitionManager, nsIStyleRuleProcessor)
+NS_IMPL_CYCLE_COLLECTION(nsTransitionManager, mEventDispatcher)
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTransitionManager)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTransitionManager)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTransitionManager)
+  NS_INTERFACE_MAP_ENTRY(nsIStyleRuleProcessor)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
 
 void
 nsTransitionManager::StyleContextChanged(dom::Element *aElement,
                                          nsStyleContext *aOldStyleContext,
                                          nsRefPtr<nsStyleContext>* aNewStyleContext /* inout */)
 {
   nsStyleContext* newStyleContext = *aNewStyleContext;
 
@@ -832,16 +840,20 @@ nsTransitionManager::UpdateCascadeResult
 /*
  * nsIStyleRuleProcessor implementation
  */
 
 /* virtual */ size_t
 nsTransitionManager::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   return CommonAnimationManager::SizeOfExcludingThis(aMallocSizeOf);
+
+  // Measurement of the following members may be added later if DMD finds it is
+  // worthwhile:
+  // - mEventDispatcher
 }
 
 /* virtual */ size_t
 nsTransitionManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
@@ -866,17 +878,16 @@ nsTransitionManager::WillRefresh(mozilla
 void
 nsTransitionManager::FlushTransitions(FlushFlags aFlags)
 {
   if (PR_CLIST_IS_EMPTY(&mElementCollections)) {
     // no transitions, leave early
     return;
   }
 
-  nsTArray<TransitionEventInfo> events;
   TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
   bool didThrottle = false;
   // Trim transitions that have completed, post restyle events for frames that
   // are still transitioning, and start transitions with delays.
   {
     PRCList *next = PR_LIST_HEAD(&mElementCollections);
     while (next != &mElementCollections) {
       AnimationCollection* collection = static_cast<AnimationCollection*>(next);
@@ -905,17 +916,17 @@ nsTransitionManager::FlushTransitions(Fl
           MOZ_ASSERT(anim->GetEffect(), "Transitions should have an effect");
           ComputedTiming computedTiming =
             anim->GetEffect()->GetComputedTiming();
           if (computedTiming.mPhase == ComputedTiming::AnimationPhase_After) {
             nsCSSProperty prop =
               anim->GetEffect()->AsTransition()->TransitionProperty();
             TimeDuration duration =
               anim->GetEffect()->Timing().mIterationDuration;
-            events.AppendElement(
+            mEventDispatcher.QueueEvent(
               TransitionEventInfo(collection->mElement, prop,
                                   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
@@ -960,17 +971,10 @@ nsTransitionManager::FlushTransitions(Fl
   }
 
   if (didThrottle) {
     mPresContext->Document()->SetNeedStyleFlush();
   }
 
   MaybeStartOrStopObservingRefreshDriver();
 
-  for (uint32_t i = 0, i_end = events.Length(); i < i_end; ++i) {
-    TransitionEventInfo &info = events[i];
-    EventDispatcher::Dispatch(info.mElement, mPresContext, &info.mEvent);
-
-    if (!mPresContext) {
-      break;
-    }
-  }
+  mEventDispatcher.DispatchEvents(mPresContext);
 }
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -207,17 +207,18 @@ class nsTransitionManager final
 {
 public:
   explicit nsTransitionManager(nsPresContext *aPresContext)
     : mozilla::CommonAnimationManager(aPresContext)
     , mInAnimationOnlyStyleUpdate(false)
   {
   }
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_CLASS(nsTransitionManager)
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   typedef mozilla::AnimationCollection AnimationCollection;
 
   /**
    * StyleContextChanged
    *
    * To be called from nsFrameManager::ReResolveStyleContext when the
    * style of an element has changed, to initiate transitions from
@@ -267,16 +268,18 @@ public:
     MOZ_MUST_OVERRIDE override;
 
   // nsARefreshObserver
   virtual void WillRefresh(mozilla::TimeStamp aTime) override;
 
   void FlushTransitions(FlushFlags aFlags);
 
 protected:
+  virtual ~nsTransitionManager() {}
+
   virtual nsIAtom* GetAnimationsAtom() override {
     return nsGkAtoms::transitionsProperty;
   }
   virtual nsIAtom* GetAnimationsBeforeAtom() override {
     return nsGkAtoms::transitionsOfBeforeProperty;
   }
   virtual nsIAtom* GetAnimationsAfterAtom() override {
     return nsGkAtoms::transitionsOfAfterProperty;
@@ -289,11 +292,14 @@ private:
                              mozilla::dom::Element* aElement,
                              AnimationCollection*& aElementTransitions,
                              nsStyleContext* aOldStyleContext,
                              nsStyleContext* aNewStyleContext,
                              bool* aStartedAny,
                              nsCSSPropertySet* aWhichStarted);
 
   bool mInAnimationOnlyStyleUpdate;
+
+  mozilla::DelayedEventDispatcher<mozilla::TransitionEventInfo>
+      mEventDispatcher;
 };
 
 #endif /* !defined(nsTransitionManager_h_) */