From a9b8dca96575ee6e73e069c8785aeed96ffbdbb9 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 21 Sep 2023 17:38:56 +0200 Subject: [PATCH] [spidermonkey] window.event --- src/ecmascript/libdom/spidermonkey/window.cpp | 18 ++++++++++++++++++ src/viewer/text/view.cpp | 9 ++++++++- test/ecmascript/onkeydown.html | 6 +++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/ecmascript/libdom/spidermonkey/window.cpp b/src/ecmascript/libdom/spidermonkey/window.cpp index 4f64a9e3..50e82fd8 100644 --- a/src/ecmascript/libdom/spidermonkey/window.cpp +++ b/src/ecmascript/libdom/spidermonkey/window.cpp @@ -25,6 +25,7 @@ #include "document/view.h" #include "ecmascript/ecmascript.h" #include "ecmascript/spidermonkey/heartbeat.h" +#include "ecmascript/spidermonkey/keyboard.h" #include "ecmascript/spidermonkey/message.h" #include "ecmascript/spidermonkey/window.h" #include "ecmascript/timer.h" @@ -51,12 +52,15 @@ static bool window_get_property_closed(JSContext *cx, unsigned int argc, JS::Value *vp); +static bool window_get_property_event(JSContext *cx, unsigned int argc, JS::Value *vp); static bool window_get_property_parent(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool window_get_property_self(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool window_get_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool window_set_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp); static bool window_get_property_top(JSContext *ctx, unsigned int argc, JS::Value *vp); +extern struct term_event last_event; + struct listener { LIST_HEAD_EL(struct listener); char *typ; @@ -133,6 +137,7 @@ enum window_prop { * comparing. */ JSPropertySpec window_props[] = { JS_PSG("closed", window_get_property_closed, JSPROP_ENUMERATE), + JS_PSG("event", window_get_property_event, JSPROP_ENUMERATE), JS_PSG("parent", window_get_property_parent, JSPROP_ENUMERATE), JS_PSG("self", window_get_property_self, JSPROP_ENUMERATE), JS_PSGS("status", window_get_property_status, window_set_property_status, 0), @@ -685,6 +690,19 @@ window_get_property_closed(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } +static bool +window_get_property_event(JSContext *ctx, unsigned int argc, JS::Value *vp) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + JS::CallArgs args = CallArgsFromVp(argc, vp); + JSObject *event = get_keyboardEvent(ctx, &last_event); + args.rval().setObject(*event); + + return true; +} + static bool window_get_property_parent(JSContext *ctx, unsigned int argc, JS::Value *vp) { diff --git a/src/viewer/text/view.cpp b/src/viewer/text/view.cpp index 2c1b7d59..c6f7f7d5 100644 --- a/src/viewer/text/view.cpp +++ b/src/viewer/text/view.cpp @@ -1306,6 +1306,8 @@ try_prefix_key(struct session *ses, struct document_view *doc_view, return FRAME_EVENT_IGNORED; } +struct term_event last_event; + static enum frame_event_status try_form_action(struct session *ses, struct document_view *doc_view, struct link *link, struct term_event *ev) @@ -1314,6 +1316,12 @@ try_form_action(struct session *ses, struct document_view *doc_view, assert(link); + if (ev) { + last_event = *ev; + } else { + memset(&last_event, 0, sizeof(last_event)); + } + if (!link_is_textinput(link)) return FRAME_EVENT_IGNORED; @@ -1344,7 +1352,6 @@ try_form_action(struct session *ses, struct document_view *doc_view, if (status != FRAME_EVENT_IGNORED && !current_link_evhook(doc_view, SEVHOOK_ONKEYPRESS)) { status = FRAME_EVENT_IGNORED; } - } #endif if (status != FRAME_EVENT_IGNORED) { diff --git a/test/ecmascript/onkeydown.html b/test/ecmascript/onkeydown.html index f8259cae..6dc6688f 100644 --- a/test/ecmascript/onkeydown.html +++ b/test/ecmascript/onkeydown.html @@ -5,13 +5,13 @@

A function is triggered when the user is pressing a key in the input field.

- +