Bug 1259296 - Make sure APZ smooth scroll animations end at their exact destination scroll offset. r=kats
authorBotond Ballo <botond@mozilla.com>
Mon, 04 Apr 2016 17:47:33 -0400
changeset 348810 14cb56cfc385945c81193d067d74a6beac0be57c
parent 348809 4334ce2047bec8deeffefc35680a711e225316d4
child 348811 719ded1e521d9a8a42e9c42c0c0eaf5c709d706f
push id14928
push userbmo:mh+mozilla@glandium.org
push dateFri, 08 Apr 2016 05:15:03 +0000
reviewerskats
bugs1259296
milestone48.0a1
Bug 1259296 - Make sure APZ smooth scroll animations end at their exact destination scroll offset. r=kats This avoids getting "stuck" at a scroll snap point with wheel scrolling. MozReview-Commit-ID: 587UC8u1bv0
gfx/layers/apz/src/AsyncPanZoomController.cpp
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -742,16 +742,24 @@ public:
    * frame. Returns true if the smooth scroll should be advanced by one frame,
    * or false if the smooth scroll has ended.
    */
   bool DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta) {
     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()))));
       return false;
     }
 
     mXAxisModel.Simulate(aDelta);
     mYAxisModel.Simulate(aDelta);
 
     CSSPoint position = CSSPoint::FromAppUnits(nsPoint(mXAxisModel.GetPosition(),
                                                        mYAxisModel.GetPosition()));