mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
protect against obj-c exceptions, b=417558 r=bent sr=roc
This commit is contained in:
parent
f7933e7360
commit
ee2caf8906
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,7 @@
|
||||
|
||||
#include "nsCocoaWindow.h"
|
||||
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsGUIEvent.h"
|
||||
@ -106,6 +107,8 @@ nsCocoaWindow::nsCocoaWindow()
|
||||
|
||||
nsCocoaWindow::~nsCocoaWindow()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// notify the children that we're gone
|
||||
for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
|
||||
nsCocoaWindow* childWindow = static_cast<nsCocoaWindow*>(kid);
|
||||
@ -128,6 +131,8 @@ nsCocoaWindow::~nsCocoaWindow()
|
||||
--gXULModalLevel;
|
||||
NS_ASSERTION(gXULModalLevel >= 0, "Wierdness setting modality!");
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -206,6 +211,8 @@ nsresult nsCocoaWindow::StandardCreate(nsIWidget *aParent,
|
||||
nsWidgetInitData *aInitData,
|
||||
nsNativeWidget aNativeWindow)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (!WindowSizeAllowed(aRect.width, aRect.height))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -415,6 +422,8 @@ nsresult nsCocoaWindow::StandardCreate(nsIWidget *aParent,
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -459,6 +468,8 @@ NS_IMETHODIMP nsCocoaWindow::Destroy()
|
||||
|
||||
void* nsCocoaWindow::GetNativeData(PRUint32 aDataType)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSNULL;
|
||||
|
||||
void* retVal = nsnull;
|
||||
|
||||
switch (aDataType) {
|
||||
@ -481,13 +492,19 @@ void* nsCocoaWindow::GetNativeData(PRUint32 aDataType)
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::IsVisible(PRBool & aState)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
aState = ([mWindow isVisible] || mSheetNeedsShow);
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -507,6 +524,8 @@ NS_IMETHODIMP nsCocoaWindow::SetModal(PRBool aState)
|
||||
// Hide or show this window
|
||||
NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
PRBool isVisible;
|
||||
IsVisible(isVisible);
|
||||
if (bState == isVisible)
|
||||
@ -712,11 +731,15 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
|
||||
mPopupContentView->Show(bState);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
void nsCocoaWindow::MakeBackgroundTransparent(PRBool aTransparent)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
BOOL currentTransparency = ![mWindow isOpaque];
|
||||
if (aTransparent != currentTransparency) {
|
||||
// Popups have an alpha value we need to toggle.
|
||||
@ -727,13 +750,19 @@ void nsCocoaWindow::MakeBackgroundTransparent(PRBool aTransparent)
|
||||
[mWindow setBackgroundColor:(aTransparent ? [NSColor clearColor] : [NSColor whiteColor])];
|
||||
[mWindow setHasShadow:!aTransparent];
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::GetHasTransparentBackground(PRBool& aTransparent)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
aTransparent = ![mWindow isOpaque];
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -741,6 +770,8 @@ NS_IMETHODIMP nsCocoaWindow::GetHasTransparentBackground(PRBool& aTransparent)
|
||||
// For other window types, nsChildView::SetHasTransparentBackground is used.
|
||||
NS_IMETHODIMP nsCocoaWindow::SetHasTransparentBackground(PRBool aTransparent)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
BOOL currentTransparency = ![mWindow isOpaque];
|
||||
if (aTransparent != currentTransparency) {
|
||||
// Take care of window transparency
|
||||
@ -754,6 +785,8 @@ NS_IMETHODIMP nsCocoaWindow::SetHasTransparentBackground(PRBool aTransparent)
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -826,6 +859,8 @@ NS_METHOD nsCocoaWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
||||
// from the dock by users.
|
||||
NS_METHOD nsCocoaWindow::SetSizeMode(PRInt32 aMode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
PRInt32 previousMode;
|
||||
nsBaseWidget::GetSizeMode(&previousMode);
|
||||
|
||||
@ -848,11 +883,15 @@ NS_METHOD nsCocoaWindow::SetSizeMode(PRInt32 aMode)
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (!WindowSizeAllowed(aWidth, aHeight))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -891,21 +930,29 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRIn
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (!WindowSizeAllowed(aWidth, aHeight))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
|
||||
return Resize(windowBounds.x, windowBounds.y, aWidth, aHeight, aRepaint);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(nsRect &aRect)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsRect windowFrame = nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]);
|
||||
aRect.x = windowFrame.x;
|
||||
aRect.y = windowFrame.y;
|
||||
@ -913,6 +960,8 @@ NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(nsRect &aRect)
|
||||
aRect.height = windowFrame.height;
|
||||
// printf("GetScreenBounds: output: %d,%d,%d,%d\n", aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -924,11 +973,15 @@ PRBool nsCocoaWindow::OnPaint(nsPaintEvent &event)
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::SetTitle(const nsAString& aTitle)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
const nsString& strTitle = PromiseFlatString(aTitle);
|
||||
NSString* title = [NSString stringWithCharacters:strTitle.get() length:strTitle.Length()];
|
||||
[mWindow setTitle:title];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -1065,6 +1118,8 @@ nsCocoaWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)
|
||||
void
|
||||
nsCocoaWindow::ReportSizeEvent(NSRect *r)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
NSRect windowFrame;
|
||||
if (r)
|
||||
windowFrame = [mWindow contentRectForFrameRect:(*r)];
|
||||
@ -1082,6 +1137,8 @@ nsCocoaWindow::ReportSizeEvent(NSRect *r)
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
DispatchEvent(&sizeEvent, status);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1117,6 +1174,8 @@ NS_IMETHODIMP nsCocoaWindow::ShowMenuBar(PRBool aShow)
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsRect r = nsCocoaUtils::CocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
|
||||
|
||||
aNewRect.x = r.x + aOldRect.x;
|
||||
@ -1125,11 +1184,15 @@ NS_IMETHODIMP nsCocoaWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNew
|
||||
aNewRect.height = aOldRect.height;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsRect r = nsCocoaUtils::CocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
|
||||
|
||||
aNewRect.x = aOldRect.x - r.x;
|
||||
@ -1138,6 +1201,8 @@ NS_IMETHODIMP nsCocoaWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNew
|
||||
aNewRect.height = aOldRect.height;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -1151,6 +1216,8 @@ NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener * aListener,
|
||||
PRBool aDoCapture,
|
||||
PRBool aConsumeRollupEvent)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_IF_RELEASE(gRollupListener);
|
||||
NS_IF_RELEASE(gRollupWidget);
|
||||
|
||||
@ -1180,18 +1247,26 @@ NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener * aListener,
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
[NSApp requestUserAttention:NSInformationalRequest];
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
// If our cocoa window isn't a ToolbarWindow, something is wrong.
|
||||
if (![mWindow isKindOfClass:[ToolbarWindow class]]) {
|
||||
// Don't output a warning for the hidden window.
|
||||
@ -1211,6 +1286,8 @@ NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor)
|
||||
alpha:NS_GET_A(aColor)/255.0]];
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -1224,19 +1301,27 @@ gfxASurface* nsCocoaWindow::GetThebesSurface()
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::BeginSecureKeyboardInput()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv = nsBaseWidget::BeginSecureKeyboardInput();
|
||||
if (NS_SUCCEEDED(rv))
|
||||
::EnableSecureEventInput();
|
||||
return rv;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv = nsBaseWidget::EndSecureKeyboardInput();
|
||||
if (NS_SUCCEEDED(rv))
|
||||
::DisableSecureEventInput();
|
||||
return rv;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -1247,7 +1332,9 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
// the application menu by itself so that a window doesn't have some other
|
||||
// window's menu bar.
|
||||
+ (void)paintMenubarForWindow:(NSWindow*)aWindow
|
||||
{
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// make sure we only act on windows that have this kind of
|
||||
// object as a delegate
|
||||
id windowDelegate = [aWindow delegate];
|
||||
@ -1282,14 +1369,20 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
[NSApp setMainMenu:newMenuBar];
|
||||
[newMenuBar release];
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
[super init];
|
||||
mGeckoWindow = geckoWind;
|
||||
return self;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
@ -1312,11 +1405,15 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
|
||||
- (void)windowDidBecomeMain:(NSNotification *)aNotification
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
RollUpPopups();
|
||||
|
||||
NSWindow* window = [aNotification object];
|
||||
if (window)
|
||||
[WindowDelegate paintMenubarForWindow:window];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1334,19 +1431,27 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification *)aNotification
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
NSWindow* window = [aNotification object];
|
||||
if ([window isSheet])
|
||||
[WindowDelegate paintMenubarForWindow:window];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)aNotification
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// If a sheet just resigned key then we should paint the menu bar
|
||||
// for whatever window is now main.
|
||||
NSWindow* window = [aNotification object];
|
||||
if ([window isSheet])
|
||||
[WindowDelegate paintMenubarForWindow:[NSApp mainWindow]];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1407,6 +1512,8 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
|
||||
- (void)didEndSheet:(NSWindow*)sheet returnCode:(int)returnCode contextInfo:(void*)contextInfo
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// Note: 'contextInfo' is the window that is the parent of the sheet,
|
||||
// we set that in nsCocoaWindow::Show. 'contextInfo' is always the top-level
|
||||
// window, not another sheet itself.
|
||||
@ -1415,6 +1522,8 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
[sheet orderOut:self];
|
||||
[[(NSWindow*)contextInfo delegate] sendFocusEvent:NS_GOTFOCUS];
|
||||
[[(NSWindow*)contextInfo delegate] sendFocusEvent:NS_ACTIVATE];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1432,7 +1541,11 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
|
||||
- (NSColor*)windowBackgroundColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
return [self backgroundColor];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1453,6 +1566,8 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
|
||||
- (id)initWithContentRect:(NSRect)aContentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)aFlag
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
aStyle = aStyle | NSTexturedBackgroundWindowMask;
|
||||
if ((self = [super initWithContentRect:aContentRect styleMask:aStyle backing:aBufferingType defer:aFlag])) {
|
||||
mColor = [[TitlebarAndBackgroundColor alloc] initWithTitlebarColor:nil
|
||||
@ -1467,13 +1582,19 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
[self setBottomCornerRounded:NO];
|
||||
}
|
||||
return self;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mColor release];
|
||||
[super dealloc];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1482,7 +1603,11 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
// custom NSColor subclass.
|
||||
- (void)setBackgroundColor:(NSColor*)aColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mColor setBackgroundColor:aColor];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1490,20 +1615,32 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
// sense) use this method instead.
|
||||
- (NSColor*)windowBackgroundColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
return [mColor backgroundColor];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
// Pass nil here to get the default appearance.
|
||||
- (void)setTitlebarColor:(NSColor*)aColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mColor setTitlebarColor:aColor];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
- (NSColor*)titlebarColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
return [mColor titlebarColor];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
@ -1517,11 +1654,15 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
// Dispatch a toolbar pill button clicked message to Gecko.
|
||||
- (void)_toolbarPillButtonClicked:(id)sender
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
nsCocoaWindow *geckoWindow = [[self delegate] geckoWidget];
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsGUIEvent guiEvent(PR_TRUE, NS_OS_TOOLBAR, geckoWindow);
|
||||
guiEvent.time = PR_IntervalNow();
|
||||
geckoWindow->DispatchEvent(&guiEvent, status);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
// Retain and release "self" to avoid crashes when our widget (and its native
|
||||
@ -1530,10 +1671,14 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
// that can become key.
|
||||
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
NSWindow *nativeWindow = [self retain];
|
||||
BOOL retval = [super performKeyEquivalent:theEvent];
|
||||
[nativeWindow release];
|
||||
return retval;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1547,6 +1692,8 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
andBackgroundColor:(NSColor*)aBackgroundColor
|
||||
forWindow:(NSWindow*)aWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
if ((self = [super init])) {
|
||||
mTitlebarColor = [aTitlebarColor retain];
|
||||
mBackgroundColor = [aBackgroundColor retain];
|
||||
@ -1558,14 +1705,20 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
||||
mTitlebarHeight = frameRect.size.height - [aWindow contentRectForFrameRect:frameRect].size.height;
|
||||
}
|
||||
return self;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mTitlebarColor release];
|
||||
[mBackgroundColor release];
|
||||
[super dealloc];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
// Our pattern width is 1 pixel. CoreGraphics can cache and tile for us.
|
||||
@ -1608,6 +1761,8 @@ static void headerShading(void* aInfo, const float* aIn, float* aOut)
|
||||
// Callback where all of the drawing for this color takes place.
|
||||
void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
TitlebarAndBackgroundColor *color = (TitlebarAndBackgroundColor*)aInfo;
|
||||
NSColor *titlebarColor = [color titlebarColor];
|
||||
NSColor *backgroundColor = [color backgroundColor];
|
||||
@ -1657,11 +1812,15 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
NSRectFill(NSMakeRect(0.0f, 0.0f, 1.0f, titlebarOrigin));
|
||||
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
- (void)setFill
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
||||
|
||||
// Set up the pattern to be as tall as our window, and one pixel wide.
|
||||
@ -1679,14 +1838,20 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
float component = 1.0f;
|
||||
CGContextSetFillPattern(context, pattern, &component);
|
||||
CGPatternRelease(pattern);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
// Pass nil here to get the default appearance.
|
||||
- (void)setTitlebarColor:(NSColor*)aColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mTitlebarColor autorelease];
|
||||
mTitlebarColor = [aColor retain];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1698,8 +1863,12 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
|
||||
- (void)setBackgroundColor:(NSColor*)aColor
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mBackgroundColor autorelease];
|
||||
mBackgroundColor = [aColor retain];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1723,7 +1892,11 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
|
||||
- (void)set
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[self setFill];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1751,8 +1924,12 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
// in the superclass.
|
||||
+ (void)drawBevel:(NSRect)bevel inFrame:(NSRect)frame topCornerRounded:(BOOL)top bottomCornerRounded:(BOOL)bottom
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if ([self respondsToSelector:@selector(drawBevel:inFrame:topCornerRounded:)])
|
||||
[self drawBevel:bevel inFrame:frame topCornerRounded:top];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1775,6 +1952,8 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
// sendEvent: method.
|
||||
- (void)nsCocoaWindow_NSWindow_sendEvent:(NSEvent *)anEvent
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
NSResponder *oldFirstResponder = nil;
|
||||
NSEventType type = [anEvent type];
|
||||
if (type == NSLeftMouseDown)
|
||||
@ -1790,6 +1969,8 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
}
|
||||
[oldFirstResponder release];
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1803,6 +1984,8 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
// events for a given NSWindow object go through its sendEvent: method.)
|
||||
- (void)sendEvent:(NSEvent *)anEvent
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
NSView *target = nil;
|
||||
NSView *contentView = nil;
|
||||
NSEventType type = [anEvent type];
|
||||
@ -1907,15 +2090,21 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
} else {
|
||||
[super sendEvent:anEvent];
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
|
||||
backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
mIsContextMenu = false;
|
||||
return [super initWithContentRect:contentRect styleMask:styleMask
|
||||
backing:bufferingType defer:deferCreation];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
@ -1951,9 +2140,13 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
// accurate test of what Apple means by "visibility".
|
||||
- (BOOL)canBecomeMainWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
if (![self isVisible])
|
||||
return NO;
|
||||
return YES;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
||||
}
|
||||
|
||||
// Retain and release "self" to avoid crashes when our widget (and its native
|
||||
@ -1962,10 +2155,14 @@ void patternDraw(void* aInfo, CGContextRef aContext)
|
||||
// that can become key.
|
||||
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
NSWindow *nativeWindow = [self retain];
|
||||
BOOL retval = [super performKeyEquivalent:theEvent];
|
||||
[nativeWindow release];
|
||||
return retval;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
#include "nsMenuItemIconX.h"
|
||||
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "prmem.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIMenuItem.h"
|
||||
@ -109,6 +110,8 @@ nsMenuItemIconX::~nsMenuItemIconX()
|
||||
nsresult
|
||||
nsMenuItemIconX::SetupIcon()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv;
|
||||
if (!mMenuRef || !mMenuItemIndex) {
|
||||
// These values are initialized here instead of in the constructor
|
||||
@ -138,6 +141,8 @@ nsMenuItemIconX::SetupIcon()
|
||||
}
|
||||
|
||||
return LoadIcon(iconURI);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -225,6 +230,8 @@ nsMenuItemIconX::GetIconURI(nsIURI** aIconURI)
|
||||
nsresult
|
||||
nsMenuItemIconX::LoadIcon(nsIURI* aIconURI)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (mIconRequest) {
|
||||
// Another icon request is already in flight. Kill it.
|
||||
mIconRequest->Cancel(NS_BINDING_ABORTED);
|
||||
@ -293,6 +300,8 @@ nsMenuItemIconX::LoadIcon(nsIURI* aIconURI)
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -421,6 +430,8 @@ NS_IMETHODIMP
|
||||
nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest,
|
||||
gfxIImageFrame* aFrame)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (aRequest != mIconRequest) return NS_ERROR_FAILURE;
|
||||
|
||||
// Only support one frame.
|
||||
@ -543,6 +554,8 @@ nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest,
|
||||
mSetIcon = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIContent.h"
|
||||
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsMenuBarX.h" // for MenuHelpers namespace
|
||||
#include "nsMenuItemX.h"
|
||||
#include "nsIMenu.h"
|
||||
@ -74,17 +74,23 @@ nsMenuItemX::nsMenuItemX()
|
||||
|
||||
nsMenuItemX::~nsMenuItemX()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mNativeMenuItem autorelease];
|
||||
if (mContent)
|
||||
mMenuBar->UnregisterForContentChanges(mContent);
|
||||
if (mCommandContent)
|
||||
mMenuBar->UnregisterForContentChanges(mCommandContent);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD nsMenuItemX::Create(nsIMenu* aParent, const nsString & aLabel, EMenuItemType aItemType,
|
||||
nsMenuBarX* aMenuBar, nsIContent* aNode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
mContent = aNode; // addref
|
||||
mMenuParent = aParent; // weak
|
||||
|
||||
@ -165,6 +171,8 @@ NS_METHOD nsMenuItemX::Create(nsIMenu* aParent, const nsString & aLabel, EMenuIt
|
||||
mIcon = new nsMenuItemIconX(static_cast<nsIMenuItem*>(this), mMenuParent, mContent, mNativeMenuItem);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -186,6 +194,8 @@ nsMenuItemX::GetEnabled(PRBool *aIsEnabled)
|
||||
|
||||
NS_METHOD nsMenuItemX::SetChecked(PRBool aIsChecked)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
mIsChecked = aIsChecked;
|
||||
|
||||
// update the content model. This will also handle unchecking our siblings
|
||||
@ -200,6 +210,8 @@ NS_METHOD nsMenuItemX::SetChecked(PRBool aIsChecked)
|
||||
[mNativeMenuItem setState:NSOffState];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -335,6 +347,8 @@ nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
|
||||
|
||||
void nsMenuItemX::SetKeyEquiv(PRUint8 aModifiers, const nsString &aText)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
mMenuBar->UnregisterKeyEquivalent([mNativeMenuItem keyEquivalentModifierMask], [mNativeMenuItem keyEquivalent]);
|
||||
|
||||
mModifiers = aModifiers;
|
||||
@ -349,7 +363,9 @@ void nsMenuItemX::SetKeyEquiv(PRUint8 aModifiers, const nsString &aText)
|
||||
else
|
||||
[mNativeMenuItem setKeyEquivalent:keyEquivalent];
|
||||
|
||||
mMenuBar->RegisterKeyEquivalent([mNativeMenuItem keyEquivalentModifierMask], [mNativeMenuItem keyEquivalent]);
|
||||
mMenuBar->RegisterKeyEquivalent([mNativeMenuItem keyEquivalentModifierMask], [mNativeMenuItem keyEquivalent]);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -361,6 +377,8 @@ void nsMenuItemX::SetKeyEquiv(PRUint8 aModifiers, const nsString &aText)
|
||||
void
|
||||
nsMenuItemX::ObserveAttributeChanged(nsIDocument *aDocument, nsIContent *aContent, nsIAtom *aAttribute)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (!aContent)
|
||||
return;
|
||||
|
||||
@ -413,6 +431,8 @@ nsMenuItemX::ObserveAttributeChanged(nsIDocument *aDocument, nsIContent *aConten
|
||||
[mNativeMenuItem setEnabled:YES];
|
||||
}
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +36,10 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsMenuX.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
@ -45,7 +48,6 @@
|
||||
#include "prinrval.h"
|
||||
#include "nsIRollupListener.h"
|
||||
|
||||
#include "nsMenuX.h"
|
||||
#include "nsMenuItemIconX.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIMenuBar.h"
|
||||
@ -91,15 +93,21 @@ nsMenuX::nsMenuX()
|
||||
mDestroyHandlerCalled(PR_FALSE), mNeedsRebuild(PR_TRUE),
|
||||
mConstructed(PR_FALSE), mVisible(PR_TRUE), mXBLAttached(PR_FALSE)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
mMenuDelegate = [[MenuDelegate alloc] initWithGeckoMenu:this];
|
||||
|
||||
if (!nsMenuBarX::sNativeEventTarget)
|
||||
nsMenuBarX::sNativeEventTarget = [[NativeMenuItemTarget alloc] init];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
nsMenuX::~nsMenuX()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
RemoveAll();
|
||||
|
||||
[mMacMenu release];
|
||||
@ -109,6 +117,8 @@ nsMenuX::~nsMenuX()
|
||||
// alert the change notifier we don't care no more
|
||||
if (mMenuContent)
|
||||
mMenuBar->UnregisterForContentChanges(mMenuContent);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -116,6 +126,8 @@ NS_IMETHODIMP
|
||||
nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsMenuBarX* aMenuBar, nsIContent* aNode)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
mMenuContent = aNode;
|
||||
NS_ASSERTION(mMenuContent, "Menu not given a dom node at creation time");
|
||||
|
||||
@ -159,6 +171,8 @@ nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString
|
||||
mIcon = new nsMenuItemIconX(static_cast<nsIMenu*>(this), menu, mMenuContent, mNativeMenuItem);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -225,6 +239,8 @@ NS_IMETHODIMP nsMenuX::AddItem(nsISupports* aItem)
|
||||
|
||||
nsresult nsMenuX::AddMenuItem(nsIMenuItem * aMenuItem)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (!aMenuItem)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
@ -250,11 +266,15 @@ nsresult nsMenuX::AddMenuItem(nsIMenuItem * aMenuItem)
|
||||
[newNativeMenuItem setTag:mMenuBar->RegisterForCommand(aMenuItem)];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsMenuX::AddMenu(nsIMenu * aMenu)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
// Add a submenu
|
||||
if (!aMenu)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
@ -277,6 +297,8 @@ nsresult nsMenuX::AddMenu(nsIMenu * aMenu)
|
||||
[newNativeMenuItem setSubmenu:childMenu];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -379,6 +401,8 @@ NS_IMETHODIMP nsMenuX::RemoveItem(const PRUint32 aPos)
|
||||
|
||||
NS_IMETHODIMP nsMenuX::RemoveAll()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (mMacMenu) {
|
||||
// clear command id's
|
||||
int itemCount = [mMacMenu numberOfItems];
|
||||
@ -393,6 +417,8 @@ NS_IMETHODIMP nsMenuX::RemoveAll()
|
||||
mVisibleItemsCount = 0;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
@ -405,14 +431,20 @@ NS_IMETHODIMP nsMenuX::GetNativeData(void ** aData)
|
||||
|
||||
NS_IMETHODIMP nsMenuX::SetNativeData(void * aData)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
[mMacMenu release];
|
||||
mMacMenu = [(NSMenu*)aData retain];
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
// printf("JOSH: MenuSelected called for %s \n", NS_LossyConvertUTF16toASCII(mLabel).get());
|
||||
|
||||
// Determine if this is the correct menu to handle the event
|
||||
@ -456,6 +488,8 @@ nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||
}
|
||||
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsEventStatus_eIgnore);
|
||||
}
|
||||
|
||||
|
||||
@ -587,6 +621,8 @@ NS_IMETHODIMP nsMenuX::GetMenuContent(nsIContent ** aMenuContent)
|
||||
|
||||
NSMenu* nsMenuX::CreateMenuWithGeckoString(nsString& menuTitle)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
NSString* title = [NSString stringWithCharacters:(UniChar*)menuTitle.get() length:menuTitle.Length()];
|
||||
NSMenu* myMenu = [[NSMenu alloc] initWithTitle:title];
|
||||
[myMenu setDelegate:mMenuDelegate];
|
||||
@ -601,6 +637,8 @@ NSMenu* nsMenuX::CreateMenuWithGeckoString(nsString& menuTitle)
|
||||
// us that a menu is about to display - see the Cocoa MenuDelegate class.
|
||||
|
||||
return myMenu;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
@ -956,6 +994,8 @@ nsMenuX::GetNativeMenuItem()
|
||||
void
|
||||
nsMenuX::ObserveAttributeChanged(nsIDocument *aDocument, nsIContent *aContent, nsIAtom *aAttribute)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// ignore the |open| attribute, which is by far the most common
|
||||
if (gConstructingMenu || (aAttribute == nsWidgetAtoms::open))
|
||||
return;
|
||||
@ -1029,6 +1069,8 @@ nsMenuX::ObserveAttributeChanged(nsIDocument *aDocument, nsIContent *aContent, n
|
||||
else if (aAttribute == nsWidgetAtoms::image) {
|
||||
SetupIcon();
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1074,6 +1116,8 @@ nsMenuX::SetupIcon()
|
||||
|
||||
static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
UInt32 kind = ::GetEventKind(event);
|
||||
if (kind == kEventMenuTargetItem) {
|
||||
// get the position of the menu item we want
|
||||
@ -1125,11 +1169,15 @@ static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRe
|
||||
}
|
||||
}
|
||||
return eventNotHandledErr;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(noErr);
|
||||
}
|
||||
|
||||
|
||||
static OSStatus InstallMyMenuEventHandler(MenuRef menuRef, void* userData, EventHandlerRef* outHandler)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
static EventTypeSpec eventList[] = {
|
||||
{kEventClassMenu, kEventMenuOpening},
|
||||
{kEventClassMenu, kEventMenuClosed},
|
||||
@ -1142,6 +1190,8 @@ static OSStatus InstallMyMenuEventHandler(MenuRef menuRef, void* userData, Event
|
||||
userData, outHandler);
|
||||
NS_ASSERTION(status == noErr,"Installing carbon menu events failed.");
|
||||
return status;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(noErr);
|
||||
}
|
||||
|
||||
|
||||
@ -1155,18 +1205,26 @@ static OSStatus InstallMyMenuEventHandler(MenuRef menuRef, void* userData, Event
|
||||
|
||||
- (id)initWithGeckoMenu:(nsMenuX*)geckoMenu
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
if ((self = [super init])) {
|
||||
mGeckoMenu = geckoMenu;
|
||||
mHaveInstalledCarbonEvents = FALSE;
|
||||
}
|
||||
return self;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
RemoveEventHandler(mEventHandler);
|
||||
[super dealloc];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -1178,6 +1236,8 @@ static OSStatus InstallMyMenuEventHandler(MenuRef menuRef, void* userData, Event
|
||||
// much trouble.
|
||||
- (void)menuNeedsUpdate:(NSMenu*)aMenu
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (!mHaveInstalledCarbonEvents) {
|
||||
MenuRef myMenuRef = _NSGetCarbonMenu(aMenu);
|
||||
if (myMenuRef) {
|
||||
@ -1185,6 +1245,8 @@ static OSStatus InstallMyMenuEventHandler(MenuRef menuRef, void* userData, Event
|
||||
mHaveInstalledCarbonEvents = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -37,6 +37,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsPrintSessionX.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsPrintSessionX
|
||||
@ -54,15 +55,21 @@ nsPrintSessionX::nsPrintSessionX()
|
||||
//-----------------------------------------------------------------------------
|
||||
nsPrintSessionX::~nsPrintSessionX()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mSession) {
|
||||
::PMRelease(mSession);
|
||||
mSession = nsnull;
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
nsresult nsPrintSessionX::Init()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv = nsPrintSession::Init();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
@ -72,6 +79,8 @@ nsresult nsPrintSessionX::Init()
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -37,6 +37,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsPrintSettingsX.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsIPrintSessionX.h"
|
||||
|
||||
#include "nsIPrefService.h"
|
||||
@ -74,18 +75,26 @@ public:
|
||||
|
||||
~StHandleOwner()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mHandle)
|
||||
::DisposeHandle(mHandle);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
Handle GetHandle() { return mHandle; }
|
||||
|
||||
void ClearHandle(Boolean disposeIt = false)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (disposeIt)
|
||||
::DisposeHandle(mHandle);
|
||||
|
||||
mHandle = nsnull;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -105,17 +114,24 @@ public:
|
||||
StHandleLocker(Handle theHandle)
|
||||
: mHandle(theHandle)
|
||||
{
|
||||
if (mHandle)
|
||||
{
|
||||
mOldHandleState = ::HGetState(mHandle);
|
||||
::HLock(mHandle);
|
||||
}
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mHandle) {
|
||||
mOldHandleState = ::HGetState(mHandle);
|
||||
::HLock(mHandle);
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
~StHandleLocker()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mHandle)
|
||||
::HSetState(mHandle, mOldHandleState);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -150,6 +166,8 @@ nsPrintSettingsX::nsPrintSettingsX(const nsPrintSettingsX& src) :
|
||||
*/
|
||||
nsPrintSettingsX::~nsPrintSettingsX()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mPageFormat != kPMNoPageFormat) {
|
||||
::PMRelease(mPageFormat);
|
||||
mPageFormat = kPMNoPageFormat;
|
||||
@ -158,12 +176,16 @@ nsPrintSettingsX::~nsPrintSettingsX()
|
||||
::PMRelease(mPrintSettings);
|
||||
mPrintSettings = kPMNoPrintSettings;
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsX& nsPrintSettingsX::operator=(const nsPrintSettingsX& rhs)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
@ -205,12 +227,16 @@ nsPrintSettingsX& nsPrintSettingsX::operator=(const nsPrintSettingsX& rhs)
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(*this);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsresult nsPrintSettingsX::Init()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
OSStatus status;
|
||||
|
||||
PMPrintSession printSession = NULL;
|
||||
@ -229,6 +255,8 @@ nsresult nsPrintSettingsX::Init()
|
||||
status = tempStatus;
|
||||
}
|
||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -267,6 +295,8 @@ NS_IMETHODIMP nsPrintSettingsX::GetPMPageFormat(PMPageFormat *aPMPageFormat)
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPMPageFormat)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG(aPMPageFormat);
|
||||
|
||||
OSStatus status = ::PMRetain(aPMPageFormat);
|
||||
@ -276,6 +306,8 @@ NS_IMETHODIMP nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPMPageFormat)
|
||||
mPageFormat = aPMPageFormat;
|
||||
}
|
||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
@ -287,15 +319,16 @@ NS_IMETHODIMP nsPrintSettingsX::GetPMPrintSettings(PMPrintSettings *aPMPrintSett
|
||||
NS_ENSURE_STATE(mPrintSettings != kPMNoPrintSettings);
|
||||
|
||||
*aPMPrintSettings = mPrintSettings;
|
||||
OSStatus status = noErr;
|
||||
|
||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::SetPMPrintSettings(PMPrintSettings aPMPrintSettings)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG(aPMPrintSettings);
|
||||
|
||||
OSStatus status = ::PMRetain(aPMPrintSettings);
|
||||
@ -305,12 +338,16 @@ NS_IMETHODIMP nsPrintSettingsX::SetPMPrintSettings(PMPrintSettings aPMPrintSetti
|
||||
mPrintSettings = aPMPrintSettings;
|
||||
}
|
||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
@ -365,12 +402,16 @@ NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs()
|
||||
}
|
||||
}
|
||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (mPageFormat == kPMNoPageFormat)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
@ -413,6 +454,8 @@ NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs()
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return prefBranch->SetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
@ -443,6 +486,8 @@ NS_IMETHODIMP nsPrintSettingsX::_Assign(nsIPrintSettings *aPS)
|
||||
//-------------------------------------------
|
||||
OSStatus nsPrintSettingsX::CreateDefaultPageFormat(PMPrintSession aSession, PMPageFormat& outFormat)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
OSStatus status;
|
||||
PMPageFormat pageFormat;
|
||||
|
||||
@ -456,12 +501,16 @@ OSStatus nsPrintSettingsX::CreateDefaultPageFormat(PMPrintSession aSession, PMPa
|
||||
}
|
||||
}
|
||||
return status;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(noErr);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
OSStatus nsPrintSettingsX::CreateDefaultPrintSettings(PMPrintSession aSession, PMPrintSettings& outSettings)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
OSStatus status;
|
||||
PMPrintSettings printSettings;
|
||||
|
||||
@ -474,6 +523,7 @@ OSStatus nsPrintSettingsX::CreateDefaultPrintSettings(PMPrintSession aSession, P
|
||||
return noErr;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(noErr);
|
||||
}
|
||||
|
@ -37,62 +37,79 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsScreenCocoa.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScreenCocoa, nsIScreen)
|
||||
|
||||
nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
|
||||
{
|
||||
mScreen = [screen retain];
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
mScreen = [screen retain];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
nsScreenCocoa::~nsScreenCocoa ()
|
||||
{
|
||||
[mScreen release];
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mScreen release];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenCocoa::GetRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
nsRect r = nsCocoaUtils::CocoaRectToGeckoRect([mScreen frame]);
|
||||
nsRect r = nsCocoaUtils::CocoaRectToGeckoRect([mScreen frame]);
|
||||
|
||||
*outX = r.x;
|
||||
*outY = r.y;
|
||||
*outWidth = r.width;
|
||||
*outHeight = r.height;
|
||||
*outX = r.x;
|
||||
*outY = r.y;
|
||||
*outWidth = r.width;
|
||||
*outHeight = r.height;
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenCocoa::GetAvailRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
nsRect r = nsCocoaUtils::CocoaRectToGeckoRect([mScreen visibleFrame]);
|
||||
nsRect r = nsCocoaUtils::CocoaRectToGeckoRect([mScreen visibleFrame]);
|
||||
|
||||
*outX = r.x;
|
||||
*outY = r.y;
|
||||
*outWidth = r.width;
|
||||
*outHeight = r.height;
|
||||
*outX = r.x;
|
||||
*outY = r.y;
|
||||
*outWidth = r.width;
|
||||
*outHeight = r.height;
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenCocoa::GetPixelDepth(PRInt32 *aPixelDepth)
|
||||
{
|
||||
NSWindowDepth depth = [mScreen depth];
|
||||
int bpp = NSBitsPerPixelFromDepth (depth);
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
*aPixelDepth = bpp;
|
||||
return NS_OK;
|
||||
NSWindowDepth depth = [mScreen depth];
|
||||
int bpp = NSBitsPerPixelFromDepth(depth);
|
||||
|
||||
*aPixelDepth = bpp;
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenCocoa::GetColorDepth(PRInt32 *aColorDepth)
|
||||
{
|
||||
NSWindowDepth depth = [mScreen depth];
|
||||
int bpp = NSBitsPerPixelFromDepth (depth);
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
*aColorDepth = bpp;
|
||||
return NS_OK;
|
||||
NSWindowDepth depth = [mScreen depth];
|
||||
int bpp = NSBitsPerPixelFromDepth (depth);
|
||||
|
||||
*aColorDepth = bpp;
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
@ -36,9 +36,9 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsScreenManagerCocoa.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScreenManagerCocoa, nsIScreenManager)
|
||||
@ -73,6 +73,8 @@ NS_IMETHODIMP
|
||||
nsScreenManagerCocoa::ScreenForRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
nsIScreen **outScreen)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator];
|
||||
NSRect inRect = nsCocoaUtils::GeckoRectToCocoaRect(nsRect(aX, aY, aWidth, aHeight));
|
||||
NSScreen *screenWindowIsOn = [NSScreen mainScreen];
|
||||
@ -94,11 +96,15 @@ nsScreenManagerCocoa::ScreenForRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRI
|
||||
*outScreen = ScreenForCocoaScreen(screenWindowIsOn);
|
||||
NS_ADDREF(*outScreen);
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenManagerCocoa::GetPrimaryScreen (nsIScreen **outScreen)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
// the mainScreen is the screen with the "key window" (focus, I assume?)
|
||||
NSScreen *sc = [[NSScreen screens] objectAtIndex:0];
|
||||
|
||||
@ -106,21 +112,29 @@ nsScreenManagerCocoa::GetPrimaryScreen (nsIScreen **outScreen)
|
||||
NS_ADDREF(*outScreen);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenManagerCocoa::GetNumberOfScreens (PRUint32 *aNumberOfScreens)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NSArray *ss = [NSScreen screens];
|
||||
|
||||
*aNumberOfScreens = [ss count];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenManagerCocoa::ScreenForNativeWidget (void *nativeWidget, nsIScreen **outScreen)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NSView *view = (NSView*) nativeWidget;
|
||||
|
||||
NSWindow *window = [view window];
|
||||
@ -133,4 +147,6 @@ nsScreenManagerCocoa::ScreenForNativeWidget (void *nativeWidget, nsIScreen **out
|
||||
|
||||
*outScreen = nsnull;
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
@ -39,13 +39,13 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSound.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURL.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSound, nsISound)
|
||||
|
||||
nsSound::nsSound()
|
||||
@ -59,8 +59,12 @@ nsSound::~nsSound()
|
||||
NS_IMETHODIMP
|
||||
nsSound::Beep()
|
||||
{
|
||||
NSBeep();
|
||||
return NS_OK;
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NSBeep();
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -70,33 +74,37 @@ nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
NSData *value = [NSData dataWithBytes:data length:dataLen];
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NSSound *sound = [[NSSound alloc] initWithData:value];
|
||||
NSData *value = [NSData dataWithBytes:data length:dataLen];
|
||||
|
||||
[sound play];
|
||||
NSSound *sound = [[NSSound alloc] initWithData:value];
|
||||
|
||||
[sound autorelease];
|
||||
[sound play];
|
||||
|
||||
return NS_OK;
|
||||
[sound autorelease];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri(do_QueryInterface(aURL));
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
return NS_NewStreamLoader(getter_AddRefs(loader), uri, this);
|
||||
nsCOMPtr<nsIURI> uri(do_QueryInterface(aURL));
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
return NS_NewStreamLoader(getter_AddRefs(loader), uri, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Init()
|
||||
{
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@
|
||||
#import <IOKit/IOMessage.h>
|
||||
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
|
||||
#include "nsWidgetAtoms.h"
|
||||
#include "nsIRollupListener.h"
|
||||
@ -128,6 +129,8 @@ nsToolkit::PostSleepWakeNotification(const char* aNotification)
|
||||
// http://developer.apple.com/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/PowerMgmt/chapter_10_section_3.html
|
||||
static void ToolkitSleepWakeCallback(void *refCon, io_service_t service, natural_t messageType, void * messageArgument)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
switch (messageType)
|
||||
{
|
||||
case kIOMessageSystemWillSleep:
|
||||
@ -150,12 +153,16 @@ static void ToolkitSleepWakeCallback(void *refCon, io_service_t service, natural
|
||||
nsToolkit::PostSleepWakeNotification("wake_notification");
|
||||
break;
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsToolkit::RegisterForSleepWakeNotifcations()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
IONotificationPortRef notifyPortRef;
|
||||
|
||||
NS_ASSERTION(!mSleepWakeNotificationRLS, "Already registered for sleep/wake");
|
||||
@ -172,12 +179,16 @@ nsToolkit::RegisterForSleepWakeNotifcations()
|
||||
kCFRunLoopDefaultMode);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsToolkit::RemoveSleepWakeNotifcations()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mSleepWakeNotificationRLS) {
|
||||
::IODeregisterForSystemPower(&mPowerNotifier);
|
||||
::CFRunLoopRemoveSource(::CFRunLoopGetCurrent(),
|
||||
@ -186,6 +197,8 @@ nsToolkit::RemoveSleepWakeNotifcations()
|
||||
|
||||
mSleepWakeNotificationRLS = nsnull;
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
@ -213,6 +226,8 @@ static NSPoint ConvertCGGlobalToCocoaScreen(CGPoint aPoint)
|
||||
// they've already been processed.
|
||||
static CGEventRef EventTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
if ((type == kCGEventTapDisabledByUserInput) ||
|
||||
(type == kCGEventTapDisabledByTimeout))
|
||||
return event;
|
||||
@ -235,6 +250,8 @@ static CGEventRef EventTapCallback(CGEventTapProxy proxy, CGEventType type, CGEv
|
||||
return event;
|
||||
gRollupListener->Rollup(nsnull);
|
||||
return event;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -248,6 +265,8 @@ static CGEventRef EventTapCallback(CGEventTapProxy proxy, CGEventType type, CGEv
|
||||
void
|
||||
nsToolkit::RegisterForAllProcessMouseEvents()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// Don't do this for apps that (like Camino) use native context menus.
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
@ -303,12 +322,16 @@ nsToolkit::RegisterForAllProcessMouseEvents()
|
||||
}
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), mEventTapRLS, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsToolkit::UnregisterAllProcessMouseEventHandlers()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
if (mEventMonitorHandler) {
|
||||
RemoveEventHandler(mEventMonitorHandler);
|
||||
mEventMonitorHandler = nsnull;
|
||||
@ -323,13 +346,17 @@ nsToolkit::UnregisterAllProcessMouseEventHandlers()
|
||||
CFRelease(mEventTapPort);
|
||||
mEventTapPort = nsnull;
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
// Return the nsIToolkit for the current thread. If a toolkit does not
|
||||
// yet exist, then one will be created...
|
||||
NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
|
||||
NS_IMETHODIMP NS_GetCurrentToolkit(nsIToolkit* *aResult)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = nsnull;
|
||||
|
||||
@ -360,11 +387,15 @@ NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
|
||||
}
|
||||
*aResult = toolkit;
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
|
||||
long nsToolkit::OSXVersion()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||
|
||||
static long gOSXVersion = 0x0;
|
||||
if (gOSXVersion == 0x0) {
|
||||
OSErr err = ::Gestalt(gestaltSystemVersion, &gOSXVersion);
|
||||
@ -375,6 +406,8 @@ long nsToolkit::OSXVersion()
|
||||
}
|
||||
}
|
||||
return gOSXVersion;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
|
||||
}
|
||||
|
||||
|
||||
@ -404,6 +437,8 @@ PRBool nsToolkit::OnLeopardOrLater()
|
||||
// of its subclasses.
|
||||
nsresult nsToolkit::SwizzleMethods(Class aClass, SEL orgMethod, SEL posedMethod)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
Method original = class_getInstanceMethod(aClass, orgMethod);
|
||||
Method posed = class_getInstanceMethod(aClass, posedMethod);
|
||||
|
||||
@ -415,4 +450,6 @@ nsresult nsToolkit::SwizzleMethods(Class aClass, SEL orgMethod, SEL posedMethod)
|
||||
posed->method_imp = aMethodImp;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsWindowMap.h"
|
||||
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsChildView.h"
|
||||
#include "nsCocoaWindow.h"
|
||||
|
||||
@ -62,45 +62,73 @@
|
||||
|
||||
+ (WindowDataMap*)sharedWindowDataMap
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
static WindowDataMap* sWindowMap = nil;
|
||||
if (!sWindowMap)
|
||||
sWindowMap = [[WindowDataMap alloc] init];
|
||||
|
||||
return sWindowMap;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
if ((self = [super init])) {
|
||||
mWindowMap = [[NSMutableDictionary alloc] initWithCapacity:10];
|
||||
}
|
||||
return self;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mWindowMap release];
|
||||
[super dealloc];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
- (id)dataForWindow:(NSWindow*)inWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
return [mWindowMap objectForKey:[self keyForWindow:inWindow]];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
- (void)setData:(id)inData forWindow:(NSWindow*)inWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mWindowMap setObject:inData forKey:[self keyForWindow:inWindow]];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
- (void)removeDataForWindow:(NSWindow*)inWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[mWindowMap removeObjectForKey:[self keyForWindow:inWindow]];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
- (NSString*)keyForWindow:(NSWindow*)inWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
return [NSString stringWithFormat:@"%p", inWindow];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -115,6 +143,8 @@
|
||||
|
||||
- (id)initWithWindow:(NSWindow*)inWindow
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
||||
|
||||
if ((self = [super init])) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowBecameKey:)
|
||||
@ -132,12 +162,18 @@
|
||||
object:inWindow];
|
||||
}
|
||||
return self;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[super dealloc];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
// As best I can tell, if the notification's object has a corresponding
|
||||
@ -163,7 +199,9 @@
|
||||
// to child widgets also avoids "win is null" assertions on debug builds
|
||||
// (see bug 354768 comments 55 and 58).
|
||||
- (void)windowBecameKey:(NSNotification*)inNotification
|
||||
{
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
NSWindow* window = (NSWindow*)[inNotification object];
|
||||
id delegate = [window delegate];
|
||||
if (delegate && [delegate respondsToSelector:@selector(sendFocusEvent:)]) {
|
||||
@ -183,6 +221,8 @@
|
||||
if ([firstResponder isKindOfClass:[ChildView class]])
|
||||
[firstResponder viewsWindowDidBecomeKey];
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
// See comments above windowBecameKey:
|
||||
@ -204,6 +244,8 @@
|
||||
// viewsWindowDidResignKey (whether or not we're using top-level widgets).
|
||||
- (void)windowResignedKey:(NSNotification*)inNotification
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
NSWindow* window = (NSWindow*)[inNotification object];
|
||||
id delegate = [window delegate];
|
||||
if (delegate && [delegate respondsToSelector:@selector(sendFocusEvent:)]) {
|
||||
@ -213,15 +255,21 @@
|
||||
id firstResponder = [window firstResponder];
|
||||
if ([firstResponder isKindOfClass:[ChildView class]])
|
||||
[firstResponder viewsWindowDidResignKey];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)inNotification
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
// postpone our destruction
|
||||
[[self retain] autorelease];
|
||||
|
||||
// remove ourselves from the window map (which owns us)
|
||||
[[WindowDataMap sharedWindowDataMap] removeDataForWindow:[inNotification object]];
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user