Bug 1105109 - Introduce a FrameMetrics::ClampAndSetScrollOffset() helper. r=kats
MozReview-Commit-ID: 6LCPKrdGM6M
--- a/gfx/layers/FrameMetrics.h
+++ b/gfx/layers/FrameMetrics.h
@@ -330,16 +330,22 @@ public:
return mIsRootContent;
}
void SetScrollOffset(const CSSPoint& aScrollOffset)
{
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;
}
void SetSmoothScrollOffset(const CSSPoint& aSmoothScrollDestination)
{
mSmoothScrollOffset = aSmoothScrollDestination;
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -577,20 +577,19 @@ public:
nsPoint oneParentLayerPixel =
CSSPoint::ToAppUnits(ParentLayerPoint(1, 1) / aFrameMetrics.GetZoom());
if (mXAxisModel.IsFinished(oneParentLayerPixel.x) &&
mYAxisModel.IsFinished(oneParentLayerPixel.y)) {
// Set the scroll offset to the exact destination. If we allow the scroll
// 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;
}
mXAxisModel.Simulate(aDelta);
mYAxisModel.Simulate(aDelta);
CSSPoint position = CSSPoint::FromAppUnits(nsPoint(mXAxisModel.GetPosition(),
mYAxisModel.GetPosition()));
@@ -3784,19 +3783,17 @@ void AsyncPanZoomController::NotifyLayer
// result in a displayport that doesn't extend upwards at all.
// Note that even if the CancelAnimation call above requested a repaint
// this is fine because we already have repaint request deduplication.
needContentRepaint = true;
} else if (scrollableRectChanged) {
// 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());
}
}
if (smoothScrollRequested) {
// A smooth scroll has been requested for animation on the compositor
// thread. This flag will be reset by the main thread when it receives
// the scroll update acknowledgement.