mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[ecmascript] keyboardEvent.target
This commit is contained in:
parent
6534c412c2
commit
44b743540e
@ -15,6 +15,7 @@
|
||||
#include "document/libdom/doc.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/mujs.h"
|
||||
#include "ecmascript/mujs/element.h"
|
||||
#include "ecmascript/mujs/keyboard.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "terminal/event.h"
|
||||
@ -27,6 +28,7 @@ static void mjs_keyboardEvent_get_property_bubbles(js_State *J);
|
||||
static void mjs_keyboardEvent_get_property_cancelable(js_State *J);
|
||||
static void mjs_keyboardEvent_get_property_composed(js_State *J);
|
||||
static void mjs_keyboardEvent_get_property_defaultPrevented(js_State *J);
|
||||
static void mjs_keyboardEvent_get_property_target(js_State *J);
|
||||
static void mjs_keyboardEvent_get_property_type(js_State *J);
|
||||
|
||||
static void mjs_keyboardEvent_preventDefault(js_State *J);
|
||||
@ -80,6 +82,7 @@ mjs_push_keyboardEvent(js_State *J, struct term_event *ev, const char *type_)
|
||||
addproperty(J, "defaultPrevented", mjs_keyboardEvent_get_property_defaultPrevented, NULL);
|
||||
addproperty(J, "key", mjs_keyboardEvent_get_property_key, NULL);
|
||||
addproperty(J, "keyCode", mjs_keyboardEvent_get_property_keyCode, NULL);
|
||||
addproperty(J, "target", mjs_keyboardEvent_get_property_target, NULL);
|
||||
addproperty(J, "type", mjs_keyboardEvent_get_property_type, NULL);
|
||||
}
|
||||
}
|
||||
@ -222,6 +225,29 @@ mjs_keyboardEvent_get_property_code(js_State *J)
|
||||
dom_string_unref(code);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_keyboardEvent_get_property_target(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
dom_keyboard_event *event = (dom_keyboard_event *)js_touserdata(J, 0, "event");
|
||||
|
||||
if (!event) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
dom_event_target *target = NULL;
|
||||
dom_exception exc = dom_event_get_target(event, &target);
|
||||
|
||||
if (exc != DOM_NO_ERR || !target) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
mjs_push_element(J, target);
|
||||
dom_node_unref(target);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_keyboardEvent_get_property_type(js_State *J)
|
||||
{
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "document/libdom/doc.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/quickjs.h"
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#include "ecmascript/quickjs/keyboard.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "terminal/event.h"
|
||||
@ -31,6 +32,7 @@ static JSValue js_keyboardEvent_get_property_bubbles(JSContext *ctx, JSValueCons
|
||||
static JSValue js_keyboardEvent_get_property_cancelable(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_keyboardEvent_get_property_composed(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_keyboardEvent_get_property_defaultPrevented(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_keyboardEvent_get_property_target(JSContext *ctx, JSValueConst this_val);
|
||||
static JSValue js_keyboardEvent_get_property_type(JSContext *ctx, JSValueConst this_val);
|
||||
|
||||
static JSValue js_keyboardEvent_preventDefault(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
|
||||
@ -60,6 +62,7 @@ static const JSCFunctionListEntry js_keyboardEvent_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("defaultPrevented", js_keyboardEvent_get_property_defaultPrevented, NULL),
|
||||
JS_CGETSET_DEF("key", js_keyboardEvent_get_property_key, NULL),
|
||||
JS_CGETSET_DEF("keyCode", js_keyboardEvent_get_property_keyCode, NULL),
|
||||
JS_CGETSET_DEF("target", js_keyboardEvent_get_property_target, NULL),
|
||||
JS_CGETSET_DEF("type", js_keyboardEvent_get_property_type, NULL),
|
||||
JS_CFUNC_DEF("preventDefault", 0, js_keyboardEvent_preventDefault)
|
||||
};
|
||||
@ -214,6 +217,30 @@ js_keyboardEvent_get_property_code(JSContext *ctx, JSValueConst this_val)
|
||||
RETURN_JS(r);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_keyboardEvent_get_property_target(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
struct dom_keyboard_event *event = (dom_keyboard_event *)(JS_GetOpaque(this_val, js_keyboardEvent_class_id));
|
||||
|
||||
if (!event) {
|
||||
return JS_NULL;
|
||||
}
|
||||
dom_event_target *target = NULL;
|
||||
dom_exception exc = dom_event_get_target(event, &target);
|
||||
|
||||
if (exc != DOM_NO_ERR || !target) {
|
||||
return JS_NULL;
|
||||
}
|
||||
JSValue r = getElement(ctx, target);
|
||||
dom_node_unref(target);
|
||||
|
||||
RETURN_JS(r);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_keyboardEvent_get_property_type(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey.h"
|
||||
#include "ecmascript/spidermonkey/element.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
#include "ecmascript/spidermonkey/keyboard.h"
|
||||
#include "ecmascript/timer.h"
|
||||
@ -70,6 +71,7 @@ static bool keyboardEvent_get_property_bubbles(JSContext *ctx, unsigned int argc
|
||||
static bool keyboardEvent_get_property_cancelable(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
//static bool keyboardEvent_get_property_composed(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool keyboardEvent_get_property_defaultPrevented(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool keyboardEvent_get_property_target(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool keyboardEvent_get_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
static bool keyboardEvent_preventDefault(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
@ -201,6 +203,7 @@ JSPropertySpec keyboardEvent_props[] = {
|
||||
JS_PSG("defaultPrevented", keyboardEvent_get_property_defaultPrevented, JSPROP_ENUMERATE),
|
||||
JS_PSG("key", keyboardEvent_get_property_key, JSPROP_ENUMERATE),
|
||||
JS_PSG("keyCode", keyboardEvent_get_property_keyCode, JSPROP_ENUMERATE),
|
||||
JS_PSG("target", keyboardEvent_get_property_target, JSPROP_ENUMERATE),
|
||||
JS_PSG("type", keyboardEvent_get_property_type, JSPROP_ENUMERATE),
|
||||
JS_PS_END
|
||||
};
|
||||
@ -422,6 +425,41 @@ keyboardEvent_get_property_code(JSContext *ctx, unsigned int argc, JS::Value *vp
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
keyboardEvent_get_property_target(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
dom_keyboard_event *keyb = JS::GetMaybePtrFromReservedSlot<dom_keyboard_event>(hobj, 0);
|
||||
|
||||
if (!keyb) {
|
||||
return false;
|
||||
}
|
||||
dom_event_target *target = NULL;
|
||||
dom_exception exc = dom_event_get_target(keyb, &target);
|
||||
|
||||
if (exc != DOM_NO_ERR || !target) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
JSObject *obj = getElement(ctx, target);
|
||||
args.rval().setObject(*obj);
|
||||
dom_node_unref(target);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
keyboardEvent_get_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user