diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 7125a184bfe4..2eba5db4546b 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -10627,6 +10627,22 @@ void nsIPresShell::MarkFixedFramesForReflow(IntrinsicDirty aIntrinsicDirty) { } } +void nsIPresShell::CompleteChangeToVisualViewportSize() { + if (nsIScrollableFrame* rootScrollFrame = GetRootScrollFrameAsScrollable()) { + rootScrollFrame->MarkScrollbarsDirtyForReflow(); + } + MarkFixedFramesForReflow(nsIPresShell::eResize); + + if (auto* window = nsGlobalWindowInner::Cast(mDocument->GetInnerWindow())) { + window->VisualViewport()->PostResizeEvent(); + } + + if (nsIScrollableFrame* rootScrollFrame = GetRootScrollFrameAsScrollable()) { + ScrollAnchorContainer* container = rootScrollFrame->Anchor(); + container->UserScrolled(); + } +} + void nsIPresShell::SetVisualViewportSize(nscoord aWidth, nscoord aHeight) { if (!mVisualViewportSizeSet || mVisualViewportSize.width != aWidth || mVisualViewportSize.height != aHeight) { @@ -10634,21 +10650,17 @@ void nsIPresShell::SetVisualViewportSize(nscoord aWidth, nscoord aHeight) { mVisualViewportSize.width = aWidth; mVisualViewportSize.height = aHeight; - if (nsIScrollableFrame* rootScrollFrame = - GetRootScrollFrameAsScrollable()) { - rootScrollFrame->MarkScrollbarsDirtyForReflow(); - } - MarkFixedFramesForReflow(nsIPresShell::eResize); + CompleteChangeToVisualViewportSize(); + } +} - if (auto* window = nsGlobalWindowInner::Cast(mDocument->GetInnerWindow())) { - window->VisualViewport()->PostResizeEvent(); - } +void nsIPresShell::ResetVisualViewportSize() { + if (mVisualViewportSizeSet) { + mVisualViewportSizeSet = false; + mVisualViewportSize.width = 0; + mVisualViewportSize.height = 0; - if (nsIScrollableFrame* rootScrollFrame = - GetRootScrollFrameAsScrollable()) { - ScrollAnchorContainer* container = rootScrollFrame->Anchor(); - container->UserScrolled(); - } + CompleteChangeToVisualViewportSize(); } } diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index c60e6f02a420..335955e4e830 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -1654,6 +1654,7 @@ class nsIPresShell : public nsStubDocumentObserver { static void ClearMouseCapture(nsIFrame* aFrame); void SetVisualViewportSize(nscoord aWidth, nscoord aHeight); + void ResetVisualViewportSize(); bool IsVisualViewportSizeSet() { return mVisualViewportSizeSet; } nsSize GetVisualViewportSize() { NS_ASSERTION(mVisualViewportSizeSet, @@ -1661,6 +1662,10 @@ class nsIPresShell : public nsStubDocumentObserver { return mVisualViewportSize; } + // This function handles all the work after VisualViewportSize is set + // or reset. + void CompleteChangeToVisualViewportSize(); + /** * The return value indicates whether the offset actually changed. */