Bug 1195180 part 8 - Tick animations from their timeline; r=heycam
authorBrian Birtles <birtles@gmail.com>
Mon, 28 Sep 2015 12:38:41 +0900
changeset 264602 05dfb6716db36f5f6045264d243eb24c595288c1
parent 264601 3ef6210305ae5d7a3aad1d9c0dff2ca23410e3f6
child 264603 3aa2e3b0f240e50c5fb3bbcc941a3bb6a595b24d
push id65690
push userbbirtles@mozilla.com
push dateMon, 28 Sep 2015 03:38:57 +0000
treeherdermozilla-inbound@005e98e2c5c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1195180
milestone44.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 1195180 part 8 - Tick animations from their timeline; r=heycam
dom/animation/DocumentTimeline.cpp
dom/animation/moz.build
layout/style/AnimationCommon.cpp
--- a/dom/animation/DocumentTimeline.cpp
+++ b/dom/animation/DocumentTimeline.cpp
@@ -3,20 +3,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DocumentTimeline.h"
 #include "mozilla/dom/DocumentTimelineBinding.h"
 #include "AnimationUtils.h"
 #include "nsContentUtils.h"
+#include "nsDOMMutationObserver.h"
+#include "nsDOMNavigationTiming.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsRefreshDriver.h"
-#include "nsDOMNavigationTiming.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(DocumentTimeline, AnimationTimeline,
                                    mDocument)
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(DocumentTimeline,
@@ -108,25 +109,36 @@ DocumentTimeline::NotifyAnimationUpdated
 void
 DocumentTimeline::WillRefresh(mozilla::TimeStamp aTime)
 {
   MOZ_ASSERT(mIsObservingRefreshDriver);
 
   bool needsTicks = false;
   AnimationArray animationsToKeep(mAnimationOrder.Length());
 
+  nsAutoAnimationMutationBatch mb(mDocument);
+
   for (Animation* animation : mAnimationOrder) {
-    if (animation->GetTimeline() != this ||
-        (!animation->IsRelevant() && !animation->NeedsTicks())) {
+    // Skip any animations that are longer need associated with this timeline.
+    if (animation->GetTimeline() != this) {
       mAnimations.RemoveEntry(animation);
       continue;
     }
 
     needsTicks |= animation->NeedsTicks();
-    animationsToKeep.AppendElement(animation);
+    // Even if |animation| doesn't need future ticks, we should still
+    // Tick it this time around since it might just need a one-off tick in
+    // order to dispatch events.
+    animation->Tick();
+
+    if (animation->IsRelevant() || animation->NeedsTicks()) {
+      animationsToKeep.AppendElement(animation);
+    } else {
+      mAnimations.RemoveEntry(animation);
+    }
   }
 
   mAnimationOrder.SwapElements(animationsToKeep);
 
   if (!needsTicks) {
     // If another refresh driver observer destroys the nsPresContext,
     // nsRefreshDriver will detect it and we won't be called.
     MOZ_ASSERT(GetRefreshDriver(),
--- a/dom/animation/moz.build
+++ b/dom/animation/moz.build
@@ -26,8 +26,12 @@ UNIFIED_SOURCES += [
     'AnimationEffectReadOnly.cpp',
     'AnimationTimeline.cpp',
     'DocumentTimeline.cpp',
     'KeyframeEffect.cpp',
     'PendingAnimationTracker.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
+
+LOCAL_INCLUDES += [
+    '/dom/base',
+]
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -422,23 +422,16 @@ CommonAnimationManager::WillRefresh(Time
     // Someone might be keeping mPresContext alive past the point
     // where it has been torn down; don't bother doing anything in
     // this case.  But do get rid of all our animations so we stop
     // triggering refreshes.
     RemoveAllElementCollections();
     return;
   }
 
-  nsAutoAnimationMutationBatch mb(mPresContext->Document());
-
-  for (AnimationCollection* collection = mElementCollections.getFirst();
-       collection; collection = collection->getNext()) {
-    collection->Tick();
-  }
-
   MaybeStartOrStopObservingRefreshDriver();
 }
 
 void
 CommonAnimationManager::ClearIsRunningOnCompositor(const nsIFrame* aFrame,
                                                    nsCSSProperty aProperty)
 {
   AnimationCollection* collection = GetAnimationCollection(aFrame);