Commit fbbbe95e authored by Hiroyuki Ikezoe's avatar Hiroyuki Ikezoe
Browse files

Bug 1766805 - Give the proper destination to GetSnapPointForDestination for...

Bug 1766805 - Give the proper destination to GetSnapPointForDestination for ScrollUnit::WHOLE on the main-thread. r=botond

Now the proper destination is same as what we do for ScrollUnit::WHOLE [1].

With the proper points we no longer need special handlings in
CalcSnapPoints::AddEdge for ScrollUnit::WHOLE. In my sense the special handling
wasn't necessary though.

[1] https://searchfox.org/mozilla-central/rev/dc09246dfbfd8dafeb6d55ebee18a6294d525443/gfx/layers/apz/src/AsyncPanZoomController.cpp#2105-2112

Differential Revision: https://phabricator.services.mozilla.com/D145190
parent 9e02f38a
Loading
Loading
Loading
Loading
+9 −22
Original line number Diff line number Diff line
@@ -118,12 +118,7 @@ void CalcSnapPoints::AddEdge(nscoord aEdge, nscoord aDestination,
      // The scroll direction is neutral - will not hit a snap point.
      return;
    }
    // ScrollUnit::WHOLE indicates that we are navigating to "home" or
    // "end".  In this case, we will always select the first or last snap point
    // regardless of the direction of the scroll.  Otherwise, we will select
    // scroll snapping points only in the direction specified by
    // aScrollingDirection.
    if (mUnit != ScrollUnit::WHOLE) {

    // Direction of the edge from the current position (before scrolling) in
    // the direction of scrolling
    nscoord direction = (aEdge - aStartPos) * aScrollingDirection;
@@ -132,7 +127,6 @@ void CalcSnapPoints::AddEdge(nscoord aEdge, nscoord aDestination,
      return;
    }
  }
  }
  if (!*aEdgeFound) {
    *aBestEdge = aEdge;
    *aEdgeFound = true;
@@ -162,7 +156,8 @@ void CalcSnapPoints::AddEdge(nscoord aEdge, nscoord aDestination,
    }
  };

  if (mUnit == ScrollUnit::DEVICE_PIXELS || mUnit == ScrollUnit::LINES) {
  if (mUnit == ScrollUnit::DEVICE_PIXELS || mUnit == ScrollUnit::LINES ||
      mUnit == ScrollUnit::WHOLE) {
    nscoord distance = std::abs(aEdge - aDestination);
    updateBestEdges(
        distance < std::abs(*aBestEdge - aDestination),
@@ -191,14 +186,6 @@ void CalcSnapPoints::AddEdge(nscoord aEdge, nscoord aDestination,
    if (overshoot > 0) {
      updateBestEdges(overshoot < curOvershoot, overshoot < secondOvershoot);
    }
  } else if (mUnit == ScrollUnit::WHOLE) {
    // the edge closest to the top/bottom/left/right is used, depending on
    // scrolling direction
    if (aScrollingDirection > 0) {
      updateBestEdges(aEdge > *aBestEdge, aEdge > *aSecondBestEdge);
    } else if (aScrollingDirection < 0) {
      updateBestEdges(aEdge < *aBestEdge, aEdge < *aSecondBestEdge);
    }
  } else {
    NS_ERROR("Invalid scroll mode");
    return;
+13 −7
Original line number Diff line number Diff line
@@ -4758,11 +4758,18 @@ nsRect ScrollFrameHelper::GetVisualOptimalViewingRect() const {
  return rect;
}

static void AdjustForWholeDelta(int32_t aDelta, nscoord* aCoord) {
  if (aDelta < 0) {
    *aCoord = nscoord_MIN;
  } else if (aDelta > 0) {
    *aCoord = nscoord_MAX;
static void AdjustDestinationForWholeDelta(const nsIntPoint& aDelta,
                                           const nsRect& aScrollRange,
                                           nsPoint& aPoint) {
  if (aDelta.x < 0) {
    aPoint.x = aScrollRange.X();
  } else if (aDelta.x > 0) {
    aPoint.x = aScrollRange.XMost();
  }
  if (aDelta.y < 0) {
    aPoint.y = aScrollRange.Y();
  } else if (aDelta.y > 0) {
    aPoint.y = aScrollRange.YMost();
  }
}

@@ -4869,8 +4876,7 @@ void ScrollFrameHelper::ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit,
        break;
      } else {
        nsPoint pos = GetScrollPosition();
        AdjustForWholeDelta(aDelta.x, &pos.x);
        AdjustForWholeDelta(aDelta.y, &pos.y);
        AdjustDestinationForWholeDelta(aDelta, GetLayoutScrollRange(), pos);
        if (aSnap == nsIScrollableFrame::ENABLE_SNAP) {
          GetSnapPointForDestination(aUnit, mDestination, pos);
        }