Have ScrollObserverImpl notify the ScrollTimeline when the scroll values along the relevant axis change
draft
Have ScrollObserverImpl notify the ScrollTimeline when the scroll values along the relevant axis change
MozReview-Commit-ID: AKxYENctjW6
--- 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