See https://bugzilla.mozilla.org/show_bug.cgi?id=562138#c8

# HG changeset patch
# User Markus Stange <mstange@themasta.com>
# Date 1296111298 -3600
# Node ID 433f39574cd72d30e47e6500fad52a0398753367
# Parent  f948c56cb86f83354f0bd9d579cd51167464b4f2
Backed out changeset f948c56cb86f (bug 562138 part 2) because it depends on changeset 44c42d8b8d08 which is going to be backed out.

diff --git a/widget/src/cocoa/nsCocoaWindow.h b/widget/src/cocoa/nsCocoaWindow.h
--- a/widget/src/cocoa/nsCocoaWindow.h
+++ b/widget/src/cocoa/nsCocoaWindow.h
@@ -291,17 +291,16 @@ public:
     NS_IMETHOD ResetInputState();
     
     NS_IMETHOD BeginSecureKeyboardInput();
     NS_IMETHOD EndSecureKeyboardInput();
 
     static void UnifiedShading(void* aInfo, const CGFloat* aIn, CGFloat* aOut);
 
     void SetPopupWindowLevel();
-    PRBool IsVisible();
 
     PRBool IsChildInFailingLeftClickThrough(NSView *aChild);
     PRBool ShouldFocusPlugin();
 
     NS_IMETHOD         ReparentNativeWidget(nsIWidget* aNewParent);
 protected:
 
   nsresult             CreateNativeWindow(const NSRect &aRect,
@@ -335,14 +334,13 @@ protected:
   PRInt32              mShadowStyle;
   NSUInteger           mWindowFilter;
 
   PRPackedBool         mWindowMadeHere; // true if we created the window, false for embedding
   PRPackedBool         mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
                                         // this is used for sibling sheet contention only
   PRPackedBool         mFullScreen;
   PRPackedBool         mModal;
-  PRPackedBool         mIsShowing;      // PR_TRUE during a Show(PR_TRUE) call.
 
   PRInt32              mNumModalDescendents;
 };
 
 #endif // nsCocoaWindow_h_
diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -143,17 +143,16 @@ nsCocoaWindow::nsCocoaWindow()
 , mSheetWindowParent(nil)
 , mPopupContentView(nil)
 , mShadowStyle(NS_STYLE_WINDOW_SHADOW_DEFAULT)
 , mWindowFilter(0)
 , mWindowMadeHere(PR_FALSE)
 , mSheetNeedsShow(PR_FALSE)
 , mFullScreen(PR_FALSE)
 , mModal(PR_FALSE)
-, mIsShowing(PR_FALSE)
 , mNumModalDescendents(0)
 {
 
 }
 
 void nsCocoaWindow::DestroyNativeWindow()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@@ -528,30 +527,24 @@ void* nsCocoaWindow::GetNativeData(PRUin
       break;
   }
 
   return retVal;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
 }
 
