mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[quickjs] window.getComputedStyle
This commit is contained in:
parent
06858c1f70
commit
e77ff5aa8b
@ -86,6 +86,9 @@ quickjs_init(struct module *xxx)
|
||||
map_form_elements = attr_create_new_form_elements_map();
|
||||
map_form_elements_rev = attr_create_new_form_elements_map_rev();
|
||||
//js_module_init_ok = spidermonkey_runtime_addref();
|
||||
|
||||
map_csses = attr_create_new_csses_map();
|
||||
map_rev_csses = attr_create_new_csses_map_rev();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -113,6 +116,9 @@ quickjs_done(struct module *xxx)
|
||||
attr_delete_map(map_form_elements);
|
||||
attr_delete_map_rev(map_form_elements_rev);
|
||||
|
||||
attr_delete_map(map_csses);
|
||||
attr_delete_map_rev(map_rev_csses);
|
||||
|
||||
// if (js_module_init_ok)
|
||||
// spidermonkey_runtime_release();
|
||||
}
|
||||
|
@ -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 heartbeat.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 heartbeat.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
|
||||
|
173
src/ecmascript/quickjs/css.c
Normal file
173
src/ecmascript/quickjs/css.c
Normal file
@ -0,0 +1,173 @@
|
||||
/* The QuickJS 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/quickjs/mapa.h"
|
||||
#include "ecmascript/quickjs.h"
|
||||
#include "ecmascript/quickjs/css.h"
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
|
||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
void *map_csses;
|
||||
void *map_rev_csses;
|
||||
|
||||
static void *
|
||||
js_CSSStyleDeclaration_GetOpaque(JSValueConst this_val)
|
||||
{
|
||||
REF_JS(this_val);
|
||||
|
||||
return attr_find_in_map_rev(map_rev_csses, this_val);
|
||||
}
|
||||
|
||||
static void
|
||||
js_CSSStyleDeclaration_SetOpaque(JSValueConst this_val, void *node)
|
||||
{
|
||||
REF_JS(this_val);
|
||||
|
||||
if (!node) {
|
||||
attr_erase_from_map_rev(map_rev_csses, this_val);
|
||||
} else {
|
||||
attr_save_in_map_rev(map_rev_csses, this_val, node);
|
||||
}
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_CSSStyleDeclaration_get_property_length(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
return JS_NewInt32(ctx, 3); // fake
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_CSSStyleDeclaration_item2(JSContext *ctx, JSValueConst this_val, int idx)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
return JS_NewString(ctx, "0"); // fake
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_CSSStyleDeclaration_item(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
if (argc != 1) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
return JS_NewString(ctx, "0"); // fake
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_CSSStyleDeclaration_namedItem2(JSContext *ctx, JSValueConst this_val, const char *str)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
return JS_NewString(ctx, "0"); // fake
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_CSSStyleDeclaration_namedItem(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
if (argc != 1) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
return JS_NewString(ctx, "0"); // fake
|
||||
}
|
||||
|
||||
static void
|
||||
js_CSSStyleDeclaration_set_items(JSContext *ctx, JSValue this_val, void *node)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
JS_DefinePropertyValueStr(ctx, this_val, "marginTop", JS_NewString(ctx, "0"), 0);
|
||||
JS_DefinePropertyValueStr(ctx, this_val, "marginLeft", JS_NewString(ctx, "0"), 0);
|
||||
JS_DefinePropertyValueStr(ctx, this_val, "marginRight", JS_NewString(ctx, "0"), 0);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_CSSStyleDeclaration_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
return JS_NewString(ctx, "[CSSStyleDeclaration object]");
|
||||
}
|
||||
|
||||
static const JSCFunctionListEntry js_CSSStyleDeclaration_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("length", js_CSSStyleDeclaration_get_property_length, NULL),
|
||||
JS_CFUNC_DEF("item", 1, js_CSSStyleDeclaration_item),
|
||||
JS_CFUNC_DEF("namedItem", 1, js_CSSStyleDeclaration_namedItem),
|
||||
JS_CFUNC_DEF("toString", 0, js_CSSStyleDeclaration_toString)
|
||||
};
|
||||
|
||||
JSValue
|
||||
getCSSStyleDeclaration(JSContext *ctx, void *node)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static int initialized;
|
||||
JSValue second;
|
||||
|
||||
if (!initialized) {
|
||||
initialized = 1;
|
||||
}
|
||||
second = attr_find_in_map(map_csses, node);
|
||||
|
||||
if (!JS_IsNull(second)) {
|
||||
JSValue r = JS_DupValue(ctx, second);
|
||||
|
||||
RETURN_JS(r);
|
||||
}
|
||||
#endif
|
||||
JSValue CSSStyleDeclaration_obj = JS_NewArray(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, CSSStyleDeclaration_obj, js_CSSStyleDeclaration_proto_funcs, countof(js_CSSStyleDeclaration_proto_funcs));
|
||||
//js_CSSStyleDeclaration_SetOpaque(CSSStyleDeclaration_obj, node);
|
||||
js_CSSStyleDeclaration_set_items(ctx, CSSStyleDeclaration_obj, node);
|
||||
//attr_save_in_map(map_csses, node, CSSStyleDeclaration_obj);
|
||||
RETURN_JS(CSSStyleDeclaration_obj);
|
||||
|
||||
// JSValue rr = JS_DupValue(ctx, CSSStyleDeclaration_obj);
|
||||
|
||||
// RETURN_JS(rr);
|
||||
}
|
16
src/ecmascript/quickjs/css.h
Normal file
16
src/ecmascript/quickjs/css.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef EL__ECMASCRIPT_QUICKJS_CSS_H
|
||||
#define EL__ECMASCRIPT_QUICKJS_CSS_H
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
JSValue getCSSStyleDeclaration(JSContext *ctx, void *node);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -41,7 +41,7 @@
|
||||
|
||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
static JSClassID js_element_class_id;
|
||||
JSClassID js_element_class_id;
|
||||
|
||||
struct element_listener {
|
||||
LIST_HEAD_EL(struct element_listener);
|
||||
@ -56,7 +56,7 @@ struct js_element_private {
|
||||
void *node;
|
||||
};
|
||||
|
||||
static void *
|
||||
void *
|
||||
js_getopaque(JSValueConst obj, JSClassID class_id)
|
||||
{
|
||||
REF_JS(obj);
|
||||
|
@ -9,6 +9,10 @@ extern "C" {
|
||||
|
||||
struct term_event;
|
||||
|
||||
extern JSClassID js_element_class_id;
|
||||
void *js_getopaque(JSValueConst obj, JSClassID class_id);
|
||||
|
||||
|
||||
JSValue getElement(JSContext *ctx, void *node);
|
||||
|
||||
int js_element_init(JSContext *ctx);
|
||||
|
@ -143,6 +143,19 @@ attr_create_new_nodelist_map(void)
|
||||
return (void *)init_hash8();
|
||||
}
|
||||
|
||||
void *
|
||||
attr_create_new_csses_map(void)
|
||||
{
|
||||
return (void *)init_hash8();
|
||||
}
|
||||
|
||||
void *
|
||||
attr_create_new_csses_map_rev(void)
|
||||
{
|
||||
return (void *)init_hash8();
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
struct classcomp {
|
||||
bool operator() (const std::string& lhs, const std::string& rhs) const
|
||||
|
@ -27,6 +27,9 @@ extern void *map_rev_nodelist;
|
||||
extern void *map_form_elements;
|
||||
extern void *map_form_elements_rev;
|
||||
|
||||
extern void *map_csses;
|
||||
extern void *map_rev_csses;
|
||||
|
||||
void attr_save_in_map(void *m, void *node, JSValueConst value);
|
||||
void attr_save_in_map_void(void *m, void *node, void *value);
|
||||
|
||||
@ -48,6 +51,9 @@ void *attr_create_new_input_map(void);
|
||||
void *attr_create_new_nodelist_map(void);
|
||||
void *attr_create_new_nodelist_map_rev(void);
|
||||
|
||||
void *attr_create_new_csses_map(void);
|
||||
void *attr_create_new_csses_map_rev(void);
|
||||
|
||||
void *attr_create_new_requestHeaders_map(void);
|
||||
void *attr_create_new_responseHeaders_map(void);
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'document.c', 'element.c', 'form.c', 'forms.c', 'heartbeat.c', 'history.c',
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'document.c', 'element.c', 'form.c', 'forms.c', 'heartbeat.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')
|
||||
|
@ -8,6 +8,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/leds.h"
|
||||
@ -17,6 +22,8 @@
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/quickjs.h"
|
||||
#include "ecmascript/quickjs/css.h"
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#include "ecmascript/quickjs/heartbeat.h"
|
||||
#include "ecmascript/quickjs/keyboard.h"
|
||||
#include "ecmascript/quickjs/location.h"
|
||||
@ -324,6 +331,25 @@ js_window_clearTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
/* @window_funcs{"getComputedStyle"} */
|
||||
JSValue
|
||||
js_window_getComputedStyle(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
if (argc < 1) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
dom_node *el = (dom_node *)(js_getopaque(argv[0], js_element_class_id));
|
||||
|
||||
if (!el) {
|
||||
return JS_NULL;
|
||||
}
|
||||
return getCSSStyleDeclaration(ctx, el);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_window_get_property_closed(JSContext *ctx, JSValueConst this_val)
|
||||
@ -784,6 +810,7 @@ static const JSCFunctionListEntry js_window_proto_funcs[] = {
|
||||
JS_CFUNC_DEF("addEventListener", 3, js_window_addEventListener),
|
||||
JS_CFUNC_DEF("alert", 1, js_window_alert),
|
||||
JS_CFUNC_DEF("clearTimeout", 1, js_window_clearTimeout),
|
||||
JS_CFUNC_DEF("getComputedStyle", 2, js_window_getComputedStyle),
|
||||
JS_CFUNC_DEF("open", 3, js_window_open),
|
||||
JS_CFUNC_DEF("postMessage", 3, js_window_postMessage),
|
||||
JS_CFUNC_DEF("removeEventListener", 3, js_window_removeEventListener),
|
||||
|
Loading…
x
Reference in New Issue
Block a user