Mercurial > osx-quasimode
annotate Quasimode.m @ 7:cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 11 Apr 2010 19:17:08 -0700 |
parents | MyApp.m@ea0dcbf6a0bc |
children | 353aee1ddf91 |
rev | line source |
---|---|
0 | 1 #import <Foundation/NSAutoreleasePool.h> |
2
d5305f9c8dce
Added trivial embedded WebKit.
Atul Varma <avarma@mozilla.com>
parents:
0
diff
changeset
|
2 #import <Foundation/NSURL.h> |
d5305f9c8dce
Added trivial embedded WebKit.
Atul Varma <avarma@mozilla.com>
parents:
0
diff
changeset
|
3 #import <Foundation/NSURLRequest.h> |
0 | 4 #import <AppKit/NSApplication.h> |
5 #import <AppKit/NSWindow.h> | |
3 | 6 #import <AppKit/NSColor.h> |
2
d5305f9c8dce
Added trivial embedded WebKit.
Atul Varma <avarma@mozilla.com>
parents:
0
diff
changeset
|
7 #import <WebKit/WebView.h> |
d5305f9c8dce
Added trivial embedded WebKit.
Atul Varma <avarma@mozilla.com>
parents:
0
diff
changeset
|
8 #import <WebKit/WebFrame.h> |
d5305f9c8dce
Added trivial embedded WebKit.
Atul Varma <avarma@mozilla.com>
parents:
0
diff
changeset
|
9 #import <WebKit/WebFrameView.h> |
6 | 10 #import <WebKit/DOMEvents.h> |
5
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
11 #import <JavaScriptCore/JavaScriptCore.h> |
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
12 |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
13 void QModeClassInitialize(JSContextRef ctx, JSObjectRef object); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
14 |
5
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
15 JSValueRef boop(JSContextRef ctx, |
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
16 JSObjectRef function, |
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
17 JSObjectRef thisObject, |
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
18 size_t argumentCount, |
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
19 const JSValueRef arguments[], |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
20 JSValueRef* exception); |
5
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
21 |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
22 @interface QMode : NSObject { |
6 | 23 NSWindow *window; |
24 WebView *view; | |
25 } | |
26 - (id)init; | |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
27 - (void)setSizeWithX:(int)X Y:(int)Y; |
6 | 28 @end |
29 | |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
30 @implementation QMode |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
31 - (void)setSizeWithX:(int)X Y:(int)Y { |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
32 printf("setSize(%d, %d)\n", X, Y); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
33 } |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
34 |
6 | 35 - (void)defineJSGlobals { |
36 JSGlobalContextRef ctx = [[view mainFrame] globalContext]; | |
37 | |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
38 JSClassDefinition classDef = kJSClassDefinitionEmpty; |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
39 classDef.initialize = QModeClassInitialize; |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
40 classDef.className = "QMode"; |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
41 |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
42 JSClassRef class = JSClassCreate(&classDef); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
43 JSObjectRef myApp = JSObjectMake(ctx, class, self); |
5
620147798b16
Added a custom 'window.boop' function to the page.
Atul Varma <avarma@mozilla.com>
parents:
4
diff
changeset
|
44 JSObjectRef global = JSContextGetGlobalObject(ctx); |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
45 JSStringRef myAppStr = JSStringCreateWithUTF8CString("myApp"); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
46 |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
47 JSObjectSetProperty(ctx, global, myAppStr, myApp, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
48 kJSPropertyAttributeReadOnly | |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
49 kJSPropertyAttributeDontDelete, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
50 NULL); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
51 } |
0 | 52 |
6 | 53 - (id)init { |
54 if (self = [super init]) { | |
55 NSRect rect = {{20, 20}, | |
56 {100, 100}}; | |
57 | |
58 window = [[NSWindow alloc] initWithContentRect: rect | |
59 styleMask: NSBorderlessWindowMask | |
60 backing: NSBackingStoreBuffered | |
61 defer: YES]; | |
62 | |
63 view = [[WebView alloc] initWithFrame: rect | |
64 frameName: nil | |
65 groupName: nil]; | |
66 | |
67 NSURL *url = [NSURL URLWithString: @"http://127.0.0.1:8000"]; | |
68 NSURLRequest *req = [ | |
69 NSURLRequest requestWithURL: url | |
70 cachePolicy: NSURLRequestReloadIgnoringLocalCacheData | |
71 timeoutInterval: 5 | |
72 ]; | |
73 | |
74 [view setDrawsBackground: NO]; | |
75 [[[view mainFrame] frameView] setAllowsScrolling: NO]; | |
76 [[view mainFrame] loadRequest: req]; | |
77 | |
78 [self defineJSGlobals]; | |
79 | |
80 [window setOpaque: NO]; | |
81 [window setBackgroundColor: [NSColor colorWithCalibratedRed: 0.0 | |
82 green: 0.0 | |
83 blue: 0.0 | |
84 alpha: 0.0]]; | |
85 [window setContentView: view]; | |
86 [window setLevel: NSScreenSaverWindowLevel]; | |
87 [window makeKeyAndOrderFront: self]; | |
88 } | |
89 return self; | |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
90 } |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
91 @end |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
92 |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
93 void QModeClassInitialize(JSContextRef ctx, JSObjectRef object) |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
94 { |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
95 JSStringRef boopStr = JSStringCreateWithUTF8CString("boop"); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
96 JSObjectRef func = JSObjectMakeFunctionWithCallback(ctx, boopStr, boop); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
97 |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
98 JSObjectSetProperty(ctx, object, boopStr, func, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
99 kJSPropertyAttributeReadOnly | |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
100 kJSPropertyAttributeDontDelete, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
101 NULL); |
6 | 102 } |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
103 |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
104 JSValueRef boop(JSContextRef ctx, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
105 JSObjectRef function, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
106 JSObjectRef thisObject, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
107 size_t argumentCount, |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
108 const JSValueRef arguments[], |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
109 JSValueRef* exception) |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
110 { |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
111 if (argumentCount >= 1 && |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
112 JSValueIsNumber(ctx, arguments[0])) { |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
113 QMode *app = (QMode *) JSObjectGetPrivate(thisObject); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
114 [app setSizeWithX: (int) JSValueToNumber(ctx, arguments[0], NULL) |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
115 Y: 0]; |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
116 } |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
117 return JSValueMakeUndefined(ctx); |
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
118 } |
6 | 119 |
0 | 120 int main(int argc, const char *argv[]) |
121 { | |
122 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
123 | |
124 [NSApplication sharedApplication]; | |
125 | |
7
cd9bef04e813
Renamed MyApp to Quasimode, made a new JSClass that reflects the app to JS
Atul Varma <avarma@mozilla.com>
parents:
6
diff
changeset
|
126 QMode *app = [[QMode alloc] init]; |
0 | 127 |
128 [NSApp run]; | |
129 | |
130 return 0; | |
131 } |