Bug 575005 - Trigger reflow when the client area changes due to fx button being hidden/shown. r=roc.
authorJim Mathies <jmathies@mozilla.com>
Fri, 16 Jul 2010 01:20:02 -0500
changeset 47788 06a815baa315e91271eaa5f79701d7b1aa30e1fe
parent 47787 6b22b96b2d6f6a6116f48bf4a7767bba4e3f17c5
child 47789 bd21c5390faff8966f067180763fc1a64d57d530
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs575005
milestone2.0b2pre
Bug 575005 - Trigger reflow when the client area changes due to fx button being hidden/shown. r=roc.
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -1881,18 +1881,45 @@ nsWindow::GetNonClientMargins(nsIntMargi
   margins.top = GetSystemMetrics(SM_CYCAPTION);
   margins.bottom = GetSystemMetrics(SM_CYFRAME);
   margins.top += margins.bottom;
   margins.left = margins.right = GetSystemMetrics(SM_CYFRAME);
 
   return NS_OK;
 }
 
+void
+nsWindow::ResetLayout()
+{
+  // This will trigger a frame changed event, triggering
+  // nc calc size and a sizemode gecko event.
+  SetWindowPos(mWnd, 0, 0, 0, 0, 0,
+               SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|
+               SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
+
+  // If hidden, just send the frame changed event for now.
+  if (!mIsVisible)
+    return;
+
+  // Send a gecko size event to trigger reflow.
+  RECT clientRc = {0};
+  GetClientRect(mWnd, &clientRc);
+  nsIntRect evRect(nsWindowGfx::ToIntRect(clientRc));
+  OnResize(evRect);
+
+  // Invalidate and update
+  Invalidate(PR_FALSE);
+}
+
+// Called when the window layout changes: full screen mode transitions,
+// theme changes, and composition changes. Calculates the new non-client
+// margins and fires off a frame changed event, which triggers an nc calc
+// size windows event, kicking the changes in.
 PRBool
-nsWindow::UpdateNonClientMargins(PRInt32 aSizeMode, PRBool aRefreshWindow)
+nsWindow::UpdateNonClientMargins(PRInt32 aSizeMode, PRBool aReflowWindow)
 {
   if (!mCustomNonClient)
     return PR_FALSE;
 
   // XXX Temp disable margins until frame rendering is supported
   mCompositorFlag = PR_TRUE;
   if(!nsUXThemeData::CheckForCompositor()) {
     mCompositorFlag = PR_FALSE;
@@ -1952,21 +1979,20 @@ nsWindow::UpdateNonClientMargins(PRInt32
     mNonClientOffset.top = 0;
   if (mNonClientOffset.left < 0)
     mNonClientOffset.left = 0;
   if (mNonClientOffset.right < 0)
     mNonClientOffset.right = 0;
   if (mNonClientOffset.bottom < 0)
     mNonClientOffset.bottom = 0;
 
-  if (aRefreshWindow) {
-    SetWindowPos(mWnd, 0, 0, 0, 0, 0,
-                 SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|
-                 SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
-    UpdateWindow(mWnd);
+  if (aReflowWindow) {
+    // Force a reflow of content based on the new client
+    // dimensions.
+    ResetLayout();
   }
 
   return PR_TRUE;
 }
 
 NS_IMETHODIMP
 nsWindow::SetNonClientMargins(nsIntMargin &margins)
 {
@@ -1975,20 +2001,19 @@ nsWindow::SetNonClientMargins(nsIntMargi
       mHideChrome)
     return NS_ERROR_INVALID_ARG;
 
   // Request for a reset
   if (margins.top == -1 && margins.left == -1 &&
       margins.right == -1 && margins.bottom == -1) {
     mCustomNonClient = PR_FALSE;
     mNonClientMargins = margins;
-    SetWindowPos(mWnd, 0, 0, 0, 0, 0,
-                 SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|
-                 SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
-    UpdateWindow(mWnd);
+    // Force a reflow of content based on the new client
+    // dimensions.
+    ResetLayout();
     return NS_OK;
   }
 
   if (margins.top < -1 || margins.bottom < -1 ||
       margins.left < -1 || margins.right < -1)
     return NS_ERROR_INVALID_ARG;
 
   mNonClientMargins = margins;
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -282,17 +282,18 @@ protected:
    * Window utilities
    */
   static BOOL             SetNSWindowPtr(HWND aWnd, nsWindow * ptr);
   LPARAM                  lParamToScreen(LPARAM lParam);
   LPARAM                  lParamToClient(LPARAM lParam);
   nsWindow*               GetParentWindow(PRBool aIncludeOwner);
   virtual void            SubclassWindow(BOOL bState);
   PRBool                  CanTakeFocus();
-  PRBool                  UpdateNonClientMargins(PRInt32 aSizeMode = -1, PRBool aRefreshWindow = PR_TRUE);
+  PRBool                  UpdateNonClientMargins(PRInt32 aSizeMode = -1, PRBool aReflowWindow = PR_TRUE);
+  void                    ResetLayout();
 #if !defined(WINCE)
   static void             InitTrackPointHack();
 #endif
 
   /**
    * Event processing helpers
    */
   void                    DispatchPendingEvents();