Bug 542617 - 'Deferred message loop mishandles WM_NCCALCSIZE'. r=jimm.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 28 Jan 2010 10:03:37 -0800
changeset 37610 977cb280a6c5e5309131bc3b9dd2b1dfacd89aa3
parent 37609 ac98eb7edabc0b8b693c32367794c26fefbff06f
child 37611 234146dafae30becc8f1ea7449b122d06d90b3e3
push idunknown
push userunknown
push dateunknown
reviewersjimm
bugs542617
milestone1.9.3a1pre
Bug 542617 - 'Deferred message loop mishandles WM_NCCALCSIZE'. r=jimm.
ipc/glue/WindowsMessageLoop.cpp
ipc/glue/WindowsMessageLoop.h
--- a/ipc/glue/WindowsMessageLoop.cpp
+++ b/ipc/glue/WindowsMessageLoop.cpp
@@ -236,20 +236,17 @@ ProcessOrDeferMessage(HWND hwnd,
     }
 
     // These messages are faked via a call to SetWindowPos.
     case WM_WINDOWPOSCHANGED: {
       deferred = new DeferredWindowPosMessage(hwnd, lParam);
       break;
     }
     case WM_NCCALCSIZE: {
-      UINT flags = SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE |
-                   SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER |
-                   SWP_DEFERERASE | SWP_NOSENDCHANGING;
-      deferred = new DeferredWindowPosMessage(hwnd, lParam, true, flags);
+      deferred = new DeferredWindowPosMessage(hwnd, lParam, true, wParam);
       break;
     }
 
     // Messages that are safe to pass to DefWindowProc go here.
     case WM_GETICON:
     case WM_GETMINMAXINFO:
     case WM_GETTEXT:
     case WM_NCHITTEST:
@@ -658,26 +655,48 @@ DeferredSettingChangeMessage::~DeferredS
 {
   if (lParamString) {
     free(lParamString);
   }
 }
 
 DeferredWindowPosMessage::DeferredWindowPosMessage(HWND aHWnd,
                                                    LPARAM aLParam,
-                                                   bool aUseCustomFlags,
-                                                   UINT aFlags)
+                                                   bool aForCalcSize,
+                                                   WPARAM aWParam)
 {
-  WINDOWPOS* source = reinterpret_cast<WINDOWPOS*>(aLParam);
-  memcpy(&windowPos, source, sizeof(windowPos));
-  NS_ASSERTION(aHWnd == source->hwnd, "Mismatched hwnds!");
-  if (aUseCustomFlags) {
-    windowPos.flags = aFlags;
+  if (aForCalcSize) {
+    if (aWParam) {
+      NCCALCSIZE_PARAMS* arg = reinterpret_cast<NCCALCSIZE_PARAMS*>(aLParam);
+      memcpy(&windowPos, arg->lppos, sizeof(windowPos));
+
+      NS_ASSERTION(aHWnd == windowPos.hwnd, "Mismatched hwnds!");
+    }
+    else {
+      RECT* arg = reinterpret_cast<RECT*>(aLParam);
+      windowPos.hwnd = aHWnd;
+      windowPos.hwndInsertAfter = NULL;
+      windowPos.x = arg->left;
+      windowPos.y = arg->top;
+      windowPos.cx = arg->right - arg->left;
+      windowPos.cy = arg->bottom - arg->top;
+
+      NS_ASSERTION(arg->right >= arg->left && arg->bottom >= arg->top,
+                   "Negative width or height!");
+    }
+    windowPos.flags = SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOOWNERZORDER |
+                      SWP_NOZORDER | SWP_DEFERERASE | SWP_NOSENDCHANGING;
   }
   else {
+    // Not for WM_NCCALCSIZE
+    WINDOWPOS* arg = reinterpret_cast<WINDOWPOS*>(aLParam);
+    memcpy(&windowPos, arg, sizeof(windowPos));
+
+    NS_ASSERTION(aHWnd == windowPos.hwnd, "Mismatched hwnds!");
+
     // Windows sends in some private flags sometimes that we can't simply copy.
     // Filter here.
     UINT mask = SWP_ASYNCWINDOWPOS | SWP_DEFERERASE | SWP_DRAWFRAME |
                 SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_NOACTIVATE |
                 SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
                 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE |
                 SWP_NOZORDER | SWP_SHOWWINDOW;
     windowPos.flags &= mask;
--- a/ipc/glue/WindowsMessageLoop.h
+++ b/ipc/glue/WindowsMessageLoop.h
@@ -140,18 +140,18 @@ private:
 
 // This class uses SetWindowPos to fake various size-related messages. Flags
 // passed to the constructor go straight through to SetWindowPos.
 class DeferredWindowPosMessage : public DeferredMessage
 {
 public:
   DeferredWindowPosMessage(HWND aHWnd,
                            LPARAM aLParam,
-                           bool aUseCustomFlags = false,
-                           UINT aFlags = 0);
+                           bool aForCalcSize = false,
+                           WPARAM aWParam = 0);
 
   virtual void Run();
 
 private:
   WINDOWPOS windowPos;
 };
 
 } /* namespace windows */