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

[ecmascript] onkeyup and onkeydown

This commit is contained in:
Witold Filipczyk 2022-11-03 19:30:57 +01:00
parent 9b895b3681
commit 3330427738
9 changed files with 25 additions and 5 deletions

View File

@ -86,6 +86,8 @@ enum script_event_hook_type {
SEVHOOK_ONFOCUS, SEVHOOK_ONFOCUS,
SEVHOOK_ONMOUSEOUT, SEVHOOK_ONMOUSEOUT,
SEVHOOK_ONBLUR, SEVHOOK_ONBLUR,
SEVHOOK_ONKEYDOWN,
SEVHOOK_ONKEYUP
}; };
struct script_event_hook { struct script_event_hook {

View File

@ -283,6 +283,8 @@ html_focusable(struct html_context *html_context, char *a)
mem_free_set(&elformat.onfocus, get_attr_val(a, "onfocus", cp)); mem_free_set(&elformat.onfocus, get_attr_val(a, "onfocus", cp));
mem_free_set(&elformat.onmouseout, get_attr_val(a, "onmouseout", cp)); mem_free_set(&elformat.onmouseout, get_attr_val(a, "onmouseout", cp));
mem_free_set(&elformat.onblur, get_attr_val(a, "onblur", cp)); mem_free_set(&elformat.onblur, get_attr_val(a, "onblur", cp));
mem_free_set(&elformat.onkeydown, get_attr_val(a, "onkeydown", cp));
mem_free_set(&elformat.onkeyup, get_attr_val(a, "onkeyup", cp));
} }
void void
@ -802,7 +804,8 @@ init_html_parser(struct uri *uri, struct document_options *options,
elformat.fontsize = 3; elformat.fontsize = 3;
elformat.link = elformat.target = elformat.image = NULL; elformat.link = elformat.target = elformat.image = NULL;
elformat.onclick = elformat.ondblclick = elformat.onmouseover = elformat.onhover elformat.onclick = elformat.ondblclick = elformat.onmouseover = elformat.onhover
= elformat.onfocus = elformat.onmouseout = elformat.onblur = NULL; = elformat.onfocus = elformat.onmouseout = elformat.onblur
= elformat.onkeydown = elformat.onkeyup = NULL;
elformat.select = NULL; elformat.select = NULL;
elformat.form = NULL; elformat.form = NULL;
elformat.title = NULL; elformat.title = NULL;

View File

@ -74,6 +74,8 @@ struct text_attrib {
char *onfocus; char *onfocus;
char *onmouseout; char *onmouseout;
char *onblur; char *onblur;
char *onkeydown;
char *onkeyup;
}; };
/* This enum is pretty ugly, yes ;). */ /* This enum is pretty ugly, yes ;). */

View File

@ -133,6 +133,8 @@ kill_html_stack_item(struct html_context *html_context, struct html_element *e)
mem_free_if(e->attr.onfocus); mem_free_if(e->attr.onfocus);
mem_free_if(e->attr.onmouseout); mem_free_if(e->attr.onmouseout);
mem_free_if(e->attr.onblur); mem_free_if(e->attr.onblur);
mem_free_if(e->attr.onkeydown);
mem_free_if(e->attr.onkeyup);
del_from_list(e); del_from_list(e);
mem_free(e); mem_free(e);
@ -171,7 +173,8 @@ html_stack_dup(struct html_context *html_context, enum html_element_mortality_ty
/* We don't want to propagate these. */ /* We don't want to propagate these. */
/* XXX: For sure? --pasky */ /* XXX: For sure? --pasky */
e->attr.onclick = e->attr.ondblclick = e->attr.onmouseover = e->attr.onhover e->attr.onclick = e->attr.ondblclick = e->attr.onmouseover = e->attr.onhover
= e->attr.onfocus = e->attr.onmouseout = e->attr.onblur = NULL; = e->attr.onfocus = e->attr.onmouseout = e->attr.onblur
= e->attr.onkeydown = e->attr.onkeyup = NULL;
#if 0 #if 0
if (e->name) { if (e->name) {

View File

@ -1448,6 +1448,8 @@ init_link_event_hooks(struct html_context *html_context, struct link *link)
add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, elformat.onfocus); add_evhook(link->event_hooks, SEVHOOK_ONFOCUS, elformat.onfocus);
add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, elformat.onmouseout); add_evhook(link->event_hooks, SEVHOOK_ONMOUSEOUT, elformat.onmouseout);
add_evhook(link->event_hooks, SEVHOOK_ONBLUR, elformat.onblur); add_evhook(link->event_hooks, SEVHOOK_ONBLUR, elformat.onblur);
add_evhook(link->event_hooks, SEVHOOK_ONKEYDOWN, elformat.onkeydown);
add_evhook(link->event_hooks, SEVHOOK_ONKEYUP, elformat.onkeyup);
#undef add_evhook #undef add_evhook
} }

View File

@ -49,7 +49,7 @@
* --pasky */ * --pasky */
static int int
current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type) current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type)
{ {
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS) #if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
@ -96,7 +96,6 @@ do { \
current_link_evhook(dv, SEVHOOK_ONBLUR); \ current_link_evhook(dv, SEVHOOK_ONBLUR); \
} while (0) } while (0)
void void
set_link(struct document_view *doc_view) set_link(struct document_view *doc_view)
{ {

View File

@ -1,7 +1,7 @@
#ifndef EL__VIEWER_TEXT_LINK_H #ifndef EL__VIEWER_TEXT_LINK_H
#define EL__VIEWER_TEXT_LINK_H #define EL__VIEWER_TEXT_LINK_H
#include "document/document.h"
#include "viewer/action.h" #include "viewer/action.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -17,6 +17,7 @@ struct terminal;
struct uri; struct uri;
struct conv_table; struct conv_table;
int current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type);
void set_link(struct document_view *doc_view); void set_link(struct document_view *doc_view);
void clear_link(struct terminal *term, struct document_view *doc_view); void clear_link(struct terminal *term, struct document_view *doc_view);
void draw_current_link(struct session *ses, struct document_view *doc_view); void draw_current_link(struct session *ses, struct document_view *doc_view);

View File

@ -1284,6 +1284,11 @@ try_form_action(struct session *ses, struct document_view *doc_view,
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)
|| !current_link_evhook(doc_view, SEVHOOK_ONKEYUP)) {
return FRAME_EVENT_IGNORED;
}
status = field_op(ses, doc_view, link, ev); status = field_op(ses, doc_view, link, ev);
if (status != FRAME_EVENT_IGNORED if (status != FRAME_EVENT_IGNORED

View File

@ -4,7 +4,10 @@
<p>A function is triggered when the user is pressing a key in the input field.</p> <p>A function is triggered when the user is pressing a key in the input field.</p>
<form action="/">
<input type="text" onkeydown="myFunction()"> <input type="text" onkeydown="myFunction()">
<input type="submit">
</form>
<script> <script>
function myFunction() { function myFunction() {