1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[quickjs] offsetHeight and offsetWidth

This commit is contained in:
Witold Filipczyk 2024-01-27 16:04:08 +01:00
parent 8b35062e10
commit 1742e87854

View File

@ -815,6 +815,47 @@ js_element_get_property_nextSibling(JSContext *ctx, JSValueConst this_val)
return getElement(ctx, node);
}
static JSValue
js_element_get_property_offsetHeight(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id));
if (!el) {
return JS_NULL;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
struct document *document = doc_view->document;
struct session *ses;
if (!document) {
return JS_NewInt32(ctx, 0);
}
int offset = find_offset(document->element_map_rev, el);
if (offset <= 0) {
return JS_NewInt32(ctx, 0);
}
struct node_rect *rect = get_element_rect(document, offset);
if (!rect) {
return JS_NewInt32(ctx, 0);
}
ses = doc_view->session;
if (!ses) {
return JS_NewInt32(ctx, 0);
}
int dy = int_max(0, (rect->y1 + 1 - rect->y0) * ses->tab->term->cell_height);
return JS_NewInt32(ctx, dy);
}
static JSValue
js_element_get_property_offsetLeft(JSContext *ctx, JSValueConst this_val)
{
@ -948,6 +989,47 @@ js_element_get_property_offsetTop(JSContext *ctx, JSValueConst this_val)
return JS_NewInt32(ctx, dy);
}
static JSValue
js_element_get_property_offsetWidth(JSContext *ctx, JSValueConst this_val)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id));
if (!el) {
return JS_NULL;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view = vs->doc_view;
struct document *document = doc_view->document;
struct session *ses;
if (!document) {
return JS_NewInt32(ctx, 0);
}
int offset = find_offset(document->element_map_rev, el);
if (offset <= 0) {
return JS_NewInt32(ctx, 0);
}
struct node_rect *rect = get_element_rect(document, offset);
if (!rect) {
return JS_NewInt32(ctx, 0);
}
ses = doc_view->session;
if (!ses) {
return JS_NewInt32(ctx, 0);
}
int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width);
return JS_NewInt32(ctx, dx);
}
static JSValue
js_element_get_property_ownerDocument(JSContext *ctx, JSValueConst this_val)
{
@ -3069,9 +3151,11 @@ static const JSCFunctionListEntry js_element_proto_funcs[] = {
JS_CGETSET_DEF("nodeName", js_element_get_property_nodeName, NULL),
JS_CGETSET_DEF("nodeType", js_element_get_property_nodeType, NULL),
JS_CGETSET_DEF("nodeValue", js_element_get_property_nodeValue, NULL),
JS_CGETSET_DEF("offsetHeight", js_element_get_property_offsetHeight, NULL),
JS_CGETSET_DEF("offsetLeft", js_element_get_property_offsetLeft, NULL),
JS_CGETSET_DEF("offsetParent", js_element_get_property_offsetParent, NULL),
JS_CGETSET_DEF("offsetTop", js_element_get_property_offsetTop, NULL),
JS_CGETSET_DEF("offsetWidth", js_element_get_property_offsetWidth, NULL),
JS_CGETSET_DEF("outerHTML", js_element_get_property_outerHtml, NULL),
JS_CGETSET_DEF("ownerDocument", js_element_get_property_ownerDocument, NULL),
JS_CGETSET_DEF("parentElement", js_element_get_property_parentElement, NULL),