From 061951346e6bafbfd28de2e0440342dd6caca1c7 Mon Sep 17 00:00:00 2001
From: SineStriker <55847490+SineStriker@users.noreply.github.com>
Date: 周二, 10 9月 2024 09:58:49 +0800
Subject: [PATCH] Fix native child widget (#133)

---
 src/core/contexts/win32windowcontext.cpp |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index 64cd0b1..8ad7ae8 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -834,9 +834,7 @@
         }
 
         if (key == QStringLiteral("title-bar-height")) {
-            return m_windowId
-                       ? int(getTitleBarHeight(reinterpret_cast<HWND>(m_windowId)))
-                       : 0;
+            return m_windowId ? int(getTitleBarHeight(reinterpret_cast<HWND>(m_windowId))) : 0;
         }
         return AbstractWindowContext::windowAttribute(key);
     }
@@ -1695,7 +1693,8 @@
                         // outside the window, that is, the three transparent window resize area.
                         // Returning HTCLIENT will confuse Windows, we can't put our controls there
                         // anyway.
-                        *result = HTNOWHERE; // Make sure we can know we don't set any value explicitly later.
+                        *result = HTNOWHERE; // Make sure we can know we don't set any value
+                                             // explicitly later.
                         if (originalHitTestResult == HTCAPTION) {
                         } else if (isFixedSize || dontOverrideCursor) {
                             *result = HTBORDER;
@@ -1724,11 +1723,13 @@
                                 } else {
                                     *result = HTLEFT;
                                 }
-                            } else if (originalHitTestResult == HTLEFT || originalHitTestResult == HTRIGHT) {
+                            } else if (originalHitTestResult == HTLEFT ||
+                                       originalHitTestResult == HTRIGHT) {
                                 if (isFixedWidth) {
                                     *result = HTBORDER;
                                 }
-                            } else if (originalHitTestResult == HTTOP || originalHitTestResult == HTBOTTOM) {
+                            } else if (originalHitTestResult == HTTOP ||
+                                       originalHitTestResult == HTBOTTOM) {
                                 if (isFixedHeight) {
                                     *result = HTBORDER;
                                 }
@@ -1757,7 +1758,8 @@
                         // inside our homemade title bar now, return HTCLIENT to let our
                         // title bar can still capture mouse events.
                         *result = [&]() {
-                            if (isFixedSize || isFixedHeight || dontOverrideCursor || (isFixedWidth && (isInLeftBorder || isInRightBorder))) {
+                            if (isFixedSize || isFixedHeight || dontOverrideCursor ||
+                                (isFixedWidth && (isInLeftBorder || isInRightBorder))) {
                                 if (isInTitleBar) {
                                     return HTCAPTION;
                                 } else {
@@ -2173,7 +2175,10 @@
         // of the upper-left non-client area. It's confirmed that this issue exists
         // from Windows 7 to Windows 10. Not tested on Windows 11 yet. Don't know
         // whether it exists on Windows XP to Windows Vista or not.
-        *result = wParam ? WVR_REDRAW : FALSE;
+
+        // https://github.com/chromium/chromium/blob/5d297da3cf2a642e9ace2b23fed097370bc70814/ui/views/win/hwnd_message_handler.cc#L2330
+        // Do not return WVR_REDRAW otherwise child HWNDs will be mispositioned.
+        *result = FALSE;
         return true;
     }
 

--
Gitblit v1.9.1