Have ScrollObserverImpl notify the ScrollTimeline when the scroll values along the relevant axis change draft
authorBotond Ballo <botond@mozilla.com>
Wed, 27 Jul 2016 14:53:23 -0400
changeset 393427 ed0eddf2cf33731d8043d93a3f0de9d61d4c193f
parent 393426 2217a6d720729474848b864961575b142d759077
child 393428 8324702c372224098cd12b445f626e28273b8165
push id24313
push userbballo@mozilla.com
push dateWed, 27 Jul 2016 21:32:22 +0000
milestone50.0a1
Have ScrollObserverImpl notify the ScrollTimeline when the scroll values along the relevant axis change MozReview-Commit-ID: AKxYENctjW6
dom/animation/ScrollTimeline.cpp
dom/animation/ScrollTimeline.h
--- a/dom/animation/ScrollTimeline.cpp
+++ b/dom/animation/ScrollTimeline.cpp
@@ -264,10 +264,36 @@ ScrollTimeline::CalculateTimeRange()
 {
   mTimeRange = 0;
   for (Animation* animation : mAnimationOrder) {
     StickyTimeDuration endTime = animation->EffectEnd();
     mTimeRange = StickyTimeDuration::Max(endTime, mTimeRange);
   }
 }
 
+void
+ScrollTimeline::SetScrollValues(double aCurrentScroll, double aMinScroll,
+                                double aMaxScroll)
+{
+  mCurrentScroll = aCurrentScroll;
+  mMinScroll = aMinScroll;
+  mMaxScroll = aMaxScroll;
+}
+
+void
+ScrollObserverImpl::notify()
+{
+    printf_stderr("[WALDOWALDO] ScrollObserverImpl::notify()\n");
+    if (mElement) {
+      if (mOrientation == Orientation::Horizontal) {
+        mTimeline->SetScrollValues(mElement->ScrollLeft(),
+                                   mElement->ScrollLeftMin(),
+                                   mElement->ScrollLeftMax());
+      } else {
+        mTimeline->SetScrollValues(mElement->ScrollTop(),
+                                   mElement->ScrollTopMin(),
+                                   mElement->ScrollTopMax());
+      }
+    }
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/animation/ScrollTimeline.h
+++ b/dom/animation/ScrollTimeline.h
@@ -20,70 +20,49 @@
 struct JSContext;
 
 namespace mozilla {
 namespace dom {
 class ScrollObserver;
 
 class ScrollObserverImpl : public ScrollObserver {
 public:
-  ScrollObserverImpl(Element* elem, LinkedList<dom::Animation>* animationOrder,
-                     Orientation aOrientation) {
+  ScrollObserverImpl(Element* elem, Orientation aOrientation,
+                     ScrollTimeline* aTimeline) {
     mElement = elem;
-    mAnimationOrder = animationOrder;
     mOrientation = aOrientation;
+    mTimeline = aTimeline;
   }
   
-  void notify() override {
-    if (mElement) {
-      if (mOrientation == Orientation::Horizontal) {
-        mCurrent = mElement->ScrollLeft();
-        mMin = mElement->ScrollLeftMin();
-        mMax = mElement->ScrollLeftMax();
-      } else {
-        mCurrent = mElement->ScrollTop();
-        mMin = mElement->ScrollTopMin();
-        mMax = mElement->ScrollTopMax();
-      }
-    }
-
-    // We will change the currentTime according to scroll volumes.
-    for (Animation* animation = mAnimationOrder->getFirst(); animation;
-         animation = animation->getNext()) {
-      StickyTimeDuration endTime = animation->EffectEnd();
-      TimeDuration time =
-        TimeDuration(endTime.MultDouble(mCurrent /(mMax - mMin)));
-
-      ErrorResult rv;
-      animation->SetCurrentTimeAsDouble(Nullable<double>(time.ToMilliseconds()), rv);
-    }
-  }
+  void notify() override;
 private:
-  double mCurrent, mMin, mMax;
   Element* mElement;
-  LinkedList<dom::Animation>* mAnimationOrder;
   Orientation mOrientation;
+  ScrollTimeline* mTimeline;
 };
 
 class ScrollTimeline final
   : public AnimationTimeline
   , public nsARefreshObserver
 {
 public:
   ScrollTimeline(nsIDocument* aDocument,
                  Element* aTarget,
                  Orientation aOrientation,
                  const Optional<double>& maxTime)
     : AnimationTimeline(aDocument->GetParentObject())
     , mDocument(aDocument)
     , mIsObservingRefreshDriver(false)
     , mOrientation(aOrientation)
     , mElement(aTarget)
+    , mCurrentScroll(0)
+    , mMinScroll(0)
+    , mMaxScroll(0)
   {
-    mScrollObserver = new ScrollObserverImpl(aTarget, &mAnimationOrder, mOrientation);
+    mScrollObserver = new ScrollObserverImpl(aTarget, mOrientation, this);
     aTarget->RegistScrollTimelineObserver(mScrollObserver);
     CalculateTimeRange();
   }
 
 protected:
   virtual ~ScrollTimeline()
   {
     MOZ_ASSERT(!mIsObservingRefreshDriver, "Timeline should have disassociated"
@@ -125,16 +104,18 @@ public:
   void RemoveAnimation(Animation* aAnimation) override;
 
   // nsARefreshObserver methods
   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
@@ -144,14 +125,15 @@ protected:
   bool mIsObservingRefreshDriver;
 
   
   Orientation mOrientation;
   double mMaxTime;
   ScrollObserverImpl *mScrollObserver;
   RefPtr<Element> mElement;
   StickyTimeDuration mTimeRange;
+  double mCurrentScroll, mMinScroll, mMaxScroll;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_ScrollTimeline_h