Determine a scroll timeline's 'timeline time' based on scroll position
MozReview-Commit-ID: 65Db8HehuCj
--- 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).