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

[mujs] window.getComputedStyle

This commit is contained in:
Witold Filipczyk 2024-01-18 20:53:17 +01:00
parent 797124fc2a
commit dd87474f06
7 changed files with 151 additions and 3 deletions

View File

@ -1,7 +1,7 @@
top_builddir=../../..
include $(top_builddir)/Makefile.config
OBJS = attr.o attributes.o collection.o console.o document.o element.o form.o forms.o history.o implementation.o input.o \
OBJS = attr.o attributes.o collection.o console.o css.o document.o element.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 window.o xhr.o
include $(top_srcdir)/Makefile.lib

113
src/ecmascript/mujs/css.c Normal file
View File

@ -0,0 +1,113 @@
/* The MuJS CSSStyleDeclaration object implementation. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef CONFIG_LIBDOM
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
#endif
#include "elinks.h"
#include "document/libdom/corestrings.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs/mapa.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/css.h"
#include "ecmascript/mujs/element.h"
static void
mjs_CSSStyleDeclaration_get_property_length(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushnumber(J, 3); // fake
}
static void
mjs_push_CSSStyleDeclaration_item2(js_State *J, int idx)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "0"); // fake
}
static void
mjs_CSSStyleDeclaration_item(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "0"); // fake
}
static void
mjs_push_CSSStyleDeclaration_namedItem2(js_State *J, const char *str)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "0"); // fake
}
static void
mjs_CSSStyleDeclaration_namedItem(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "0");
}
static void
mjs_CSSStyleDeclaration_set_items(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "0");
js_setproperty(J, -2, "marginTop");
js_pushstring(J, "0");
js_setproperty(J, -2, "marginLeft");
js_pushstring(J, "0");
js_setproperty(J, -2, "marginRight");
}
static void
mjs_CSSStyleDeclaration_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[CSSStyleDeclaration object]");
}
static void
mjs_CSSStyleDeclaration_finalizer(js_State *J, void *node)
{
}
void
mjs_push_CSSStyleDeclaration(js_State *J, void *node)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_newarray(J);
{
js_newuserdata(J, "CSSStyleDeclaration", node, mjs_CSSStyleDeclaration_finalizer);
addmethod(J, "item", mjs_CSSStyleDeclaration_item, 1);
addmethod(J, "namedItem", mjs_CSSStyleDeclaration_namedItem, 1);
addmethod(J, "toString", mjs_CSSStyleDeclaration_toString, 0);
addproperty(J, "length", mjs_CSSStyleDeclaration_get_property_length, NULL);
mjs_CSSStyleDeclaration_set_items(J, node);
}
}

16
src/ecmascript/mujs/css.h Normal file
View File

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

View File

@ -72,7 +72,7 @@ struct mjs_element_private {
int ref_count;
};
static void *
void *
mjs_getprivate(js_State *J, int idx)
{
struct mjs_element_private *priv = (struct mjs_element_private *)js_touserdata(J, idx, "element");

View File

@ -9,6 +9,7 @@ extern "C" {
struct term_event;
void *mjs_getprivate(js_State *J, int idx);
int mjs_element_init(js_State *J);
void mjs_push_element(js_State *J, void *node);
void walk_tree(struct string *buf, void *nod, bool start, bool toSortAttrs);

View File

@ -1,2 +1,2 @@
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'document.c', 'element.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', 'document.c', 'element.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', 'window.c', 'xhr.c')

View File

@ -12,6 +12,11 @@
#include <stdlib.h>
#include <string.h>
#ifdef CONFIG_LIBDOM
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
#endif
#include "elinks.h"
#include "bfu/dialog.h"
@ -25,6 +30,8 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/css.h"
#include "ecmascript/mujs/element.h"
#include "ecmascript/mujs/keyboard.h"
#include "ecmascript/mujs/location.h"
#include "ecmascript/mujs/message.h"
@ -295,6 +302,16 @@ mjs_window_clearTimeout(js_State *J)
js_pushundefined(J);
}
static void
mjs_window_getComputedStyle(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(mjs_getprivate(J, 1));
mjs_push_CSSStyleDeclaration(J, el);
}
static void
mjs_window_open(js_State *J)
{
@ -678,6 +695,7 @@ mjs_window_init(js_State *J)
addmethod(J, "window.addEventListener", mjs_window_addEventListener, 3);
addmethod(J, "window.alert", mjs_window_alert, 1);
addmethod(J, "window.clearTimeout", mjs_window_clearTimeout, 1);
addmethod(J, "window.getComputedStyle", mjs_window_getComputedStyle, 2);
addmethod(J, "window.open", mjs_window_open, 3);
addmethod(J, "window.postMessage", mjs_window_postMessage, 3);
addmethod(J, "window.removeEventListener", mjs_window_removeEventListener, 3);