mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[spidermonkey] KeyboardEvent.keyCode (Enter only)
Only Enter is handled. Strings are not "finalized".
This commit is contained in:
parent
4439f4e976
commit
20ab63c1d1
@ -211,3 +211,162 @@ convert_key_to_dom_string(term_event_key_T key, dom_string **res)
|
|||||||
*res = dom_key;
|
*res = dom_key;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *__keys_names[] = {
|
||||||
|
"Enter",
|
||||||
|
"ArrowLeft",
|
||||||
|
"ArrowRight",
|
||||||
|
"ArrowUp",
|
||||||
|
"ArrowDown",
|
||||||
|
"PageUp",
|
||||||
|
"PageDown",
|
||||||
|
"Home",
|
||||||
|
"End",
|
||||||
|
"Escape",
|
||||||
|
"Backspace",
|
||||||
|
"Tab",
|
||||||
|
"Insert",
|
||||||
|
"Delete",
|
||||||
|
"F1",
|
||||||
|
"F1",
|
||||||
|
"F2",
|
||||||
|
"F3",
|
||||||
|
"F4",
|
||||||
|
"F5",
|
||||||
|
"F6",
|
||||||
|
"F7",
|
||||||
|
"F8",
|
||||||
|
"F9",
|
||||||
|
"F10",
|
||||||
|
"F11",
|
||||||
|
"F12",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static enum {
|
||||||
|
KEYB_ENTER,
|
||||||
|
KEYB_ARROW_LEFT,
|
||||||
|
KEYB_ARROW_RIGHT,
|
||||||
|
KEYB_ARROW_UP,
|
||||||
|
KEYB_ARROW_DOWN,
|
||||||
|
KEYB_PAGE_UP,
|
||||||
|
KEYB_PAGE_DOWN,
|
||||||
|
KEYB_HOME,
|
||||||
|
KEYB_END,
|
||||||
|
KEYB_ESCAPE,
|
||||||
|
KEYB_TAB,
|
||||||
|
KEYB_INSERT,
|
||||||
|
KEYB_DELETE,
|
||||||
|
KEYB_F1,
|
||||||
|
KEYB_F2,
|
||||||
|
KEYB_F3,
|
||||||
|
KEYB_F4,
|
||||||
|
KEYB_F5,
|
||||||
|
KEYB_F6,
|
||||||
|
KEYB_F7,
|
||||||
|
KEYB_F8,
|
||||||
|
KEYB_F9,
|
||||||
|
KEYB_F10,
|
||||||
|
KEYB_F11,
|
||||||
|
KEYB_F12,
|
||||||
|
KEYB_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
static lwc_string *keyb_lwc[KEYB_COUNT];
|
||||||
|
|
||||||
|
static void
|
||||||
|
initialize_keyb(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < KEYB_COUNT; i++) {
|
||||||
|
dom_exception err = lwc_intern_string(__keys_names[i], strlen(__keys_names[i]), &keyb_lwc[i]);
|
||||||
|
|
||||||
|
if (err != lwc_error_ok) {
|
||||||
|
return;
|
||||||
|
//return _dom_exception_from_lwc_error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
finalize_keyb(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < KEYB_COUNT; i++) {
|
||||||
|
if (keyb_lwc[i] != NULL) {
|
||||||
|
lwc_string_unref(keyb_lwc[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unicode_val_T
|
||||||
|
convert_dom_string_to_keycode(dom_string *dom_key)
|
||||||
|
{
|
||||||
|
static int initialized = 0;
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
initialize_keyb();
|
||||||
|
initialized = 1;
|
||||||
|
}
|
||||||
|
if (!dom_key) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int et = -1;
|
||||||
|
lwc_string *t = NULL;
|
||||||
|
dom_exception err;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
err = dom_string_intern(dom_key, &t);
|
||||||
|
|
||||||
|
if (err != DOM_NO_ERR) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
assert(t != NULL);
|
||||||
|
|
||||||
|
for (i = 0; i < KEYB_COUNT; i++) {
|
||||||
|
if (keyb_lwc[i] == t) {
|
||||||
|
et = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lwc_string_unref(t);
|
||||||
|
|
||||||
|
switch (et) {
|
||||||
|
case KEYB_ENTER:
|
||||||
|
return 13;
|
||||||
|
case KEYB_ARROW_LEFT:
|
||||||
|
case KEYB_ARROW_RIGHT:
|
||||||
|
case KEYB_ARROW_UP:
|
||||||
|
case KEYB_ARROW_DOWN:
|
||||||
|
case KEYB_PAGE_UP:
|
||||||
|
case KEYB_PAGE_DOWN:
|
||||||
|
case KEYB_HOME:
|
||||||
|
case KEYB_END:
|
||||||
|
case KEYB_ESCAPE:
|
||||||
|
case KEYB_TAB:
|
||||||
|
case KEYB_INSERT:
|
||||||
|
case KEYB_DELETE:
|
||||||
|
case KEYB_F1:
|
||||||
|
case KEYB_F2:
|
||||||
|
case KEYB_F3:
|
||||||
|
case KEYB_F4:
|
||||||
|
case KEYB_F5:
|
||||||
|
case KEYB_F6:
|
||||||
|
case KEYB_F7:
|
||||||
|
case KEYB_F8:
|
||||||
|
case KEYB_F9:
|
||||||
|
case KEYB_F10:
|
||||||
|
case KEYB_F11:
|
||||||
|
case KEYB_F12:
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
char *utf8 = dom_string_data(dom_key);
|
||||||
|
char *end = utf8 + dom_string_length(dom_key);
|
||||||
|
return utf8_to_unicode(&utf8, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ void free_document(void *doc);
|
|||||||
void *el_match_selector(const char *selector, void *node);
|
void *el_match_selector(const char *selector, void *node);
|
||||||
void add_lowercase_to_string(struct string *buf, const char *str, int len);
|
void add_lowercase_to_string(struct string *buf, const char *str, int len);
|
||||||
bool convert_key_to_dom_string(term_event_key_T key, dom_string **res);
|
bool convert_key_to_dom_string(term_event_key_T key, dom_string **res);
|
||||||
|
unicode_val_T convert_dom_string_to_keycode(dom_string *dom_key);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
static bool keyboardEvent_get_property_code(JSContext *cx, unsigned int argc, JS::Value *vp);
|
static bool keyboardEvent_get_property_code(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
static bool keyboardEvent_get_property_key(JSContext *cx, unsigned int argc, JS::Value *vp);
|
static bool keyboardEvent_get_property_key(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool keyboardEvent_get_property_keyCode(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
static bool keyboardEvent_get_property_bubbles(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool keyboardEvent_get_property_bubbles(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool keyboardEvent_get_property_cancelable(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool keyboardEvent_get_property_cancelable(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
@ -199,6 +200,7 @@ JSPropertySpec keyboardEvent_props[] = {
|
|||||||
// JS_PSG("composed", keyboardEvent_get_property_composed, JSPROP_ENUMERATE),
|
// JS_PSG("composed", keyboardEvent_get_property_composed, JSPROP_ENUMERATE),
|
||||||
JS_PSG("defaultPrevented", keyboardEvent_get_property_defaultPrevented, JSPROP_ENUMERATE),
|
JS_PSG("defaultPrevented", keyboardEvent_get_property_defaultPrevented, JSPROP_ENUMERATE),
|
||||||
JS_PSG("key", keyboardEvent_get_property_key, JSPROP_ENUMERATE),
|
JS_PSG("key", keyboardEvent_get_property_key, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("keyCode", keyboardEvent_get_property_keyCode, JSPROP_ENUMERATE),
|
||||||
JS_PSG("type", keyboardEvent_get_property_type, JSPROP_ENUMERATE),
|
JS_PSG("type", keyboardEvent_get_property_type, JSPROP_ENUMERATE),
|
||||||
JS_PS_END
|
JS_PS_END
|
||||||
};
|
};
|
||||||
@ -353,6 +355,40 @@ keyboardEvent_get_property_key(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
keyboardEvent_get_property_keyCode(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dom_keyboard_event *event = JS::GetMaybePtrFromReservedSlot<dom_keyboard_event>(hobj, 0);
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dom_string *key = NULL;
|
||||||
|
dom_exception exc = dom_keyboard_event_get_key(event, &key);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
unicode_val_T keyCode = convert_dom_string_to_keycode(key);
|
||||||
|
args.rval().setInt32(keyCode);
|
||||||
|
if (key) dom_string_unref(key);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
keyboardEvent_get_property_code(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
keyboardEvent_get_property_code(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
var e = new KeyboardEvent('message', { cancelable: true, key: "e" });
|
var e = new KeyboardEvent('message', { cancelable: true, key: "Enter" });
|
||||||
|
|
||||||
console.error('keyboardEvent.html');
|
console.error('keyboardEvent.html');
|
||||||
console.assert(e.cancelable, 'cancelable true');
|
console.assert(e.cancelable, 'cancelable true');
|
||||||
@ -7,6 +7,7 @@ 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 === 'message', 'message');
|
||||||
console.assert(e.key === 'e', 'key e');
|
console.assert(e.key === 'Enter', 'key Enter');
|
||||||
|
console.assert(e.keyCode === 13, 'ENTER = 13');
|
||||||
console.exit(0);
|
console.exit(0);
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user