Skip to content

Commit

Permalink
Bug 1806438 - Make sure not to save/restore bounds when going from/in…
Browse files Browse the repository at this point in the history
…to minimized state. r=rkraesig

Otherwise we might restore nonsensical bounds because Windows moves
minimized windows to crazy positions like -32000, -32000.

Differential Revision: https://phabricator.services.mozilla.com/D165913
  • Loading branch information
emilio committed Jan 10, 2023
1 parent 53a2f11 commit 00eb6f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3659,15 +3659,22 @@ void nsWindow::OnFullscreenWillChange(bool aFullScreen) {
}
}

void nsWindow::OnFullscreenChanged(bool aFullScreen) {
void nsWindow::OnFullscreenChanged(nsSizeMode aOldSizeMode, bool aFullScreen) {
// If we are going fullscreen, the window size continues to change
// and the window will be reflow again then.
UpdateNonClientMargins(/* Reflow */ !aFullScreen);

// Will call hide chrome, reposition window. Note this will
// also cache dimensions for restoration, so it should only
// be called once per fullscreen request.
nsBaseWidget::InfallibleMakeFullScreen(aFullScreen);
// Hide chrome and reposition window. Note this will also cache dimensions for
// restoration, so it should only be called once per fullscreen request.
//
// Don't do this when minimized, since our bounds make no sense then, nor when
// coming back from that state.
const bool toOrFromMinimized =
mFrameState->GetSizeMode() == nsSizeMode_Minimized ||
aOldSizeMode == nsSizeMode_Minimized;
if (!toOrFromMinimized) {
InfallibleMakeFullScreen(aFullScreen);
}

if (mIsVisible && !aFullScreen &&
mFrameState->GetSizeMode() == nsSizeMode_Normal) {
Expand Down Expand Up @@ -9375,7 +9382,8 @@ void nsWindow::FrameState::SetSizeModeInternal(nsSizeMode aMode) {
mWindow->OnFullscreenWillChange(fullscreen);
}

mLastSizeMode = mSizeMode;
const auto oldSizeMode = mSizeMode;
mLastSizeMode = oldSizeMode;
mSizeMode = aMode;

if (mWindow->mIsVisible) {
Expand All @@ -9389,7 +9397,7 @@ void nsWindow::FrameState::SetSizeModeInternal(nsSizeMode aMode) {
}

if (fullscreenChange) {
mWindow->OnFullscreenChanged(fullscreen);
mWindow->OnFullscreenChanged(oldSizeMode, fullscreen);
}
}

Expand Down
2 changes: 1 addition & 1 deletion widget/windows/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class nsWindow final : public nsBaseWidget {
uint32_t aOrientation = 90);

void OnFullscreenWillChange(bool aFullScreen);
void OnFullscreenChanged(bool aFullScreen);
void OnFullscreenChanged(nsSizeMode aOldSizeMode, bool aFullScreen);

static void OnCloakEvent(HWND aWnd, bool aCloaked);
void OnCloakChanged(bool aCloaked);
Expand Down

0 comments on commit 00eb6f3

Please sign in to comment.