Determine a scroll timeline's 'timeline time' based on scroll position draft
authorBotond Ballo <botond@mozilla.com>
Wed, 27 Jul 2016 14:31:26 -0400
changeset 393428 8324702c372224098cd12b445f626e28273b8165
parent 393427 ed0eddf2cf33731d8043d93a3f0de9d61d4c193f
child 393429 d6feb7e51adfbe4a622dda5dafe313ec6df76f01
push id24313
push userbballo@mozilla.com
push dateWed, 27 Jul 2016 21:32:22 +0000
milestone50.0a1
Determine a scroll timeline's 'timeline time' based on scroll position MozReview-Commit-ID: 65Db8HehuCj
dom/animation/ScrollTimeline.cpp
dom/animation/ScrollTimeline.h
--- a/dom/animation/ScrollTimeline.cpp
+++ b/dom/animation/ScrollTimeline.cpp
@@ -55,55 +55,22 @@ ScrollTimeline::Constructor(const Global
                                                        orientation,
                                                        maxTime);
   return timeline.forget();
 }
 
 Nullable<TimeDuration>
 ScrollTimeline::GetCurrentTime() const
 {
-  // Memo: We should retrun current time which related with scroll value.
-  return ToTimelineTime(GetCurrentTimeStamp());
-}
-
-TimeStamp
-ScrollTimeline::GetCurrentTimeStamp() const
-{
-  // Memo: We should return current timestamp wich related with scroll value.
-  //       The following implementation is DocumentTimeline. So we should remove
-  //       this implementation, and return new concept time.
-  //       Maybe, we don't need to use RefreshDriver.
-  // Idea: Perhaps, We will return 
-  nsRefreshDriver* refreshDriver = GetRefreshDriver();
-  TimeStamp refreshTime = refreshDriver
-                          ? refreshDriver->MostRecentRefresh()
-                          : TimeStamp();
-
-  // Always return the same object to benefit from return-value optimization.
-  TimeStamp result = !refreshTime.IsNull()
-                     ? refreshTime
-                     : mLastRefreshDriverTime;
-
-  // If we don't have a refresh driver and we've never had one use the
-  // timeline's zero time.
-  if (result.IsNull()) {
-    RefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
-    if (timing) {
-      result = timing->GetNavigationStartTimeStamp();
-      // Also, let this time represent the current refresh time. This way
-      // we'll save it as the last refresh time and skip looking up
-      // navigation timing each time.
-      refreshTime = result;
-    }
+  Nullable<TimeDuration> result;  // Initializes to null
+  double scrollRange = mMaxScroll - mMinScroll;
+  if (scrollRange != 0 && !mTimeRange.IsZero()) {
+    result.SetValue(
+        TimeDuration(mTimeRange.MultDouble(mCurrentScroll / scrollRange)));
   }
-
-  if (!refreshTime.IsNull()) {
-    mLastRefreshDriverTime = refreshTime;
-  }
-
   return result;
 }
 
 Nullable<TimeDuration>
 ScrollTimeline::ToTimelineTime(const TimeStamp& aTimeStamp) const
 {
   // Memo: We don't concern about clock time and zero time.
   Nullable<TimeDuration> result; // Initializes to null
--- a/dom/animation/ScrollTimeline.h
+++ b/dom/animation/ScrollTimeline.h
@@ -107,17 +107,16 @@ public:
   void WillRefresh(TimeStamp aTime) override;
 
   void NotifyRefreshDriverCreated(nsRefreshDriver* aDriver);
   void NotifyRefreshDriverDestroying(nsRefreshDriver* aDriver);
 
   void SetScrollValues(double aCurrent, double aMin, double aMax);
 
 protected:
-  TimeStamp GetCurrentTimeStamp() const;
   nsRefreshDriver* GetRefreshDriver() const;
   void CalculateTimeRange();
 
   nsCOMPtr<nsIDocument> mDocument;
 
   // The most recently used refresh driver time. This is used in cases where
   // we don't have a refresh driver (e.g. because we are in a display:none
   // iframe).