From 52074b4cac0c66900236baef705d27f6d6d55542 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 18 Apr 2011 10:49:47 +0200 Subject: [PATCH] [broadway] Report most special keys in keypressed 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 | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js index d6fb43d36..806ed7622 100644 --- a/gdk/broadway/broadway.js +++ b/gdk/broadway/broadway.js @@ -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) -- 2.43.2