diff --git a/src/viewer/text/Makefile b/src/viewer/text/Makefile index f1f84b65..87338810 100644 --- a/src/viewer/text/Makefile +++ b/src/viewer/text/Makefile @@ -5,6 +5,6 @@ INCLUDES += $(TRE_CFLAGS) OBJS-$(CONFIG_MARKS) += marks.o -OBJS = draw.o form.obj link.obj search.o textarea.o view.o vs.obj +OBJS = draw.o form.obj link.obj search.o textarea.o view.obj vs.obj include $(top_srcdir)/Makefile.lib diff --git a/src/viewer/text/link.cpp b/src/viewer/text/link.cpp index 71f35ef4..84edceb6 100644 --- a/src/viewer/text/link.cpp +++ b/src/viewer/text/link.cpp @@ -24,6 +24,7 @@ #ifdef CONFIG_ECMASCRIPT_SMJS #include "ecmascript/spidermonkey/element.h" #include +#include #endif #include "intl/libintl.h" @@ -50,7 +51,6 @@ #include "viewer/text/view.h" #include "viewer/text/vs.h" -#include /* Perhaps some of these would be more fun to have in viewer/common/, dunno. * --pasky */ diff --git a/src/viewer/text/meson.build b/src/viewer/text/meson.build index 656300cb..ddb20d6b 100644 --- a/src/viewer/text/meson.build +++ b/src/viewer/text/meson.build @@ -4,4 +4,4 @@ if conf_data.get('CONFIG_MARKS') srcs += files('marks.c') endif -srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.c', 'vs.cpp') +srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.cpp', 'vs.cpp') diff --git a/src/viewer/text/view.c b/src/viewer/text/view.cpp similarity index 98% rename from src/viewer/text/view.c rename to src/viewer/text/view.cpp index b2002cb8..a86c399f 100644 --- a/src/viewer/text/view.c +++ b/src/viewer/text/view.cpp @@ -27,6 +27,11 @@ #include "document/options.h" #include "document/renderer.h" #include "document/view.h" +#ifdef CONFIG_ECMASCRIPT_SMJS +#include "ecmascript/spidermonkey/element.h" +#include +#include +#endif #include "intl/charsets.h" #include "intl/libintl.h" #include "main/event.h" @@ -1277,19 +1282,38 @@ static enum frame_event_status try_form_action(struct session *ses, struct document_view *doc_view, struct link *link, struct term_event *ev) { - enum frame_event_status status; + enum frame_event_status status = FRAME_EVENT_OK; assert(link); if (!link_is_textinput(link)) return FRAME_EVENT_IGNORED; - if (!current_link_evhook(doc_view, SEVHOOK_ONKEYDOWN) - || !current_link_evhook(doc_view, SEVHOOK_ONKEYUP)) { - return FRAME_EVENT_IGNORED; +#ifdef CONFIG_ECMASCRIPT + std::map *mapa = (std::map *)doc_view->document->element_map; + + if (mapa) { + auto element = (*mapa).find(link->element_offset); + + if (element != (*mapa).end()) { + const char *event_name = script_event_hook_name[SEVHOOK_ONKEYDOWN]; + + check_element_event(element->second, event_name); + event_name = script_event_hook_name[SEVHOOK_ONKEYUP]; + check_element_event(element->second, event_name); + } } - status = field_op(ses, doc_view, link, ev); + if (!current_link_evhook(doc_view, SEVHOOK_ONKEYDOWN)) { + status = FRAME_EVENT_IGNORED; + } + if (status != FRAME_EVENT_IGNORED && !current_link_evhook(doc_view, SEVHOOK_ONKEYUP)) { + status = FRAME_EVENT_IGNORED; + } +#endif + if (status != FRAME_EVENT_IGNORED) { + status = field_op(ses, doc_view, link, ev); + } if (status != FRAME_EVENT_IGNORED && ses->insert_mode == INSERT_MODE_ON) { diff --git a/test/ecmascript/keyListener.html b/test/ecmascript/keyListener.html new file mode 100644 index 00000000..9fdb2282 --- /dev/null +++ b/test/ecmascript/keyListener.html @@ -0,0 +1,20 @@ + + + + +

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

+ +
+ + +
+ + +