diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 075c590ff1b7..d5880a36770b 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -68,7 +68,7 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsCocoaWindow, Inherited, nsPIWidgetCocoa) // returns the height of the title bar for a given cocoa NSWindow -static float titleBarHeightForWindow(NSWindow* aWindow) +static float TitleBarHeightForWindow(NSWindow* aWindow) { NS_ASSERTION(aWindow, "Must have a window to calculate a title bar height!"); @@ -78,9 +78,14 @@ static float titleBarHeightForWindow(NSWindow* aWindow) } -// -// nsCocoaWindow constructor -// +// roll up any popup windows +static void RollUpPopups() +{ + if (gRollupListener && gRollupWidget) + gRollupListener->Rollup(); +} + + nsCocoaWindow::nsCocoaWindow() : mParent(nsnull) , mWindow(nil) @@ -97,9 +102,6 @@ nsCocoaWindow::nsCocoaWindow() } -// -// nsCocoaWindow destructor -// nsCocoaWindow::~nsCocoaWindow() { // notify the children that we're gone @@ -153,10 +155,8 @@ static nsIMenuBar* GetHiddenWindowMenuBar() } -// // Utility method for implementing both Create(nsIWidget ...) and // Create(nsNativeWidget...) -// nsresult nsCocoaWindow::StandardCreate(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, @@ -355,9 +355,7 @@ nsresult nsCocoaWindow::StandardCreate(nsIWidget *aParent, } -// // Create a nsCocoaWindow using a native window provided by the application -// NS_IMETHODIMP nsCocoaWindow::Create(nsNativeWidget aNativeWindow, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, @@ -430,9 +428,7 @@ NS_IMETHODIMP nsCocoaWindow::IsVisible(PRBool & aState) } -// // Hide or show this window -// NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) { nsIWidget* parentWidget = mParent; @@ -503,10 +499,8 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState) } else { // roll up any popups if a top-level window is going away - if (mWindowType == eWindowType_toplevel) { - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); - } + if (mWindowType == eWindowType_toplevel) + RollUpPopups(); // now get rid of the window/sheet if (mWindowType == eWindowType_sheet) { @@ -709,9 +703,6 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRIn } -// -// Resize this window -// NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) { if (mWindow) { @@ -730,7 +721,7 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRep // being shown as a sheet the content area and window frame differ. float newHeight = (float)aHeight; if (mWindowType != eWindowType_popup && ![mWindow isSheet]) - newHeight += titleBarHeightForWindow(mWindow); // add height of title bar + newHeight += TitleBarHeightForWindow(mWindow); // add height of title bar // Now we need to adjust for the fact that gecko wants the top of the window // to remain in the same place. newFrame.origin.y += newFrame.size.height - newHeight; @@ -758,11 +749,9 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRep } -// // We return the origin for the entire window (title bar and all) but // the size of the content area. I have no idea why it was originally done // this way, but it matches Carbon and makes things work nicely. -// NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(nsRect &aRect) { nsRect windowFrame = cocoaRectToGeckoRect([mWindow frame]); @@ -818,7 +807,6 @@ NS_IMETHODIMP nsCocoaWindow::Update() } -// // Pass notification of some drag event to Gecko // // The drag manager has let us know that something related to a drag has @@ -826,8 +814,7 @@ NS_IMETHODIMP nsCocoaWindow::Update() // a drop, to a drag enter/leave, or a drag over event. The actual event // is passed in |aMessage| and is passed along to our event hanlder so Gecko // knows about it. -// -PRBool nsCocoaWindow::DragEvent ( unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers ) +PRBool nsCocoaWindow::DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers) { return PR_FALSE; } @@ -908,9 +895,7 @@ NS_IMETHODIMP nsCocoaWindow::ResetInputState() } -// // Invokes callback and ProcessEvent method on Event Listener object -// NS_IMETHODIMP nsCocoaWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus) { @@ -939,16 +924,13 @@ nsCocoaWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus) void nsCocoaWindow::ReportSizeEvent() { - // nsEvent nsSizeEvent sizeEvent(PR_TRUE, NS_SIZE, this); sizeEvent.time = PR_IntervalNow(); - // nsSizeEvent sizeEvent.windowSize = &mBounds; sizeEvent.mWinWidth = mBounds.width; sizeEvent.mWinHeight = mBounds.height; - // dispatch event nsEventStatus status = nsEventStatus_eIgnore; DispatchEvent(&sizeEvent, status); } @@ -1114,9 +1096,7 @@ NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation) - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize { - // roll up any popups - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); + RollUpPopups(); return proposedFrameSize; } @@ -1136,9 +1116,7 @@ NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation) - (void)windowDidBecomeMain:(NSNotification *)aNotification { - // roll up any popups - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); + RollUpPopups(); NSWindow* window = [aNotification object]; if (window) @@ -1148,9 +1126,7 @@ NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation) - (void)windowDidResignMain:(NSNotification *)aNotification { - // roll up any popups - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); + RollUpPopups(); nsCOMPtr hiddenWindowMenuBar = GetHiddenWindowMenuBar(); if (hiddenWindowMenuBar) { @@ -1180,9 +1156,7 @@ NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation) - (void)windowWillMove:(NSNotification *)aNotification { - // roll up any popups - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); + RollUpPopups(); } - (void)windowDidMove:(NSNotification *)aNotification @@ -1211,17 +1185,13 @@ NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation) - (void)windowWillClose:(NSNotification *)aNotification { - // roll up any popups - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); + RollUpPopups(); } - (void)windowWillMiniaturize:(NSNotification *)aNotification { - // roll up any popups - if (gRollupListener != nsnull && gRollupWidget != nsnull) - gRollupListener->Rollup(); + RollUpPopups(); } @@ -1275,14 +1245,10 @@ NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation) return mGeckoWindow; } - @end @implementation ToolbarWindow -// Toolbar pill button methods, DANGER! The underscore means DANGEROUS! -// "You aren't expected to understand this." - // The carbon widget code was saying we want a toolbar for all top level // windows, and since we're only using this class for top level windows, we // always want to return yes from here.