Bug 397381 - Enable @try/@catch/@finally for Cocoa widgets r=josh sr+a1.9=roc

This commit is contained in:
cbarrett%mozilla.com 2007-10-12 18:30:17 +00:00
Родитель 48dd1fc8b2
Коммит a2182db8b4
3 изменённых файлов: 24 добавлений и 21 удалений

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

@ -182,5 +182,6 @@ LDFLAGS += \
$(NULL)
CXXFLAGS += \
-DUSE_COCOA \
$(NULL)
-DUSE_COCOA \
-fobjc-exceptions \
$(NULL)

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

@ -48,6 +48,7 @@
#include "nsStringStream.h"
#include "nsDragService.h"
#include "nsEscape.h"
#include "nsPrintfCString.h"
// Screenshots use the (undocumented) png pasteboard type.
#define IMAGE_PASTEBOARD_TYPES NSTIFFPboardType, @"Apple PNG pasteboard type", nil
@ -210,17 +211,6 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, PRInt32 aWhi
if (!type)
continue;
// Read data off the clipboard, make sure to catch any exceptions (timeouts)
// XXX should convert to @try/@catch someday?
NSData *pasteboardData = nil;
NS_DURING
pasteboardData = [cocoaPasteboard dataForType:type];
NS_HANDLER
NS_ASSERTION(0, "Exception raised while getting data from the pasteboard.");
NS_ENDHANDLER
if (!pasteboardData)
continue;
// Figure out what type we're converting to
CFStringRef outputType = NULL;
if (flavorStr.EqualsLiteral(kJPEGImageMime))
@ -232,6 +222,16 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, PRInt32 aWhi
else
continue;
// Read data off the clipboard
NSData *pasteboardData = nil;
@try {
pasteboardData = [cocoaPasteboard dataForType:type];
} @catch (NSException* e) {
NS_WARNING(nsPrintfCString(256, "Exception raised while getting data from the pasteboard: \"%s - %s\"",
[[e name] UTF8String], [[e reason] UTF8String]).get());
continue;
}
// Use ImageIO to interpret the data on the clipboard and transcode.
// Note that ImageIO, like all CF APIs, allows NULLs to propagate freely
// and safely in most cases (like ObjC). A notable exception is CFRelease.

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

@ -189,13 +189,14 @@ nsNativeThemeCocoa::DrawButton(CGContextRef cgContext, ThemeButtonKind inKind,
drawFrame.size.height = offscreenHeight - NATIVE_PUSH_BUTTON_HEIGHT_DIFF;
// draw into offscreen image
NS_DURING
@try {
[image lockFocus];
NS_HANDLER
NS_ASSERTION(0, "Could not lock focus on offscreen buffer");
} @catch (NSException* e) {
NS_WARNING(nsPrintfCString(256, "Exception raised while drawing to offscreen buffer: \"%s - %s\"",
[[e name] UTF8String], [[e reason] UTF8String]).get());
[image release];
return;
NS_ENDHANDLER
}
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationLow];
HIThemeDrawButton(&drawFrame, &bdi, (CGContext*)[[NSGraphicsContext currentContext] graphicsPort], kHIThemeOrientationInverted, NULL);
[image unlockFocus];
@ -520,13 +521,14 @@ nsNativeThemeCocoa::DrawScrollbar(CGContextRef aCGContext, const HIRect& aBoxRec
::HIThemeDrawTrack(&tdi, NULL, aCGContext, HITHEME_ORIENTATION);
else {
NSImage *buffer = [[NSImage alloc] initWithSize:NSMakeSize(aBoxRect.size.width, aBoxRect.size.height)];
NS_DURING
@try {
[buffer lockFocus];
NS_HANDLER
NS_ASSERTION(0, "Could not lock focus on offscreen buffer");
} @catch (NSException* e) {
NS_WARNING(nsPrintfCString(256, "Exception raised while drawing to offscreen buffer: \"%s - %s\"",
[[e name] UTF8String], [[e reason] UTF8String]).get());
[buffer release];
return;
NS_ENDHANDLER
}
::HIThemeDrawTrack(&tdi, NULL, (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort],
kHIThemeOrientationInverted);
[buffer unlockFocus];