1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

[mujs] DOMRect

This commit is contained in:
Witold Filipczyk 2024-06-16 20:18:16 +02:00
parent 86affcf076
commit 189115b661
5 changed files with 362 additions and 2 deletions

View File

@ -1,7 +1,7 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
OBJS = attr.o attributes.o collection.o console.o css.o customevent.o document.o element.o event.o form.o forms.o history.o implementation.o input.o \
OBJS = attr.o attributes.o collection.o console.o css.o customevent.o document.o domrect.o element.o event.o form.o forms.o history.o implementation.o input.o \
keyboard.o localstorage.o location.o mapa.o message.o navigator.o nodelist.o screen.o style.o unibar.o url.o window.o xhr.o
include $(top_srcdir)/Makefile.lib

View File

@ -0,0 +1,327 @@
/* The MuJS DOMRect implementation. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/libdom/dom.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/domrect.h"
struct eljs_domrect {
double x;
double y;
double width;
double height;
double top;
double right;
double bottom;
double left;
};
static void mjs_domRect_get_property_bottom(js_State *J);
static void mjs_domRect_get_property_height(js_State *J);
static void mjs_domRect_get_property_left(js_State *J);
static void mjs_domRect_get_property_right(js_State *J);
static void mjs_domRect_get_property_top(js_State *J);
static void mjs_domRect_get_property_width(js_State *J);
static void mjs_domRect_get_property_x(js_State *J);
static void mjs_domRect_get_property_y(js_State *J);
static void mjs_domRect_set_property_bottom(js_State *J);
static void mjs_domRect_set_property_height(js_State *J);
static void mjs_domRect_set_property_left(js_State *J);
static void mjs_domRect_set_property_right(js_State *J);
static void mjs_domRect_set_property_top(js_State *J);
static void mjs_domRect_set_property_width(js_State *J);
static void mjs_domRect_set_property_x(js_State *J);
static void mjs_domRect_set_property_y(js_State *J);
static void
mjs_domRect_finalizer(js_State *J, void *val)
{
struct eljs_domrect *d = (struct eljs_domrect *)val;
if (d) {
mem_free(d);
}
}
void
mjs_push_domRect(js_State *J)
{
struct eljs_domrect *d = (struct eljs_domrect *)mem_calloc(1, sizeof(*d));
if (!d) {
js_error(J, "out of memory");
return;
}
js_newobject(J);
{
js_newuserdata(J, "DOMRect", d, mjs_domRect_finalizer);
addproperty(J, "bottom", mjs_domRect_get_property_bottom, mjs_domRect_set_property_bottom);
addproperty(J, "height", mjs_domRect_get_property_height, mjs_domRect_set_property_height);
addproperty(J, "left", mjs_domRect_get_property_left, mjs_domRect_set_property_left);
addproperty(J, "right", mjs_domRect_get_property_right, mjs_domRect_set_property_right);
addproperty(J, "top", mjs_domRect_get_property_top, mjs_domRect_set_property_top);
addproperty(J, "width", mjs_domRect_get_property_width, mjs_domRect_set_property_width);
addproperty(J, "x", mjs_domRect_get_property_x, mjs_domRect_set_property_x);
addproperty(J, "y", mjs_domRect_get_property_y, mjs_domRect_set_property_y);
}
}
static void
mjs_domRect_get_property_bottom(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->bottom);
}
static void
mjs_domRect_get_property_height(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->height);
}
static void
mjs_domRect_get_property_left(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->left);
}
static void
mjs_domRect_get_property_right(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->right);
}
static void
mjs_domRect_get_property_top(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->top);
}
static void
mjs_domRect_get_property_width(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->width);
}
static void
mjs_domRect_get_property_x(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->x);
}
static void
mjs_domRect_get_property_y(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
js_pushnumber(J, d->y);
}
static void
mjs_domRect_set_property_bottom(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->bottom = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_height(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->height = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_left(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->left = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_right(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->right = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_top(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->top = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_width(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->width = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_x(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->x = js_tonumber(J, 1);
js_pushundefined(J);
}
static void
mjs_domRect_set_property_y(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_domrect *d = (struct eljs_domrect *)js_touserdata(J, 0, "DOMRect");
if (!d) {
js_pushnull(J);
return;
}
d->y = js_tonumber(J, 1);
js_pushundefined(J);
}

View File

@ -0,0 +1,16 @@
#ifndef EL__ECMASCRIPT_MUJS_DOMRECT_H
#define EL__ECMASCRIPT_MUJS_DOMRECT_H
#include <mujs.h>
#ifdef __cplusplus
extern "C" {
#endif
void mjs_push_domRect(js_State *J);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -36,6 +36,7 @@
#include "ecmascript/mujs/attributes.h"
#include "ecmascript/mujs/collection.h"
#include "ecmascript/mujs/document.h"
#include "ecmascript/mujs/domrect.h"
#include "ecmascript/mujs/element.h"
#include "ecmascript/mujs/event.h"
#include "ecmascript/mujs/keyboard.h"
@ -2657,6 +2658,21 @@ mjs_element_getAttributeNode(js_State *J)
mjs_push_attr(J, attr);
}
static void
mjs_element_getBoundingClientRect(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
if (!el) {
js_pushundefined(J);
return;
}
mjs_push_domRect(J);
}
static void
mjs_element_getElementsByTagName(js_State *J)
{
@ -3186,6 +3202,7 @@ mjs_push_element(js_State *J, void *node)
addmethod(J, "focus", mjs_element_focus, 0);
addmethod(J, "getAttribute", mjs_element_getAttribute, 1);
addmethod(J, "getAttributeNode", mjs_element_getAttributeNode, 1);
addmethod(J, "getBoundingClientRect", mjs_element_getBoundingClientRect, 0);
addmethod(J, "getElementsByTagName", mjs_element_getElementsByTagName, 1);
addmethod(J, "hasAttribute", mjs_element_hasAttribute, 1);
addmethod(J, "hasAttributes", mjs_element_hasAttributes, 0);

View File

@ -1,2 +1,2 @@
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'customevent.c', 'document.c', 'element.c', 'event.c', 'form.c', 'forms.c', 'history.c', 'implementation.c', 'input.c', 'keyboard.c',
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'customevent.c', 'document.c', 'domrect.c', 'element.c', 'event.c', 'form.c', 'forms.c', 'history.c', 'implementation.c', 'input.c', 'keyboard.c',
'localstorage.c', 'location.c', 'mapa.c', 'message.c', 'navigator.c', 'nodelist.c', 'screen.c', 'style.c', 'unibar.c', 'url.c', 'window.c', 'xhr.c')