diff --git a/src/ecmascript/mujs/Makefile b/src/ecmascript/mujs/Makefile index 778f7c1ad..f4074ab95 100644 --- a/src/ecmascript/mujs/Makefile +++ b/src/ecmascript/mujs/Makefile @@ -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 diff --git a/src/ecmascript/mujs/css.c b/src/ecmascript/mujs/css.c new file mode 100644 index 000000000..3ebf552ce --- /dev/null +++ b/src/ecmascript/mujs/css.c @@ -0,0 +1,113 @@ +/* The MuJS CSSStyleDeclaration object implementation. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef CONFIG_LIBDOM +#include +#include +#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); + } +} diff --git a/src/ecmascript/mujs/css.h b/src/ecmascript/mujs/css.h new file mode 100644 index 000000000..2f0c57a43 --- /dev/null +++ b/src/ecmascript/mujs/css.h @@ -0,0 +1,16 @@ +#ifndef EL__ECMASCRIPT_MUJS_CSS_H +#define EL__ECMASCRIPT_MUJS_CSS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void mjs_push_CSSStyleDeclaration(js_State *J, void *node); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/ecmascript/mujs/element.c b/src/ecmascript/mujs/element.c index eabab1b21..9f0bdb651 100644 --- a/src/ecmascript/mujs/element.c +++ b/src/ecmascript/mujs/element.c @@ -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"); diff --git a/src/ecmascript/mujs/element.h b/src/ecmascript/mujs/element.h index 0c2145303..a449c46bf 100644 --- a/src/ecmascript/mujs/element.h +++ b/src/ecmascript/mujs/element.h @@ -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); diff --git a/src/ecmascript/mujs/meson.build b/src/ecmascript/mujs/meson.build index 4db2186b8..6800f4bc1 100644 --- a/src/ecmascript/mujs/meson.build +++ b/src/ecmascript/mujs/meson.build @@ -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') diff --git a/src/ecmascript/mujs/window.c b/src/ecmascript/mujs/window.c index 05ccd8b09..3393259cd 100644 --- a/src/ecmascript/mujs/window.c +++ b/src/ecmascript/mujs/window.c @@ -12,6 +12,11 @@ #include #include +#ifdef CONFIG_LIBDOM +#include +#include +#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);