summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2019-12-01 20:58:00 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2019-12-01 21:25:46 +0000
commit65e55121601a1f1b5a7dc1ec9130b333388a6de8 (patch)
tree1c37d76386c68d4131f578c2b1255bd19b5ab5d5
parentf620ea9d17b36ca0d07aefd82f6619b9433129eb (diff)
downloadnetsurf-65e55121601a1f1b5a7dc1ec9130b333388a6de8.tar.gz
netsurf-65e55121601a1f1b5a7dc1ec9130b333388a6de8.tar.bz2
html: Fire DOM KeyboardEvents on keypresses.
-rw-r--r--content/handlers/html/interaction.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c
index bc130f077..651199ce2 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);