Bug 1954012 - Make nsWindow::OnDPIChanged refresh screens before retrieving nsIScreens r=jfkthame

`WM_DPICHANGED` is sent before `WM_DISPLAYCHANGE`.  Therefore, when `nsWindow`
tries to adjust the window size into the new screen, it retrieves old
`nsIScreen` instance.  Therefore, it may shrink the window too much.  Therefore,
it needs to refresh all screens before retrieving a screen.

Differential Revision: https://phabricator.services.mozilla.com/D241613
This commit is contained in:
Masayuki Nakano
2025-03-14 23:25:43 +00:00
parent 9aad21887c
commit a984745d37

View File

@@ -6987,10 +6987,14 @@ void nsWindow::OnDPIChanged(int32_t x, int32_t y, int32_t width,
if (mResizeState != RESIZING &&
mFrameState->GetSizeMode() == nsSizeMode_Normal) {
// Limit the position (if not in the middle of a drag-move) & size,
// if it would overflow the destination screen
nsCOMPtr<nsIScreenManager> sm = do_GetService(sScreenManagerContractID);
if (sm) {
if (nsCOMPtr<nsIScreenManager> sm =
do_GetService(sScreenManagerContractID)) {
// Before getting the screen which will contain this window, we need to
// refresh the screens because WM_DPICHANGED is sent before
// WM_DISPLAYCHANGE.
ScreenHelperWin::RefreshScreens();
// Limit the position (if not in the middle of a drag-move) & size,
// if it would overflow the destination screen
nsCOMPtr<nsIScreen> screen;
sm->ScreenForRect(x, y, width, height, getter_AddRefs(screen));
if (screen) {