Mercurial > osx-quasimode
view Quasimode.m @ 8:353aee1ddf91
renamed boop() to setSize(), setSize() now passes both x and y args
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 11 Apr 2010 19:20:52 -0700 |
parents | cd9bef04e813 |
children | d8d966549380 |
line wrap: on
line source
#import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSURL.h> #import <Foundation/NSURLRequest.h> #import <AppKit/NSApplication.h> #import <AppKit/NSWindow.h> #import <AppKit/NSColor.h> #import <WebKit/WebView.h> #import <WebKit/WebFrame.h> #import <WebKit/WebFrameView.h> #import <WebKit/DOMEvents.h> #import <JavaScriptCore/JavaScriptCore.h> void QModeClassInitialize(JSContextRef ctx, JSObjectRef object); JSValueRef setSize(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); @interface QMode : NSObject { NSWindow *window; WebView *view; } - (id)init; - (void)setSizeWithX:(int)X Y:(int)Y; @end @implementation QMode - (void)setSizeWithX:(int)X Y:(int)Y { printf("setSize(%d, %d)\n", X, Y); } - (void)defineJSGlobals { JSGlobalContextRef ctx = [[view mainFrame] globalContext]; JSClassDefinition classDef = kJSClassDefinitionEmpty; classDef.initialize = QModeClassInitialize; classDef.className = "QMode"; JSClassRef class = JSClassCreate(&classDef); JSObjectRef myApp = JSObjectMake(ctx, class, self); JSObjectRef global = JSContextGetGlobalObject(ctx); JSStringRef myAppStr = JSStringCreateWithUTF8CString("myApp"); JSObjectSetProperty(ctx, global, myAppStr, myApp, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); } - (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 void QModeClassInitialize(JSContextRef ctx, JSObjectRef object) { JSStringRef setSizeStr = JSStringCreateWithUTF8CString("setSize"); JSObjectRef func = JSObjectMakeFunctionWithCallback(ctx, setSizeStr, setSize); JSObjectSetProperty(ctx, object, setSizeStr, func, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); } JSValueRef setSize(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount >= 2 && JSValueIsNumber(ctx, arguments[0]) && JSValueIsNumber(ctx, arguments[1])) { QMode *app = (QMode *) JSObjectGetPrivate(thisObject); [app setSizeWithX: (int) JSValueToNumber(ctx, arguments[0], NULL) Y: (int) JSValueToNumber(ctx, arguments[1], NULL)]; } return JSValueMakeUndefined(ctx); } int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [NSApplication sharedApplication]; QMode *app = [[QMode alloc] init]; [NSApp run]; return 0; }