changeset 24:f2f634d576cf

quasimodal events now propogate to JS.
author Atul Varma <avarma@mozilla.com>
date Mon, 12 Apr 2010 01:40:16 -0700
parents 0e91c6d2a547
children 5396bc2158b9
files QuasimodalEventTap.m Quasimode.m
diffstat 2 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/QuasimodalEventTap.m	Mon Apr 12 01:09:30 2010 -0700
+++ b/QuasimodalEventTap.m	Mon Apr 12 01:40:16 2010 -0700
@@ -37,7 +37,7 @@
     if (inQuasimode) {
       if (!(flags & quasimodeKey)) {
         NSArray *keys = [NSArray arrayWithObjects: @"type", nil];
-        NSArray *values = [NSArray arrayWithObjects: @"quasimodeEnd", nil];
+        NSArray *values = [NSArray arrayWithObjects: @"quasimodeend", nil];
         NSDictionary *dict = [NSDictionary dictionaryWithObjects: values
                                            forKeys: keys];
 
@@ -77,7 +77,7 @@
     } else {
       if (flags & quasimodeKey) {
         NSArray *keys = [NSArray arrayWithObjects: @"type", nil];
-        NSArray *values = [NSArray arrayWithObjects: @"quasimodeStart", nil];
+        NSArray *values = [NSArray arrayWithObjects: @"quasimodestart", nil];
         NSDictionary *dict = [NSDictionary dictionaryWithObjects: values
                                            forKeys: keys];
 
@@ -120,9 +120,9 @@
         numQuasimodalKeyDowns += 1;
         lastQuasimodalKeyCode = keycode;
         lastQuasimodalKeyFlags = CGEventGetFlags(event);
-        eventType = @"keyDown";
+        eventType = @"quasimodekeydown";
       } else
-        eventType = @"keyUp";
+        eventType = @"quasimodekeyup";
 
       NSNumber *keycodeNum = [NSNumber numberWithUnsignedInt: keycode];
 
--- a/Quasimode.m	Mon Apr 12 01:09:30 2010 -0700
+++ b/Quasimode.m	Mon Apr 12 01:40:16 2010 -0700
@@ -12,10 +12,35 @@
 #import "QuasimodalEventTap.h"
 
 @implementation Quasimode
+- onEvent:(NSNotification *)notification {
+  NSString *type = [[notification userInfo] valueForKey: @"type"];
+  DOMDocument *document = [[view mainFrame] DOMDocument];
+  DOMEvent *event = [document createEvent: @"KeyboardEvent"];
+  DOMKeyboardEvent *keyEvent = (DOMKeyboardEvent *) event;
+  [keyEvent initKeyboardEvent: type
+            canBubble: NO
+            cancelable: NO
+            view: [document defaultView]
+            keyIdentifier: nil
+            keyLocation: 0
+            ctrlKey: NO
+            altKey: NO
+            shiftKey: NO
+            metaKey: YES
+            altGraphKey: NO];
+  [document dispatchEvent: event];
+}
+
 - (id)initWithEventSource:(NSString *)sourceName {
   if (self = [super init]) {
     eventSource = [sourceName copy];
 
+    [[NSNotificationCenter defaultCenter]
+      addObserver: self
+      selector: @selector(onEvent:)
+      name: @"QuasimodeEvent"
+      object: eventSource];
+
     NSRect rect = {{20, 20},
                    {100, 100}};