Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/65e55121601a1f1b5a7dc1ec9130b333388a6de8
...commit
http://git.netsurf-browser.org/netsurf.git/commit/65e55121601a1f1b5a7dc1ec9130b333388a6de8
...tree
http://git.netsurf-browser.org/netsurf.git/tree/65e55121601a1f1b5a7dc1ec9130b333388a6de8
The branch, master has been updated
via 65e55121601a1f1b5a7dc1ec9130b333388a6de8 (commit)
via f620ea9d17b36ca0d07aefd82f6619b9433129eb (commit)
via 49ed538729ec2fbc440cd8cc056e82a4c6c904b0 (commit)
via 23d413c5619b8be0792fb88f2934ec4b423cdf5a (commit)
via 7e6723e27a5bc61d6be9401cd41b644c97bae1e6 (commit)
via 23b7f7b3331098835395ff1953366ed976c6e3a3 (commit)
via a2190f91c91f1d0468b9286bf43ac874b9b64ba1 (commit)
via 12fd5ddd69500f504735d458093fe41e3da40a49 (commit)
from c4919105baf663ae3cd8fa79e303eca032b11a33 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=65e55121601a1f1b5a7dc1ec9130b333388a6de8
commit 65e55121601a1f1b5a7dc1ec9130b333388a6de8
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: Fire DOM KeyboardEvents on keypresses.
diff --git a/content/handlers/html/interaction.c
b/content/handlers/html/interaction.c
index bc130f0..651199c 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -1223,6 +1223,42 @@ bool html_keypress(struct content *c, uint32_t key)
html_content *html = (html_content *) c;
struct selection *sel = &html->sel;
+ /** \todo
+ * At the moment, the front end interface for keypress only gives
+ * us a UCS4 key value. This doesn't doesn't have all the information
+ * we need to fill out the event properly. We don't get to know about
+ * modifier keys, and things like CTRL+C are passed in as
+ * \ref NS_KEY_COPY_SELECTION, a magic value outside the valid Unicode
+ * range.
+ *
+ * We need to:
+ *
+ * 1. Update the front end interface so that both press and release
+ * events reach the core.
+ * 2. Stop encoding the special keys like \ref NS_KEY_COPY_SELECTION as
+ * magic values in the front ends, so we just get the events, e.g.:
+ * 1. Press ctrl
+ * 2. Press c
+ * 3. Release c
+ * 4. Release ctrl
+ * 3. Pass all the new info to the DOM KeyboardEvent events.
+ * 4. If there is a focused element, fire the event at that, instead of
+ * `html->layout->node`.
+ * 5. Rebuild the \ref NS_KEY_COPY_SELECTION values from the info we
+ * now get given, and use that for the code below this
+ * \ref fire_dom_keyboard_event call.
+ * 6. Move the code after this \ref fire_dom_keyboard_event call into
+ * the default action handler for DOM events.
+ *
+ * This will mean that if the JavaScript event listener does
+ * `event.preventDefault()` then we won't handle the event when
+ * we're not supposed to.
+ */
+ if (html->layout != NULL && html->layout->node != NULL) {
+ fire_dom_keyboard_event(corestring_dom_keydown,
+ html->layout->node, true, true, key);
+ }
+
switch (html->focus_type) {
case HTML_FOCUS_CONTENT:
return content_keypress(html->focus_owner.content->object, key);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=f620ea9d17b36ca0d07aefd82f6619b9433129eb
commit f620ea9d17b36ca0d07aefd82f6619b9433129eb
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
dukky_push_event: Enable KeyboardEvent specialisation.
diff --git a/content/handlers/javascript/duktape/dukky.c
b/content/handlers/javascript/duktape/dukky.c
index 5980b2b..4d21573 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -852,6 +852,36 @@ handle_error:
return false;
}
+static const char* dukky_event_proto(dom_event *evt)
+{
+ const char *ret = PROTO_NAME(EVENT);
+ dom_string *type = NULL;
+ dom_exception err;
+
+ err = dom_event_get_type(evt, &type);
+ if (err != DOM_NO_ERR) {
+ goto out;
+ }
+
+ if (dom_string_isequal(type, corestring_dom_keydown)) {
+ ret = PROTO_NAME(KEYBOARDEVENT);
+ goto out;
+ } else if (dom_string_isequal(type, corestring_dom_keyup)) {
+ ret = PROTO_NAME(KEYBOARDEVENT);
+ goto out;
+ } else if (dom_string_isequal(type, corestring_dom_keypress)) {
+ ret = PROTO_NAME(KEYBOARDEVENT);
+ goto out;
+ }
+
+out:
+ if (type != NULL) {
+ dom_string_unref(type);
+ }
+
+ return ret;
+}
+
/*** New style event handling ***/
void dukky_push_event(duk_context *ctx, dom_event *evt)
@@ -868,7 +898,7 @@ void dukky_push_event(duk_context *ctx, dom_event *evt)
duk_pop(ctx);
/* ... events */
duk_push_pointer(ctx, evt);
- if (dukky_create_object(ctx, PROTO_NAME(EVENT), 1) !=
DUK_EXEC_SUCCESS) {
+ if (dukky_create_object(ctx, dukky_event_proto(evt), 1) !=
DUK_EXEC_SUCCESS) {
/* ... events err */
duk_pop(ctx);
/* ... events */
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=49ed538729ec2fbc440cd8cc056e82a4c6c904b0
commit 49ed538729ec2fbc440cd8cc056e82a4c6c904b0
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Documentation: Update JavaScript unimplemented bindings.
diff --git a/docs/UnimplementedJavascript.md b/docs/UnimplementedJavascript.md
index 343c399..f03da37 100644
--- a/docs/UnimplementedJavascript.md
+++ b/docs/UnimplementedJavascript.md
@@ -48,15 +48,7 @@ getter | UIEvent::view(user);
getter | UIEvent::detail(long);
method | CompositionEvent::initCompositionEvent();
getter | CompositionEvent::data(string);
-method | KeyboardEvent::getModifierState();
method | KeyboardEvent::initKeyboardEvent();
-getter | KeyboardEvent::key(string);
-getter | KeyboardEvent::code(string);
-getter | KeyboardEvent::location(unsigned long);
-getter | KeyboardEvent::ctrlKey(boolean);
-getter | KeyboardEvent::shiftKey(boolean);
-getter | KeyboardEvent::altKey(boolean);
-getter | KeyboardEvent::metaKey(boolean);
getter | KeyboardEvent::repeat(boolean);
getter | KeyboardEvent::isComposing(boolean);
getter | KeyboardEvent::charCode(unsigned long);
@@ -1506,7 +1498,6 @@ getter | Document::doctype(user);
getter | Document::domain(string);
setter | Document::domain(string);
getter | Document::referrer(string);
-setter | Document::cookie(string);
getter | Document::lastModified(string);
getter | Document::readyState(user);
getter | Document::title(string);
@@ -1587,5 +1578,5 @@ method | EventListener::handleEvent();
method | CustomEvent::initCustomEvent();
getter | CustomEvent::detail(any);
- 1581 unimplemented bindings
+ 1572 unimplemented bindings
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=23d413c5619b8be0792fb88f2934ec4b423cdf5a
commit 23d413c5619b8be0792fb88f2934ec4b423cdf5a
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
JavaScript: Add KeyboardEvent bindings.
diff --git a/content/handlers/javascript/duktape/KeyboardEvent.bnd
b/content/handlers/javascript/duktape/KeyboardEvent.bnd
new file mode 100644
index 0000000..67c4564
--- /dev/null
+++ b/content/handlers/javascript/duktape/KeyboardEvent.bnd
@@ -0,0 +1,142 @@
+/* Binding for browser using duktape and libdom
+ *
+ * Copyright 2019 Michael Drake <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+init KeyboardEvent (struct dom_keyboard_event *evt::ui_event);
+
+getter KeyboardEvent::key ()
+%{
+ dom_exception err;
+ dom_string *key;
+
+ err = dom_keyboard_event_get_key(priv->parent.parent.evt, &key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_lstring(ctx, dom_string_data(key), dom_string_length(key));
+ dom_string_unref(key);
+ return 1;
+%}
+
+getter KeyboardEvent::code ()
+%{
+ dom_exception err;
+ dom_string *code;
+
+ err = dom_keyboard_event_get_code(priv->parent.parent.evt, &code);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_lstring(ctx, dom_string_data(code), dom_string_length(code));
+ dom_string_unref(code);
+ return 1;
+%}
+
+getter KeyboardEvent::location ()
+%{
+ dom_exception err;
+ dom_key_location location;
+
+ err = dom_keyboard_event_get_location(priv->parent.parent.evt,
+ &location);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_uint(ctx, (duk_uint_t) location);
+ return 1;
+%}
+
+getter KeyboardEvent::ctrlKey ()
+%{
+ dom_exception err;
+ bool ctrl_key;
+
+ err = dom_keyboard_event_get_ctrl_key(priv->parent.parent.evt,
+ &ctrl_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) ctrl_key);
+ return 1;
+%}
+
+getter KeyboardEvent::shiftKey ()
+%{
+ dom_exception err;
+ bool shift_key;
+
+ err = dom_keyboard_event_get_shift_key(priv->parent.parent.evt,
+ &shift_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) shift_key);
+ return 1;
+%}
+
+getter KeyboardEvent::altKey ()
+%{
+ dom_exception err;
+ bool alt_key;
+
+ err = dom_keyboard_event_get_alt_key(priv->parent.parent.evt,
+ &alt_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) alt_key);
+ return 1;
+%}
+
+getter KeyboardEvent::metaKey ()
+%{
+ dom_exception err;
+ bool meta_key;
+
+ err = dom_keyboard_event_get_meta_key(priv->parent.parent.evt,
+ &meta_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) meta_key);
+ return 1;
+%}
+
+method KeyboardEvent::getModifierState ()
+%{
+ dom_string *modifier;
+ dom_exception err;
+ duk_size_t slen;
+ const char *s;
+ bool state;
+
+ s = duk_safe_to_lstring(ctx, 0, &slen);
+ err = dom_string_create((const uint8_t *)s, slen, &modifier);
+ duk_pop(ctx);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ err = dom_keyboard_event_get_modifier_state(priv->parent.parent.evt,
+ modifier, &state);
+ dom_string_unref(modifier);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) state);
+ return 1;
+%}
diff --git a/content/handlers/javascript/duktape/netsurf.bnd
b/content/handlers/javascript/duktape/netsurf.bnd
index 2a56ccc..628b2a3 100644
--- a/content/handlers/javascript/duktape/netsurf.bnd
+++ b/content/handlers/javascript/duktape/netsurf.bnd
@@ -68,6 +68,7 @@ struct dom_html_br_element;
/* events */
#include "Event.bnd"
+#include "KeyboardEvent.bnd"
init MutationEvent(struct dom_mutation_event *evt::evt);
init UIEvent(struct dom_ui_event *evt::evt);
@@ -76,7 +77,6 @@ init MutationNameEvent(struct dom_mutation_name_event
*evt::evt);
init MouseWheelEvent(struct dom_mouse_wheel_event *evt::evt);
init MouseMultiWheelEvent(struct dom_mouse_multi_wheel_event *evt::evt);
init MouseEvent(struct dom_mouse_event *evt::evt);
-init KeyboardEvent(struct dom_keyboard_event *evt::evt);
init DocumentEvent(struct dom_document_event *evt::evt);
init CustomEvent(struct dom_custom_event *evt::evt);
init CompositionEvent(struct dom_ui_event *evt::evt);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=7e6723e27a5bc61d6be9401cd41b644c97bae1e6
commit 7e6723e27a5bc61d6be9401cd41b644c97bae1e6
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: Add function for issuing a keypress event.
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index e47ee7f..6e389ab 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -44,6 +44,7 @@
#include "netsurf/content.h"
#include "netsurf/browser_window.h"
#include "netsurf/utf8.h"
+#include "netsurf/keypress.h"
#include "netsurf/layout.h"
#include "netsurf/misc.h"
#include "content/hlcache.h"
@@ -121,6 +122,84 @@ bool fire_generic_dom_event(dom_string *type, dom_node
*target,
return result;
}
+/* Exported interface, see html_internal.h */
+bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
+ bool bubbles, bool cancelable, uint32_t key)
+{
+ bool is_special = key <= 0x001F || (0x007F <= key && key <= 0x009F);
+ dom_string *dom_key = NULL;
+ dom_keyboard_event *evt;
+ dom_exception exc;
+ bool result;
+
+ if (is_special) {
+ switch (key) {
+ case NS_KEY_ESCAPE:
+ dom_key = dom_string_ref(corestring_dom_Escape);
+ break;
+ case NS_KEY_LEFT:
+ dom_key = dom_string_ref(corestring_dom_ArrowLeft);
+ break;
+ case NS_KEY_RIGHT:
+ dom_key = dom_string_ref(corestring_dom_ArrowRight);
+ break;
+ case NS_KEY_UP:
+ dom_key = dom_string_ref(corestring_dom_ArrowUp);
+ break;
+ case NS_KEY_DOWN:
+ dom_key = dom_string_ref(corestring_dom_ArrowDown);
+ break;
+ case NS_KEY_PAGE_UP:
+ dom_key = dom_string_ref(corestring_dom_PageUp);
+ break;
+ case NS_KEY_PAGE_DOWN:
+ dom_key = dom_string_ref(corestring_dom_PageDown);
+ break;
+ case NS_KEY_TEXT_START:
+ dom_key = dom_string_ref(corestring_dom_Home);
+ break;
+ case NS_KEY_TEXT_END:
+ dom_key = dom_string_ref(corestring_dom_End);
+ break;
+ default:
+ dom_key = NULL;
+ break;
+ }
+ } else {
+ char utf8[6];
+ size_t length = utf8_from_ucs4(key, utf8);
+ utf8[length] = '\0';
+
+ exc = dom_string_create((const uint8_t *)utf8, strlen(utf8),
+ &dom_key);
+ if (exc != DOM_NO_ERR) {
+ return exc;
+ }
+ }
+
+ exc = dom_keyboard_event_create(&evt);
+ if (exc != DOM_NO_ERR) {
+ dom_string_unref(dom_key);
+ return false;
+ }
+
+ exc = dom_keyboard_event_init(evt, type, bubbles, cancelable, NULL,
+ dom_key, NULL, DOM_KEY_LOCATION_STANDARD, false,
+ false, false, false, false, false);
+ dom_string_unref(dom_key);
+ if (exc != DOM_NO_ERR) {
+ dom_event_unref(evt);
+ return false;
+ }
+
+ NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
+ dom_string_length(type), dom_string_data(type), target);
+
+ result = fire_dom_event((dom_event *) evt, target);
+ dom_event_unref(evt);
+ return result;
+}
+
/**
* Perform post-box-creation conversion of a document
*
diff --git a/content/handlers/html/html_internal.h
b/content/handlers/html/html_internal.h
index f24acff..2ff3410 100644
--- a/content/handlers/html/html_internal.h
+++ b/content/handlers/html/html_internal.h
@@ -404,6 +404,12 @@ nserror html_object_abort_objects(html_content *html);
bool fire_generic_dom_event(dom_string *type, dom_node *target,
bool bubbles, bool cancelable);
+/**
+ * Construct a keyboard event and fire it at the DOM
+ */
+bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
+ bool bubbles, bool cancelable, uint32_t key);
+
/* Useful dom_string pointers */
struct dom_string;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=23b7f7b3331098835395ff1953366ed976c6e3a3
commit 23b7f7b3331098835395ff1953366ed976c6e3a3
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
corestrings: Add DOM event keypress strings.
diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index 8bb5b42..53774ba 100644
--- a/utils/corestringlist.h
+++ b/utils/corestringlist.h
@@ -190,6 +190,10 @@ CORESTRING_DOM_STRING(afterprint);
CORESTRING_DOM_STRING(align);
CORESTRING_DOM_STRING(alt);
CORESTRING_DOM_STRING(area);
+CORESTRING_DOM_STRING(ArrowDown);
+CORESTRING_DOM_STRING(ArrowLeft);
+CORESTRING_DOM_STRING(ArrowRight);
+CORESTRING_DOM_STRING(ArrowUp);
CORESTRING_DOM_STRING(async);
CORESTRING_DOM_STRING(background);
CORESTRING_DOM_STRING(beforeprint);
@@ -233,12 +237,15 @@ CORESTRING_DOM_STRING(dragstart);
CORESTRING_DOM_STRING(drop);
CORESTRING_DOM_STRING(durationchange);
CORESTRING_DOM_STRING(emptied);
+CORESTRING_DOM_STRING(End);
CORESTRING_DOM_STRING(ended);
CORESTRING_DOM_STRING(error);
+CORESTRING_DOM_STRING(Escape);
CORESTRING_DOM_STRING(focus);
CORESTRING_DOM_STRING(frameborder);
CORESTRING_DOM_STRING(hashchange);
CORESTRING_DOM_STRING(height);
+CORESTRING_DOM_STRING(Home);
CORESTRING_DOM_STRING(href);
CORESTRING_DOM_STRING(hreflang);
CORESTRING_DOM_STRING(hspace);
@@ -272,8 +279,10 @@ CORESTRING_DOM_STRING(noresize);
CORESTRING_DOM_STRING(nowrap);
CORESTRING_DOM_STRING(offline);
CORESTRING_DOM_STRING(online);
+CORESTRING_DOM_STRING(PageDown);
CORESTRING_DOM_STRING(pagehide);
CORESTRING_DOM_STRING(pageshow);
+CORESTRING_DOM_STRING(PageUp);
CORESTRING_DOM_STRING(pause);
CORESTRING_DOM_STRING(play);
CORESTRING_DOM_STRING(playing);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=a2190f91c91f1d0468b9286bf43ac874b9b64ba1
commit a2190f91c91f1d0468b9286bf43ac874b9b64ba1
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: Split out helper for firing DOM events and swallowing errors.
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index c66d2ac..e47ee7f 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -77,6 +77,28 @@ static const char *html_types[] = {
"text/html"
};
+/**
+ * Fire an event at the DOM
+ *
+ * Helper that swallows DOM errors.
+ *
+ * \param[in] event the event to fire at the DOM
+ * \param[in] target the event target
+ * \return true on success
+ */
+static bool fire_dom_event(dom_event *event, dom_node *target)
+{
+ dom_exception exc;
+ bool result;
+
+ exc = dom_event_target_dispatch_event(target, event, &result);
+ if (exc != DOM_NO_ERR) {
+ return false;
+ }
+
+ return result;
+}
+
/* Exported interface, see html_internal.h */
bool fire_generic_dom_event(dom_string *type, dom_node *target,
bool bubbles, bool cancelable)
@@ -94,10 +116,7 @@ bool fire_generic_dom_event(dom_string *type, dom_node
*target,
}
NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
dom_string_length(type), dom_string_data(type), target);
- exc = dom_event_target_dispatch_event(target, evt, &result);
- if (exc != DOM_NO_ERR) {
- result = false;
- }
+ result = fire_dom_event(evt, target);
dom_event_unref(evt);
return result;
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=12fd5ddd69500f504735d458093fe41e3da40a49
commit 12fd5ddd69500f504735d458093fe41e3da40a49
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
HTML: Rename fire_dom_event to fire_generic_dom_event.
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 631045a..c66d2ac 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -78,8 +78,8 @@ static const char *html_types[] = {
};
/* Exported interface, see html_internal.h */
-bool fire_dom_event(dom_string *type, dom_node *target,
- bool bubbles, bool cancelable)
+bool fire_generic_dom_event(dom_string *type, dom_node *target,
+ bool bubbles, bool cancelable)
{
dom_exception exc;
dom_event *evt;
diff --git a/content/handlers/html/html_internal.h
b/content/handlers/html/html_internal.h
index 11891e6..f24acff 100644
--- a/content/handlers/html/html_internal.h
+++ b/content/handlers/html/html_internal.h
@@ -401,7 +401,7 @@ nserror html_object_abort_objects(html_content *html);
* Construct an event and fire it at the DOM
*
*/
-bool fire_dom_event(dom_string *type, dom_node *target,
+bool fire_generic_dom_event(dom_string *type, dom_node *target,
bool bubbles, bool cancelable);
/* Useful dom_string pointers */
diff --git a/content/handlers/html/interaction.c
b/content/handlers/html/interaction.c
index 61f4173..bc130f0 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -1172,7 +1172,7 @@ html_mouse_action(struct content *c,
/* fire dom click event */
if (mouse & BROWSER_MOUSE_CLICK_1) {
- fire_dom_event(corestring_dom_click, node, true, true);
+ fire_generic_dom_event(corestring_dom_click, node, true, true);
}
/* deferred actions that can cause this browser_window to be destroyed
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/html.c | 106 ++++++++++++++-
content/handlers/html/html_internal.h | 8 +-
content/handlers/html/interaction.c | 38 +++++-
.../handlers/javascript/duktape/KeyboardEvent.bnd | 142 ++++++++++++++++++++
content/handlers/javascript/duktape/dukky.c | 32 ++++-
content/handlers/javascript/duktape/netsurf.bnd | 2 +-
docs/UnimplementedJavascript.md | 11 +-
utils/corestringlist.h | 9 ++
8 files changed, 330 insertions(+), 18 deletions(-)
create mode 100644 content/handlers/javascript/duktape/KeyboardEvent.bnd
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 631045a..6e389ab 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -44,6 +44,7 @@
#include "netsurf/content.h"
#include "netsurf/browser_window.h"
#include "netsurf/utf8.h"
+#include "netsurf/keypress.h"
#include "netsurf/layout.h"
#include "netsurf/misc.h"
#include "content/hlcache.h"
@@ -77,9 +78,31 @@ static const char *html_types[] = {
"text/html"
};
+/**
+ * Fire an event at the DOM
+ *
+ * Helper that swallows DOM errors.
+ *
+ * \param[in] event the event to fire at the DOM
+ * \param[in] target the event target
+ * \return true on success
+ */
+static bool fire_dom_event(dom_event *event, dom_node *target)
+{
+ dom_exception exc;
+ bool result;
+
+ exc = dom_event_target_dispatch_event(target, event, &result);
+ if (exc != DOM_NO_ERR) {
+ return false;
+ }
+
+ return result;
+}
+
/* Exported interface, see html_internal.h */
-bool fire_dom_event(dom_string *type, dom_node *target,
- bool bubbles, bool cancelable)
+bool fire_generic_dom_event(dom_string *type, dom_node *target,
+ bool bubbles, bool cancelable)
{
dom_exception exc;
dom_event *evt;
@@ -94,10 +117,85 @@ bool fire_dom_event(dom_string *type, dom_node *target,
}
NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
dom_string_length(type), dom_string_data(type), target);
- exc = dom_event_target_dispatch_event(target, evt, &result);
+ result = fire_dom_event(evt, target);
+ dom_event_unref(evt);
+ return result;
+}
+
+/* Exported interface, see html_internal.h */
+bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
+ bool bubbles, bool cancelable, uint32_t key)
+{
+ bool is_special = key <= 0x001F || (0x007F <= key && key <= 0x009F);
+ dom_string *dom_key = NULL;
+ dom_keyboard_event *evt;
+ dom_exception exc;
+ bool result;
+
+ if (is_special) {
+ switch (key) {
+ case NS_KEY_ESCAPE:
+ dom_key = dom_string_ref(corestring_dom_Escape);
+ break;
+ case NS_KEY_LEFT:
+ dom_key = dom_string_ref(corestring_dom_ArrowLeft);
+ break;
+ case NS_KEY_RIGHT:
+ dom_key = dom_string_ref(corestring_dom_ArrowRight);
+ break;
+ case NS_KEY_UP:
+ dom_key = dom_string_ref(corestring_dom_ArrowUp);
+ break;
+ case NS_KEY_DOWN:
+ dom_key = dom_string_ref(corestring_dom_ArrowDown);
+ break;
+ case NS_KEY_PAGE_UP:
+ dom_key = dom_string_ref(corestring_dom_PageUp);
+ break;
+ case NS_KEY_PAGE_DOWN:
+ dom_key = dom_string_ref(corestring_dom_PageDown);
+ break;
+ case NS_KEY_TEXT_START:
+ dom_key = dom_string_ref(corestring_dom_Home);
+ break;
+ case NS_KEY_TEXT_END:
+ dom_key = dom_string_ref(corestring_dom_End);
+ break;
+ default:
+ dom_key = NULL;
+ break;
+ }
+ } else {
+ char utf8[6];
+ size_t length = utf8_from_ucs4(key, utf8);
+ utf8[length] = '\0';
+
+ exc = dom_string_create((const uint8_t *)utf8, strlen(utf8),
+ &dom_key);
+ if (exc != DOM_NO_ERR) {
+ return exc;
+ }
+ }
+
+ exc = dom_keyboard_event_create(&evt);
if (exc != DOM_NO_ERR) {
- result = false;
+ dom_string_unref(dom_key);
+ return false;
}
+
+ exc = dom_keyboard_event_init(evt, type, bubbles, cancelable, NULL,
+ dom_key, NULL, DOM_KEY_LOCATION_STANDARD, false,
+ false, false, false, false, false);
+ dom_string_unref(dom_key);
+ if (exc != DOM_NO_ERR) {
+ dom_event_unref(evt);
+ return false;
+ }
+
+ NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",
+ dom_string_length(type), dom_string_data(type), target);
+
+ result = fire_dom_event((dom_event *) evt, target);
dom_event_unref(evt);
return result;
}
diff --git a/content/handlers/html/html_internal.h
b/content/handlers/html/html_internal.h
index 11891e6..2ff3410 100644
--- a/content/handlers/html/html_internal.h
+++ b/content/handlers/html/html_internal.h
@@ -401,9 +401,15 @@ nserror html_object_abort_objects(html_content *html);
* Construct an event and fire it at the DOM
*
*/
-bool fire_dom_event(dom_string *type, dom_node *target,
+bool fire_generic_dom_event(dom_string *type, dom_node *target,
bool bubbles, bool cancelable);
+/**
+ * Construct a keyboard event and fire it at the DOM
+ */
+bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
+ bool bubbles, bool cancelable, uint32_t key);
+
/* Useful dom_string pointers */
struct dom_string;
diff --git a/content/handlers/html/interaction.c
b/content/handlers/html/interaction.c
index 61f4173..651199c 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -1172,7 +1172,7 @@ html_mouse_action(struct content *c,
/* fire dom click event */
if (mouse & BROWSER_MOUSE_CLICK_1) {
- fire_dom_event(corestring_dom_click, node, true, true);
+ fire_generic_dom_event(corestring_dom_click, node, true, true);
}
/* deferred actions that can cause this browser_window to be destroyed
@@ -1223,6 +1223,42 @@ bool html_keypress(struct content *c, uint32_t key)
html_content *html = (html_content *) c;
struct selection *sel = &html->sel;
+ /** \todo
+ * At the moment, the front end interface for keypress only gives
+ * us a UCS4 key value. This doesn't doesn't have all the information
+ * we need to fill out the event properly. We don't get to know about
+ * modifier keys, and things like CTRL+C are passed in as
+ * \ref NS_KEY_COPY_SELECTION, a magic value outside the valid Unicode
+ * range.
+ *
+ * We need to:
+ *
+ * 1. Update the front end interface so that both press and release
+ * events reach the core.
+ * 2. Stop encoding the special keys like \ref NS_KEY_COPY_SELECTION as
+ * magic values in the front ends, so we just get the events, e.g.:
+ * 1. Press ctrl
+ * 2. Press c
+ * 3. Release c
+ * 4. Release ctrl
+ * 3. Pass all the new info to the DOM KeyboardEvent events.
+ * 4. If there is a focused element, fire the event at that, instead of
+ * `html->layout->node`.
+ * 5. Rebuild the \ref NS_KEY_COPY_SELECTION values from the info we
+ * now get given, and use that for the code below this
+ * \ref fire_dom_keyboard_event call.
+ * 6. Move the code after this \ref fire_dom_keyboard_event call into
+ * the default action handler for DOM events.
+ *
+ * This will mean that if the JavaScript event listener does
+ * `event.preventDefault()` then we won't handle the event when
+ * we're not supposed to.
+ */
+ if (html->layout != NULL && html->layout->node != NULL) {
+ fire_dom_keyboard_event(corestring_dom_keydown,
+ html->layout->node, true, true, key);
+ }
+
switch (html->focus_type) {
case HTML_FOCUS_CONTENT:
return content_keypress(html->focus_owner.content->object, key);
diff --git a/content/handlers/javascript/duktape/KeyboardEvent.bnd
b/content/handlers/javascript/duktape/KeyboardEvent.bnd
new file mode 100644
index 0000000..67c4564
--- /dev/null
+++ b/content/handlers/javascript/duktape/KeyboardEvent.bnd
@@ -0,0 +1,142 @@
+/* Binding for browser using duktape and libdom
+ *
+ * Copyright 2019 Michael Drake <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+init KeyboardEvent (struct dom_keyboard_event *evt::ui_event);
+
+getter KeyboardEvent::key ()
+%{
+ dom_exception err;
+ dom_string *key;
+
+ err = dom_keyboard_event_get_key(priv->parent.parent.evt, &key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_lstring(ctx, dom_string_data(key), dom_string_length(key));
+ dom_string_unref(key);
+ return 1;
+%}
+
+getter KeyboardEvent::code ()
+%{
+ dom_exception err;
+ dom_string *code;
+
+ err = dom_keyboard_event_get_code(priv->parent.parent.evt, &code);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_lstring(ctx, dom_string_data(code), dom_string_length(code));
+ dom_string_unref(code);
+ return 1;
+%}
+
+getter KeyboardEvent::location ()
+%{
+ dom_exception err;
+ dom_key_location location;
+
+ err = dom_keyboard_event_get_location(priv->parent.parent.evt,
+ &location);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_uint(ctx, (duk_uint_t) location);
+ return 1;
+%}
+
+getter KeyboardEvent::ctrlKey ()
+%{
+ dom_exception err;
+ bool ctrl_key;
+
+ err = dom_keyboard_event_get_ctrl_key(priv->parent.parent.evt,
+ &ctrl_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) ctrl_key);
+ return 1;
+%}
+
+getter KeyboardEvent::shiftKey ()
+%{
+ dom_exception err;
+ bool shift_key;
+
+ err = dom_keyboard_event_get_shift_key(priv->parent.parent.evt,
+ &shift_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) shift_key);
+ return 1;
+%}
+
+getter KeyboardEvent::altKey ()
+%{
+ dom_exception err;
+ bool alt_key;
+
+ err = dom_keyboard_event_get_alt_key(priv->parent.parent.evt,
+ &alt_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) alt_key);
+ return 1;
+%}
+
+getter KeyboardEvent::metaKey ()
+%{
+ dom_exception err;
+ bool meta_key;
+
+ err = dom_keyboard_event_get_meta_key(priv->parent.parent.evt,
+ &meta_key);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) meta_key);
+ return 1;
+%}
+
+method KeyboardEvent::getModifierState ()
+%{
+ dom_string *modifier;
+ dom_exception err;
+ duk_size_t slen;
+ const char *s;
+ bool state;
+
+ s = duk_safe_to_lstring(ctx, 0, &slen);
+ err = dom_string_create((const uint8_t *)s, slen, &modifier);
+ duk_pop(ctx);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ err = dom_keyboard_event_get_modifier_state(priv->parent.parent.evt,
+ modifier, &state);
+ dom_string_unref(modifier);
+ if (err != DOM_NO_ERR) {
+ return 0;
+ }
+
+ duk_push_boolean(ctx, (duk_bool_t) state);
+ return 1;
+%}
diff --git a/content/handlers/javascript/duktape/dukky.c
b/content/handlers/javascript/duktape/dukky.c
index 5980b2b..4d21573 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -852,6 +852,36 @@ handle_error:
return false;
}
+static const char* dukky_event_proto(dom_event *evt)
+{
+ const char *ret = PROTO_NAME(EVENT);
+ dom_string *type = NULL;
+ dom_exception err;
+
+ err = dom_event_get_type(evt, &type);
+ if (err != DOM_NO_ERR) {
+ goto out;
+ }
+
+ if (dom_string_isequal(type, corestring_dom_keydown)) {
+ ret = PROTO_NAME(KEYBOARDEVENT);
+ goto out;
+ } else if (dom_string_isequal(type, corestring_dom_keyup)) {
+ ret = PROTO_NAME(KEYBOARDEVENT);
+ goto out;
+ } else if (dom_string_isequal(type, corestring_dom_keypress)) {
+ ret = PROTO_NAME(KEYBOARDEVENT);
+ goto out;
+ }
+
+out:
+ if (type != NULL) {
+ dom_string_unref(type);
+ }
+
+ return ret;
+}
+
/*** New style event handling ***/
void dukky_push_event(duk_context *ctx, dom_event *evt)
@@ -868,7 +898,7 @@ void dukky_push_event(duk_context *ctx, dom_event *evt)
duk_pop(ctx);
/* ... events */
duk_push_pointer(ctx, evt);
- if (dukky_create_object(ctx, PROTO_NAME(EVENT), 1) !=
DUK_EXEC_SUCCESS) {
+ if (dukky_create_object(ctx, dukky_event_proto(evt), 1) !=
DUK_EXEC_SUCCESS) {
/* ... events err */
duk_pop(ctx);
/* ... events */
diff --git a/content/handlers/javascript/duktape/netsurf.bnd
b/content/handlers/javascript/duktape/netsurf.bnd
index 2a56ccc..628b2a3 100644
--- a/content/handlers/javascript/duktape/netsurf.bnd
+++ b/content/handlers/javascript/duktape/netsurf.bnd
@@ -68,6 +68,7 @@ struct dom_html_br_element;
/* events */
#include "Event.bnd"
+#include "KeyboardEvent.bnd"
init MutationEvent(struct dom_mutation_event *evt::evt);
init UIEvent(struct dom_ui_event *evt::evt);
@@ -76,7 +77,6 @@ init MutationNameEvent(struct dom_mutation_name_event
*evt::evt);
init MouseWheelEvent(struct dom_mouse_wheel_event *evt::evt);
init MouseMultiWheelEvent(struct dom_mouse_multi_wheel_event *evt::evt);
init MouseEvent(struct dom_mouse_event *evt::evt);
-init KeyboardEvent(struct dom_keyboard_event *evt::evt);
init DocumentEvent(struct dom_document_event *evt::evt);
init CustomEvent(struct dom_custom_event *evt::evt);
init CompositionEvent(struct dom_ui_event *evt::evt);
diff --git a/docs/UnimplementedJavascript.md b/docs/UnimplementedJavascript.md
index 343c399..f03da37 100644
--- a/docs/UnimplementedJavascript.md
+++ b/docs/UnimplementedJavascript.md
@@ -48,15 +48,7 @@ getter | UIEvent::view(user);
getter | UIEvent::detail(long);
method | CompositionEvent::initCompositionEvent();
getter | CompositionEvent::data(string);
-method | KeyboardEvent::getModifierState();
method | KeyboardEvent::initKeyboardEvent();
-getter | KeyboardEvent::key(string);
-getter | KeyboardEvent::code(string);
-getter | KeyboardEvent::location(unsigned long);
-getter | KeyboardEvent::ctrlKey(boolean);
-getter | KeyboardEvent::shiftKey(boolean);
-getter | KeyboardEvent::altKey(boolean);
-getter | KeyboardEvent::metaKey(boolean);
getter | KeyboardEvent::repeat(boolean);
getter | KeyboardEvent::isComposing(boolean);
getter | KeyboardEvent::charCode(unsigned long);
@@ -1506,7 +1498,6 @@ getter | Document::doctype(user);
getter | Document::domain(string);
setter | Document::domain(string);
getter | Document::referrer(string);
-setter | Document::cookie(string);
getter | Document::lastModified(string);
getter | Document::readyState(user);
getter | Document::title(string);
@@ -1587,5 +1578,5 @@ method | EventListener::handleEvent();
method | CustomEvent::initCustomEvent();
getter | CustomEvent::detail(any);
- 1581 unimplemented bindings
+ 1572 unimplemented bindings
diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index 8bb5b42..53774ba 100644
--- a/utils/corestringlist.h
+++ b/utils/corestringlist.h
@@ -190,6 +190,10 @@ CORESTRING_DOM_STRING(afterprint);
CORESTRING_DOM_STRING(align);
CORESTRING_DOM_STRING(alt);
CORESTRING_DOM_STRING(area);
+CORESTRING_DOM_STRING(ArrowDown);
+CORESTRING_DOM_STRING(ArrowLeft);
+CORESTRING_DOM_STRING(ArrowRight);
+CORESTRING_DOM_STRING(ArrowUp);
CORESTRING_DOM_STRING(async);
CORESTRING_DOM_STRING(background);
CORESTRING_DOM_STRING(beforeprint);
@@ -233,12 +237,15 @@ CORESTRING_DOM_STRING(dragstart);
CORESTRING_DOM_STRING(drop);
CORESTRING_DOM_STRING(durationchange);
CORESTRING_DOM_STRING(emptied);
+CORESTRING_DOM_STRING(End);
CORESTRING_DOM_STRING(ended);
CORESTRING_DOM_STRING(error);
+CORESTRING_DOM_STRING(Escape);
CORESTRING_DOM_STRING(focus);
CORESTRING_DOM_STRING(frameborder);
CORESTRING_DOM_STRING(hashchange);
CORESTRING_DOM_STRING(height);
+CORESTRING_DOM_STRING(Home);
CORESTRING_DOM_STRING(href);
CORESTRING_DOM_STRING(hreflang);
CORESTRING_DOM_STRING(hspace);
@@ -272,8 +279,10 @@ CORESTRING_DOM_STRING(noresize);
CORESTRING_DOM_STRING(nowrap);
CORESTRING_DOM_STRING(offline);
CORESTRING_DOM_STRING(online);
+CORESTRING_DOM_STRING(PageDown);
CORESTRING_DOM_STRING(pagehide);
CORESTRING_DOM_STRING(pageshow);
+CORESTRING_DOM_STRING(PageUp);
CORESTRING_DOM_STRING(pause);
CORESTRING_DOM_STRING(play);
CORESTRING_DOM_STRING(playing);
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org