1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[quickjs] window.event

This commit is contained in:
Witold Filipczyk 2023-09-21 17:59:47 +02:00
parent a9b8dca965
commit ced7b7b294
3 changed files with 29 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/keyboard.h"
#include "ecmascript/mujs/message.h"
#include "ecmascript/mujs/window.h"
#include "ecmascript/timer.h"
@ -63,6 +64,8 @@ struct el_message {
struct el_window *elwin;
};
extern struct term_event last_event;
static
void mjs_window_finalizer(js_State *J, void *val)
{
@ -91,6 +94,15 @@ mjs_window_get_property_closed(js_State *J)
js_pushboolean(J, 0);
}
static void
mjs_window_get_property_event(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
mjs_push_keyboardEvent(J, &last_event);
}
static void
mjs_window_get_property_parent(js_State *J)
{
@ -631,6 +643,7 @@ mjs_window_init(js_State *J)
addmethod(J, "toString", mjs_window_toString, 0);
addproperty(J, "closed", mjs_window_get_property_closed, NULL);
addproperty(J, "event", mjs_window_get_property_event, NULL);
addproperty(J, "parent", mjs_window_get_property_parent, NULL);
addproperty(J, "self", mjs_window_get_property_self, NULL);
addproperty(J, "status", mjs_window_get_property_status, mjs_window_set_property_status);

View File

@ -2760,7 +2760,7 @@ check_element_event(void *interp, void *elem, const char *event_name, struct ter
if (strcmp(l->typ, event_name)) {
continue;
}
if (ev && ev->ev == EVENT_KBD && (!strcmp(event_name, "keydown") || !strcmp(event_name, "keyup") || !strcmp(event_name("keypress")))) {
if (ev && ev->ev == EVENT_KBD && (!strcmp(event_name, "keydown") || !strcmp(event_name, "keyup") || !strcmp(event_name, "keypress"))) {
JSValue func = JS_DupValue(ctx, l->fun);
JSValue arg = get_keyboardEvent(ctx, ev);
JSValue ret = JS_Call(ctx, func, el_private->thisval, 1, (JSValueConst *) &arg);

View File

@ -18,6 +18,7 @@
#include "ecmascript/ecmascript.h"
#include "ecmascript/quickjs.h"
#include "ecmascript/quickjs/heartbeat.h"
#include "ecmascript/quickjs/keyboard.h"
#include "ecmascript/quickjs/message.h"
#include "ecmascript/quickjs/window.h"
#include "ecmascript/timer.h"
@ -52,6 +53,8 @@ struct el_message {
struct el_window *elwin;
};
extern struct term_event last_event;
static void
js_window_finalize(JSRuntime *rt, JSValue val)
{
@ -332,6 +335,17 @@ js_window_get_property_closed(JSContext *ctx, JSValueConst this_val)
return JS_FALSE;
}
static JSValue
js_window_get_property_event(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
return get_keyboardEvent(ctx, &last_event);
}
static JSValue
js_window_get_property_parent(JSContext *ctx, JSValueConst this_val)
{
@ -710,6 +724,7 @@ js_window_postMessage(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo
static const JSCFunctionListEntry js_window_proto_funcs[] = {
JS_CGETSET_DEF("closed", js_window_get_property_closed, NULL),
JS_CGETSET_DEF("event", js_window_get_property_event, NULL),
JS_CGETSET_DEF("parent", js_window_get_property_parent, NULL),
JS_CGETSET_DEF("self", js_window_get_property_self, NULL),
JS_CGETSET_DEF("status", js_window_get_property_status, js_window_set_property_status),