clean up, consolidate some code. b=383560 r=smorgan sr=pinkerton

This commit is contained in:
joshmoz%gmail.com 2007-06-12 20:26:24 +00:00
Родитель 0f76a5d504
Коммит 1629a7bb57
1 изменённых файлов: 19 добавлений и 53 удалений

Просмотреть файл

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