Bug 1752214 - Don't use screen coordinates for the last resort autoscroll. r=tnikkel

Screen coordinates may not be quite accurate enough on Wayland, see the
blocked bug. It seems however that this should do the job and should be
simpler as well.

Differential Revision: https://phabricator.services.mozilla.com/D137069
This commit is contained in:
Emilio Cobos Álvarez 2022-01-27 10:11:24 +00:00
Родитель 50fa24f109
Коммит 7f74d54dd1
1 изменённых файлов: 11 добавлений и 13 удалений

Просмотреть файл

@ -1809,7 +1809,9 @@ nsresult AutoScroller::DoAutoScroll(nsIFrame* aFrame, nsPoint aPoint) {
nsPresContext* presContext = aFrame->PresContext();
RefPtr<PresShell> presShell = presContext->PresShell();
nsRootPresContext* rootPC = presContext->GetRootPresContext();
if (!rootPC) return NS_OK;
if (!rootPC) {
return NS_OK;
}
nsIFrame* rootmostFrame = rootPC->PresShell()->GetRootFrame();
AutoWeakFrame weakRootFrame(rootmostFrame);
AutoWeakFrame weakFrame(aFrame);
@ -1827,22 +1829,18 @@ nsresult AutoScroller::DoAutoScroll(nsIFrame* aFrame, nsPoint aPoint) {
return NS_OK;
}
if (!didScroll && !done) {
// If aPoint is at the screen edge then try to scroll anyway, once.
RefPtr<nsDeviceContext> dx =
presShell->GetViewManager()->GetDeviceContext();
nsRect screen;
dx->GetRect(screen);
nsPoint screenPoint =
globalPoint + rootmostFrame->GetScreenRectInAppUnits().TopLeft();
// If aPoint is at the very edge of the root, then try to scroll anyway,
// once.
nsRect rootRect = rootmostFrame->GetRect();
nscoord onePx = AppUnitsPerCSSPixel();
nscoord scrollAmount = 10 * onePx;
if (std::abs(screen.x - screenPoint.x) <= onePx) {
if (std::abs(rootRect.x - globalPoint.x) <= onePx) {
aPoint.x -= scrollAmount;
} else if (std::abs(screen.XMost() - screenPoint.x) <= onePx) {
} else if (std::abs(rootRect.XMost() - globalPoint.x) <= onePx) {
aPoint.x += scrollAmount;
} else if (std::abs(screen.y - screenPoint.y) <= onePx) {
} else if (std::abs(rootRect.y - globalPoint.y) <= onePx) {
aPoint.y -= scrollAmount;
} else if (std::abs(screen.YMost() - screenPoint.y) <= onePx) {
} else if (std::abs(rootRect.YMost() - globalPoint.y) <= onePx) {
aPoint.y += scrollAmount;
} else {
break;
@ -1857,7 +1855,7 @@ nsresult AutoScroller::DoAutoScroll(nsIFrame* aFrame, nsPoint aPoint) {
// `ScrollFrameRectIntoView` above may have run script and this may have
// forbidden to continue scrolling.
if (didScroll &&
(mFurtherScrollingAllowed == FurtherScrollingAllowed::kYes)) {
mFurtherScrollingAllowed == FurtherScrollingAllowed::kYes) {
nsPoint presContextPoint =
globalPoint -
presShell->GetRootFrame()->GetOffsetToCrossDoc(rootmostFrame);