mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] DOMRect
This commit is contained in:
parent
6f4e30f8b6
commit
0bcdbef902
@ -2,7 +2,7 @@ top_builddir=../../..
|
|||||||
include $(top_builddir)/Makefile.config
|
include $(top_builddir)/Makefile.config
|
||||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
OBJS = attr.obj attributes.obj collection.obj console.obj css.obj customevent.obj document.obj element.obj event.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
OBJS = attr.obj attributes.obj collection.obj console.obj css.obj customevent.obj document.obj domrect.obj element.obj event.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
||||||
keyboard.obj localstorage.obj location.obj message.obj navigator.obj nodelist.obj screen.obj style.obj unibar.obj url.obj urlsearchparams.obj window.obj xhr.obj
|
keyboard.obj localstorage.obj location.obj message.obj navigator.obj nodelist.obj screen.obj style.obj unibar.obj url.obj urlsearchparams.obj window.obj xhr.obj
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
558
src/ecmascript/spidermonkey/domrect.cpp
Normal file
558
src/ecmascript/spidermonkey/domrect.cpp
Normal file
@ -0,0 +1,558 @@
|
|||||||
|
/* The SiderMonkey DOMRect implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
#include <js/BigInt.h>
|
||||||
|
#include <js/Conversions.h>
|
||||||
|
|
||||||
|
#include "bfu/dialog.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "cookies/cookies.h"
|
||||||
|
#include "dialogs/menu.h"
|
||||||
|
#include "dialogs/status.h"
|
||||||
|
#include "document/html/frames.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/forms.h"
|
||||||
|
#include "document/view.h"
|
||||||
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/libdom/dom.h"
|
||||||
|
#include "ecmascript/spidermonkey.h"
|
||||||
|
#include "ecmascript/spidermonkey/domrect.h"
|
||||||
|
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
static bool domRect_get_property_x(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_y(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_width(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_height(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_top(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_right(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_bottom(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_get_property_left(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
static bool domRect_set_property_x(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_y(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_width(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_height(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_top(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_right(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_bottom(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool domRect_set_property_left(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
struct eljs_domrect {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
float top;
|
||||||
|
float right;
|
||||||
|
float bottom;
|
||||||
|
float left;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
domRect_finalize(JS::GCContext *op, JSObject *domRect_obj)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(domRect_obj, 0);
|
||||||
|
|
||||||
|
if (d) {
|
||||||
|
mem_free(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSClassOps domRect_ops = {
|
||||||
|
nullptr, // addProperty
|
||||||
|
nullptr, // deleteProperty
|
||||||
|
nullptr, // enumerate
|
||||||
|
nullptr, // newEnumerate
|
||||||
|
nullptr, // resolve
|
||||||
|
nullptr, // mayResolve
|
||||||
|
domRect_finalize, // finalize
|
||||||
|
nullptr, // call
|
||||||
|
nullptr, // construct
|
||||||
|
JS_GlobalObjectTraceHook // trace
|
||||||
|
};
|
||||||
|
|
||||||
|
JSClass domRect_class = {
|
||||||
|
"DOMRect",
|
||||||
|
JSCLASS_HAS_RESERVED_SLOTS(1),
|
||||||
|
&domRect_ops
|
||||||
|
};
|
||||||
|
|
||||||
|
JSPropertySpec domRect_props[] = {
|
||||||
|
JS_PSGS("bottom", domRect_get_property_bottom, domRect_set_property_bottom, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("height", domRect_get_property_height, domRect_set_property_height, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("left", domRect_get_property_left, domRect_set_property_left, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("right", domRect_get_property_right, domRect_set_property_right, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("top", domRect_get_property_top, domRect_set_property_top, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("width", domRect_get_property_width, domRect_set_property_width, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("x", domRect_get_property_x, domRect_set_property_x, JSPROP_ENUMERATE),
|
||||||
|
JS_PSGS("y", domRect_get_property_y, domRect_set_property_y, JSPROP_ENUMERATE),
|
||||||
|
JS_PS_END
|
||||||
|
};
|
||||||
|
|
||||||
|
const spidermonkeyFunctionSpec domRect_funcs[] = {
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_bottom(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->bottom);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_height(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->height);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_left(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->left);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_right(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->right);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_top(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->top);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_width(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->width);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_x(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->x);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_get_property_y(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.rval().setNumber(d->y);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_bottom(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->bottom = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_height(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->height = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_left(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->left = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_right(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->right = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_top(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->top = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_width(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->width = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_x(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->x = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
domRect_set_property_y(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;
|
||||||
|
}
|
||||||
|
struct eljs_domrect *d = JS::GetMaybePtrFromReservedSlot<eljs_domrect>(hobj, 0);
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->y = args[0].toNumber();
|
||||||
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSObject *
|
||||||
|
getDomRect(JSContext *ctx)
|
||||||
|
{
|
||||||
|
struct eljs_domrect *d = mem_calloc(1, sizeof(*d));
|
||||||
|
|
||||||
|
if (!d) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
JSObject *dr = JS_NewObject(ctx, &domRect_class);
|
||||||
|
|
||||||
|
if (!dr) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
JS::RootedObject r_domrect(ctx, dr);
|
||||||
|
JS_DefineProperties(ctx, r_domrect, (JSPropertySpec *)domRect_props);
|
||||||
|
JS::SetReservedSlot(dr, 0, JS::PrivateValue(d));
|
||||||
|
|
||||||
|
return dr;
|
||||||
|
}
|
10
src/ecmascript/spidermonkey/domrect.h
Normal file
10
src/ecmascript/spidermonkey/domrect.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_DOMRECT_H
|
||||||
|
#define EL__ECMASCRIPT_SPIDERMONKEY_DOMRECT_H
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
|
||||||
|
extern JSClass domRect_class;
|
||||||
|
extern JSPropertySpec domRect_props[];
|
||||||
|
JSObject *getDomRect(JSContext *ctx);
|
||||||
|
|
||||||
|
#endif
|
@ -33,6 +33,7 @@
|
|||||||
#include "ecmascript/spidermonkey/attr.h"
|
#include "ecmascript/spidermonkey/attr.h"
|
||||||
#include "ecmascript/spidermonkey/attributes.h"
|
#include "ecmascript/spidermonkey/attributes.h"
|
||||||
#include "ecmascript/spidermonkey/collection.h"
|
#include "ecmascript/spidermonkey/collection.h"
|
||||||
|
#include "ecmascript/spidermonkey/domrect.h"
|
||||||
#include "ecmascript/spidermonkey/event.h"
|
#include "ecmascript/spidermonkey/event.h"
|
||||||
#include "ecmascript/spidermonkey/element.h"
|
#include "ecmascript/spidermonkey/element.h"
|
||||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||||
@ -3740,6 +3741,7 @@ static bool element_dispatchEvent(JSContext *ctx, unsigned int argc, JS::Value *
|
|||||||
static bool element_focus(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_focus(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_getAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_getAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
static bool element_getBoundingRect(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool element_hasAttributes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool element_hasAttributes(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
@ -3768,6 +3770,7 @@ const spidermonkeyFunctionSpec element_funcs[] = {
|
|||||||
{ "focus", element_focus, 0 },
|
{ "focus", element_focus, 0 },
|
||||||
{ "getAttribute", element_getAttribute, 1 },
|
{ "getAttribute", element_getAttribute, 1 },
|
||||||
{ "getAttributeNode", element_getAttributeNode, 1 },
|
{ "getAttributeNode", element_getAttributeNode, 1 },
|
||||||
|
{ "getBoundingRect", element_getBoundingRect, 0 },
|
||||||
{ "getElementsByTagName", element_getElementsByTagName, 1 },
|
{ "getElementsByTagName", element_getElementsByTagName, 1 },
|
||||||
{ "hasAttribute", element_hasAttribute, 1 },
|
{ "hasAttribute", element_hasAttribute, 1 },
|
||||||
{ "hasAttributes", element_hasAttributes, 0 },
|
{ "hasAttributes", element_hasAttributes, 0 },
|
||||||
@ -4528,6 +4531,40 @@ element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
element_getBoundingRect(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
if (!JS_InstanceOf(ctx, hobj, &element_class, NULL)) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JSObject *drect = getDomRect(ctx);
|
||||||
|
|
||||||
|
if (!drect) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
args.rval().setObject(*drect);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
element_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
element_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'css.cpp', 'customevent.cpp', 'document.cpp', 'element.cpp', 'event.cpp',
|
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'css.cpp', 'customevent.cpp', 'document.cpp', 'domrect.cpp', 'element.cpp', 'event.cpp',
|
||||||
'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp', 'keyboard.cpp',
|
'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp', 'keyboard.cpp',
|
||||||
'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'style.cpp', 'unibar.cpp', 'url.cpp',
|
'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'style.cpp', 'unibar.cpp', 'url.cpp',
|
||||||
'urlsearchparams.cpp', 'window.cpp', 'xhr.cpp')
|
'urlsearchparams.cpp', 'window.cpp', 'xhr.cpp')
|
||||||
|
Loading…
Reference in New Issue
Block a user