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

[quickjs] offsetWidth and offsetHeight call clientWidth and clientHeight

For <body>, <html> full height.
For <body>, <html> and <div> full width.
This commit is contained in:
Witold Filipczyk 2024-01-28 16:47:52 +01:00
parent 5841cd5c94
commit 2da397a44e

View File

@ -349,6 +349,24 @@ js_element_get_property_clientHeight(JSContext *ctx, JSValueConst this_val)
if (!document) { if (!document) {
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
ses = doc_view->session;
if (!ses) {
return JS_NewInt32(ctx, 0);
}
dom_string *tag_name = NULL;
dom_exception exc = dom_node_get_node_name(el, &tag_name);
if (exc != DOM_NO_ERR || !tag_name) {
return JS_NewInt32(ctx, 0);
}
bool root = (!strcmp(dom_string_data(tag_name), "BODY") || !strcmp(dom_string_data(tag_name), "HTML"));
dom_string_unref(tag_name);
if (root) {
int height = doc_view->box.height * ses->tab->term->cell_height;
return JS_NewInt32(ctx, height);
}
int offset = find_offset(document->element_map_rev, el); int offset = find_offset(document->element_map_rev, el);
if (offset <= 0) { if (offset <= 0) {
@ -359,11 +377,6 @@ js_element_get_property_clientHeight(JSContext *ctx, JSValueConst this_val)
if (!rect) { if (!rect) {
return JS_NewInt32(ctx, 0); 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); int dy = int_max(0, (rect->y1 + 1 - rect->y0) * ses->tab->term->cell_height);
return JS_NewInt32(ctx, dy); return JS_NewInt32(ctx, dy);
@ -407,6 +420,24 @@ js_element_get_property_clientWidth(JSContext *ctx, JSValueConst this_val)
if (!document) { if (!document) {
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
ses = doc_view->session;
if (!ses) {
return JS_NewInt32(ctx, 0);
}
dom_string *tag_name = NULL;
dom_exception exc = dom_node_get_node_name(el, &tag_name);
if (exc != DOM_NO_ERR || !tag_name) {
return JS_NewInt32(ctx, 0);
}
bool root = (!strcmp(dom_string_data(tag_name), "BODY") || !strcmp(dom_string_data(tag_name), "HTML") || !strcmp(dom_string_data(tag_name), "DIV"));
dom_string_unref(tag_name);
if (root) {
int width = doc_view->box.width * ses->tab->term->cell_width;
return JS_NewInt32(ctx, width);
}
int offset = find_offset(document->element_map_rev, el); int offset = find_offset(document->element_map_rev, el);
if (offset <= 0) { if (offset <= 0) {
@ -417,11 +448,6 @@ js_element_get_property_clientWidth(JSContext *ctx, JSValueConst this_val)
if (!rect) { if (!rect) {
return JS_NewInt32(ctx, 0); 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); int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width);
return JS_NewInt32(ctx, dx); return JS_NewInt32(ctx, dx);
@ -821,38 +847,7 @@ js_element_get_property_offsetHeight(JSContext *ctx, JSValueConst this_val)
#ifdef ECMASCRIPT_DEBUG #ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif #endif
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id)); return js_element_get_property_clientHeight(ctx, this_val);
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);
} }
@ -995,41 +990,9 @@ js_element_get_property_offsetWidth(JSContext *ctx, JSValueConst this_val)
#ifdef ECMASCRIPT_DEBUG #ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif #endif
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id)); return js_element_get_property_clientWidth(ctx, this_val);
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 static JSValue
js_element_get_property_ownerDocument(JSContext *ctx, JSValueConst this_val) js_element_get_property_ownerDocument(JSContext *ctx, JSValueConst this_val)
{ {