From 1707a114203d41f19fefb4b8bb25ac6a84aab4ad Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 18 Jan 2011 08:24:19 +0100 Subject: [PATCH 1/2] Bug 562138 - Paint popup widgets synchronously when showing them by making the window's content view visible earlier. r=josh, a=final --- widget/src/cocoa/nsCocoaWindow.h | 2 ++ widget/src/cocoa/nsCocoaWindow.mm | 38 +++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/widget/src/cocoa/nsCocoaWindow.h b/widget/src/cocoa/nsCocoaWindow.h index 875c62e5557a..595d5124b236 100644 --- a/widget/src/cocoa/nsCocoaWindow.h +++ b/widget/src/cocoa/nsCocoaWindow.h @@ -296,6 +296,7 @@ public: static void UnifiedShading(void* aInfo, const CGFloat* aIn, CGFloat* aOut); void SetPopupWindowLevel(); + PRBool IsVisible(); PRBool IsChildInFailingLeftClickThrough(NSView *aChild); PRBool ShouldFocusPlugin(); @@ -339,6 +340,7 @@ protected: // this is used for sibling sheet contention only PRPackedBool mFullScreen; PRPackedBool mModal; + PRPackedBool mIsShowing; // PR_TRUE during a Show(PR_TRUE) call. PRInt32 mNumModalDescendents; }; diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 5f889ca5fb0b..0f0e9af9bbd1 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -148,6 +148,7 @@ nsCocoaWindow::nsCocoaWindow() , mSheetNeedsShow(PR_FALSE) , mFullScreen(PR_FALSE) , mModal(PR_FALSE) +, mIsShowing(PR_FALSE) , mNumModalDescendents(0) { @@ -532,14 +533,20 @@ void* nsCocoaWindow::GetNativeData(PRUint32 aDataType) 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) { - NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - - aState = ([mWindow isVisible] || mSheetNeedsShow); + aState = IsVisible(); return NS_OK; - - NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState) @@ -624,7 +631,7 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) // We need to re-execute sometimes in order to bring already-visible // windows forward. - if (!mSheetNeedsShow && !bState && ![mWindow isVisible]) + if (!bState && !IsVisible()) return NS_OK; nsIWidget* parentWidget = mParent; @@ -633,10 +640,23 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) (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) + if (!nativeParentWindow || !piParentWidget) { + mIsShowing = PR_FALSE; return NS_ERROR_FAILURE; + } NSWindow* topNonSheetWindow = nativeParentWindow; @@ -729,6 +749,7 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) NS_OBJC_END_TRY_LOGONLY_BLOCK; SendSetZLevelEvent(); } + mIsShowing = PR_FALSE; } else { // roll up any popups if a top-level window is going away @@ -834,9 +855,6 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) } } } - - if (mPopupContentView) - mPopupContentView->Show(bState); return NS_OK; From bea9483dfd2d875e04d38d88d8facb73314425dd Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Thu, 27 Jan 2011 07:54:58 +0100 Subject: [PATCH 2/2] Backed out changeset f948c56cb86f (bug 562138 part 2) because it depends on changeset 44c42d8b8d08 which is going to be backed out. --- widget/src/cocoa/nsCocoaWindow.h | 2 -- widget/src/cocoa/nsCocoaWindow.mm | 38 ++++++++----------------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/widget/src/cocoa/nsCocoaWindow.h b/widget/src/cocoa/nsCocoaWindow.h index 595d5124b236..875c62e5557a 100644 --- a/widget/src/cocoa/nsCocoaWindow.h +++ b/widget/src/cocoa/nsCocoaWindow.h @@ -296,7 +296,6 @@ public: static void UnifiedShading(void* aInfo, const CGFloat* aIn, CGFloat* aOut); void SetPopupWindowLevel(); - PRBool IsVisible(); PRBool IsChildInFailingLeftClickThrough(NSView *aChild); PRBool ShouldFocusPlugin(); @@ -340,7 +339,6 @@ protected: // this is used for sibling sheet contention only PRPackedBool mFullScreen; PRPackedBool mModal; - PRPackedBool mIsShowing; // PR_TRUE during a Show(PR_TRUE) call. PRInt32 mNumModalDescendents; }; diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 0f0e9af9bbd1..5f889ca5fb0b 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -148,7 +148,6 @@ nsCocoaWindow::nsCocoaWindow() , mSheetNeedsShow(PR_FALSE) , mFullScreen(PR_FALSE) , mModal(PR_FALSE) -, mIsShowing(PR_FALSE) , mNumModalDescendents(0) { @@ -533,20 +532,14 @@ void* nsCocoaWindow::GetNativeData(PRUint32 aDataType) 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) @@ -631,7 +624,7 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) // 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; @@ -640,23 +633,10 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) (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; @@ -749,7 +729,6 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) NS_OBJC_END_TRY_LOGONLY_BLOCK; SendSetZLevelEvent(); } - mIsShowing = PR_FALSE; } else { // roll up any popups if a top-level window is going away @@ -855,6 +834,9 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) } } } + + if (mPopupContentView) + mPopupContentView->Show(bState); return NS_OK;