diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 333742ab613..488b43c67d7 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -533,8 +533,8 @@ NS_IMETHODIMP nsChildView::Destroy() // just to be safe. If we're going away and for some reason we're still // the rollup widget, rollup and turn off capture. - if ( this == gRollupWidget ) { - if ( gRollupListener ) + if (this == gRollupWidget) { + if (gRollupListener) gRollupListener->Rollup(); CaptureRollupEvents(nsnull, PR_FALSE, PR_TRUE); } @@ -1868,8 +1868,8 @@ void nsChildView::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY) NS_IMETHODIMP nsChildView::CaptureRollupEvents(nsIRollupListener * aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent) + PRBool aDoCapture, + PRBool aConsumeRollupEvent) { if (aDoCapture) { NS_IF_RELEASE(gRollupListener); @@ -1880,7 +1880,6 @@ NS_IMETHODIMP nsChildView::CaptureRollupEvents(nsIRollupListener * aListener, NS_ADDREF(this); } else { NS_IF_RELEASE(gRollupListener); - //gRollupListener = nsnull; NS_IF_RELEASE(gRollupWidget); } diff --git a/widget/src/cocoa/nsCocoaWindow.h b/widget/src/cocoa/nsCocoaWindow.h index 7051b81c026..b3b613268fb 100644 --- a/widget/src/cocoa/nsCocoaWindow.h +++ b/widget/src/cocoa/nsCocoaWindow.h @@ -41,7 +41,6 @@ #undef DARWIN #import -#include #include "nsBaseWidget.h" @@ -142,10 +141,10 @@ public: NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) { return NS_OK; } NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) { return NS_OK; } NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ; - NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) { return NS_OK; } + NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent); // be notified that a some form of drag event needs to go into Gecko - virtual PRBool DragEvent ( unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers ) ; + virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers); // Helpers to prevent recursive resizing during live-resize PRBool IsResizing () const { return mIsResizing; } diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 978b920e056..0383928bbf1 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -54,25 +54,13 @@ #include "nsIEventQueueService.h" -#include - // Define Class IDs -- i hate having to do this static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID); -// from MacHeaders.c -#ifndef topLeft - #define topLeft(r) (((Point *) &(r))[0]) -#endif -#ifndef botRight - #define botRight(r) (((Point *) &(r))[1]) -#endif - -// externs defined in nsWindow.cpp +// externs defined in nsChildView.mm extern nsIRollupListener * gRollupListener; extern nsIWidget * gRollupWidget; -#define kWindowPositionSlop 20 - NS_IMPL_ISUPPORTS_INHERITED0(nsCocoaWindow, Inherited) // @@ -609,6 +597,26 @@ nsIMenuBar* nsCocoaWindow::GetMenuBar() } +NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener * aListener, + PRBool aDoCapture, + PRBool aConsumeRollupEvent) +{ + if (aDoCapture) { + NS_IF_RELEASE(gRollupListener); + NS_IF_RELEASE(gRollupWidget); + gRollupListener = aListener; + NS_ADDREF(aListener); + gRollupWidget = this; + NS_ADDREF(this); + } else { + NS_IF_RELEASE(gRollupListener); + NS_IF_RELEASE(gRollupWidget); + } + + return NS_OK; +} + + @implementation WindowDelegate @@ -622,14 +630,15 @@ nsIMenuBar* nsCocoaWindow::GetMenuBar() - (void)windowDidResize:(NSNotification *)aNotification { - if (!mGeckoWindow->IsResizing()) { - // must remember to give Gecko top-left, not straight cocoa origin - // and that Gecko already compensates for the title bar, so we have to - // strip it out here. - NSRect frameRect = [[aNotification object] frame]; - mGeckoWindow->Resize (NS_STATIC_CAST(PRInt32,frameRect.size.width), - NS_STATIC_CAST(PRInt32,frameRect.size.height - nsCocoaWindow::kTitleBarHeight), PR_TRUE); - } + if (mGeckoWindow->IsResizing()) + return; + + // must remember to give Gecko top-left, not straight cocoa origin + // and that Gecko already compensates for the title bar, so we have to + // strip it out here. + NSRect frameRect = [[aNotification object] frame]; + mGeckoWindow->Resize (NS_STATIC_CAST(PRInt32,frameRect.size.width), + NS_STATIC_CAST(PRInt32,frameRect.size.height - nsCocoaWindow::kTitleBarHeight), PR_TRUE); } @@ -648,28 +657,32 @@ nsIMenuBar* nsCocoaWindow::GetMenuBar() - (void)windowDidResignMain:(NSNotification *)aNotification { - //printf(@"got deactivate"); + // roll up any popups + if (gRollupListener != nsnull && gRollupWidget != nsnull) + gRollupListener->Rollup(); + + // tell Gecko that we lost focus + nsGUIEvent guiEvent(PR_TRUE, NS_LOSTFOCUS, mGeckoWindow); + guiEvent.time = PR_IntervalNow(); + nsEventStatus status = nsEventStatus_eIgnore; + mGeckoWindow->DispatchEvent(&guiEvent, status); } -- (void)windowDidBecomeKey:(NSNotification *)aNotification +- (void)windowWillMove:(NSNotification *)aNotification { - //printf("we're key window\n"); + // roll up any popups + if (gRollupListener != nsnull && gRollupWidget != nsnull) + gRollupListener->Rollup(); } -- (void)windowDidResignKey:(NSNotification *)aNotification -{ - //printf("we're not the key window\n"); -} - - -- (void)windowDidMove:(NSNotification *)aNotification -{ -} - -(void)windowWillClose:(NSNotification *)aNotification { + // roll up any popups + if (gRollupListener != nsnull && gRollupWidget != nsnull) + gRollupListener->Rollup(); + nsGUIEvent guiEvent(PR_TRUE, NS_XUL_CLOSE, mGeckoWindow); guiEvent.time = PR_IntervalNow(); nsEventStatus status = nsEventStatus_eIgnore; @@ -677,4 +690,12 @@ nsIMenuBar* nsCocoaWindow::GetMenuBar() } +- (void)windowWillMiniaturize:(NSNotification *)aNotification +{ + // roll up any popups + if (gRollupListener != nsnull && gRollupWidget != nsnull) + gRollupListener->Rollup(); +} + + @end