chore: Import windows titlebar calculation for RC build 2, b=no-bug, c=no-component

This commit is contained in:
Mr. M
2025-12-07 00:25:24 +01:00
parent fa6bb8d27f
commit 53181ea34c
6 changed files with 243 additions and 13 deletions

37
package-lock.json generated
View File

@@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "MPL-2.0",
"dependencies": {
"@zen-browser/surfer": "^1.11.26"
"@zen-browser/surfer": "^1.12.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.27.0",
@@ -35,6 +35,7 @@
"integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==",
"dev": true,
"license": "Apache-2.0",
"peer": true,
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.5",
"@jridgewell/trace-mapping": "^0.3.24"
@@ -64,6 +65,7 @@
"integrity": "sha512-oH5UPLMWR3L2wEFLnFJ1TZXqHufiTKAiLfqw5zkhS4dKXLJ10yVztfil/twG8EDTA4F/tvVNw9nOl4ZMslB8rQ==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=6.9.0"
}
@@ -106,6 +108,7 @@
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"dev": true,
"license": "ISC",
"peer": true,
"bin": {
"semver": "bin/semver.js"
}
@@ -146,6 +149,7 @@
"integrity": "sha512-LVk7fbXml0H2xH34dFzKQ7TDZ2G4/rVTOrq9V+icbbadjbVxxeFeDsNHv2SrZeWoA+6ZiTyWYWtScEIW07EAcA==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/compat-data": "^7.26.8",
"@babel/helper-validator-option": "^7.25.9",
@@ -163,6 +167,7 @@
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"dev": true,
"license": "ISC",
"peer": true,
"bin": {
"semver": "bin/semver.js"
}
@@ -336,6 +341,7 @@
"integrity": "sha512-U5eyP/CTFPuNE3qk+WZMxFkp/4zUzdceQlfzf7DdGdhp+Fezd7HD+i8Y24ZuTMKX3wQBld449jijbGq6OdGNQg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/template": "^7.27.0",
"@babel/types": "^7.27.0"
@@ -1109,9 +1115,9 @@
"license": "MIT"
},
"node_modules/@zen-browser/surfer": {
"version": "1.11.26",
"resolved": "https://registry.npmjs.org/@zen-browser/surfer/-/surfer-1.11.26.tgz",
"integrity": "sha512-NZcFZ4a/HWvEJlEr5IlQto/xHLOr6tZjkZALue2qHg+rjRKR5v2BEV4hV5mfAo85gKhyM2Ism0sD+0+/VQIESg==",
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/@zen-browser/surfer/-/surfer-1.12.0.tgz",
"integrity": "sha512-I5nxDgGpFGtdOAC9DZkoQp9GJ4cAqCW+0p0DoQRjW/jdnQJUH20ygvPyPr+sgjXISPFclYX+KrVoT2kJqTdlTw==",
"license": "MPL-2.0",
"dependencies": {
"@resvg/resvg-js": "^1.4.0",
@@ -1147,7 +1153,6 @@
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -1819,7 +1824,8 @@
"url": "https://github.com/sponsors/ai"
}
],
"license": "CC-BY-4.0"
"license": "CC-BY-4.0",
"peer": true
},
"node_modules/chalk": {
"version": "4.1.2",
@@ -2006,7 +2012,8 @@
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
"dev": true,
"license": "MIT"
"license": "MIT",
"peer": true
},
"node_modules/core-js-pure": {
"version": "3.41.0",
@@ -2326,7 +2333,8 @@
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.139.tgz",
"integrity": "sha512-GGnRYOTdN5LYpwbIr0rwP/ZHOQSvAF6TG0LSzp28uCBb9JiXHJGmaaKw29qjNJc5bGnnp6kXJqRnGMQoELwi5w==",
"dev": true,
"license": "ISC"
"license": "ISC",
"peer": true
},
"node_modules/emoji-regex": {
"version": "8.0.0",
@@ -2562,6 +2570,7 @@
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=6"
}
@@ -2585,7 +2594,6 @@
"integrity": "sha512-LSehfdpgMeWcTZkWZVIJl+tkZ2nuSkyyB9C27MZqFWXuph7DvaowgcTvKqxvpLW1JZIk8PN7hFY3Rj9LQ7m7lg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.12.1",
@@ -3433,6 +3441,7 @@
"integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=6.9.0"
}
@@ -4430,6 +4439,7 @@
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"json5": "lib/cli.js"
},
@@ -4864,6 +4874,7 @@
"integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
"dev": true,
"license": "ISC",
"peer": true,
"dependencies": {
"yallist": "^3.0.2"
}
@@ -5078,7 +5089,8 @@
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz",
"integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==",
"dev": true,
"license": "MIT"
"license": "MIT",
"peer": true
},
"node_modules/normalize-path": {
"version": "3.0.0",
@@ -5534,7 +5546,6 @@
"integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"prettier": "bin/prettier.cjs"
},
@@ -6949,6 +6960,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"escalade": "^3.2.0",
"picocolors": "^1.1.1"
@@ -7252,7 +7264,8 @@
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
"dev": true,
"license": "ISC"
"license": "ISC",
"peer": true
},
"node_modules/yaml": {
"version": "2.7.0",

View File

@@ -49,7 +49,7 @@
},
"homepage": "https://github.com/zen-browser/desktop#readme",
"dependencies": {
"@zen-browser/surfer": "^1.11.26"
"@zen-browser/surfer": "^1.12.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.27.0",

View File

@@ -0,0 +1,91 @@
From 433cc8224790300fdabe76bd225b644c1812da34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= <emilio@crisal.io>
Date: Thu, 27 Nov 2025 15:28:12 +0000
Subject: [PATCH] Bug 1993474 - Ensure our WNDPROC has precedence over
WinAppSDK's. r=gstoll,win-reviewers
See the comment for reasoning. WM_NCCALCSIZE wasn't getting called, and
we rely on that to get the right client area on things like maximized
windows.
Differential Revision: https://phabricator.services.mozilla.com/D274281
---
widget/windows/nsWindow.cpp | 32 ++++++++++++++++++++++----------
widget/windows/nsWindow.h | 2 ++
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp
index 0b98d157097da..b357df236cfcd 100644
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -1520,12 +1520,31 @@ DWORD nsWindow::WindowExStyle() {
*
**************************************************************/
+bool nsWindow::ShouldAssociateWithWinAppSDK() const {
+ // We currently don't need any SDK functionality for for PiP windows,
+ // and using the SDK on these windows causes them to go under the
+ // taskbar (bug 1995838).
+ //
+ // TODO(emilio): That might not be true anymore after bug 1993474,
+ // consider re-testing and removing that special-case.
+ return IsTopLevelWidget() && !mIsPIPWindow;
+}
+
bool nsWindow::AssociateWithNativeWindow() {
if (!mWnd || !IsWindow(mWnd)) {
NS_ERROR("Invalid window handle");
return false;
}
+ if (ShouldAssociateWithWinAppSDK()) {
+ // Make sure to call this here to associate our window with the
+ // Windows App SDK _before_ setting our WNDPROC, if needed.
+ // This is important because the SDKs WNDPROC might handle messages like
+ // WM_NCCALCSIZE without calling into us, and that can cause sizing issues,
+ // see bug 1993474.
+ WindowsUIUtils::SetIsTitlebarCollapsed(mWnd, mCustomNonClient);
+ }
+
// Connect the this pointer to the native window handle.
// This should be done before SetWindowLongPtrW, because nsWindow::WindowProc
// uses WinUtils::GetNSWindowPtr internally.
@@ -1552,12 +1571,7 @@ void nsWindow::DissociateFromNativeWindow() {
DebugOnly<WNDPROC> wndProcBeforeDissociate =
reinterpret_cast<WNDPROC>(::SetWindowLongPtrW(
mWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(*mPrevWndProc)));
- // If we've used the Windows App SDK to remove the minimize/maximize/close
- // entries from the titlebar, then the Windows App SDK sets its own WNDPROC
- // own the window, so this assertion would fail. But we only do this if
- // Mica is available.
- NS_ASSERTION(WinUtils::MicaAvailable() ||
- wndProcBeforeDissociate == nsWindow::WindowProc,
+ NS_ASSERTION(wndProcBeforeDissociate == nsWindow::WindowProc,
"Unstacked an unexpected native window procedure");
WinUtils::SetNSWindowPtr(mWnd, nullptr);
@@ -2835,9 +2849,7 @@ void nsWindow::SetCustomTitlebar(bool aCustomTitlebar) {
mCustomNonClientMetrics = {};
ResetLayout();
}
- // Not needed for PiP windows, and using the Windows App SDK on
- // these windows causes them to go under the taskbar (bug 1995838)
- if (!mPIPWindow) {
+ if (ShouldAssociateWithWinAppSDK()) {
WindowsUIUtils::SetIsTitlebarCollapsed(mWnd, mCustomNonClient);
}
}
diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h
index 20f016757dfee..2756b248368a3 100644
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -335,6 +335,8 @@ class nsWindow final : public nsIWidget {
bool IsRTL() const { return mIsRTL; }
+ bool ShouldAssociateWithWinAppSDK() const;
+
/**
* AssociateDefaultIMC() associates or disassociates the default IMC for
* the window.

View File

@@ -0,0 +1,58 @@
diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -850,13 +850,10 @@
bool mHasTaskbarIconBeenCreated = false;
// Whether we're in the process of sending a WM_SETTEXT ourselves
bool mSendingSetText = false;
- // Whether we're a PIP window.
- bool mPIPWindow : 1;
-
// Whether we are asked to render a mica backdrop.
bool mMicaBackdrop : 1;
int32_t mCachedHitTestResult = 0;
diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -815,11 +815,10 @@
**************************************************************/
nsWindow::nsWindow()
: nsIWidget(BorderStyle::Default),
mFrameState(std::in_place, this),
- mPIPWindow(false),
mMicaBackdrop(false),
mLastPaintEndTime(TimeStamp::Now()),
mCachedHitTestTime(TimeStamp::Now()),
mSizeConstraintsScale(GetDefaultScale().scale) {
if (!gInitializedVirtualDesktopManager) {
@@ -1026,11 +1025,10 @@
HWND parent =
aParent ? (HWND)aParent->GetNativeData(NS_NATIVE_WINDOW) : nullptr;
mIsRTL = aInitData.mRTL;
- mPIPWindow = aInitData.mPIPWindow;
mOpeningAnimationSuppressed = aInitData.mIsAnimationSuppressed;
mAlwaysOnTop = aInitData.mAlwaysOnTop;
mIsAlert = aInitData.mIsAlert;
mResizable = aInitData.mResizable;
@@ -2805,11 +2803,11 @@
} else if (sizeMode == nsSizeMode_Maximized) {
// We make the entire frame part of the client area. We leave the default
// frame sizes for left, right and bottom since Windows will automagically
// position the edges "offscreen" for maximized windows.
metrics.mOffset.top = metrics.mCaptionHeight;
- } else if (mPIPWindow &&
+ } else if (mIsPIPWindow &&
!StaticPrefs::widget_windows_pip_decorations_enabled()) {
metrics.mOffset = metrics.DefaultMargins();
} else {
metrics.mOffset = NormalWindowNonClientOffset();
}

View File

@@ -0,0 +1,34 @@
From dd4460727998a53e9fa7372afba2a93a9546cec3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= <emilio@crisal.io>
Date: Fri, 28 Nov 2025 15:06:26 +0000
Subject: [PATCH] Bug 2002986 - Use IAppWindowTitlebar::ResetToDefault() for
non-collapsed titlebar. r=win-reviewers,gstoll
This seems to actually go to the default DWM stuff and is the documented
way of doing so:
https://learn.microsoft.com/en-us/windows/apps/develop/title-bar#reset-the-title-bar
Differential Revision: https://phabricator.services.mozilla.com/D274413
---
widget/windows/WindowsUIUtils.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/widget/windows/WindowsUIUtils.cpp b/widget/windows/WindowsUIUtils.cpp
index a5a6c893e7056..abaabfba69dfa 100644
--- a/widget/windows/WindowsUIUtils.cpp
+++ b/widget/windows/WindowsUIUtils.cpp
@@ -1394,7 +1394,11 @@ void WindowsUIUtils::SetIsTitlebarCollapsed(HWND aWnd, bool aIsCollapsed) {
MOZ_ASSERT_UNREACHABLE("IAppWindowTitleBar could not be acquired");
return;
}
- hr = titleBar->put_ExtendsContentIntoTitleBar(aIsCollapsed);
+ if (aIsCollapsed) {
+ hr = titleBar->put_ExtendsContentIntoTitleBar(aIsCollapsed);
+ } else {
+ hr = titleBar->ResetToDefault();
+ }
if (FAILED(hr)) {
MOZ_LOG(gWindowsLog, LogLevel::Error,
("Skipping SetIsTitlebarCollapsed() because "

View File

@@ -0,0 +1,34 @@
From dd4460727998a53e9fa7372afba2a93a9546cec3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= <emilio@crisal.io>
Date: Fri, 28 Nov 2025 15:06:26 +0000
Subject: [PATCH] Bug 2002986 - Use IAppWindowTitlebar::ResetToDefault() for
non-collapsed titlebar. r=win-reviewers,gstoll
This seems to actually go to the default DWM stuff and is the documented
way of doing so:
https://learn.microsoft.com/en-us/windows/apps/develop/title-bar#reset-the-title-bar
Differential Revision: https://phabricator.services.mozilla.com/D274413
---
widget/windows/WindowsUIUtils.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/widget/windows/WindowsUIUtils.cpp b/widget/windows/WindowsUIUtils.cpp
index a5a6c893e7056..abaabfba69dfa 100644
--- a/widget/windows/WindowsUIUtils.cpp
+++ b/widget/windows/WindowsUIUtils.cpp
@@ -1394,7 +1394,11 @@ void WindowsUIUtils::SetIsTitlebarCollapsed(HWND aWnd, bool aIsCollapsed) {
MOZ_ASSERT_UNREACHABLE("IAppWindowTitleBar could not be acquired");
return;
}
- hr = titleBar->put_ExtendsContentIntoTitleBar(aIsCollapsed);
+ if (aIsCollapsed) {
+ hr = titleBar->put_ExtendsContentIntoTitleBar(aIsCollapsed);
+ } else {
+ hr = titleBar->ResetToDefault();
+ }
if (FAILED(hr)) {
MOZ_LOG(gWindowsLog, LogLevel::Error,
("Skipping SetIsTitlebarCollapsed() because "