From 1f8527337b4f33f4f0bdc56d5dd1263f10bffd32 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Wed, 1 Dec 2010 10:20:28 -0800 Subject: [PATCH] Backing out changeset e1983b9db75d from bug 596955 for causing bug 615858. a=backout --- widget/src/cocoa/nsCocoaWindow.h | 6 ++++++ widget/src/cocoa/nsCocoaWindow.mm | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/widget/src/cocoa/nsCocoaWindow.h b/widget/src/cocoa/nsCocoaWindow.h index 849fc324ec03..b9673af41b7e 100644 --- a/widget/src/cocoa/nsCocoaWindow.h +++ b/widget/src/cocoa/nsCocoaWindow.h @@ -281,6 +281,11 @@ public: // be notified that a some form of drag event needs to go into Gecko virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers); + // Helpers to prevent recursive resizing during live-resize + PRBool IsResizing () const { return mIsResizing; } + void StartResizing () { mIsResizing = PR_TRUE; } + void StopResizing () { mIsResizing = PR_FALSE; } + PRBool HasModalDescendents() { return mNumModalDescendents > 0; } NSWindow *GetCocoaWindow() { return mWindow; } @@ -333,6 +338,7 @@ protected: PRInt32 mShadowStyle; NSUInteger mWindowFilter; + PRPackedBool mIsResizing; // we originated the resize, prevent infinite recursion 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 diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 675774a65323..0b1fd44688af 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -139,6 +139,7 @@ nsCocoaWindow::nsCocoaWindow() , mPopupContentView(nil) , mShadowStyle(NS_STYLE_WINDOW_SHADOW_DEFAULT) , mWindowFilter(0) +, mIsResizing(PR_FALSE) , mWindowMadeHere(PR_FALSE) , mSheetNeedsShow(PR_FALSE) , mFullScreen(PR_FALSE) @@ -1133,16 +1134,35 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRIn BOOL isMoving = (windowBounds.x != newBounds.x || windowBounds.y != newBounds.y); BOOL isResizing = (windowBounds.width != newBounds.width || windowBounds.height != newBounds.height); - if (!mWindow || (!isMoving && !isResizing)) + if (IsResizing() || !mWindow || (!isMoving && !isResizing)) return NS_OK; mBounds = newBounds; NSRect newFrame = nsCocoaUtils::GeckoRectToCocoaRect(mBounds); + // We have to report the size event -first-, to make sure that content + // repositions itself. Cocoa views are anchored at the bottom left, + // so if we don't do this our child view will end up being stuck in the + // wrong place during a resize. + if (isResizing) + ReportSizeEvent(&newFrame); + + StartResizing(); // We ignore aRepaint -- we have to call display:YES, otherwise the // title bar doesn't immediately get repainted and is displayed in // the wrong place, leading to a visual jump. [mWindow setFrame:newFrame display:YES]; + StopResizing(); + + // now, check whether we got the frame that we wanted + NSRect actualFrame = [mWindow frame]; + if (newFrame.size.width != actualFrame.size.width || newFrame.size.height != actualFrame.size.height) { + // We didn't; the window must have been too big or otherwise invalid. + // Report -another- resize in this case, to make sure things are in + // the right place. This will cause some visual jitter, but + // shouldn't happen often. + ReportSizeEvent(); + } return NS_OK; @@ -1768,7 +1788,7 @@ PRBool nsCocoaWindow::ShouldFocusPlugin() - (void)windowDidResize:(NSNotification *)aNotification { - if (!mGeckoWindow) + if (!mGeckoWindow || mGeckoWindow->IsResizing()) return; // Resizing might have changed our zoom state.