Bug 1501665 Part 7: Add a new function to allow visual viewport size to be un-set. r=smaug

Once nsIPresShell::SetVisualViewportSize is called, we currently have
no way to restore the default viewport sizing behavior. This corrects that.
We need the default behavior to get correctly-placed scrollbars when
turning off meta viewport handling in Responsive Design Mode panes.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brad Werth 2019-03-18 14:58:07 +00:00
Родитель 046007b94f
Коммит 1e6b91bfc7
2 изменённых файлов: 30 добавлений и 13 удалений

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

@ -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();
}
}

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

@ -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.
*/