Bug 1182856 - Part 1: Add StopTransitionsForElement. r=heycam
authorBoris Chiou <boris.chiou@gmail.com>
Sun, 10 Apr 2016 21:25:00 +0200
changeset 316568 fd79b8c38ccbf39cc78248ae6ff7625d8e589c9d
parent 316567 fd676a6ad20bc83c19f363d9e05f0af9e98f10d8
child 316569 8278f70e662c456896b46c67acc328d456957ed1
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1182856
milestone48.0a1
Bug 1182856 - Part 1: Add StopTransitionsForElement. r=heycam Add a new API in nsTransitionManager, so we can cancel transitions for a specific element easily. The purpose of this API is for cancelling transitions without dispatching the event.
layout/style/nsTransitionManager.cpp
layout/style/nsTransitionManager.h
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -818,8 +818,24 @@ nsTransitionManager::PruneCompletedTrans
   } while (i != 0);
 
   if (collection->mAnimations.IsEmpty()) {
     collection->Destroy();
     // |collection| is now a dangling pointer!
     collection = nullptr;
   }
 }
+
+void
+nsTransitionManager::StopTransitionsForElement(
+  mozilla::dom::Element* aElement,
+  mozilla::CSSPseudoElementType aPseudoType)
+{
+  MOZ_ASSERT(aElement);
+  CSSTransitionCollection* collection =
+    CSSTransitionCollection::GetAnimationCollection(aElement, aPseudoType);
+  if (!collection) {
+    return;
+  }
+
+  nsAutoAnimationMutationBatch mb(aElement->OwnerDoc());
+  collection->Destroy();
+}
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -336,16 +336,22 @@ public:
   void DispatchEvents()
   {
     RefPtr<nsTransitionManager> kungFuDeathGrip(this);
     mEventDispatcher.DispatchEvents(mPresContext);
   }
   void SortEvents()      { mEventDispatcher.SortEvents(); }
   void ClearEventQueue() { mEventDispatcher.ClearEventQueue(); }
 
+  // Stop transitions on the element. This method takes the real element
+  // rather than the element for the generated content for transitions on
+  // ::before and ::after.
+  void StopTransitionsForElement(mozilla::dom::Element* aElement,
+                                 mozilla::CSSPseudoElementType aPseudoType);
+
 protected:
   virtual ~nsTransitionManager() {}
 
   typedef nsTArray<RefPtr<mozilla::dom::CSSTransition>>
     OwningCSSTransitionPtrArray;
 
   void
   ConsiderStartingTransition(nsCSSProperty aProperty,