1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[ecmascript] Added keydown and keyup code for eventListeners.

TODO: KeyEvent (keycode etc.)
This commit is contained in:
Witold Filipczyk 2022-11-08 19:43:01 +01:00
parent d7f4f94a62
commit 56ab960cce
5 changed files with 52 additions and 8 deletions

View File

@ -5,6 +5,6 @@ INCLUDES += $(TRE_CFLAGS)
OBJS-$(CONFIG_MARKS) += marks.o 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 include $(top_srcdir)/Makefile.lib

View File

@ -24,6 +24,7 @@
#ifdef CONFIG_ECMASCRIPT_SMJS #ifdef CONFIG_ECMASCRIPT_SMJS
#include "ecmascript/spidermonkey/element.h" #include "ecmascript/spidermonkey/element.h"
#include <libxml++/libxml++.h> #include <libxml++/libxml++.h>
#include <map>
#endif #endif
#include "intl/libintl.h" #include "intl/libintl.h"
@ -50,7 +51,6 @@
#include "viewer/text/view.h" #include "viewer/text/view.h"
#include "viewer/text/vs.h" #include "viewer/text/vs.h"
#include <map>
/* Perhaps some of these would be more fun to have in viewer/common/, dunno. /* Perhaps some of these would be more fun to have in viewer/common/, dunno.
* --pasky */ * --pasky */

View File

@ -4,4 +4,4 @@ if conf_data.get('CONFIG_MARKS')
srcs += files('marks.c') srcs += files('marks.c')
endif 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')

View File

@ -27,6 +27,11 @@
#include "document/options.h" #include "document/options.h"
#include "document/renderer.h" #include "document/renderer.h"
#include "document/view.h" #include "document/view.h"
#ifdef CONFIG_ECMASCRIPT_SMJS
#include "ecmascript/spidermonkey/element.h"
#include <libxml++/libxml++.h>
#include <map>
#endif
#include "intl/charsets.h" #include "intl/charsets.h"
#include "intl/libintl.h" #include "intl/libintl.h"
#include "main/event.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, try_form_action(struct session *ses, struct document_view *doc_view,
struct link *link, struct term_event *ev) struct link *link, struct term_event *ev)
{ {
enum frame_event_status status; enum frame_event_status status = FRAME_EVENT_OK;
assert(link); assert(link);
if (!link_is_textinput(link)) if (!link_is_textinput(link))
return FRAME_EVENT_IGNORED; return FRAME_EVENT_IGNORED;
if (!current_link_evhook(doc_view, SEVHOOK_ONKEYDOWN) #ifdef CONFIG_ECMASCRIPT
|| !current_link_evhook(doc_view, SEVHOOK_ONKEYUP)) { std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)doc_view->document->element_map;
return FRAME_EVENT_IGNORED;
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 if (status != FRAME_EVENT_IGNORED
&& ses->insert_mode == INSERT_MODE_ON) { && ses->insert_mode == INSERT_MODE_ON) {

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user is pressing a key in the input field.</p>
<form action="/">
<input id="k" type="text">
<input type="submit">
</form>
<script>
function myFunction(event)
{
alert("You pressed a key inside the input field");
}
document.getElementById('k').addEventListener('keydown', myFunction);
</script>
</body>
</html>