1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[mujs] offsetWidth and offsetHeight

This commit is contained in:
Witold Filipczyk 2024-01-27 15:59:49 +01:00
parent 8b3ece5b82
commit 8b35062e10

View File

@ -750,6 +750,50 @@ mjs_element_get_property_nextSibling(js_State *J)
mjs_push_element(J, node);
}
static void
mjs_element_get_property_offsetHeight(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
if (!el) {
js_pushnull(J);
return;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
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) {
js_pushnumber(J, 0);
return;
}
int offset = find_offset(document->element_map_rev, el);
if (offset <= 0) {
js_pushnumber(J, 0);
return;
}
struct node_rect *rect = get_element_rect(document, offset);
if (!rect) {
js_pushnumber(J, 0);
return;
}
ses = doc_view->session;
if (!ses) {
js_pushnumber(J, 0);
return;
}
int dy = int_max(0, (rect->y1 + 1 - rect->y0) * ses->tab->term->cell_height);
js_pushnumber(J, dy);
}
static void
mjs_element_get_property_offsetLeft(js_State *J)
{
@ -899,6 +943,50 @@ mjs_element_get_property_offsetTop(js_State *J)
js_pushnumber(J, dy);
}
static void
mjs_element_get_property_offsetWidth(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
if (!el) {
js_pushnull(J);
return;
}
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
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) {
js_pushnumber(J, 0);
return;
}
int offset = find_offset(document->element_map_rev, el);
if (offset <= 0) {
js_pushnumber(J, 0);
return;
}
struct node_rect *rect = get_element_rect(document, offset);
if (!rect) {
js_pushnumber(J, 0);
return;
}
ses = doc_view->session;
if (!ses) {
js_pushnumber(J, 0);
return;
}
int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width);
js_pushnumber(J, dx);
}
static void
mjs_element_get_property_ownerDocument(js_State *J)
{
@ -2954,9 +3042,11 @@ mjs_push_element(js_State *J, void *node)
addproperty(J, "nodeName", mjs_element_get_property_nodeName, NULL);
addproperty(J, "nodeType", mjs_element_get_property_nodeType, NULL);
addproperty(J, "nodeValue", mjs_element_get_property_nodeValue, NULL);
addproperty(J, "offsetHeight", mjs_element_get_property_offsetHeight, NULL);
addproperty(J, "offsetLeft", mjs_element_get_property_offsetLeft, NULL);
addproperty(J, "offsetParent", mjs_element_get_property_offsetParent, NULL);
addproperty(J, "offsetTop", mjs_element_get_property_offsetTop, NULL);
addproperty(J, "offsetWidth", mjs_element_get_property_offsetWidth, NULL);
addproperty(J, "outerHTML", mjs_element_get_property_outerHtml, NULL);
addproperty(J, "ownerDocument", mjs_element_get_property_ownerDocument, NULL);
addproperty(J, "parentElement", mjs_element_get_property_parentElement, NULL);