summaryrefslogtreecommitdiff
path: root/javascript/jsapi
diff options
context:
space:
mode:
Diffstat (limited to 'javascript/jsapi')
-rw-r--r--javascript/jsapi/htmldocument.bnd50
-rw-r--r--javascript/jsapi/htmlelement.bnd178
-rw-r--r--javascript/jsapi/nodelist.bnd41
3 files changed, 253 insertions, 16 deletions
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 8d5c69eb5..4aacccf4e 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -52,6 +52,9 @@ binding document {
/** location instantiated on first use */
property unshared location;
+ /* compatability mode instantiated on first use */
+ property unshared compatMode;
+
/* events through a single interface */
property unshared type EventHandler;
}
@@ -66,7 +69,7 @@ api finalise %{
getter location %{
- if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
+ if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) {
/* already created - return it */
return JS_TRUE;
}
@@ -95,6 +98,32 @@ getter documentURI %{
jsret = JSVAL_TO_STRING(jsstr);
%}
+
+getter compatMode %{
+ /* Returns the string "CSS1Compat" if document is in no-quirks
+ * mode or limited-quirks mode, and "BackCompat", if document
+ * is in quirks mode.
+ */
+ if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) {
+ /* already created, just use it */
+ return JS_TRUE;
+ }
+ if (private->htmlc->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL) {
+ jsret = JS_NewStringCopyN(cx, "BackCompat", SLEN("BackCompat"));
+ } else {
+ jsret = JS_NewStringCopyN(cx, "CSS1Compat", SLEN("CSS1Compat"));
+ }
+
+%}
+
+/*
+getter characterSet %{
+%}
+
+getter contentType %{
+%}
+*/
+
getter cookie %{
char *cookie_str;
cookie_str = urldb_get_cookie(llcache_handle_get_url(private->htmlc->base.llcache), false);
@@ -144,7 +173,7 @@ getter body %{
dom_node *body;
dom_exception exc;
- JSLOG("Getting your body");
+ JSDBG("Getting your body");
/* document (html) element */
exc = dom_document_get_document_element(private->node, &element);
@@ -160,7 +189,7 @@ getter body %{
dom_node_unref(element);
}
- JSLOG("returning jsobject %p",jsret);
+ JSDBG("returning jsobject %p",jsret);
%}
@@ -190,6 +219,7 @@ operation getElementById %{
* Dom 4 says this should return a htmlcollection, libdom currently
* returns DOM 3 spec of a nodelist
*/
+/* HTMLCollection Document::getElementsByTagName(DOMString localName); */
operation getElementsByTagName %{
dom_string *localName_dom;
/* dom_html_collection *collection;*/
@@ -236,7 +266,7 @@ operation createTextNode %{
if (data != NULL) {
- JSLOG("Creating text node for string \"%s\"", data);
+ JSDBG("Creating text node for string \"%s\"", data);
exc = dom_string_create((unsigned char*)data, data_len, &data_dom);
if (exc != DOM_NO_ERR) {
return JS_FALSE;
@@ -251,7 +281,7 @@ operation createTextNode %{
jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc);
}
- JSLOG("returning jsobject %p",jsret);
+ JSDBG("returning jsobject %p",jsret);
%}
@@ -263,7 +293,7 @@ operation createComment %{
if (data != NULL) {
- JSLOG("Creating string \"%s\"", data);
+ JSDBG("Creating string \"%s\"", data);
exc = dom_string_create((unsigned char*)data,
data_len,
&data_dom);
@@ -271,7 +301,7 @@ operation createComment %{
return JS_FALSE;
}
- JSLOG("Creating comment object for dom string \"%s\"",
+ JSDBG("Creating comment object for dom string \"%s\"",
dom_string_data(data_dom));
exc = dom_document_create_comment(private->node,
data_dom,
@@ -284,7 +314,7 @@ operation createComment %{
jsret = jsapi_new_Comment(cx, NULL, NULL, comment, private->htmlc);
}
- JSLOG("returning jsobject %p", jsret);
+ JSDBG("returning jsobject %p", jsret);
%}
@@ -295,7 +325,7 @@ operation createElement %{
dom_element *element;
if (localName != NULL) {
- JSLOG("Creating text node for string \"%s\"", localName);
+ JSDBG("Creating text node for string \"%s\"", localName);
exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom);
if (exc != DOM_NO_ERR) {
return JS_FALSE;
@@ -310,7 +340,7 @@ operation createElement %{
jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
}
- JSLOG("returning jsobject %p",jsret);
+ JSDBG("returning jsobject %p",jsret);
%}
diff --git a/javascript/jsapi/htmlelement.bnd b/javascript/jsapi/htmlelement.bnd
index 5e22f7e7d..33b495195 100644
--- a/javascript/jsapi/htmlelement.bnd
+++ b/javascript/jsapi/htmlelement.bnd
@@ -29,6 +29,7 @@ preamble %{
#include "htmlelement.h"
#include "text.h"
#include "location.h"
+#include "nodelist.h"
%}
@@ -114,6 +115,9 @@ binding htmlelement {
private "dom_element *" node;
private "struct html_content *" htmlc;
+ /* tag name retrieved first time its fetched and doesnt change */
+ property unshared tagName;
+
/* events through a single interface */
property unshared type EventHandler;
}
@@ -126,6 +130,180 @@ api finalise %{
/* interface Element in dom idl */
+/* readonly attribute DOMString Element::tagName; */
+getter tagName %{
+ if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) {
+ /* already created - return it */
+ return JS_TRUE;
+ }
+
+ dom_exception exc;
+ dom_string *name;
+
+ exc = dom_element_get_tag_name(private->node, &name);
+ if (name != NULL) {
+ jsret = JS_NewStringCopyN(cx, dom_string_data(name), dom_string_length(name));
+ dom_string_unref(name);
+ }
+%}
+
+/* attribute DOMString Element::id; */
+getter id %{
+ dom_string *value;
+ dom_exception exc;
+
+ exc = dom_element_get_attribute(private->node, corestring_dom_id, &value);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (value != NULL) {
+ jsret = JS_NewStringCopyN(cx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+ }
+%}
+
+/* attribute DOMString Element::className; */
+getter className %{
+ dom_string *value;
+ dom_exception exc;
+
+ exc = dom_element_get_attribute(private->node, corestring_dom_class, &value);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (value != NULL) {
+ jsret = JS_NewStringCopyN(cx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+ }
+%}
+
+/* DOMString? Element::getAttribute(DOMString name); */
+operation getAttribute %{
+ dom_string *value;
+ dom_string *name_dom;
+ dom_exception exc;
+
+ exc = dom_string_create((unsigned char*)name, name_len, &name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ exc = dom_element_get_attribute(private->node, name_dom, &value);
+ dom_string_unref(name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (value != NULL) {
+ jsret = JS_NewStringCopyN(cx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+ }
+%}
+
+/* void Element::setAttribute(DOMString name, DOMString value); */
+operation setAttribute %{
+ dom_string *value_dom;
+ dom_string *name_dom;
+ dom_exception exc;
+
+ exc = dom_string_create((unsigned char*)name, name_len, &name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ exc = dom_string_create((unsigned char*)name, name_len, &value_dom);
+ if (exc != DOM_NO_ERR) {
+ dom_string_unref(name_dom);
+ return JS_FALSE;
+ }
+
+ exc = dom_element_set_attribute(private->node, name_dom, value_dom);
+ dom_string_unref(name_dom);
+ dom_string_unref(value_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+%}
+
+/* void Element::removeAttribute(DOMString name); */
+operation removeAttribute %{
+ dom_string *name_dom;
+ dom_exception exc;
+
+ exc = dom_string_create((unsigned char*)name, name_len, &name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ exc = dom_element_remove_attribute(private->node, name_dom);
+ dom_string_unref(name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+%}
+
+/* boolean Element::hasAttribute(DOMString name); */
+operation hasAttribute %{
+ bool result;
+ dom_string *name_dom;
+ dom_exception exc;
+
+ exc = dom_string_create((unsigned char*)name, name_len, &name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ exc = dom_element_has_attribute(private->node, name_dom, &result);
+ dom_string_unref(name_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (result) {
+ jsret = JS_TRUE;
+ }
+%}
+
+/*
+ *
+ * Dom 4 says this should return a htmlcollection, libdom currently
+ * returns DOM 3 spec of a nodelist
+ */
+/* HTMLCollection Element::getElementsByTagName(DOMString localName); */
+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;
+ }
+
+ exc = dom_element_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist);
+ dom_string_unref(localName_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (/*collection*/nodelist != NULL) {
+ /*jsret = jsapi_new_HTMLCollection(cx,
+ NULL,
+ NULL,
+ collection,
+ private->htmlc);*/
+ jsret = jsapi_new_NodeList(cx,
+ NULL,
+ NULL,
+ nodelist,
+ private->htmlc);
+ }
+
+%}
+
/*
* DOM 3 has these as the element traversal extension
*
diff --git a/javascript/jsapi/nodelist.bnd b/javascript/jsapi/nodelist.bnd
index 4aa8c47f5..379809659 100644
--- a/javascript/jsapi/nodelist.bnd
+++ b/javascript/jsapi/nodelist.bnd
@@ -39,6 +39,41 @@ binding nodelist {
private "struct html_content *" htmlc;
}
+api finalise %{
+ if (private != NULL) {
+ dom_nodelist_unref(private->nodelist);
+ }
+%}
+
+/* default handler for numericaly indexed property values */
+api getproperty %{
+ jsval queryprop;
+ int idx;
+ JSObject *jsret = NULL; /* Node */
+ dom_exception err;
+ dom_node *domnode;
+
+ JSAPI_PROP_IDVAL(cx, &queryprop);
+ if (JSVAL_IS_INT(queryprop)) {
+ idx = JSVAL_TO_INT(queryprop);
+ JSDBG("Index was %d", idx);
+
+
+ err = dom_nodelist_item(private->nodelist, idx, &domnode);
+ if (err != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (domnode != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
+
+ JSDBG("return object:%p", jsret);
+
+ JSAPI_PROP_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsret));
+ }
+ }
+%}
+
getter length %{
dom_exception err;
@@ -62,9 +97,3 @@ operation item %{
}
%}
-api finalise %{
- if (private != NULL) {
- dom_nodelist_unref(private->nodelist);
- }
-%}
-