Mercurial > osx-quasimode
changeset 6:ea0dcbf6a0bc
Converted app to objective C
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 11 Apr 2010 18:33:24 -0700 |
parents | 620147798b16 |
children | cd9bef04e813 |
files | MyApp.m |
diffstat | 1 files changed, 53 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/MyApp.m Sun Apr 11 17:30:57 2010 -0700 +++ b/MyApp.m Sun Apr 11 18:33:24 2010 -0700 @@ -7,6 +7,7 @@ #import <WebKit/WebView.h> #import <WebKit/WebFrame.h> #import <WebKit/WebFrameView.h> +#import <WebKit/DOMEvents.h> #import <JavaScriptCore/JavaScriptCore.h> JSValueRef boop(JSContextRef ctx, @@ -24,56 +25,71 @@ return JSValueMakeUndefined(ctx); } -void defineJSGlobals(JSGlobalContextRef ctx) -{ - JSGlobalContextRetain(ctx); +@interface MyApp : NSObject { + NSWindow *window; + WebView *view; +} +- (id)init; +@end + +@implementation MyApp +- (void)defineJSGlobals { + JSGlobalContextRef ctx = [[view mainFrame] globalContext]; + JSObjectRef global = JSContextGetGlobalObject(ctx); JSStringRef boopStr = JSStringCreateWithUTF8CString("boop"); JSObjectRef func = JSObjectMakeFunctionWithCallback(ctx, boopStr, boop); JSObjectSetProperty(ctx, global, boopStr, func, NULL, kJSPropertyAttributeNone); - JSGlobalContextRelease(ctx); } +- (id)init { + if (self = [super init]) { + NSRect rect = {{20, 20}, + {100, 100}}; + + window = [[NSWindow alloc] initWithContentRect: rect + styleMask: NSBorderlessWindowMask + backing: NSBackingStoreBuffered + defer: YES]; + + view = [[WebView alloc] initWithFrame: rect + frameName: nil + groupName: nil]; + + NSURL *url = [NSURL URLWithString: @"http://127.0.0.1:8000"]; + NSURLRequest *req = [ + NSURLRequest requestWithURL: url + cachePolicy: NSURLRequestReloadIgnoringLocalCacheData + timeoutInterval: 5 + ]; + + [view setDrawsBackground: NO]; + [[[view mainFrame] frameView] setAllowsScrolling: NO]; + [[view mainFrame] loadRequest: req]; + + [self defineJSGlobals]; + + [window setOpaque: NO]; + [window setBackgroundColor: [NSColor colorWithCalibratedRed: 0.0 + green: 0.0 + blue: 0.0 + alpha: 0.0]]; + [window setContentView: view]; + [window setLevel: NSScreenSaverWindowLevel]; + [window makeKeyAndOrderFront: self]; + } + return self; +} +@end + int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [NSApplication sharedApplication]; - NSRect rect = {{20, 20}, - {100, 100}}; - - NSWindow *window = [[NSWindow alloc] initWithContentRect: rect - styleMask: NSBorderlessWindowMask - backing: NSBackingStoreBuffered - defer: YES]; - - WebView *view = [[WebView alloc] initWithFrame: rect - frameName: nil - groupName: nil]; - - NSURL *url = [NSURL URLWithString: @"http://127.0.0.1:8000"]; - NSURLRequest *req = [ - NSURLRequest requestWithURL: url - cachePolicy: NSURLRequestReloadIgnoringLocalCacheData - timeoutInterval: 5 - ]; - - [view setDrawsBackground: NO]; - [[[view mainFrame] frameView] setAllowsScrolling: NO]; - [[view mainFrame] loadRequest: req]; - - defineJSGlobals([[view mainFrame] globalContext]); - - [window setOpaque: NO]; - [window setBackgroundColor: [NSColor colorWithCalibratedRed: 0.0 - green: 0.0 - blue: 0.0 - alpha: 0.0]]; - [window setContentView: view]; - [window setLevel: NSScreenSaverWindowLevel]; - [window makeKeyAndOrderFront: NSApp]; + MyApp *app = [[MyApp alloc] init]; [NSApp run];