Bug 1742241. Don't access the PresShell's visual viewport offset if we haven't set one. r=botond

If the visual viewport offset is not set on the presshell then calling GetVisualViewportOffset returns (0, 0). This then causes us to introduce an incorrect offset between the layout scroll offset and the visual viewport offset that didn't exist before.

Logically we want to treat an unset visual viewport offset as the layout scroll offset.

Other possible fixes:
-make PresShell::GetVisualViewportOffset return the layout scroll offset if a visual viewport offset is not set
-make this if conditional on a visual viewport offset already being set
-the combination of the two above
All of these fail some tests on try server. I haven't investigated why. If we want to go with any of those potential fixes in the future then this patch is a step on the way there

Differential Revision: https://phabricator.services.mozilla.com/D137873
This commit is contained in:
Timothy Nikkel 2022-02-11 11:56:44 +00:00
parent 2f01d4dbd4
commit 4ea6801e49

View File

@ -3234,8 +3234,13 @@ void ScrollFrameHelper::ScrollToImpl(
AutoScrollbarRepaintSuppression repaintSuppression(this, weakFrame,
!schedulePaint);
nsPoint relativeOffset =
presContext->PresShell()->GetVisualViewportOffset() - curPos;
nsPoint visualViewportOffset = curPos;
if (presContext->PresShell()->IsVisualViewportOffsetSet()) {
visualViewportOffset =
presContext->PresShell()->GetVisualViewportOffset();
}
nsPoint relativeOffset = visualViewportOffset - curPos;
presContext->PresShell()->SetVisualViewportOffset(pt + relativeOffset,
curPos);
if (!weakFrame.IsAlive()) {