Bug 927349 part 7 - Factor out AnimationTimeline::GetRefreshDriver into a separate method; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Thu, 18 Dec 2014 08:42:41 +0900
changeset 220180 1e4ce2a592b820029a7b864f3af6aceeeb9c0160
parent 220179 19407030d97a2c2f66d3207e9a39201e09b8e7ef
child 220181 190df6248c74a717c02470421a85cce7b80bb1cc
push id53039
push userbbirtles@mozilla.com
push dateWed, 17 Dec 2014 23:43:01 +0000
treeherdermozilla-inbound@1e4ce2a592b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs927349
milestone37.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 927349 part 7 - Factor out AnimationTimeline::GetRefreshDriver into a separate method; r=jwatt This is in preparation for adding AnimationTimeline::FastForward in the next patch which will reuse this code.
dom/animation/AnimationTimeline.cpp
dom/animation/AnimationTimeline.h
--- a/dom/animation/AnimationTimeline.cpp
+++ b/dom/animation/AnimationTimeline.cpp
@@ -50,27 +50,22 @@ AnimationTimeline::GetCurrentTimeStamp()
   if (result.IsNull()) {
     nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
     if (!timing) {
       return result;
     }
     result = timing->GetNavigationStartTimeStamp();
   }
 
-  nsIPresShell* presShell = mDocument->GetShell();
-  if (MOZ_UNLIKELY(!presShell)) {
+  nsRefreshDriver* refreshDriver = GetRefreshDriver();
+  if (!refreshDriver) {
     return result;
   }
 
-  nsPresContext* presContext = presShell->GetPresContext();
-  if (MOZ_UNLIKELY(!presContext)) {
-    return result;
-  }
-
-  result = presContext->RefreshDriver()->MostRecentRefresh();
+  result = refreshDriver->MostRecentRefresh();
   // FIXME: We would like to assert that:
   //   mLastCurrentTime.IsNull() || result >= mLastCurrentTime
   // but due to bug 1043078 this will not be the case when the refresh driver
   // is restored from test control.
   mLastCurrentTime = result;
   return result;
 }
 
@@ -99,10 +94,26 @@ AnimationTimeline::ToTimeStamp(const Tim
   if (MOZ_UNLIKELY(!timing)) {
     return result;
   }
 
   result = timing->GetNavigationStartTimeStamp() + aTimeDuration;
   return result;
 }
 
+nsRefreshDriver*
+AnimationTimeline::GetRefreshDriver() const
+{
+  nsIPresShell* presShell = mDocument->GetShell();
+  if (MOZ_UNLIKELY(!presShell)) {
+    return nullptr;
+  }
+
+  nsPresContext* presContext = presShell->GetPresContext();
+  if (MOZ_UNLIKELY(!presContext)) {
+    return nullptr;
+  }
+
+  return presContext->RefreshDriver();
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/animation/AnimationTimeline.h
+++ b/dom/animation/AnimationTimeline.h
@@ -9,28 +9,33 @@
 #include "nsWrapperCache.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/TimeStamp.h"
 #include "js/TypeDecls.h"
 #include "nsIDocument.h"
 
 struct JSContext;
+class nsRefreshDriver;
 
 namespace mozilla {
 namespace dom {
 
 class AnimationTimeline MOZ_FINAL : public nsWrapperCache
 {
 public:
   explicit AnimationTimeline(nsIDocument* aDocument)
     : mDocument(aDocument)
   {
   }
 
+protected:
+  virtual ~AnimationTimeline() { }
+
+public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationTimeline)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationTimeline)
 
   nsIGlobalObject* GetParentObject() const
   {
     return mDocument->GetParentObject();
   }
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
@@ -42,18 +47,17 @@ public:
   // script.
   Nullable<double> GetCurrentTimeAsDouble() const;
 
   Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const;
   TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const;
 
 protected:
   TimeStamp GetCurrentTimeStamp() const;
-
-  virtual ~AnimationTimeline() { }
+  nsRefreshDriver* GetRefreshDriver() const;
 
   nsCOMPtr<nsIDocument> mDocument;
 
   // Store the most recently returned value of current time. This is used
   // in cases where we don't have a refresh driver (e.g. because we are in
   // a display:none iframe).
   mutable TimeStamp mLastCurrentTime;
 };