Bug 1602258. Use GetAvailableScrollingDirectionsForUserInputEvents in WheelHandlingUtils::CanScrollOn. r=botond

We also need to adjust the scroll range we use. We do this by adding GetScrollRangeForUserInputEvents which just uses the range that GetAvailableScrollingDirectionsForUserInputEvents computed.

This should give two improvements:
1) CanScrollOn will not report that the user can scroll in an overflow hidden direction.
2) CanScrollOn will report that the user can scroll in an overflow hidden direction if the document is pinch zoomed in so that the user can scroll around the layout viewport.

Differential Revision: https://phabricator.services.mozilla.com/D56301

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Timothy Nikkel 2019-12-18 23:08:24 +00:00
parent 8d223d13dd
commit 36ab8e6657
4 changed files with 25 additions and 7 deletions

View File

@ -70,8 +70,9 @@ bool WheelHandlingUtils::CanScrollOn(nsIScrollableFrame* aScrollFrame,
"One of the delta values must be non-zero at least");
nsPoint scrollPt = aScrollFrame->GetVisualViewportOffset();
nsRect scrollRange = aScrollFrame->GetVisualScrollRange();
uint32_t directions = aScrollFrame->GetAvailableVisualScrollingDirections();
nsRect scrollRange = aScrollFrame->GetScrollRangeForUserInputEvents();
uint32_t directions =
aScrollFrame->GetAvailableScrollingDirectionsForUserInputEvents();
return (aDirectionX && (directions & nsIScrollableFrame::HORIZONTAL) &&
CanScrollInRange(scrollRange.x, scrollPt.x, scrollRange.XMost(),

View File

@ -6659,10 +6659,9 @@ uint32_t nsIScrollableFrame::GetAvailableVisualScrollingDirections() const {
return directions;
}
uint32_t ScrollFrameHelper::GetAvailableScrollingDirectionsForUserInputEvents()
const {
// This function basically computes a scroll range based on a scrolled rect
// and scroll port defined as follows:
nsRect ScrollFrameHelper::GetScrollRangeForUserInputEvents() const {
// This function computes a scroll range based on a scrolled rect and scroll
// port defined as follows:
// scrollable rect = overflow:hidden ? layout viewport : scrollable rect
// scroll port = have visual viewport ? visual viewport : layout viewport
// The results in the same notion of scroll range that APZ uses (the combined
@ -6681,10 +6680,17 @@ uint32_t ScrollFrameHelper::GetAvailableScrollingDirectionsForUserInputEvents()
nsSize scrollPort = GetVisualViewportSize();
nsSize scrollRange;
nsRect scrollRange = scrolledRect;
scrollRange.width = std::max(scrolledRect.width - scrollPort.width, 0);
scrollRange.height = std::max(scrolledRect.height - scrollPort.height, 0);
return scrollRange;
}
uint32_t ScrollFrameHelper::GetAvailableScrollingDirectionsForUserInputEvents()
const {
nsRect scrollRange = GetScrollRangeForUserInputEvents();
// We check if there is at least one half of a screen pixel of scroll range to
// roughly match what apz does when it checks if the change in scroll position
// in screen pixels round to zero or not.

View File

@ -177,6 +177,7 @@ class ScrollFrameHelper : public nsIReflowCallback {
nsSize GetVisualViewportSize() const;
nsPoint GetVisualViewportOffset() const;
nsRect GetVisualScrollRange() const;
nsRect GetScrollRangeForUserInputEvents() const;
/**
* Return the 'optimal viewing region' as a rect suitable for use by
@ -909,6 +910,9 @@ class nsHTMLScrollFrame : public nsContainerFrame,
nsRect GetVisualScrollRange() const final {
return mHelper.GetVisualScrollRange();
}
nsRect GetScrollRangeForUserInputEvents() const final {
return mHelper.GetScrollRangeForUserInputEvents();
}
nsSize GetLineScrollAmount() const final {
return mHelper.GetLineScrollAmount();
}
@ -1374,6 +1378,9 @@ class nsXULScrollFrame final : public nsBoxFrame,
nsRect GetVisualScrollRange() const final {
return mHelper.GetVisualScrollRange();
}
nsRect GetScrollRangeForUserInputEvents() const final {
return mHelper.GetScrollRangeForUserInputEvents();
}
nsSize GetLineScrollAmount() const final {
return mHelper.GetLineScrollAmount();
}

View File

@ -206,6 +206,10 @@ class nsIScrollableFrame : public nsIScrollbarMediator {
* Get the area that must contain the visual viewport offset.
*/
virtual nsRect GetVisualScrollRange() const = 0;
/**
* Like GetVisualScrollRange but also takes into account overflow: hidden.
*/
virtual nsRect GetScrollRangeForUserInputEvents() const = 0;
/**
* Return how much we would try to scroll by in each direction if
* asked to scroll by one "line" vertically and horizontally.