1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[dom] keyCodes like in Firefox

KeyboardEvent.keyCode returns 0 in Firefox for test case.
I won't change the test, because elinks relies on libdom API.
This commit is contained in:
Witold Filipczyk 2024-05-12 16:51:04 +02:00
parent 2b4dd0f7ba
commit 8a2e85b73f
2 changed files with 33 additions and 4 deletions

View File

@ -228,7 +228,6 @@ static const char *__keys_names[] = {
"Insert", "Insert",
"Delete", "Delete",
"F1", "F1",
"F1",
"F2", "F2",
"F3", "F3",
"F4", "F4",
@ -254,6 +253,7 @@ static enum {
KEYB_HOME, KEYB_HOME,
KEYB_END, KEYB_END,
KEYB_ESCAPE, KEYB_ESCAPE,
KEYB_BACKSPACE,
KEYB_TAB, KEYB_TAB,
KEYB_INSERT, KEYB_INSERT,
KEYB_DELETE, KEYB_DELETE,
@ -338,30 +338,55 @@ convert_dom_string_to_keycode(dom_string *dom_key)
case KEYB_ENTER: case KEYB_ENTER:
return 13; return 13;
case KEYB_ARROW_LEFT: case KEYB_ARROW_LEFT:
return 37;
case KEYB_ARROW_RIGHT: case KEYB_ARROW_RIGHT:
return 39;
case KEYB_ARROW_UP: case KEYB_ARROW_UP:
return 38;
case KEYB_ARROW_DOWN: case KEYB_ARROW_DOWN:
return 40;
case KEYB_PAGE_UP: case KEYB_PAGE_UP:
return 33;
case KEYB_PAGE_DOWN: case KEYB_PAGE_DOWN:
return 34;
case KEYB_HOME: case KEYB_HOME:
return 36;
case KEYB_END: case KEYB_END:
return 35;
case KEYB_ESCAPE: case KEYB_ESCAPE:
return 27;
case KEYB_BACKSPACE:
return 8;
case KEYB_TAB: case KEYB_TAB:
return 9;
case KEYB_INSERT: case KEYB_INSERT:
return 45;
case KEYB_DELETE: case KEYB_DELETE:
return 46;
case KEYB_F1: case KEYB_F1:
return 112;
case KEYB_F2: case KEYB_F2:
return 113;
case KEYB_F3: case KEYB_F3:
return 114;
case KEYB_F4: case KEYB_F4:
return 115;
case KEYB_F5: case KEYB_F5:
return 116;
case KEYB_F6: case KEYB_F6:
return 117;
case KEYB_F7: case KEYB_F7:
return 118;
case KEYB_F8: case KEYB_F8:
return 119;
case KEYB_F9: case KEYB_F9:
return 120;
case KEYB_F10: case KEYB_F10:
return 121;
case KEYB_F11: case KEYB_F11:
return 122;
case KEYB_F12: case KEYB_F12:
return 0; return 123;
default: default:
{ {
char *utf8 = dom_string_data(dom_key); char *utf8 = dom_string_data(dom_key);

View File

@ -1,13 +1,17 @@
<script> <script>
var e = new KeyboardEvent('message', { cancelable: true, key: "Enter" }); var e = new KeyboardEvent('keydown', { cancelable: true, key: "Enter" });
console.error('keyboardEvent.html'); console.error('keyboardEvent.html');
console.assert(e.cancelable, 'cancelable true'); console.assert(e.cancelable, 'cancelable true');
console.assert(!e.defaultPrevented, 'false'); console.assert(!e.defaultPrevented, 'false');
e.preventDefault(); e.preventDefault();
console.assert(e.defaultPrevented, 'true'); console.assert(e.defaultPrevented, 'true');
console.assert(e.type === 'message', 'message'); console.assert(e.type === 'keydown', 'keydown');
console.assert(e.key === 'Enter', 'key Enter'); console.assert(e.key === 'Enter', 'key Enter');
console.assert(e.keyCode === 13, 'ENTER = 13'); console.assert(e.keyCode === 13, 'ENTER = 13');
var e = new KeyboardEvent('keydown', { cancelable: true, key: "F12" });
console.assert(e.keyCode === 123, e.keyCode);
console.exit(0); console.exit(0);
</script> </script>