summaryrefslogtreecommitdiff
path: root/javascript/jsapi
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2012-11-07 22:52:03 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2012-11-07 22:52:03 +0000
commit55c6841eca063e8fe4db0b8ac67c8a61da9b7312 (patch)
tree17e0ed1b1d0130404e15e73708903c3ed729a6b6 /javascript/jsapi
parentf37a8ad58be683bc42e7cff692c78797a580b921 (diff)
parent9482bb464a157265a555dfa38fcf2dc37ade12fd (diff)
downloadnetsurf-55c6841eca063e8fe4db0b8ac67c8a61da9b7312.tar.gz
netsurf-55c6841eca063e8fe4db0b8ac67c8a61da9b7312.tar.bz2
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
Diffstat (limited to 'javascript/jsapi')
-rw-r--r--javascript/jsapi/binding.h14
-rw-r--r--javascript/jsapi/dom.bnd5
-rw-r--r--javascript/jsapi/htmldocument.bnd83
-rw-r--r--javascript/jsapi/text.bnd44
-rw-r--r--javascript/jsapi/window.bnd5
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 %{