diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2012-11-07 18:47:35 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2012-11-07 18:53:05 +0000 |
commit | 43fb761f450e463dbce7431d20606cf795daf04c (patch) | |
tree | b7d45686726ed0eabc02d78349cd12fdcc17d536 /javascript/jsapi | |
parent | ecd8364fe12197ec2ac3735d85ef24c35f92be01 (diff) | |
download | netsurf-43fb761f450e463dbce7431d20606cf795daf04c.tar.gz netsurf-43fb761f450e463dbce7431d20606cf795daf04c.tar.bz2 |
add document.body, head and documentElement getters
add a dom utility file and use it
Diffstat (limited to 'javascript/jsapi')
-rw-r--r-- | javascript/jsapi/htmldocument.bnd | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 7574512dd..1432ce5da 100644 --- a/javascript/jsapi/htmldocument.bnd +++ b/javascript/jsapi/htmldocument.bnd @@ -12,6 +12,8 @@ preamble %{ #include "utils/config.h" #include "utils/log.h" +#include "utils/corestrings.h" +#include "utils/domutils.h" #include "content/urldb.h" @@ -23,13 +25,13 @@ preamble %{ binding document { type js_libdom; /* the binding type */ + interface Document; /* Web IDL interface to generate */ + /* parameters to constructor value stored in private * context structure. */ private "dom_document *" node; private "struct html_content *" htmlc; - - interface Document; /* Web IDL interface to generate */ } api finalise %{ @@ -49,6 +51,61 @@ getter cookie %{ } %} +getter documentElement %{ + dom_exception exc; + dom_element *element; + + /* document (html) element */ + exc = dom_document_get_document_element(private->node, (void *)&element); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + if (element != NULL) { + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); + } +%} + +getter head %{ + dom_node *element; + dom_node *head; + dom_exception exc; + + /* document (html) element */ + exc = dom_document_get_document_element(private->node, &element); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + if (element != NULL) { + head = find_first_named_dom_element(element, corestring_lwc_head) ; + if (head != NULL) { + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)head, private->htmlc); + } + dom_node_unref(element); + } +%} + +getter body %{ + dom_node *element; + dom_node *body; + dom_exception exc; + + /* document (html) element */ + exc = dom_document_get_document_element(private->node, &element); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + if (element != NULL) { + body = find_first_named_dom_element(element, corestring_lwc_body) ; + if (body != NULL) { + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)body, private->htmlc); + } + dom_node_unref(element); + } +%} + operation getElementById %{ dom_string *elementId_dom; dom_element *element; |