mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] convert keyCode to dom_string
This commit is contained in:
parent
c45fa86605
commit
4439f4e976
@ -377,6 +377,29 @@ CORESTRING_DOM_VALUE(text_javascript, "text/javascript");
|
||||
CORESTRING_DOM_VALUE(http_equiv, "http-equiv");
|
||||
CORESTRING_DOM_VALUE(html_namespace, "http://www.w3.org/1999/xhtml");
|
||||
|
||||
/* keyboardEvent keys */
|
||||
CORESTRING_DOM_STRING(Enter);
|
||||
CORESTRING_DOM_STRING(Insert);
|
||||
CORESTRING_DOM_STRING(ArrowLeft);
|
||||
CORESTRING_DOM_STRING(ArrowRight);
|
||||
CORESTRING_DOM_STRING(ArrowUp);
|
||||
CORESTRING_DOM_STRING(ArrowDown);
|
||||
CORESTRING_DOM_STRING(Backspace);
|
||||
CORESTRING_DOM_STRING(Tab);
|
||||
CORESTRING_DOM_STRING(Delete);
|
||||
CORESTRING_DOM_STRING(F1);
|
||||
CORESTRING_DOM_STRING(F2);
|
||||
CORESTRING_DOM_STRING(F3);
|
||||
CORESTRING_DOM_STRING(F4);
|
||||
CORESTRING_DOM_STRING(F5);
|
||||
CORESTRING_DOM_STRING(F6);
|
||||
CORESTRING_DOM_STRING(F7);
|
||||
CORESTRING_DOM_STRING(F8);
|
||||
CORESTRING_DOM_STRING(F9);
|
||||
CORESTRING_DOM_STRING(F10);
|
||||
CORESTRING_DOM_STRING(F11);
|
||||
CORESTRING_DOM_STRING(F12);
|
||||
|
||||
//CORESTRING_NSURL(about_blank, "about:blank");
|
||||
//CORESTRING_NSURL(about_query_ssl, "about:query/ssl");
|
||||
//CORESTRING_NSURL(about_query_auth, "about:query/auth");
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "cache/cache.h"
|
||||
#include "document/document.h"
|
||||
#include "document/libdom/corestrings.h"
|
||||
#include "document/libdom/doc.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "util/string.h"
|
||||
@ -104,3 +105,109 @@ add_lowercase_to_string(struct string *buf, const char *str, int len)
|
||||
add_bytes_to_string(buf, tmp, len);
|
||||
mem_free(tmp);
|
||||
}
|
||||
|
||||
bool
|
||||
convert_key_to_dom_string(term_event_key_T key, dom_string **res)
|
||||
{
|
||||
bool is_special = key <= 0x001F || (0x007F <= key && key <= 0x009F);
|
||||
dom_string *dom_key = NULL;
|
||||
dom_exception exc;
|
||||
|
||||
if (is_special) {
|
||||
switch (key) {
|
||||
case KBD_ENTER:
|
||||
dom_key = dom_string_ref(corestring_dom_Enter);
|
||||
break;
|
||||
case KBD_LEFT:
|
||||
dom_key = dom_string_ref(corestring_dom_ArrowLeft);
|
||||
break;
|
||||
case KBD_RIGHT:
|
||||
dom_key = dom_string_ref(corestring_dom_ArrowRight);
|
||||
break;
|
||||
case KBD_UP:
|
||||
dom_key = dom_string_ref(corestring_dom_ArrowUp);
|
||||
break;
|
||||
case KBD_DOWN:
|
||||
dom_key = dom_string_ref(corestring_dom_ArrowDown);
|
||||
break;
|
||||
case KBD_PAGE_UP:
|
||||
dom_key = dom_string_ref(corestring_dom_PageUp);
|
||||
break;
|
||||
case KBD_PAGE_DOWN:
|
||||
dom_key = dom_string_ref(corestring_dom_PageDown);
|
||||
break;
|
||||
case KBD_HOME:
|
||||
dom_key = dom_string_ref(corestring_dom_Home);
|
||||
break;
|
||||
case KBD_END:
|
||||
dom_key = dom_string_ref(corestring_dom_End);
|
||||
break;
|
||||
case KBD_ESC:
|
||||
dom_key = dom_string_ref(corestring_dom_Escape);
|
||||
break;
|
||||
case KBD_BS: // Backspace
|
||||
dom_key = dom_string_ref(corestring_dom_Backspace);
|
||||
break;
|
||||
case KBD_TAB: // Tab
|
||||
dom_key = dom_string_ref(corestring_dom_Tab);
|
||||
break;
|
||||
case KBD_INS: // Insert
|
||||
dom_key = dom_string_ref(corestring_dom_Insert);
|
||||
break;
|
||||
case KBD_DEL: // Delete
|
||||
dom_key = dom_string_ref(corestring_dom_Delete);
|
||||
break;
|
||||
case KBD_F1: // F1
|
||||
dom_key = dom_string_ref(corestring_dom_F1);
|
||||
break;
|
||||
case KBD_F2: // F2
|
||||
dom_key = dom_string_ref(corestring_dom_F2);
|
||||
break;
|
||||
case KBD_F3: // F3
|
||||
dom_key = dom_string_ref(corestring_dom_F3);
|
||||
break;
|
||||
case KBD_F4: // F4
|
||||
dom_key = dom_string_ref(corestring_dom_F4);
|
||||
break;
|
||||
case KBD_F5: // F5
|
||||
dom_key = dom_string_ref(corestring_dom_F5);
|
||||
break;
|
||||
case KBD_F6: // F6
|
||||
dom_key = dom_string_ref(corestring_dom_F6);
|
||||
break;
|
||||
case KBD_F7: // F7
|
||||
dom_key = dom_string_ref(corestring_dom_F7);
|
||||
break;
|
||||
case KBD_F8: // F8
|
||||
dom_key = dom_string_ref(corestring_dom_F8);
|
||||
break;
|
||||
case KBD_F9: // F9
|
||||
dom_key = dom_string_ref(corestring_dom_F9);
|
||||
break;
|
||||
case KBD_F10: // F10
|
||||
dom_key = dom_string_ref(corestring_dom_F10);
|
||||
break;
|
||||
case KBD_F11: // F11
|
||||
dom_key = dom_string_ref(corestring_dom_F11);
|
||||
break;
|
||||
case KBD_F12: // F12
|
||||
dom_key = dom_string_ref(corestring_dom_F12);
|
||||
break;
|
||||
default:
|
||||
dom_key = NULL;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
char *utf8 = encode_utf8(key);
|
||||
|
||||
if (utf8) {
|
||||
exc = dom_string_create((const uint8_t *)utf8, strlen(utf8), &dom_key);
|
||||
|
||||
if (exc != DOM_NO_ERR) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
*res = dom_key;
|
||||
return true;
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef EL__DOCUMENT_LIBDOM_DOC_H
|
||||
#define EL__DOCUMENT_LIBDOM_DOC_H
|
||||
|
||||
#include <dom/dom.h>
|
||||
#include "terminal/kbd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -13,6 +16,7 @@ void *document_parse(struct document *document, struct string *source);
|
||||
void free_document(void *doc);
|
||||
void *el_match_selector(const char *selector, void *node);
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
|
||||
#include "dialogs/status.h"
|
||||
#include "document/document.h"
|
||||
#include "document/libdom/doc.h"
|
||||
@ -593,3 +595,4 @@ walk_tree_query_append(dom_node *root, dom_node *node, const char *selector, int
|
||||
} while (child != NULL); /* No more children */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "document/document.h"
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "main/module.h"
|
||||
#include "terminal/kbd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
|
||||
#include "config/home.h"
|
||||
#include "config/options.h"
|
||||
#include "dialogs/status.h"
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "document/libdom/doc.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/libdom/parse.h"
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include <js/BigInt.h>
|
||||
#include <js/Conversions.h>
|
||||
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
|
||||
#include "bfu/dialog.h"
|
||||
#include "cache/cache.h"
|
||||
#include "cookies/cookies.h"
|
||||
@ -22,9 +24,9 @@
|
||||
#include "document/html/frames.h"
|
||||
#include "document/document.h"
|
||||
#include "document/forms.h"
|
||||
#include "document/libdom/doc.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "ecmascript/spidermonkey.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
#include "ecmascript/spidermonkey/keyboard.h"
|
||||
@ -72,7 +74,7 @@ static bool keyboardEvent_get_property_type(JSContext *ctx, unsigned int argc, J
|
||||
static bool keyboardEvent_preventDefault(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
|
||||
static unicode_val_T keyCode;
|
||||
static term_event_key_T keyCode;
|
||||
|
||||
static void
|
||||
keyboardEvent_finalize(JS::GCContext *op, JSObject *keyb_obj)
|
||||
@ -463,16 +465,25 @@ get_keyboardEvent(JSContext *ctx, struct term_event *ev)
|
||||
if (exc != DOM_NO_ERR) {
|
||||
return NULL;
|
||||
}
|
||||
keyCode = get_kbd_key(ev);
|
||||
term_event_key_T keyCode = get_kbd_key(ev);
|
||||
|
||||
if (keyCode == KBD_ENTER) {
|
||||
keyCode = 13;
|
||||
}
|
||||
exc = dom_keyboard_event_init(keyb, NULL, false, false,
|
||||
NULL, NULL, NULL, DOM_KEY_LOCATION_STANDARD,
|
||||
dom_string *dom_key = NULL;
|
||||
convert_key_to_dom_string(keyCode, &dom_key);
|
||||
|
||||
dom_string *keydown = NULL;
|
||||
exc = dom_string_create("keydown", strlen("keydown"), &keydown);
|
||||
|
||||
exc = dom_keyboard_event_init(keyb, keydown, false, false,
|
||||
NULL, dom_key, NULL, DOM_KEY_LOCATION_STANDARD,
|
||||
false, false, false, false,
|
||||
false, false);
|
||||
|
||||
if (dom_key) {
|
||||
dom_string_unref(dom_key);
|
||||
}
|
||||
if (keydown) {
|
||||
dom_string_unref(keydown);
|
||||
}
|
||||
// keyb->keyCode = keyCode;
|
||||
JS::SetReservedSlot(k, 0, JS::PrivateValue(keyb));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user