From 9da4eab494402ae99180b21e4d3d58d6afe977b2 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Fri, 28 Jul 2017 14:57:54 -0400 Subject: [PATCH] Bug 1105109 - Introduce a FrameMetrics::ClampAndSetScrollOffset() helper. r=kats MozReview-Commit-ID: 6LCPKrdGM6M --HG-- extra : rebase_source : 65f51ce5c40d9f1ac64c1f94055aa87d44a72cae --- gfx/layers/FrameMetrics.h | 6 ++++++ gfx/layers/apz/src/AsyncPanZoomController.cpp | 11 ++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gfx/layers/FrameMetrics.h b/gfx/layers/FrameMetrics.h index 5fc0143f6f86..41c1ce6ec5bc 100644 --- a/gfx/layers/FrameMetrics.h +++ b/gfx/layers/FrameMetrics.h @@ -335,6 +335,12 @@ public: mScrollOffset = aScrollOffset; } + // Set scroll offset, first clamping to the scroll range. + void ClampAndSetScrollOffset(const CSSPoint& aScrollOffset) + { + SetScrollOffset(CalculateScrollRange().ClampPoint(aScrollOffset)); + } + const CSSPoint& GetScrollOffset() const { return mScrollOffset; diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 90002ce5a3b0..ad563fd834d4 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -582,10 +582,9 @@ public: // offset to end up being a bit off from the destination, we can get // artefacts like "scroll to the next snap point in this direction" // scrolling to the snap point we're already supposed to be at. - aFrameMetrics.SetScrollOffset( - aFrameMetrics.CalculateScrollRange().ClampPoint( - CSSPoint::FromAppUnits(nsPoint(mXAxisModel.GetDestination(), - mYAxisModel.GetDestination())))); + aFrameMetrics.ClampAndSetScrollOffset( + CSSPoint::FromAppUnits(nsPoint(mXAxisModel.GetDestination(), + mYAxisModel.GetDestination()))); return false; } @@ -3789,9 +3788,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const ScrollMetadata& aScrollMe // Even if we didn't accept a new scroll offset from content, the // scrollable rect may have changed in a way that makes our local // scroll offset out of bounds, so re-clamp it. - mFrameMetrics.SetScrollOffset( - mFrameMetrics.CalculateScrollRange().ClampPoint( - mFrameMetrics.GetScrollOffset())); + mFrameMetrics.ClampAndSetScrollOffset(mFrameMetrics.GetScrollOffset()); } }