From 4319c44f5f5125fc0e4762dee6e0dc11895b921d Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Sat, 16 Mar 2002 02:24:13 +0000 Subject: [PATCH] stop reentrant window zooming and switch to user state after sizing. bug 125711 r=pinkerton,scc a=asa --- widget/src/mac/nsMacWindow.cpp | 48 +++++++++++++++++++++++++++++++--- widget/src/mac/nsMacWindow.h | 23 +++++++++------- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/widget/src/mac/nsMacWindow.cpp b/widget/src/mac/nsMacWindow.cpp index bb11ed747a1..e3699443c13 100644 --- a/widget/src/mac/nsMacWindow.cpp +++ b/widget/src/mac/nsMacWindow.cpp @@ -193,11 +193,12 @@ nsMacWindow::nsMacWindow() : Inherited() , mAcceptsActivation(PR_TRUE) , mIsActive(PR_FALSE) , mZoomOnShow(PR_FALSE) + , mZooming(PR_FALSE) + , mResizeIsFromUs(PR_FALSE) #if !TARGET_CARBON , mPhantomScrollbar(nsnull) , mPhantomScrollbarData(nsnull) #endif - , mResizeIsFromUs(PR_FALSE) { mMacEventHandler.reset(new nsMacEventHandler(this)); WIDGET_SET_CLASSNAME("nsMacWindow"); @@ -1188,8 +1189,14 @@ NS_METHOD nsMacWindow::SetSizeMode(PRInt32 aMode) if (aMode == nsSizeMode_Minimized) // unlikely on the Mac return NS_ERROR_UNEXPECTED; + // resize during zoom may attempt to unzoom us. here's where we put a stop to that. + if (mZooming) + return NS_OK; + // already done? it's bad to rezoom a window, so do nothing rv = nsBaseWidget::GetSizeMode(¤tMode); + if (currentMode == nsSizeMode_Normal && !mVisible && mZoomOnShow) + currentMode = nsSizeMode_Maximized; if (NS_SUCCEEDED(rv) && currentMode == aMode) return NS_OK; @@ -1197,10 +1204,10 @@ NS_METHOD nsMacWindow::SetSizeMode(PRInt32 aMode) /* zooming on the Mac doesn't seem to work until the window is visible. the rest of the app is structured to zoom before the window is visible to avoid flashing. here's where we defeat that. */ - if (aMode == nsSizeMode_Maximized) - mZoomOnShow = PR_TRUE; + mZoomOnShow = aMode == nsSizeMode_Maximized; } else { Rect macRect; + mZooming = PR_TRUE; rv = nsBaseWidget::SetSizeMode(aMode); if (NS_SUCCEEDED(rv)) { if (aMode == nsSizeMode_Maximized) { @@ -1211,12 +1218,47 @@ NS_METHOD nsMacWindow::SetSizeMode(PRInt32 aMode) ::GetWindowPortBounds(mWindowPtr, &macRect); Resize(macRect.right - macRect.left, macRect.bottom - macRect.top, PR_FALSE); } + mZooming = PR_FALSE; } return rv; } +// we're resizing. if we happen to be zoomed ("standard" state), +// switch to the user state without changing the window size. +void +nsMacWindow::UserStateForResize() +{ + nsresult rv; + PRInt32 currentMode; + + // but not if we're currently zooming + if (mZooming) + return; + + // nothing to do if we're already in the user state + rv = nsBaseWidget::GetSizeMode(¤tMode); + if (NS_SUCCEEDED(rv) && currentMode == nsSizeMode_Normal) + return; + + // we've just finished sizing, so make our current size our user state, + // and switch to the user state + StPortSetter portState(mWindowPtr); + StOriginSetter originState(mWindowPtr); + Rect bounds; + + ::GetWindowPortBounds(mWindowPtr, &bounds); + ::LocalToGlobal((Point *)&bounds.top); + ::LocalToGlobal((Point *)&bounds.bottom); + ::SetWindowUserState(mWindowPtr, &bounds); + ::ZoomWindow(mWindowPtr, inZoomIn, false); + + // finally, reset our internal state to match + nsBaseWidget::SetSizeMode(nsSizeMode_Normal); +} + + // // CalculateAndSetZoomedSize // diff --git a/widget/src/mac/nsMacWindow.h b/widget/src/mac/nsMacWindow.h index f6d6028a86d..ac67a1796a0 100644 --- a/widget/src/mac/nsMacWindow.h +++ b/widget/src/mac/nsMacWindow.h @@ -117,7 +117,9 @@ public: NS_IMETHOD GetScreenBounds(nsRect &aRect); virtual PRBool OnPaint(nsPaintEvent &event); - NS_IMETHOD SetTitle(const nsString& aTitle); + NS_IMETHOD SetTitle(const nsString& aTitle); + + void UserStateForResize(); // nsIKBStateControl interface NS_IMETHOD ResetInputState(); @@ -148,16 +150,17 @@ protected: EventRef inEvent, void* userData ) ; #endif - PRBool mWindowMadeHere; // true if we created the window - PRBool mIsDialog; // true if the window is a dialog - PRBool mIsSheet; // true if the window is a sheet (Mac OS X) - PRBool mIgnoreDeactivate; // true if this window has a (Mac OS X) sheet opening - auto_ptr mMacEventHandler; + PRPackedBool mWindowMadeHere; // true if we created the window + PRPackedBool mIsDialog; // true if the window is a dialog + PRPackedBool mIsSheet; // true if the window is a sheet (Mac OS X) + PRPackedBool mIgnoreDeactivate; // true if this window has a (Mac OS X) sheet opening + PRPackedBool mAcceptsActivation; + PRPackedBool mIsActive; + PRPackedBool mZoomOnShow; + PRPackedBool mZooming; + PRPackedBool mResizeIsFromUs; // we originated the resize, prevent infinite recursion + auto_ptr mMacEventHandler; nsIWidget *mOffsetParent; - PRBool mAcceptsActivation; - PRBool mIsActive; - PRBool mZoomOnShow; - PRBool mResizeIsFromUs; // we originated the resize, prevent infinite recursion #if !TARGET_CARBON ControlHandle mPhantomScrollbar; // a native scrollbar for the scrollwheel