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

This commit is contained in:
reed@reedloden.com 2007-10-22 22:44:25 -07:00
Родитель 239238cfa5
Коммит 8b9ad94571
3 изменённых файлов: 44 добавлений и 20 удалений

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

@ -181,5 +181,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
@ -73,6 +74,23 @@ nsClipboard::~nsClipboard()
}
// We separate this into its own function because after an @try, all local
// variables within that function get marked as volatile, and our C++ type
// system doesn't like volatile things.
static NSData*
GetDataFromPasteboard(NSPasteboard* aPasteboard, NSString* aType)
{
NSData *data = nil;
@try {
data = [aPasteboard dataForType:aType];
} @catch (NSException* e) {
NS_WARNING(nsPrintfCString(256, "Exception raised while getting data from the pasteboard: \"%s - %s\"",
[[e name] UTF8String], [[e reason] UTF8String]).get());
}
return data;
}
NS_IMETHODIMP
nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard)
{
@ -213,14 +231,8 @@ 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
// Read data off the clipboard
NSData *pasteboardData = GetDataFromPasteboard(cocoaPasteboard, type);
if (!pasteboardData)
continue;

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

@ -110,6 +110,23 @@ IsTransformOnlyTranslateOrFlip(CGAffineTransform aTransform)
}
// We separate this into its own function because after an @try, all local
// variables within that function get marked as volatile, and our C++ type
// system doesn't like volatile things.
static PRBool
LockFocusOnImage(NSImage* aImage)
{
@try {
[aImage lockFocus];
} @catch (NSException* e) {
NS_WARNING(nsPrintfCString(256, "Exception raised while drawing to offscreen buffer: \"%s - %s\"",
[[e name] UTF8String], [[e reason] UTF8String]).get());
return PR_FALSE;
}
return PR_TRUE;
}
void
nsNativeThemeCocoa::DrawCheckboxRadio(CGContextRef cgContext, ThemeButtonKind inKind,
const HIRect& inBoxRect, PRBool inChecked,
@ -189,13 +206,10 @@ nsNativeThemeCocoa::DrawButton(CGContextRef cgContext, ThemeButtonKind inKind,
drawFrame.size.height = offscreenHeight - NATIVE_PUSH_BUTTON_HEIGHT_DIFF;
// draw into offscreen image
NS_DURING
[image lockFocus];
NS_HANDLER
NS_ASSERTION(0, "Could not lock focus on offscreen buffer");
if (!LockFocusOnImage(image)) {
[image release];
return;
NS_ENDHANDLER
}
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationLow];
HIThemeDrawButton(&drawFrame, &bdi, (CGContext*)[[NSGraphicsContext currentContext] graphicsPort], kHIThemeOrientationInverted, NULL);
[image unlockFocus];
@ -520,13 +534,10 @@ 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
[buffer lockFocus];
NS_HANDLER
NS_ASSERTION(0, "Could not lock focus on offscreen buffer");
if (!LockFocusOnImage(buffer)) {
[buffer release];
return;
NS_ENDHANDLER
}
::HIThemeDrawTrack(&tdi, NULL, (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort],
kHIThemeOrientationInverted);
[buffer unlockFocus];