diff options
Diffstat (limited to 'javascript/jsapi')
-rw-r--r-- | javascript/jsapi/binding.h | 14 | ||||
-rw-r--r-- | javascript/jsapi/dom.bnd | 5 | ||||
-rw-r--r-- | javascript/jsapi/htmldocument.bnd | 83 | ||||
-rw-r--r-- | javascript/jsapi/text.bnd | 44 | ||||
-rw-r--r-- | javascript/jsapi/window.bnd | 5 |
5 files changed, 149 insertions, 2 deletions
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h index c1006589e..446fb0c51 100644 --- a/javascript/jsapi/binding.h +++ b/javascript/jsapi/binding.h @@ -124,4 +124,18 @@ JSObject *jsapi_new_NodeList(JSContext *cx, dom_nodelist *nodelist, struct html_content *htmlc); + +JSObject *jsapi_InitClass_Text(JSContext *cx, JSObject *parent); +/** Create a new javascript text object + * + * @param cx The javascript context. + * @param parent The parent object, usually a global window object + * @param node The dom node to use in the object + * @return new javascript object or NULL on error + */ +JSObject *jsapi_new_Text(JSContext *cx, + JSObject *prototype, + JSObject *parent, + dom_text *node); + #endif diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd index cd252fc27..bf3b44ea3 100644 --- a/javascript/jsapi/dom.bnd +++ b/javascript/jsapi/dom.bnd @@ -2,6 +2,8 @@ webidlfile "dom.idl"; +/* interface Node members */ + getter textContent %{ dom_exception exc; @@ -21,3 +23,6 @@ getter textContent %{ +operation appendChild %{ +/* void * JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv); */ +%} diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 7574512dd..b642cabe6 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; @@ -112,3 +169,25 @@ operation write %{ dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); } %} + +/* in dom Document */ +operation createTextNode %{ + dom_string *data_dom; + dom_element *element; + dom_exception exc; + dom_text *text; + + exc = dom_string_create((unsigned char*)data, data_len, &data_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + exc = dom_document_create_text_node(private->node, data_dom, &text); + dom_string_unref(data_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + jsret = jsapi_new_Text(cx, NULL, NULL, text); + +%} diff --git a/javascript/jsapi/text.bnd b/javascript/jsapi/text.bnd new file mode 100644 index 000000000..53e93803d --- /dev/null +++ b/javascript/jsapi/text.bnd @@ -0,0 +1,44 @@ +/* Binding to generate Text interface + * + * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * Released under the terms of the MIT License, + * http://www.opensource.org/licenses/mit-license + */ + +#include "dom.bnd" + +webidlfile "html.idl"; + +hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; +hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; +hdrcomment "Released under the terms of the MIT License,"; +hdrcomment " http://www.opensource.org/licenses/mit-license"; + +preamble %{ + +#include <dom/dom.h> + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +binding text { + type js_libdom; /* the binding type */ + + interface Text; /* Web IDL interface to generate */ + + private "dom_text *" node; +} + +api finalise %{ + if (private != NULL) { + dom_node_unref(private->node); + } +%} diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd index 865cbf3d4..5a7de530f 100644 --- a/javascript/jsapi/window.bnd +++ b/javascript/jsapi/window.bnd @@ -130,6 +130,11 @@ api init %{ return NULL; } + user_proto = jsapi_InitClass_Text(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + %} api new %{ |