-PRBool
-nsCocoaWindow::IsVisible()
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
-
-  return [mWindow isVisible] || mSheetNeedsShow || mIsShowing;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
-}
-
 NS_IMETHODIMP nsCocoaWindow::IsVisible(PRBool & aState)
 {
-  aState = IsVisible();
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+
+  aState = ([mWindow isVisible] || mSheetNeedsShow);
   return NS_OK;
+
+  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState)
 {
   // This is used during startup (outside the event loop) when creating
   // the add-ons compatibility checking dialog and the profile manager UI;
   // therefore, it needs to provide an autorelease pool to avoid cocoa
   // objects leaking.
@@ -626,42 +619,29 @@ NS_IMETHODIMP nsCocoaWindow::SetModal(PR
 
 // Hide or show this window
 NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // We need to re-execute sometimes in order to bring already-visible
   // windows forward.
-  if (!bState && !IsVisible())
+  if (!mSheetNeedsShow && !bState && ![mWindow isVisible])
     return NS_OK;
 
   nsIWidget* parentWidget = mParent;
   nsCOMPtr<nsPIWidgetCocoa> piParentWidget(do_QueryInterface(parentWidget));
   NSWindow* nativeParentWindow = (parentWidget) ?
     (NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW) : nil;
 
   if (bState && !mBounds.IsEmpty()) {
-    // IsVisible can be entered from inside this method, for example through
-    // synchronous painting. Unfortunately, at that point [mWindow isVisible]
-    // still returns NO, so we use mIsShowing to tell us that we should return
-    // true from IsVisible anyway.
-    mIsShowing = PR_TRUE;
-
-    if (mPopupContentView) {
-      // Ensure our content view is visible. We never need to hide it.
-      mPopupContentView->Show(PR_TRUE);
-    }
-
     if (mWindowType == eWindowType_sheet) {
       // bail if no parent window (its basically what we do in Carbon)
-      if (!nativeParentWindow || !piParentWidget) {
-        mIsShowing = PR_FALSE;
+      if (!nativeParentWindow || !piParentWidget)
         return NS_ERROR_FAILURE;
-      }
 
       NSWindow* topNonSheetWindow = nativeParentWindow;
       
       // If this sheet is the child of another sheet, hide the parent so that
       // this sheet can be displayed. Leave the parent mSheetNeedsShow alone,
       // that is only used to handle sibling sheet contention. The parent will
       // return once there are no more child sheets.
       PRBool parentIsSheet = PR_FALSE;
@@ -744,17 +724,16 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool
     }
     else {
       [mWindow setAcceptsMouseMovedEvents:YES];
       NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
       [mWindow makeKeyAndOrderFront:nil];
       NS_OBJC_END_TRY_LOGONLY_BLOCK;
       SendSetZLevelEvent();
     }
-    mIsShowing = PR_FALSE;
   }
   else {
     // roll up any popups if a top-level window is going away
     if (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
       RollUpPopups();
 
     // now get rid of the window/sheet
     if (mWindowType == eWindowType_sheet) {
@@ -850,16 +829,19 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool
       if ([mWindow isKindOfClass:[PopupWindow class]] &&
           [(PopupWindow*) mWindow isContextMenu]) {
         [[NSDistributedNotificationCenter defaultCenter]
           postNotificationName:@"com.apple.HIToolbox.endMenuTrackingNotification"
                         object:@"org.mozilla.gecko.PopupWindow"];
       }
     }
   }
+  
+  if (mPopupContentView)
+      mPopupContentView->Show(bState);
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 struct ShadowParams {
   float standardDeviation;


# HG changeset patch
# User Markus Stange <mstange@themasta.com>
# Date 1296111382 -3600
# Node ID 2cfc443d28ee87835e17b665d41be3a6fb0dca23
# Parent  44c42d8b8d087ed22c02ffe90f7d23f84ee8abbb
Backed out changeset 44c42d8b8d08 (bug 562138 part 1) because it caused bug 627824 and bug 628861.

diff --git a/view/src/nsView.cpp b/view/src/nsView.cpp
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -433,63 +433,51 @@ nsIntRect nsIView::CalcWidgetBounds(nsWi
 void nsView::DoResetWidgetBounds(PRBool aMoveOnly,
                                  PRBool aInvalidateChangedSize) {
   // The geometry of a root view's widget is controlled externally,
   // NOT by sizing or positioning the view
   if (mViewManager->GetRootView() == this) {
     return;
   }
   
-  NS_PRECONDITION(mWindow, "Why was this called??");
-
   nsIntRect curBounds;
   mWindow->GetBounds(curBounds);
 
   nsWindowType type;
   mWindow->GetWindowType(type);
 
   if (curBounds.IsEmpty() && mDimBounds.IsEmpty() && type == eWindowType_popup) {
     // Don't manipulate empty popup widgets. For example there's no point
     // moving hidden comboboxes around, or doing X server roundtrips
     // to compute their true screen position. This could mean that WidgetToScreen
     // operations on these widgets don't return up-to-date values, but popup
     // positions aren't reliable anyway because of correction to be on or off-screen.
     return;
   }
 
+  NS_PRECONDITION(mWindow, "Why was this called??");
+
   nsIntRect newBounds = CalcWidgetBounds(type);
 
   PRBool changedPos = curBounds.TopLeft() != newBounds.TopLeft();
   PRBool changedSize = curBounds.Size() != newBounds.Size();
 
-  PRBool curVisibility;
-  mWindow->IsVisible(curVisibility);
-  PRBool newVisibility = IsEffectivelyVisible();
-
-  if (curVisibility && !newVisibility) {
-    mWindow->Show(PR_FALSE);
-  }
-
   // Child views are never attached to top level widgets, this is safe.
   if (changedPos) {
     if (changedSize && !aMoveOnly) {
       mWindow->Resize(newBounds.x, newBounds.y, newBounds.width, newBounds.height,
                       aInvalidateChangedSize);
     } else {
       mWindow->Move(newBounds.x, newBounds.y);
     }
   } else {
     if (changedSize && !aMoveOnly) {
       mWindow->Resize(newBounds.width, newBounds.height, aInvalidateChangedSize);
     } // else do nothing!
   }
-
-  if (!curVisibility && newVisibility) {
-    mWindow->Show(PR_TRUE);
-  }
 }
 
 void nsView::SetDimensions(const nsRect& aRect, PRBool aPaint, PRBool aResizeWidget)
 {
   nsRect dims = aRect;
   dims.MoveBy(mPosX, mPosY);
 
   // Don't use nsRect's operator== here, since it returns true when
@@ -511,17 +499,23 @@ void nsView::NotifyEffectiveVisibilityCh
 {
   if (!aEffectivelyVisible)
   {
     DropMouseGrabbing();
   }
 
   if (nsnull != mWindow)
   {
-    ResetWidgetBounds(PR_FALSE, PR_TRUE, PR_FALSE);
+    if (aEffectivelyVisible)
+    {
+      DoResetWidgetBounds(PR_FALSE, PR_TRUE);
+      mWindow->Show(PR_TRUE);
+    }
+    else
+      mWindow->Show(PR_FALSE);
   }
 
   for (nsView* child = mFirstChild; child; child = child->mNextSibling) {
     if (child->mVis == nsViewVisibility_kHide) {
       // It was effectively hidden and still is
       continue;
     }
     // Our child is visible if we are