From 9c1b4db87624e9c0688fdd22118adc762efb69cb Mon Sep 17 00:00:00 2001 From: "joshmoz%gmail.com" Date: Tue, 3 Apr 2007 20:19:36 +0000 Subject: [PATCH] Package cursor images correctly on Mac OS X so that all CSS cursor values work. b=349618 r=smorgan sr=bsmedberg --- widget/src/cocoa/Makefile.in | 1 + widget/src/cocoa/nsMacCursor.mm | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/widget/src/cocoa/Makefile.in b/widget/src/cocoa/Makefile.in index 06c77506d1f..148a7004aba 100644 --- a/widget/src/cocoa/Makefile.in +++ b/widget/src/cocoa/Makefile.in @@ -170,6 +170,7 @@ ifneq ($(ABS_topsrcdir),$(MOZ_BUILD_ROOT)) export:: ln -fs $(srcdir)/cursors endif + $(INSTALL) $(srcdir)/cursors $(DIST)/bin/res $(RESOURCE): $(RES_SRC) /Developer/Tools/Rez -i /Developer/Headers/FlatCarbon -useDF $< -o $@ diff --git a/widget/src/cocoa/nsMacCursor.mm b/widget/src/cocoa/nsMacCursor.mm index 18804c2dc24..df4f08bf87d 100644 --- a/widget/src/cocoa/nsMacCursor.mm +++ b/widget/src/cocoa/nsMacCursor.mm @@ -37,6 +37,10 @@ #include "nsMacCursor.h" #include "nsDebug.h" +#include "nsDirectoryServiceDefs.h" +#include "nsCOMPtr.h" +#include "nsIFile.h" +#include "nsString.h" /*! @category nsMacCursor (PrivateMethods) @abstract Private methods internal to the nsMacCursor class. @@ -345,7 +349,32 @@ - (id) initWithImageNamed: (NSString *) aCursorImage hotSpot: (NSPoint) aPoint { - return [self initWithCursor: [[NSCursor alloc] initWithImage: [NSImage imageNamed: aCursorImage] hotSpot: aPoint]]; + nsCOMPtr resDir; + nsCAutoString resPath; + NSString* pathToImage; + NSImage* cursorImage; + + nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(resDir)); + if (NS_FAILED(rv)) goto INIT_FAILURE; + resDir->AppendNative(NS_LITERAL_CSTRING("res")); + resDir->AppendNative(NS_LITERAL_CSTRING("cursors")); + + rv = resDir->GetNativePath(resPath); + if (NS_FAILED(rv)) goto INIT_FAILURE; + + pathToImage = [NSString stringWithUTF8String:(const char*)resPath.get()]; + if (!pathToImage) goto INIT_FAILURE; + pathToImage = [pathToImage stringByAppendingPathComponent:aCursorImage]; + pathToImage = [pathToImage stringByAppendingPathExtension:@"tiff"]; + + cursorImage = [[[NSImage alloc] initWithContentsOfFile:pathToImage] autorelease]; + if (!cursorImage) goto INIT_FAILURE; + return [self initWithCursor: [[NSCursor alloc] initWithImage: cursorImage hotSpot: aPoint]]; + +INIT_FAILURE: + NS_WARNING("Problem getting path to cursor image file!"); + [self release]; + return nil; } - (void) setFrame: (int) aFrameIndex