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

[spidermonkey] window.event

This commit is contained in:
Witold Filipczyk 2023-09-21 17:38:56 +02:00
parent 447aa41dc9
commit a9b8dca965
3 changed files with 29 additions and 4 deletions

View File

@ -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)
{

View File

@ -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) {

View File

@ -5,13 +5,13 @@
<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(event)">
<input type="submit">
</form>
<script>
function myFunction() {
alert("You pressed a key inside the input field");
function myFunction(event) {
alert("You pressed a key inside the input field " + event.keyCode);
}
</script>