]> Pileus Git - ~andy/gtk/commitdiff
[broadway] Report most special keys in keypressed
authorAlexander Larsson <alexl@redhat.com>
Mon, 18 Apr 2011 08:49:47 +0000 (10:49 +0200)
committerAlexander Larsson <alexl@redhat.com>
Mon, 18 Apr 2011 08:55:41 +0000 (10:55 +0200)
Some special key keycode values as seen in keydown actually match
normal keys (like "." has a keyCode 46 on keyPress, which is the same
as Delete, but 190 for KeyDown). So we must match the special keys on
keypress. However, some things must be checked on keydown as they are not
generating keypress events.

gdk/broadway/broadway.js

index d6fb43d3667a361889e1531685d85d586eff7624..806ed7622dda3c98c03f05f71313d4c006d27aec 100644 (file)
@@ -2376,10 +2376,17 @@ var unicodeTable = {
     0x28ff: 0x10028ff
 };
 
+var ON_KEYDOWN = 1 << 0; /* Report on keydown, otherwise wait until keypress  */
+
+
 var specialKeyTable = {
-    8: 0xFF08, // BACKSPACE
-    13: 0xFF0D, // ENTER
-    9: 0xFF09, // TAB
+    // These generate a keyDown and keyPress in Firefox and Opera
+    8: [0xFF08, ON_KEYDOWN], // BACKSPACE
+    13: [0xFF0D, ON_KEYDOWN], // ENTER
+
+    // This generates a keyDown and keyPress in Opera
+    9: [0xFF09, ON_KEYDOWN], // TAB
+
     27: 0xFF1B, // ESCAPE
     46: 0xFFFF, // DELETE
     36: 0xFF50, // HOME
@@ -2420,10 +2427,16 @@ function getEventKeySym(ev) {
 // with the key. The rest we pass on to keypress so we can get the
 // translated keysym.
 function getKeysymSpecial(ev) {
-    // These are simple and risky to pass on to browser, handle directly
-   if ((ev.keyCode in specialKeyTable))
-       return specialKeyTable[ev.keyCode];
-
+    if (ev.keyCode in specialKeyTable) {
+       var r = specialKeyTable[ev.keyCode];
+       var flags = 0;
+       if (typeof r != 'number') {
+           flags = r[1];
+           r = r[0];
+       }
+       if (ev.type === 'keydown' || flags & ON_KEYDOWN)
+           return r;
+    }
     // If we don't hold alt or ctrl, then we should be safe to pass
     // on to keypressed and look at the translated data
     if (!ev.ctrlKey && !ev.altKey)