Bug 1032573 part 4 - Add AnimationTimeline::ToTimelineTime helper method; r=dbaron
authorBrian Birtles <birtles@gmail.com>
Wed, 16 Jul 2014 09:02:30 +0900
changeset 216192 08f2190d7e40f18e738b6c32a83dc07fb45af29d
parent 216191 35f359aca0c3021e3e385b697fe55ef6a0cbb541
child 216193 e672d5bffa8f0b3635c2cd1ff7811376e5a377f7
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1032573
milestone33.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 1032573 part 4 - Add AnimationTimeline::ToTimelineTime helper method; r=dbaron This patch simply factors out the conversion from a TimeStamp value to a nullable-double value relative to the start of the timeline. This is so that, in a subsequent patch, this functionality can be reused by ElementAnimation when it reports its start time (which is currently recorded as a TimeStamp).
dom/animation/AnimationTimeline.cpp
dom/animation/AnimationTimeline.h
--- a/dom/animation/AnimationTimeline.cpp
+++ b/dom/animation/AnimationTimeline.cpp
@@ -24,30 +24,17 @@ JSObject*
 AnimationTimeline::WrapObject(JSContext* aCx)
 {
   return AnimationTimelineBinding::Wrap(aCx, this);
 }
 
 Nullable<double>
 AnimationTimeline::GetCurrentTime() const
 {
-  Nullable<double> result; // Default ctor initializes to null
-
-  nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
-  if (!timing) {
-    return result;
-  }
-
-  TimeStamp now = GetCurrentTimeStamp();
-  if (now.IsNull()) {
-    return result;
-  }
-
-  result.SetValue(timing->TimeStampToDOMHighRes(now));
-  return result;
+  return ToTimelineTime(GetCurrentTimeStamp());
 }
 
 TimeStamp
 AnimationTimeline::GetCurrentTimeStamp() const
 {
   // Always return the same object to benefit from return-value optimization.
   TimeStamp result; // Initializes to null timestamp
 
@@ -60,10 +47,27 @@ AnimationTimeline::GetCurrentTimeStamp()
   if (MOZ_UNLIKELY(!presContext)) {
     return result;
   }
 
   result = presContext->RefreshDriver()->MostRecentRefresh();
   return result;
 }
 
+Nullable<double>
+AnimationTimeline::ToTimelineTime(const mozilla::TimeStamp& aTimeStamp) const
+{
+  Nullable<double> result; // Initializes to null
+  if (aTimeStamp.IsNull()) {
+    return result;
+  }
+
+  nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
+  if (MOZ_UNLIKELY(!timing)) {
+    return result;
+  }
+
+  result.SetValue(timing->TimeStampToDOMHighRes(aTimeStamp));
+  return result;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/animation/AnimationTimeline.h
+++ b/dom/animation/AnimationTimeline.h
@@ -33,16 +33,18 @@ public:
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationTimeline)
 
   nsISupports* GetParentObject() const { return mDocument; }
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
   Nullable<double> GetCurrentTime() const;
   mozilla::TimeStamp GetCurrentTimeStamp() const;
 
+  Nullable<double> ToTimelineTime(const mozilla::TimeStamp& aTimeStamp) const;
+
 protected:
   virtual ~AnimationTimeline() { }
 
   nsCOMPtr<nsIDocument> mDocument;
 };
 
 } // namespace dom
 } // namespace mozilla