summaryrefslogtreecommitdiff
path: root/javascript/jsapi
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2012-11-03 21:37:06 +0000
committerVincent Sanders <vince@netsurf-browser.org>2012-11-03 21:37:06 +0000
commit3f1b68384562fe294a1a263214a3fd26ea869bc9 (patch)
tree21be758e3205fb8c13144c39f3790e380a9e8f5f /javascript/jsapi
parent6648ba39ade5ed8c1a5ceccab82eed567478c950 (diff)
downloadnetsurf-3f1b68384562fe294a1a263214a3fd26ea869bc9.tar.gz
netsurf-3f1b68384562fe294a1a263214a3fd26ea869bc9.tar.bz2
implement dom-getElementsByTagName and nodelist and htmlcollection
Diffstat (limited to 'javascript/jsapi')
-rw-r--r--javascript/jsapi/binding.h28
-rw-r--r--javascript/jsapi/dom.bnd52
-rw-r--r--javascript/jsapi/htmlcollection.bnd85
-rw-r--r--javascript/jsapi/nodelist.bnd67
-rw-r--r--javascript/jsapi/window.bnd10
5 files changed, 240 insertions, 2 deletions
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 68ab6d1ed..c1006589e 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -96,4 +96,32 @@ JSObject *jsapi_new_HTMLElement(JSContext *cx,
dom_element *node,
struct html_content *htmlc);
+JSObject *jsapi_InitClass_HTMLCollection(JSContext *cx, JSObject *parent);
+/** Create a new javascript element object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param doc_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_HTMLCollection(JSContext *cx,
+ JSObject *prototype,
+ JSObject *parent,
+ dom_html_collection *collection,
+ struct html_content *htmlc);
+
+JSObject *jsapi_InitClass_NodeList(JSContext *cx, JSObject *parent);
+/** Create a new javascript element object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param doc_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_NodeList(JSContext *cx,
+ JSObject *prototype,
+ JSObject *parent,
+ dom_nodelist *nodelist,
+ struct html_content *htmlc);
+
#endif
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index 362c828f6..14068ba2e 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -7,14 +7,59 @@ operation getElementById %{
dom_element *element;
dom_exception exc;
- dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
+ exc = dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
- if ((exc == DOM_NO_ERR) && (element != NULL)) {
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (element != NULL) {
jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
}
%}
+/* Dom 4 says this should return a htmlcollection, libdom currently
+ * returns DOM 3 spec of a nodelist
+ */
+
+operation getElementsByTagName %{
+ dom_string *localName_dom;
+ /* dom_html_collection *collection;*/
+ dom_nodelist *nodelist;
+ dom_exception exc;
+
+ exc = dom_string_create((uint8_t *)localName, localName_len, &localName_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ LOG(("here"));
+
+ exc = dom_document_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+ LOG(("nodelist %p", nodelist));
+
+ if (/*collection*/nodelist != NULL) {
+ /* jsret = jsapi_new_HTMLCollection(cx,
+ NULL,
+ NULL,
+ collection,
+ private->htmlc);*/
+ jsret = jsapi_new_NodeList(cx,
+ NULL,
+ NULL,
+ nodelist,
+ private->htmlc);
+ }
+
+%}
+
getter textContent %{
dom_exception exc;
dom_string *content;
@@ -24,3 +69,6 @@ getter textContent %{
jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content));
}
%}
+
+
+
diff --git a/javascript/jsapi/htmlcollection.bnd b/javascript/jsapi/htmlcollection.bnd
new file mode 100644
index 000000000..a7947cd29
--- /dev/null
+++ b/javascript/jsapi/htmlcollection.bnd
@@ -0,0 +1,85 @@
+/* Binding to generate HTMLcolelction interface
+ *
+ * The js_libdom (javascript to libdom) binding type is currently the
+ * only one implemented and this principly describes that binding.
+ *
+ * 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
+ */
+
+/* The hdrcomment are added into the geenrated output comment header */
+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"
+
+%}
+
+webidlfile "dom.idl";
+
+binding htmlcollection {
+ type js_libdom; /* the binding type */
+
+ interface HTMLCollection; /* The WebIDL interface to generate a binding for */
+
+ private "dom_html_collection *" collection;
+ private "struct html_content *" htmlc;
+}
+
+getter length %{
+ dom_exception err;
+
+ err = dom_html_collection_get_length(private->collection, &jsret);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+ %}
+
+operation item %{
+ dom_exception err;
+ dom_node *domnode;
+
+ err = dom_html_collection_item(private->collection, index, &domnode);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (domnode != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
+ }
+ %}
+
+operation namedItem %{
+ dom_exception err;
+ dom_node *domnode;
+ dom_string *name_dom;
+
+ err = dom_string_create((uint8_t *)name, name_len, &name_dom);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ err = dom_html_collection_named_item(private->collection, name_dom, &domnode);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (domnode != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
+ }
+
+ %}
diff --git a/javascript/jsapi/nodelist.bnd b/javascript/jsapi/nodelist.bnd
new file mode 100644
index 000000000..710536dcf
--- /dev/null
+++ b/javascript/jsapi/nodelist.bnd
@@ -0,0 +1,67 @@
+/* Binding to generate NodeList interface
+ *
+ * The js_libdom (javascript to libdom) binding type is currently the
+ * only one implemented and this principly describes that binding.
+ *
+ * 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
+ */
+
+/* The hdrcomment are added into the geenrated output comment header */
+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"
+
+%}
+
+webidlfile "dom.idl";
+
+binding nodelist {
+ type js_libdom; /* the binding type */
+
+ interface NodeList; /* The WebIDL interface to generate a binding for */
+
+ private "dom_nodelist *" nodelist;
+ private "struct html_content *" htmlc;
+}
+
+getter length %{
+ dom_exception err;
+
+ err = dom_nodelist_get_length(private->nodelist, &jsret);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+%}
+
+operation item %{
+ dom_exception err;
+ dom_node *domnode;
+
+ err = dom_nodelist_item(private->nodelist, index, &domnode);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (domnode != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
+ }
+%}
+
+
+
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index da6400332..6f5e1af47 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -103,6 +103,16 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_HTMLCollection(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
+ user_proto = jsapi_InitClass_NodeList(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
%}
api new %{