mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[quickjs] element.offsetTop
This commit is contained in:
parent
7c72d49f0c
commit
224c198781
@ -893,6 +893,61 @@ js_element_get_property_offsetParent(JSContext *ctx, JSValueConst this_val)
|
||||
return getElement(ctx, node);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_get_property_offsetTop(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);
|
||||
}
|
||||
dom_node *node = NULL;
|
||||
dom_exception exc = dom_node_get_parent_node(el, &node);
|
||||
if (exc != DOM_NO_ERR || !node) {
|
||||
return JS_NewInt32(ctx, 0);
|
||||
}
|
||||
int offset_parent = find_offset(document->element_map_rev, node);
|
||||
|
||||
if (offset_parent <= 0) {
|
||||
return JS_NewInt32(ctx, 0);
|
||||
}
|
||||
struct node_rect *rect_parent = get_element_rect(document, offset_parent);
|
||||
|
||||
if (!rect_parent) {
|
||||
return JS_NewInt32(ctx, 0);
|
||||
}
|
||||
int dy = int_max(0, (rect->y0 - rect_parent->y0) * ses->tab->term->cell_height);
|
||||
dom_node_unref(node);
|
||||
return JS_NewInt32(ctx, dy);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_element_get_property_ownerDocument(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
@ -3016,6 +3071,7 @@ static const JSCFunctionListEntry js_element_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("nodeValue", js_element_get_property_nodeValue, 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("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),
|
||||
|
Loading…
Reference in New Issue
Block a user