summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-07 18:25:30 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-07 18:25:30 +0100
commit7984f00c4cce1d599da95a8c8cbbd912f33444b1 (patch)
treeb00b2061b386fc929b08150870f208fee2bebacb
parent814a54e5ef738654b6ee168a1763e1f1242a18d4 (diff)
parent287c31a83c21076b45388fa8e7f880ec861ce745 (diff)
downloadlibdom-7984f00c4cce1d599da95a8c8cbbd912f33444b1.tar.gz
libdom-7984f00c4cce1d599da95a8c8cbbd912f33444b1.tar.bz2
Merge element work, adds 5 element types and enables 27 tests.
-rw-r--r--.gitignore2
-rw-r--r--Makefile8
-rw-r--r--include/dom/dom.h8
-rw-r--r--include/dom/html/html_form_element.h32
-rw-r--r--include/dom/html/html_head_element.h7
-rw-r--r--include/dom/html/html_html_element.h8
-rw-r--r--include/dom/html/html_link_element.h49
-rw-r--r--include/dom/html/html_meta_element.h26
-rw-r--r--src/core/nodelist.c83
-rw-r--r--src/core/nodelist.h4
-rw-r--r--src/html/TODO57
-rw-r--r--src/html/html_document.c166
-rw-r--r--src/html/html_document.h19
-rw-r--r--src/html/html_document_strings.h135
-rw-r--r--src/html/html_element.c6
-rw-r--r--src/html/html_element.h2
-rw-r--r--src/html/html_form_element.c78
-rw-r--r--src/html/html_form_element.h2
-rw-r--r--src/html/html_head_element.c53
-rw-r--r--src/html/html_head_element.h2
-rw-r--r--src/html/html_html_element.c52
-rw-r--r--src/html/html_html_element.h4
-rw-r--r--src/html/html_link_element.c65
-rw-r--r--src/html/html_link_element.h2
-rw-r--r--src/html/html_meta_element.c61
-rw-r--r--src/html/html_meta_element.h2
-rw-r--r--src/html/html_title_element.c22
-rw-r--r--src/html/html_title_element.h2
-rw-r--r--test/DOMTSHandler.pm28
-rw-r--r--test/testcases/tests/level1/html/HTMLCollection02.xml.kfail (renamed from test/testcases/tests/level1/html/HTMLCollection02.xml.notimpl)0
-rw-r--r--test/testcases/tests/level1/html/HTMLCollection03.xml.kfail (renamed from test/testcases/tests/level1/html/HTMLCollection03.xml.notimpl)0
-rw-r--r--test/testcases/tests/level1/html/HTMLCollection10.xml.kfail (renamed from test/testcases/tests/level1/html/HTMLCollection10.xml.notimpl)0
-rw-r--r--test/testcases/tests/level1/html/HTMLCollection11.xml.kfail (renamed from test/testcases/tests/level1/html/HTMLCollection11.xml.notimpl)0
-rw-r--r--test/testcases/tests/level1/html/HTMLCollection12.xml (renamed from test/testcases/tests/level1/html/HTMLCollection12.xml.notimpl)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement01.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement02.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement02.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement03.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement03.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement04.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement04.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement05.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement05.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement06.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement06.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement07.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement07.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement08.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement08.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement09.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement09.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLFormElement10.xml (renamed from test/testcases/tests/level1/html/HTMLFormElement10.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLHeadElement01.xml (renamed from test/testcases/tests/level1/html/HTMLHeadElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLHtmlElement01.xml (renamed from test/testcases/tests/level1/html/HTMLHtmlElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement01.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement02.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement02.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement03.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement03.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement04.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement04.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement05.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement05.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement06.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement06.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement07.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement07.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement08.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement08.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLinkElement09.xml (renamed from test/testcases/tests/level1/html/HTMLLinkElement09.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLMetaElement01.xml (renamed from test/testcases/tests/level1/html/HTMLMetaElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLMetaElement02.xml (renamed from test/testcases/tests/level1/html/HTMLMetaElement02.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLMetaElement03.xml (renamed from test/testcases/tests/level1/html/HTMLMetaElement03.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLMetaElement04.xml (renamed from test/testcases/tests/level1/html/HTMLMetaElement04.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLTitleElement01.xml (renamed from test/testcases/tests/level1/html/HTMLTitleElement01.xml.kfail)0
-rw-r--r--test/testutils/domtsasserts.c152
-rw-r--r--test/testutils/domtsasserts.h7
-rw-r--r--test/testutils/utils.c9
-rw-r--r--test/testutils/utils.h2
64 files changed, 988 insertions, 167 deletions
diff --git a/.gitignore b/.gitignore
index 670c484..a12a172 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,4 @@ build/docs
examples/dom-structure-dump
test/level*.c
test/INDEX
-
+*~
diff --git a/Makefile b/Makefile
index e48f41c..a66bee0 100644
--- a/Makefile
+++ b/Makefile
@@ -79,8 +79,14 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/document_event.h
Is := include/dom/html
I := /include/dom/html
-INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_document.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_collection.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_html_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_head_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_link_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_title_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_meta_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_form_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /lib/pkgconfig:lib$(COMPONENT).pc.in
diff --git a/include/dom/dom.h b/include/dom/dom.h
index 94d97ff..05ce3e6 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -38,8 +38,14 @@
#include <dom/core/comment.h>
/* DOM HTML headers */
-#include <dom/html/html_element.h>
+#include <dom/html/html_collection.h>
#include <dom/html/html_document.h>
+#include <dom/html/html_element.h>
+#include <dom/html/html_html_element.h>
+#include <dom/html/html_head_element.h>
+#include <dom/html/html_link_element.h>
+#include <dom/html/html_title_element.h>
+#include <dom/html/html_meta_element.h>
#include <dom/html/html_form_element.h>
/* DOM Events header */
diff --git a/include/dom/html/html_form_element.h b/include/dom/html/html_form_element.h
index 230846c..c4ee1d8 100644
--- a/include/dom/html/html_form_element.h
+++ b/include/dom/html/html_form_element.h
@@ -9,6 +9,7 @@
#define dom_html_form_element_h_
#include <dom/core/exceptions.h>
+#include <dom/core/string.h>
struct dom_html_collection;
@@ -18,6 +19,37 @@ dom_exception dom_html_form_element_get_elements(dom_html_form_element *ele,
struct dom_html_collection **col);
dom_exception dom_html_form_element_get_length(dom_html_form_element *ele,
unsigned long *len);
+
+dom_exception dom_html_form_element_get_accept_charset(
+ dom_html_form_element *ele, dom_string **accept_charset);
+
+dom_exception dom_html_form_element_set_accept_charset(
+ dom_html_form_element *ele, dom_string *accept_charset);
+
+dom_exception dom_html_form_element_get_action(
+ dom_html_form_element *ele, dom_string **action);
+
+dom_exception dom_html_form_element_set_action(
+ dom_html_form_element *ele, dom_string *action);
+
+dom_exception dom_html_form_element_get_enctype(
+ dom_html_form_element *ele, dom_string **enctype);
+
+dom_exception dom_html_form_element_set_enctype(
+ dom_html_form_element *ele, dom_string *enctype);
+
+dom_exception dom_html_form_element_get_method(
+ dom_html_form_element *ele, dom_string **method);
+
+dom_exception dom_html_form_element_set_method(
+ dom_html_form_element *ele, dom_string *method);
+
+dom_exception dom_html_form_element_get_target(
+ dom_html_form_element *ele, dom_string **target);
+
+dom_exception dom_html_form_element_set_target(
+ dom_html_form_element *ele, dom_string *target);
+
dom_exception dom_html_form_element_submit(dom_html_form_element *ele);
dom_exception dom_html_form_element_reset(dom_html_form_element *ele);
diff --git a/include/dom/html/html_head_element.h b/include/dom/html/html_head_element.h
index e00fc19..cb10358 100644
--- a/include/dom/html/html_head_element.h
+++ b/include/dom/html/html_head_element.h
@@ -8,7 +8,14 @@
#ifndef dom_html_head_element_h_
#define dom_html_head_element_h_
+#include <dom/html/html_element.h>
+
typedef struct dom_html_head_element dom_html_head_element;
+dom_exception dom_html_head_element_get_profile(
+ struct dom_html_head_element *element, dom_string **profile);
+dom_exception dom_html_head_element_set_profile(
+ struct dom_html_head_element *element, dom_string *profile);
+
#endif
diff --git a/include/dom/html/html_html_element.h b/include/dom/html/html_html_element.h
index 80ef6af..5593daa 100644
--- a/include/dom/html/html_html_element.h
+++ b/include/dom/html/html_html_element.h
@@ -8,7 +8,15 @@
#ifndef dom_html_html_element_h_
#define dom_html_html_element_h_
+#include <dom/html/html_element.h>
+
typedef struct dom_html_html_element dom_html_html_element;
+dom_exception dom_html_html_element_get_version(
+ struct dom_html_html_element *element, dom_string **version);
+dom_exception dom_html_html_element_set_version(
+ struct dom_html_html_element *element, dom_string *version);
+
+
#endif
diff --git a/include/dom/html/html_link_element.h b/include/dom/html/html_link_element.h
index c96d020..f0b1f3c 100644
--- a/include/dom/html/html_link_element.h
+++ b/include/dom/html/html_link_element.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <dom/core/exceptions.h>
+#include <dom/core/string.h>
typedef struct dom_html_link_element dom_html_link_element;
@@ -19,5 +20,53 @@ dom_exception dom_html_link_element_get_disabled(dom_html_link_element *ele,
dom_exception dom_html_link_element_set_disabled(dom_html_link_element *ele,
bool disabled);
+dom_exception dom_html_link_element_get_charset(dom_html_link_element *ele,
+ dom_string **charset);
+
+dom_exception dom_html_link_element_set_charset(dom_html_link_element *ele,
+ dom_string *charset);
+
+dom_exception dom_html_link_element_get_href(dom_html_link_element *ele,
+ dom_string **href);
+
+dom_exception dom_html_link_element_set_href(dom_html_link_element *ele,
+ dom_string *href);
+
+dom_exception dom_html_link_element_get_hreflang(dom_html_link_element *ele,
+ dom_string **hreflang);
+
+dom_exception dom_html_link_element_set_hreflang(dom_html_link_element *ele,
+ dom_string *hreflang);
+
+dom_exception dom_html_link_element_get_media(dom_html_link_element *ele,
+ dom_string **media);
+
+dom_exception dom_html_link_element_set_media(dom_html_link_element *ele,
+ dom_string *media);
+
+dom_exception dom_html_link_element_get_rel(dom_html_link_element *ele,
+ dom_string **rel);
+
+dom_exception dom_html_link_element_set_rel(dom_html_link_element *ele,
+ dom_string *rel);
+
+dom_exception dom_html_link_element_get_rev(dom_html_link_element *ele,
+ dom_string **rev);
+
+dom_exception dom_html_link_element_set_rev(dom_html_link_element *ele,
+ dom_string *rev);
+
+dom_exception dom_html_link_element_get_target(dom_html_link_element *ele,
+ dom_string **target);
+
+dom_exception dom_html_link_element_set_target(dom_html_link_element *ele,
+ dom_string *target);
+
+dom_exception dom_html_link_element_get_type(dom_html_link_element *ele,
+ dom_string **type);
+
+dom_exception dom_html_link_element_set_type(dom_html_link_element *ele,
+ dom_string *type);
+
#endif
diff --git a/include/dom/html/html_meta_element.h b/include/dom/html/html_meta_element.h
index 8ceb459..b9898f1 100644
--- a/include/dom/html/html_meta_element.h
+++ b/include/dom/html/html_meta_element.h
@@ -8,7 +8,33 @@
#ifndef dom_html_meta_element_h_
#define dom_html_meta_element_h_
+#include <dom/core/string.h>
+
typedef struct dom_html_meta_element dom_html_meta_element;
+dom_exception dom_html_meta_element_get_content(dom_html_meta_element *ele,
+ dom_string **content);
+
+dom_exception dom_html_meta_element_set_content(dom_html_meta_element *ele,
+ dom_string *content);
+
+dom_exception dom_html_meta_element_get_http_equiv(dom_html_meta_element *ele,
+ dom_string **http_equiv);
+
+dom_exception dom_html_meta_element_set_http_equiv(dom_html_meta_element *ele,
+ dom_string *http_equiv);
+
+dom_exception dom_html_meta_element_get_name(dom_html_meta_element *ele,
+ dom_string **name);
+
+dom_exception dom_html_meta_element_set_name(dom_html_meta_element *ele,
+ dom_string *name);
+
+dom_exception dom_html_meta_element_get_scheme(dom_html_meta_element *ele,
+ dom_string **scheme);
+
+dom_exception dom_html_meta_element_set_scheme(dom_html_meta_element *ele,
+ dom_string *scheme);
+
#endif
diff --git a/src/core/nodelist.c b/src/core/nodelist.c
index 1100329..8ce9475 100644
--- a/src/core/nodelist.c
+++ b/src/core/nodelist.c
@@ -84,7 +84,8 @@ dom_exception _dom_nodelist_create(dom_document *doc, nodelist_type type,
l->type = type;
- if (type == DOM_NODELIST_BY_NAME) {
+ if (type == DOM_NODELIST_BY_NAME ||
+ type == DOM_NODELIST_BY_NAME_CASELESS) {
assert(tagname != NULL);
l->data.n.any_name = false;
if (dom_string_byte_length(tagname) == 1) {
@@ -95,7 +96,8 @@ dom_exception _dom_nodelist_create(dom_document *doc, nodelist_type type,
}
l->data.n.name = dom_string_ref(tagname);
- } else if (type == DOM_NODELIST_BY_NAMESPACE) {
+ } else if (type == DOM_NODELIST_BY_NAMESPACE ||
+ type == DOM_NODELIST_BY_NAMESPACE_CASELESS) {
l->data.ns.any_localname = false;
l->data.ns.any_namespace = false;
if (localname != NULL) {
@@ -159,12 +161,14 @@ void dom_nodelist_unref(dom_nodelist *list)
/* Nothing to do */
break;
case DOM_NODELIST_BY_NAMESPACE:
+ case DOM_NODELIST_BY_NAMESPACE_CASELESS:
if (list->data.ns.namespace != NULL)
dom_string_unref(list->data.ns.namespace);
if (list->data.ns.localname != NULL)
dom_string_unref(list->data.ns.localname);
break;
case DOM_NODELIST_BY_NAME:
+ case DOM_NODELIST_BY_NAME_CASELESS:
assert(list->data.n.name != NULL);
dom_string_unref(list->data.n.name);
break;
@@ -210,7 +214,15 @@ dom_exception dom_nodelist_get_length(dom_nodelist *list, unsigned long *length)
if (cur->type == DOM_ELEMENT_NODE)
len++;
}
- } else {
+ } else if (list->type == DOM_NODELIST_BY_NAME_CASELESS) {
+ if (list->data.n.any_name == true || (
+ cur->name != NULL &&
+ dom_string_caseless_isequal(cur->name,
+ list->data.n.name))) {
+ if (cur->type == DOM_ELEMENT_NODE)
+ len++;
+ }
+ } else if (list->type == DOM_NODELIST_BY_NAMESPACE) {
if (list->data.ns.any_namespace == true ||
dom_string_isequal(cur->namespace,
list->data.ns.namespace)) {
@@ -222,6 +234,22 @@ dom_exception dom_nodelist_get_length(dom_nodelist *list, unsigned long *length)
len++;
}
}
+ } else if (list->type == DOM_NODELIST_BY_NAMESPACE_CASELESS) {
+ if (list->data.ns.any_namespace == true ||
+ dom_string_caseless_isequal(
+ cur->namespace,
+ list->data.ns.namespace)) {
+ if (list->data.ns.any_localname == true ||
+ (cur->name != NULL &&
+ dom_string_caseless_isequal(
+ cur->name,
+ list->data.ns.localname))) {
+ if (cur->type == DOM_ELEMENT_NODE)
+ len++;
+ }
+ }
+ } else {
+ assert("Unknown list type" == NULL);
}
/* Now, find next node */
@@ -290,7 +318,15 @@ dom_exception _dom_nodelist_item(dom_nodelist *list,
if (cur->type == DOM_ELEMENT_NODE)
count++;
}
- } else {
+ } else if (list->type == DOM_NODELIST_BY_NAME_CASELESS) {
+ if (list->data.n.any_name == true || (
+ cur->name != NULL &&
+ dom_string_caseless_isequal(cur->name,
+ list->data.n.name))) {
+ if (cur->type == DOM_ELEMENT_NODE)
+ count++;
+ }
+ } else if (list->type == DOM_NODELIST_BY_NAMESPACE) {
if (list->data.ns.any_namespace == true ||
(cur->namespace != NULL &&
dom_string_isequal(cur->namespace,
@@ -303,6 +339,23 @@ dom_exception _dom_nodelist_item(dom_nodelist *list,
count++;
}
}
+ } else if (list->type == DOM_NODELIST_BY_NAMESPACE_CASELESS) {
+ if (list->data.ns.any_namespace == true ||
+ (cur->namespace != NULL &&
+ dom_string_caseless_isequal(
+ cur->namespace,
+ list->data.ns.namespace))) {
+ if (list->data.ns.any_localname == true ||
+ (cur->name != NULL &&
+ dom_string_caseless_isequal(
+ cur->name,
+ list->data.ns.localname))) {
+ if (cur->type == DOM_ELEMENT_NODE)
+ count++;
+ }
+ }
+ } else {
+ assert("Unknown list type" == NULL);
}
/* Stop if this is the requested index */
@@ -366,20 +419,24 @@ bool _dom_nodelist_match(dom_nodelist *list, nodelist_type type,
if (list->type != type)
return false;
-
- if (list->type == DOM_NODELIST_CHILDREN) {
+
+ switch (list->type) {
+ case DOM_NODELIST_CHILDREN:
return true;
- }
-
- if (list->type == DOM_NODELIST_BY_NAME) {
+ case DOM_NODELIST_BY_NAME:
return dom_string_isequal(list->data.n.name, tagname);
- }
-
- if (list->type == DOM_NODELIST_BY_NAMESPACE) {
+ case DOM_NODELIST_BY_NAMESPACE:
return dom_string_isequal(list->data.ns.namespace, namespace) &&
dom_string_isequal(list->data.ns.localname, localname);
+ case DOM_NODELIST_BY_NAME_CASELESS:
+ return dom_string_caseless_isequal(list->data.n.name, tagname);
+ case DOM_NODELIST_BY_NAMESPACE_CASELESS:
+ return dom_string_caseless_isequal(list->data.ns.namespace,
+ namespace) &&
+ dom_string_caseless_isequal(list->data.ns.localname,
+ localname);
}
-
+
return false;
}
diff --git a/src/core/nodelist.h b/src/core/nodelist.h
index 6bc36d7..4fe5b61 100644
--- a/src/core/nodelist.h
+++ b/src/core/nodelist.h
@@ -22,7 +22,9 @@ struct dom_nodelist;
typedef enum {
DOM_NODELIST_CHILDREN,
DOM_NODELIST_BY_NAME,
- DOM_NODELIST_BY_NAMESPACE
+ DOM_NODELIST_BY_NAMESPACE,
+ DOM_NODELIST_BY_NAME_CASELESS,
+ DOM_NODELIST_BY_NAMESPACE_CASELESS
} nodelist_type;
/* Create a nodelist */
diff --git a/src/html/TODO b/src/html/TODO
new file mode 100644
index 0000000..8ff489d
--- /dev/null
+++ b/src/html/TODO
@@ -0,0 +1,57 @@
+The following is the status of the HTML Element and derived objects, at least
+as far as the test suite is concerned.
+
+HTMLElement html_element DONE
+HTMLHtmlElement html_html_element DONE
+HTMLHeadElement html_head_element DONE
+HTMLLinkElement html_link_element MISSING
+HTMLTitleElement html_title_element DONE
+HTMLMetaElement html_meta_element MISSING
+HTMLBaseElement html_base_element MISSING
+HTMLIsIndexElement html_isindex_element MISSING
+HTMLStyleElement html_style_element MISSING
+HTMLBodyElement html_body_element MISSING
+HTMLFormElement html_form_element DONE
+HTMLSelectElement html_select_element MISSING
+HTMLOptGroupElement html_optgroup_element MISSING
+HTMLOptionElement html_option_element MISSING
+HTMLInputElement html_input_element MISSING
+HTMLTextAreaElement html_textarea_element MISSING
+HTMLButtonElement html_button_element MISSING
+HTMLLabelElement html_label_element MISSING
+HTMLFieldSetElement html_fieldset_element MISSING
+HTMLLegendElement html_legend_element MISSING
+HTMLUListElement html_ulist_element MISSING
+HTMLOListElement html_olist_element MISSING
+HTMLDListElement html_dlist_element MISSING
+HTMLDirectoryElement html_directory_element MISSING
+HTMLMenuElement html_menu_element MISSING
+HTMLLIElement html_li_element MISSING
+HTMLBlockquoteElement html_blockquote_element MISSING
+HTMLDivElement html_div_element MISSING
+HTMLParagraphElement html_paragraph_element MISSING
+HTMLHeadingElement html_heading_element MISSING
+HTMLQuoteElement html_quote_element MISSING
+HTMLPreElement html_pre_element MISSING
+HTMLBRElement html_br_element MISSING
+HTMLBaseFontElement html_basefont_element MISSING
+HTMLFontElement html_font_element MISSING
+HTMLHRElement html_hr_element MISSING
+HTMLModElement html_mod_element MISSING
+HTMLAnchorElement html_anchor_element MISSING
+HTMLImageElement html_image_element MISSING
+HTMLObjectElement html_object_element MISSING
+HTMLParamElement html_param_element MISSING
+HTMLAppletElement html_applet_element MISSING
+HTMLMapElement html_map_element MISSING
+HTMLAreaElement html_area_element MISSING
+HTMLScriptElement html_script_element MISSING
+HTMLTableElement html_table_element MISSING
+HTMLTableCaptionElement html_tablecaption_element MISSING
+HTMLTableColElement html_tablecol_element MISSING
+HTMLTableSectionElement html_tablesection_element MISSING
+HTMLTableRowElement html_tablerow_element MISSING
+HTMLTableCellElement html_tablecell_element MISSING
+HTMLFrameSetElement html_frameset_element MISSING
+HTMLFrameElement html_frame_element MISSING
+HTMLIFrameElement html_iframe_element MISSING
diff --git a/src/html/html_document.c b/src/html/html_document.c
index a18218b..b266844 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -11,6 +11,12 @@
#include "html/html_document.h"
#include "html/html_element.h"
#include "html/html_collection.h"
+#include "html/html_html_element.h"
+#include "html/html_head_element.h"
+#include "html/html_link_element.h"
+#include "html/html_title_element.h"
+#include "html/html_meta_element.h"
+#include "html/html_form_element.h"
#include "core/string.h"
#include "utils/namespace.h"
@@ -64,6 +70,7 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc,
dom_events_default_action_fetcher daf)
{
dom_exception error;
+ int sidx;
error = _dom_document_initialise(&doc->base, daf);
if (error != DOM_NO_ERR)
@@ -75,47 +82,55 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc,
doc->url = NULL;
doc->cookie = NULL;
- doc->_memo_id = doc->_memo_title = doc->_memo_lang =
- doc->_memo_dir = doc->_memo_class = NULL;
+ doc->memoised = calloc(sizeof(dom_string *), hds_COUNT);
+ if (doc->memoised == NULL) {
+ error = DOM_NO_MEM_ERR;
+ goto out;
+ }
-#define MEMOISE(attr) \
- error = dom_string_create_interned((const uint8_t *) #attr, \
- SLEN(#attr), &doc->_memo_##attr); \
+#define HTML_DOCUMENT_STRINGS_ACTION(attr,str) \
+ error = dom_string_create_interned((const uint8_t *) #str, \
+ SLEN(#str), &doc->memoised[hds_##attr]); \
if (error != DOM_NO_ERR) { \
- if (doc->_memo_id != NULL) \
- dom_string_unref(doc->_memo_id); \
- if (doc->_memo_title != NULL) \
- dom_string_unref(doc->_memo_title); \
- if (doc->_memo_lang != NULL) \
- dom_string_unref(doc->_memo_lang); \
- if (doc->_memo_dir != NULL) \
- dom_string_unref(doc->_memo_dir); \
- return error; \
+ goto out; \
+ }
+
+#include "html_document_strings.h"
+#undef HTML_DOCUMENT_STRINGS_ACTION
+
+out:
+ if (doc->memoised != NULL && error != DOM_NO_ERR) {
+ for(sidx = 0; sidx < hds_COUNT; ++sidx) {
+ if (doc->memoised[sidx] != NULL) {
+ dom_string_unref(doc->memoised[sidx]);
+ }
+ }
+ free(doc->memoised);
+ doc->memoised = NULL;
}
-
- MEMOISE(id)
- MEMOISE(title)
- MEMOISE(lang)
- MEMOISE(dir)
- MEMOISE(class)
-
return error;
}
/* Finalise a HTMLDocument */
void _dom_html_document_finalise(dom_html_document *doc)
{
+ int sidx;
+
dom_string_unref(doc->cookie);
dom_string_unref(doc->url);
dom_string_unref(doc->domain);
dom_string_unref(doc->referrer);
dom_string_unref(doc->title);
- dom_string_unref(doc->_memo_id);
- dom_string_unref(doc->_memo_title);
- dom_string_unref(doc->_memo_lang);
- dom_string_unref(doc->_memo_dir);
- dom_string_unref(doc->_memo_class);
+ if (doc->memoised != NULL) {
+ for(sidx = 0; sidx < hds_COUNT; ++sidx) {
+ if (doc->memoised[sidx] != NULL) {
+ dom_string_unref(doc->memoised[sidx]);
+ }
+ }
+ free(doc->memoised);
+ doc->memoised = NULL;
+ }
_dom_document_finalise(&doc->base);
}
@@ -140,7 +155,43 @@ dom_exception _dom_html_document_copy(dom_node_internal *old,
}
/* Overloaded methods inherited from super class */
-/** \todo: dispatch on tag name to create correct HTMLElement subclass */
+
+/** Internal method to support both kinds of create method */
+static dom_exception
+_dom_html_document_create_element_internal(dom_html_document *html,
+ dom_string *tag_name,
+ dom_string *namespace,
+ dom_string *prefix,
+ dom_html_element **result)
+{
+ if (dom_string_caseless_isequal(tag_name, html->memoised[hds_HTML])) {
+ return _dom_html_html_element_create(html, namespace, prefix,
+ (dom_html_html_element **) result);
+ }
+
+ if (dom_string_caseless_isequal(tag_name, html->memoised[hds_HEAD])) {
+ return _dom_html_head_element_create(html, namespace, prefix,
+ (dom_html_head_element **) result);
+ }
+
+ if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TITLE])) {
+ return _dom_html_title_element_create(html, namespace, prefix,
+ (dom_html_title_element **) result);
+ }
+
+ if (dom_string_caseless_isequal(tag_name, html->memoised[hds_FORM])) {
+ return _dom_html_form_element_create(html, namespace, prefix,
+ (dom_html_form_element **) result);
+ }
+
+ if (dom_string_caseless_isequal(tag_name, html->memoised[hds_LINK])) {
+ return _dom_html_link_element_create(html, namespace, prefix,
+ (dom_html_link_element **) result);
+ }
+
+ return _dom_html_element_create(html, tag_name, namespace, prefix,
+ result);
+}
dom_exception _dom_html_document_create_element(dom_document *doc,
dom_string *tag_name, dom_element **result)
@@ -150,8 +201,9 @@ dom_exception _dom_html_document_create_element(dom_document *doc,
if (_dom_validate_name(tag_name) == false)
return DOM_INVALID_CHARACTER_ERR;
- return _dom_html_element_create(html, tag_name, NULL, NULL,
- (dom_html_element **) result);
+ return _dom_html_document_create_element_internal(html,
+ tag_name, NULL, NULL,
+ (dom_html_element **)result);
}
dom_exception _dom_html_document_create_element_ns(dom_document *doc,
@@ -178,8 +230,8 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc,
}
/* Attempt to create element */
- err = _dom_html_element_create(html, localname, namespace, prefix,
- (dom_html_element **) result);
+ err = _dom_html_document_create_element_internal(html, localname,
+ namespace, prefix, (dom_html_element **)result);
/* Tidy up */
if (localname != NULL) {
@@ -193,6 +245,48 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc,
return err;
}
+/**
+ * Retrieve a list of all elements with a given tag name
+ *
+ * \param doc The document to search in
+ * \param tagname The tag name to search for ("*" for all)
+ * \param result Pointer to location to receive result
+ * \return DOM_NO_ERR.
+ *
+ * The returned list will have its reference count increased. It is
+ * the responsibility of the caller to unref the list once it has
+ * finished with it.
+ */
+dom_exception _dom_html_document_get_elements_by_tag_name(dom_document *doc,
+ dom_string *tagname, dom_nodelist **result)
+{
+ return _dom_document_get_nodelist(doc, DOM_NODELIST_BY_NAME_CASELESS,
+ (dom_node_internal *) doc, tagname, NULL, NULL,
+ result);
+}
+
+/**
+ * Retrieve a list of all elements with a given local name and namespace URI
+ *
+ * \param doc The document to search in
+ * \param namespace The namespace URI
+ * \param localname The local name
+ * \param result Pointer to location to receive result
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ *
+ * The returned list will have its reference count increased. It is
+ * the responsibility of the caller to unref the list once it has
+ * finished with it.
+ */
+dom_exception _dom_html_document_get_elements_by_tag_name_ns(
+ dom_document *doc, dom_string *namespace,
+ dom_string *localname, dom_nodelist **result)
+{
+ return _dom_document_get_nodelist(doc, DOM_NODELIST_BY_NAMESPACE_CASELESS,
+ (dom_node_internal *) doc, NULL, namespace, localname,
+ result);
+}
+
/*-----------------------------------------------------------------------*/
/* The DOM spec public API */
@@ -218,20 +312,12 @@ dom_exception _dom_html_document_get_title(dom_html_document *doc,
*title = dom_string_ref(doc->title);
} else {
dom_element *node;
- dom_string *title_str;
dom_nodelist *nodes;
unsigned long len;
- exc = dom_string_create_interned((uint8_t*)"title",
- 5, &title_str);
- if (exc != DOM_NO_ERR) {
- return exc;
- }
-
exc = dom_document_get_elements_by_tag_name(doc,
- title_str,
+ doc->memoised[hds_TITLE],
&nodes);
- dom_string_unref(title_str);
if (exc != DOM_NO_ERR) {
return exc;
}
diff --git a/src/html/html_document.h b/src/html/html_document.h
index 57ec1ec..fbe7155 100644
--- a/src/html/html_document.h
+++ b/src/html/html_document.h
@@ -24,14 +24,12 @@ struct dom_html_document {
dom_string *url; /**< HTML document URL */
dom_string *cookie; /**< HTML document cookie */
- /* Cached strings for html objects to use */
- dom_string *_memo_id; /**< Memoised 'id' */
- dom_string *_memo_title;/**< Memoised 'title' */
- dom_string *_memo_lang; /**< Memoised 'lang' */
- dom_string *_memo_dir; /**< Memoised 'dir' */
- dom_string *_memo_class;/**< Memoised 'class' */
+ /** Cached strings for html objects to use */
+ dom_string **memoised;
};
+#include "html_document_strings.h"
+
/* Create a HTMLDocument */
dom_exception _dom_html_document_create(
dom_events_default_action_fetcher daf,
@@ -115,6 +113,11 @@ dom_exception _dom_html_document_create_element(dom_document *doc,
dom_exception _dom_html_document_create_element_ns(dom_document *doc,
dom_string *namespace, dom_string *qname,
dom_element **result);
+dom_exception _dom_html_document_get_elements_by_tag_name(dom_document *doc,
+ dom_string *tagname, dom_nodelist **result);
+dom_exception _dom_html_document_get_elements_by_tag_name_ns(
+ dom_document *doc, dom_string *namespace,
+ dom_string *localname, dom_nodelist **result);
#define DOM_DOCUMENT_VTABLE_HTML \
_dom_document_get_doctype, \
@@ -128,11 +131,11 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc,
_dom_document_create_processing_instruction, \
_dom_document_create_attribute, \
_dom_document_create_entity_reference, \
- _dom_document_get_elements_by_tag_name, \
+ _dom_html_document_get_elements_by_tag_name, \
_dom_document_import_node, \
_dom_html_document_create_element_ns, \
_dom_document_create_attribute_ns, \
- _dom_document_get_elements_by_tag_name_ns, \
+ _dom_html_document_get_elements_by_tag_name_ns, \
_dom_document_get_element_by_id, \
_dom_document_get_input_encoding, \
_dom_document_get_xml_encoding, \
diff --git a/src/html/html_document_strings.h b/src/html/html_document_strings.h
new file mode 100644
index 0000000..632b686
--- /dev/null
+++ b/src/html/html_document_strings.h
@@ -0,0 +1,135 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2012 Daniel Silverstone <dsilvers@netsurf-browser.org>
+ */
+
+/* Note, this file deliberately lacks guards since it's included many times
+ * in many places in order to correctly handle the loading of the strings.
+ */
+
+#ifndef HTML_DOCUMENT_STRINGS_ACTION
+#define HTML_DOCUMENT_STRINGS_INTERNAL_ACTION 1
+#define HTML_DOCUMENT_STRINGS_PREFIX \
+ typedef enum {
+#define HTML_DOCUMENT_STRINGS_SUFFIX \
+ hds_COUNT \
+ } html_document_memo_string_e;
+#define HTML_DOCUMENT_STRINGS_ACTION(tag,str) \
+ hds_##tag,
+#endif
+
+#define HTML_DOCUMENT_STRINGS_ACTION1(x) HTML_DOCUMENT_STRINGS_ACTION(x,x)
+
+#ifdef HTML_DOCUMENT_STRINGS_PREFIX
+HTML_DOCUMENT_STRINGS_PREFIX
+#endif
+
+/* Useful attributes for HTMLElement */
+HTML_DOCUMENT_STRINGS_ACTION1(id)
+HTML_DOCUMENT_STRINGS_ACTION1(title)
+HTML_DOCUMENT_STRINGS_ACTION1(lang)
+HTML_DOCUMENT_STRINGS_ACTION1(dir)
+HTML_DOCUMENT_STRINGS_ACTION1(class)
+/* Useful attributes used by HTMLHtmlElement */
+HTML_DOCUMENT_STRINGS_ACTION1(version)
+/* Useful attributes used by HTMLHeadElement */
+HTML_DOCUMENT_STRINGS_ACTION1(profile)
+/* Useful attributes used by HTMLLinkElement */
+HTML_DOCUMENT_STRINGS_ACTION1(charset)
+HTML_DOCUMENT_STRINGS_ACTION1(href)
+HTML_DOCUMENT_STRINGS_ACTION1(hreflang)
+HTML_DOCUMENT_STRINGS_ACTION1(media)
+HTML_DOCUMENT_STRINGS_ACTION1(rel)
+HTML_DOCUMENT_STRINGS_ACTION1(rev)
+HTML_DOCUMENT_STRINGS_ACTION1(target)
+HTML_DOCUMENT_STRINGS_ACTION1(type)
+/* Useful attributes used by HTMLMetaElement */
+HTML_DOCUMENT_STRINGS_ACTION1(content)
+HTML_DOCUMENT_STRINGS_ACTION(http_equiv,http-equiv)
+HTML_DOCUMENT_STRINGS_ACTION1(name)
+HTML_DOCUMENT_STRINGS_ACTION1(scheme)
+/* Useful attributes used by HTMLFormElement */
+HTML_DOCUMENT_STRINGS_ACTION(accept_charset,accept-charset)
+HTML_DOCUMENT_STRINGS_ACTION1(action)
+HTML_DOCUMENT_STRINGS_ACTION1(enctype)
+HTML_DOCUMENT_STRINGS_ACTION1(method)
+/* HTML_DOCUMENT_STRINGS_ACTION1(target) */
+/* Names for elements which get specialised. */
+HTML_DOCUMENT_STRINGS_ACTION1(HTML)
+HTML_DOCUMENT_STRINGS_ACTION1(HEAD)
+HTML_DOCUMENT_STRINGS_ACTION1(LINK)
+HTML_DOCUMENT_STRINGS_ACTION1(TITLE)
+HTML_DOCUMENT_STRINGS_ACTION1(META)
+HTML_DOCUMENT_STRINGS_ACTION1(BASE)
+HTML_DOCUMENT_STRINGS_ACTION1(ISINDEX)
+HTML_DOCUMENT_STRINGS_ACTION1(STYLE)
+HTML_DOCUMENT_STRINGS_ACTION1(BODY)
+HTML_DOCUMENT_STRINGS_ACTION1(FORM)
+HTML_DOCUMENT_STRINGS_ACTION1(SELECT)
+HTML_DOCUMENT_STRINGS_ACTION1(OPTGROUP)
+HTML_DOCUMENT_STRINGS_ACTION1(OPTION)
+HTML_DOCUMENT_STRINGS_ACTION1(INPUT)
+HTML_DOCUMENT_STRINGS_ACTION1(TEXTAREA)
+HTML_DOCUMENT_STRINGS_ACTION1(BUTTON)
+HTML_DOCUMENT_STRINGS_ACTION1(LABEL)
+HTML_DOCUMENT_STRINGS_ACTION1(FIELDSET)
+HTML_DOCUMENT_STRINGS_ACTION1(LEGEND)
+HTML_DOCUMENT_STRINGS_ACTION1(UL)
+HTML_DOCUMENT_STRINGS_ACTION1(OL)
+HTML_DOCUMENT_STRINGS_ACTION1(DL)
+HTML_DOCUMENT_STRINGS_ACTION1(DIR)
+HTML_DOCUMENT_STRINGS_ACTION1(MENU)
+HTML_DOCUMENT_STRINGS_ACTION1(LI)
+HTML_DOCUMENT_STRINGS_ACTION1(BLOCKQUOTE)
+HTML_DOCUMENT_STRINGS_ACTION1(DIV)
+HTML_DOCUMENT_STRINGS_ACTION1(P)
+HTML_DOCUMENT_STRINGS_ACTION1(H1)
+HTML_DOCUMENT_STRINGS_ACTION1(H2)
+HTML_DOCUMENT_STRINGS_ACTION1(H3)
+HTML_DOCUMENT_STRINGS_ACTION1(H4)
+HTML_DOCUMENT_STRINGS_ACTION1(H5)
+HTML_DOCUMENT_STRINGS_ACTION1(H6)
+HTML_DOCUMENT_STRINGS_ACTION1(Q)
+HTML_DOCUMENT_STRINGS_ACTION1(PRE)
+HTML_DOCUMENT_STRINGS_ACTION1(BR)
+HTML_DOCUMENT_STRINGS_ACTION1(BASEFONT)
+HTML_DOCUMENT_STRINGS_ACTION1(FONT)
+HTML_DOCUMENT_STRINGS_ACTION1(HR)
+HTML_DOCUMENT_STRINGS_ACTION1(INS)
+HTML_DOCUMENT_STRINGS_ACTION1(DEL)
+HTML_DOCUMENT_STRINGS_ACTION1(A)
+HTML_DOCUMENT_STRINGS_ACTION1(IMG)
+HTML_DOCUMENT_STRINGS_ACTION1(OBJECT)
+HTML_DOCUMENT_STRINGS_ACTION1(PARAM)
+HTML_DOCUMENT_STRINGS_ACTION1(APPLET)
+HTML_DOCUMENT_STRINGS_ACTION1(MAP)
+HTML_DOCUMENT_STRINGS_ACTION1(AREA)
+HTML_DOCUMENT_STRINGS_ACTION1(SCRIPT)
+HTML_DOCUMENT_STRINGS_ACTION1(TABLE)
+HTML_DOCUMENT_STRINGS_ACTION1(CAPTION)
+HTML_DOCUMENT_STRINGS_ACTION1(COL)
+HTML_DOCUMENT_STRINGS_ACTION1(COLGROUP)
+HTML_DOCUMENT_STRINGS_ACTION1(THEAD)
+HTML_DOCUMENT_STRINGS_ACTION1(TFOOT)
+HTML_DOCUMENT_STRINGS_ACTION1(TBODY)
+HTML_DOCUMENT_STRINGS_ACTION1(TR)
+HTML_DOCUMENT_STRINGS_ACTION1(TH)
+HTML_DOCUMENT_STRINGS_ACTION1(TD)
+HTML_DOCUMENT_STRINGS_ACTION1(FRAMESET)
+HTML_DOCUMENT_STRINGS_ACTION1(FRAME)
+HTML_DOCUMENT_STRINGS_ACTION1(IFRAME)
+
+#ifdef HTML_DOCUMENT_STRINGS_SUFFIX
+HTML_DOCUMENT_STRINGS_SUFFIX
+#endif
+
+#undef HTML_DOCUMENT_STRINGS_ACTION1
+
+#ifdef HTML_DOCUMENT_STRINGS_INTERNAL_ACTION
+#undef HTML_DOCUMENT_STRINGS_INTERNAL_ACTION
+#undef HTML_DOCUMENT_STRINGS_PREFIX
+#undef HTML_DOCUMENT_STRINGS_SUFFIX
+#undef HTML_DOCUMENT_STRINGS_ACTION
+#endif
diff --git a/src/html/html_element.c b/src/html/html_element.c
index 18607d7..3642c6c 100644
--- a/src/html/html_element.c
+++ b/src/html/html_element.c
@@ -16,7 +16,7 @@
#include "core/document.h"
#include "utils/utils.h"
-static struct dom_html_element_vtable _dom_html_element_vtable = {
+struct dom_html_element_vtable _dom_html_element_vtable = {
{
{
{
@@ -112,7 +112,7 @@ dom_exception _dom_html_element_get_##fattr(dom_html_element *element, \
\
_memo_##attr = \
((struct dom_html_document *) \
- ((struct dom_node_internal *)element)->owner)->_memo_##attr; \
+ ((struct dom_node_internal *)element)->owner)->memoised[hds_##attr]; \
\
ret = dom_element_get_attribute(element, _memo_##attr, fattr); \
\
@@ -127,7 +127,7 @@ dom_exception _dom_html_element_set_##fattr(dom_html_element *element, \
\
_memo_##attr = \
((struct dom_html_document *) \
- ((struct dom_node_internal *)element)->owner)->_memo_##attr; \
+ ((struct dom_node_internal *)element)->owner)->memoised[hds_##attr]; \
\
ret = dom_element_set_attribute(element, _memo_##attr, fattr); \
\
diff --git a/src/html/html_element.h b/src/html/html_element.h
index 2766dab..4a81102 100644
--- a/src/html/html_element.h
+++ b/src/html/html_element.h
@@ -83,5 +83,7 @@ dom_exception dom_html_element_get_bool_property(dom_html_element *ele,
dom_exception dom_html_element_set_bool_property(dom_html_element *ele,
const char *name, unsigned long len, bool has);
+extern struct dom_html_element_vtable _dom_html_element_vtable;
+
#endif
diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c
index b24a08e..d0a453d 100644
--- a/src/html/html_form_element.c
+++ b/src/html/html_form_element.c
@@ -8,6 +8,8 @@
#include <assert.h>
#include <stdlib.h>
+#include <dom/html/html_form_element.h>
+
#include "html/html_form_element.h"
#include "html/html_collection.h"
@@ -33,6 +35,7 @@ static bool _dom_is_form_control(struct dom_node_internal *node);
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_form_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_form_element **ele)
{
struct dom_node_internal *node;
@@ -43,10 +46,10 @@ dom_exception _dom_html_form_element_create(struct dom_html_document *doc,
/* Set up vtables */
node = (struct dom_node_internal *) *ele;
- node->base.vtable = &_dom_element_vtable;
+ node->base.vtable = &_dom_html_element_vtable;
node->vtable = &_protect_vtable;
- return _dom_html_form_element_initialise(doc, *ele);
+ return _dom_html_form_element_initialise(doc, namespace, prefix, *ele);
}
/**
@@ -57,18 +60,15 @@ dom_exception _dom_html_form_element_create(struct dom_html_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_form_element *ele)
{
- dom_string *name = NULL;
dom_exception err;
- err = dom_string_create((const uint8_t *) "FORM", SLEN("FORM"), &name);
- if (err != DOM_NO_ERR)
- return err;
+ err = _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_FORM],
+ namespace, prefix);
- err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
- dom_string_unref(name);
-
ele->col = NULL;
return err;
@@ -184,6 +184,48 @@ dom_exception dom_html_form_element_get_length(dom_html_form_element *ele,
return dom_html_collection_get_length(ele->col, len);
}
+#define SIMPLE_GET_SET(attr) \
+ dom_exception dom_html_form_element_get_##attr( \
+ dom_html_form_element *element, \
+ dom_string **attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_get_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ } \
+ \
+ dom_exception dom_html_form_element_set_##attr( \
+ dom_html_form_element *element, \
+ dom_string *attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_set_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ }
+
+SIMPLE_GET_SET(accept_charset)
+SIMPLE_GET_SET(action)
+SIMPLE_GET_SET(enctype)
+SIMPLE_GET_SET(method)
+SIMPLE_GET_SET(target)
+
+
/**
* Submit this form
*
@@ -231,11 +273,25 @@ dom_exception dom_html_form_element_reset(dom_html_form_element *ele)
* src/html/html_collection.h for detail. */
static bool _dom_is_form_control(struct dom_node_internal *node)
{
- UNUSED(node);
+ struct dom_html_document *doc =
+ (struct dom_html_document *)(node->owner);
assert(node->type == DOM_ELEMENT_NODE);
- /** \todo: implement */
+ /* Form controls are INPUT TEXTAREA SELECT and BUTTON */
+ if (dom_string_caseless_isequal(node->name,
+ doc->memoised[hds_INPUT]))
+ return true;
+ if (dom_string_caseless_isequal(node->name,
+ doc->memoised[hds_TEXTAREA]))
+ return true;
+ if (dom_string_caseless_isequal(node->name,
+ doc->memoised[hds_SELECT]))
+ return true;
+ if (dom_string_caseless_isequal(node->name,
+ doc->memoised[hds_BUTTON]))
+ return true;
+
return false;
}
diff --git a/src/html/html_form_element.h b/src/html/html_form_element.h
index dbf6267..1ee9878 100644
--- a/src/html/html_form_element.h
+++ b/src/html/html_form_element.h
@@ -23,10 +23,12 @@ struct dom_html_form_element {
/* Create a dom_html_form_element object */
dom_exception _dom_html_form_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_form_element **ele);
/* Initialise a dom_html_form_element object */
dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_form_element *ele);
/* Finalise a dom_html_form_element object */
diff --git a/src/html/html_head_element.c b/src/html/html_head_element.c
index d74b8d1..00d4476 100644
--- a/src/html/html_head_element.c
+++ b/src/html/html_head_element.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
+#include "html/html_document.h"
#include "html/html_head_element.h"
#include "core/node.h"
@@ -27,6 +28,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_head_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_head_element **ele)
{
struct dom_node_internal *node;
@@ -37,10 +39,10 @@ dom_exception _dom_html_head_element_create(struct dom_html_document *doc,
/* Set up vtables */
node = (struct dom_node_internal *) *ele;
- node->base.vtable = &_dom_element_vtable;
+ node->base.vtable = &_dom_html_element_vtable;
node->vtable = &_protect_vtable;
- return _dom_html_head_element_initialise(doc, *ele);
+ return _dom_html_head_element_initialise(doc, namespace, prefix, *ele);
}
/**
@@ -51,19 +53,12 @@ dom_exception _dom_html_head_element_create(struct dom_html_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_head_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_head_element *ele)
{
- dom_string *name = NULL;
- dom_exception err;
-
- err = dom_string_create((const uint8_t *) "HEAD", SLEN("HEAD"), &name);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
- dom_string_unref(name);
-
- return err;
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_HEAD],
+ namespace, prefix);
}
/**
@@ -118,3 +113,35 @@ dom_exception _dom_html_head_element_copy(dom_node_internal *old,
return _dom_html_element_copy(old, copy);
}
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+dom_exception dom_html_head_element_get_profile(dom_html_head_element *element,
+ dom_string **profile)
+{
+ dom_exception ret;
+ dom_string *_memo_profile;
+
+ _memo_profile =
+ ((struct dom_html_document *)
+ ((struct dom_node_internal *)element)->owner)->memoised[hds_profile];
+
+ ret = dom_element_get_attribute(element, _memo_profile, profile);
+
+ return ret;
+}
+
+dom_exception dom_html_head_element_set_profile(dom_html_head_element *element,
+ dom_string *profile)
+{
+ dom_exception ret;
+ dom_string *_memo_profile;
+
+ _memo_profile =
+ ((struct dom_html_document *)
+ ((struct dom_node_internal *)element)->owner)->memoised[hds_profile];
+
+ ret = dom_element_set_attribute(element, _memo_profile, profile);
+
+ return ret;
+}
diff --git a/src/html/html_head_element.h b/src/html/html_head_element.h
index aa6e21a..deb2d6a 100644
--- a/src/html/html_head_element.h
+++ b/src/html/html_head_element.h
@@ -19,10 +19,12 @@ struct dom_html_head_element {
/* Create a dom_html_head_element object */
dom_exception _dom_html_head_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_head_element **ele);
/* Initialise a dom_html_head_element object */
dom_exception _dom_html_head_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_head_element *ele);
/* Finalise a dom_html_head_element object */
diff --git a/src/html/html_html_element.c b/src/html/html_html_element.c
index 1bdf590..ee26019 100644
--- a/src/html/html_html_element.c
+++ b/src/html/html_html_element.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
+#include "html/html_document.h"
#include "html/html_html_element.h"
#include "core/node.h"
@@ -27,6 +28,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_html_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_html_element **ele)
{
struct dom_node_internal *node;
@@ -37,10 +39,10 @@ dom_exception _dom_html_html_element_create(struct dom_html_document *doc,
/* Set up vtables */
node = (struct dom_node_internal *) *ele;
- node->base.vtable = &_dom_element_vtable;
+ node->base.vtable = &_dom_html_element_vtable;
node->vtable = &_protect_vtable;
- return _dom_html_html_element_initialise(doc, *ele);
+ return _dom_html_html_element_initialise(doc, namespace, prefix, *ele);
}
/**
@@ -51,19 +53,11 @@ dom_exception _dom_html_html_element_create(struct dom_html_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_html_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_html_element *ele)
{
- dom_string *name = NULL;
- dom_exception err;
-
- err = dom_string_create((const uint8_t *) "HTML", SLEN("HTML"), &name);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
- dom_string_unref(name);
-
- return err;
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_HTML], namespace, prefix);
}
/**
@@ -119,3 +113,35 @@ dom_exception _dom_html_html_element_copy(dom_node_internal *old,
return _dom_html_element_copy(old, copy);
}
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+dom_exception dom_html_html_element_get_version(dom_html_html_element *element,
+ dom_string **version)
+{
+ dom_exception ret;
+ dom_string *_memo_version;
+
+ _memo_version =
+ ((struct dom_html_document *)
+ ((struct dom_node_internal *)element)->owner)->memoised[hds_version];
+
+ ret = dom_element_get_attribute(element, _memo_version, version);
+
+ return ret;
+}
+
+dom_exception dom_html_html_element_set_version(dom_html_html_element *element,
+ dom_string *version)
+{
+ dom_exception ret;
+ dom_string *_memo_version;
+
+ _memo_version =
+ ((struct dom_html_document *)
+ ((struct dom_node_internal *)element)->owner)->memoised[hds_version];
+
+ ret = dom_element_set_attribute(element, _memo_version, version);
+
+ return ret;
+}
diff --git a/src/html/html_html_element.h b/src/html/html_html_element.h
index f943f7b..61eb626 100644
--- a/src/html/html_html_element.h
+++ b/src/html/html_html_element.h
@@ -19,10 +19,12 @@ struct dom_html_html_element {
/* Create a dom_html_html_element object */
dom_exception _dom_html_html_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_html_element **ele);
/* Initialise a dom_html_html_element object */
dom_exception _dom_html_html_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_html_element *ele);
/* Finalise a dom_html_html_element object */
@@ -40,7 +42,7 @@ dom_exception _dom_html_html_element_copy(dom_node_internal *old,
dom_node_internal **copy);
#define DOM_HTML_HTML_ELEMENT_PROTECT_VTABLE \
- _dom_html_html_element_parse_attribute
+ _dom_element_parse_attribute
#define DOM_NODE_PROTECT_VTABLE_HTML_HTML_ELEMENT \
_dom_virtual_html_html_element_destroy, \
diff --git a/src/html/html_link_element.c b/src/html/html_link_element.c
index 92ca4f5..8e9a302 100644
--- a/src/html/html_link_element.c
+++ b/src/html/html_link_element.c
@@ -8,6 +8,7 @@
#include <assert.h>
#include <stdlib.h>
+#include "html/html_document.h"
#include "html/html_link_element.h"
#include "core/node.h"
@@ -29,6 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_link_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_link_element **ele)
{
struct dom_node_internal *node;
@@ -42,7 +44,7 @@ dom_exception _dom_html_link_element_create(struct dom_html_document *doc,
node->base.vtable = &_dom_element_vtable;
node->vtable = &_protect_vtable;
- return _dom_html_link_element_initialise(doc, *ele);
+ return _dom_html_link_element_initialise(doc, namespace, prefix, *ele);
}
/**
@@ -53,19 +55,12 @@ dom_exception _dom_html_link_element_create(struct dom_html_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_link_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_link_element *ele)
{
- dom_string *name = NULL;
- dom_exception err;
-
- err = dom_string_create((const uint8_t *) "HEAD", SLEN("HEAD"), &name);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
- dom_string_unref(name);
-
- return err;
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_LINK],
+ namespace, prefix);
}
/**
@@ -151,3 +146,49 @@ dom_exception _dom_html_link_element_copy(dom_node_internal *old,
return _dom_html_element_copy(old, copy);
}
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+#define SIMPLE_GET_SET(attr) \
+ dom_exception dom_html_link_element_get_##attr( \
+ dom_html_link_element *element, \
+ dom_string **attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_get_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ } \
+ \
+ dom_exception dom_html_link_element_set_##attr( \
+ dom_html_link_element *element, \
+ dom_string *attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_set_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ }
+
+SIMPLE_GET_SET(charset)
+SIMPLE_GET_SET(href)
+SIMPLE_GET_SET(hreflang)
+SIMPLE_GET_SET(media)
+SIMPLE_GET_SET(rel)
+SIMPLE_GET_SET(rev)
+SIMPLE_GET_SET(target)
+SIMPLE_GET_SET(type)
diff --git a/src/html/html_link_element.h b/src/html/html_link_element.h
index b281cfb..960dcdc 100644
--- a/src/html/html_link_element.h
+++ b/src/html/html_link_element.h
@@ -19,10 +19,12 @@ struct dom_html_link_element {
/* Create a dom_html_link_element object */
dom_exception _dom_html_link_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_link_element **ele);
/* Initialise a dom_html_link_element object */
dom_exception _dom_html_link_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_link_element *ele);
/* Finalise a dom_html_link_element object */
diff --git a/src/html/html_meta_element.c b/src/html/html_meta_element.c
index f1b6c3f..7a254e6 100644
--- a/src/html/html_meta_element.c
+++ b/src/html/html_meta_element.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
+#include "html/html_document.h"
#include "html/html_meta_element.h"
#include "core/node.h"
@@ -27,6 +28,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_meta_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_meta_element **ele)
{
struct dom_node_internal *node;
@@ -40,7 +42,7 @@ dom_exception _dom_html_meta_element_create(struct dom_html_document *doc,
node->base.vtable = &_dom_element_vtable;
node->vtable = &_protect_vtable;
- return _dom_html_meta_element_initialise(doc, *ele);
+ return _dom_html_meta_element_initialise(doc, namespace, prefix, *ele);
}
/**
@@ -51,19 +53,12 @@ dom_exception _dom_html_meta_element_create(struct dom_html_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_meta_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_meta_element *ele)
{
- dom_string *name = NULL;
- dom_exception err;
-
- err = dom_string_create((const uint8_t *) "META", SLEN("META"), &name);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
- dom_string_unref(name);
-
- return err;
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_META],
+ namespace, prefix);
}
/**
@@ -118,3 +113,45 @@ dom_exception _dom_html_meta_element_copy(dom_node_internal *old,
return _dom_html_element_copy(old, copy);
}
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+#define SIMPLE_GET_SET(attr) \
+ dom_exception dom_html_meta_element_get_##attr( \
+ dom_html_meta_element *element, \
+ dom_string **attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_get_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ } \
+ \
+ dom_exception dom_html_meta_element_set_##attr( \
+ dom_html_meta_element *element, \
+ dom_string *attr) \
+ { \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_set_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+ }
+
+SIMPLE_GET_SET(content)
+SIMPLE_GET_SET(http_equiv)
+SIMPLE_GET_SET(name)
+SIMPLE_GET_SET(scheme)
diff --git a/src/html/html_meta_element.h b/src/html/html_meta_element.h
index d302d24..d4a1076 100644
--- a/src/html/html_meta_element.h
+++ b/src/html/html_meta_element.h
@@ -19,10 +19,12 @@ struct dom_html_meta_element {
/* Create a dom_html_meta_element object */
dom_exception _dom_html_meta_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_meta_element **ele);
/* Initialise a dom_html_meta_element object */
dom_exception _dom_html_meta_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_meta_element *ele);
/* Finalise a dom_html_meta_element object */
diff --git a/src/html/html_title_element.c b/src/html/html_title_element.c
index ea4d24c..80da5e1 100644
--- a/src/html/html_title_element.c
+++ b/src/html/html_title_element.c
@@ -11,6 +11,7 @@
#include <dom/core/characterdata.h>
#include <dom/core/text.h>
+#include "html/html_document.h"
#include "html/html_title_element.h"
#include "core/node.h"
@@ -31,6 +32,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_title_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_title_element **ele)
{
struct dom_node_internal *node;
@@ -41,10 +43,10 @@ dom_exception _dom_html_title_element_create(struct dom_html_document *doc,
/* Set up vtables */
node = (struct dom_node_internal *) *ele;
- node->base.vtable = &_dom_element_vtable;
+ node->base.vtable = &_dom_html_element_vtable;
node->vtable = &_protect_vtable;
- return _dom_html_title_element_initialise(doc, *ele);
+ return _dom_html_title_element_initialise(doc, namespace, prefix, *ele);
}
/**
@@ -55,20 +57,12 @@ dom_exception _dom_html_title_element_create(struct dom_html_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_html_title_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_title_element *ele)
{
- dom_string *name = NULL;
- dom_exception err;
-
- err = dom_string_create((const uint8_t *) "TITLE", SLEN("TITLE"),
- &name);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
- dom_string_unref(name);
-
- return err;
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_TITLE],
+ namespace, prefix);
}
/**
diff --git a/src/html/html_title_element.h b/src/html/html_title_element.h
index 958c3fe..51adaf9 100644
--- a/src/html/html_title_element.h
+++ b/src/html/html_title_element.h
@@ -19,10 +19,12 @@ struct dom_html_title_element {
/* Create a dom_html_title_element object */
dom_exception _dom_html_title_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_title_element **ele);
/* Initialise a dom_html_title_element object */
dom_exception _dom_html_title_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
struct dom_html_title_element *ele);
/* Finalise a dom_html_title_element object */
diff --git a/test/DOMTSHandler.pm b/test/DOMTSHandler.pm
index e440f64..65efff3 100644
--- a/test/DOMTSHandler.pm
+++ b/test/DOMTSHandler.pm
@@ -38,6 +38,7 @@ our %special_type = (
DOMImplementation => "dom_implementation *",
NamedNodeMap => "dom_namednodemap *",
NodeList => "dom_nodelist *",
+ HTMLCollection => "dom_html_collection *",
CharacterData => "dom_characterdata *",
CDATASection => "dom_cdata_section *",
);
@@ -46,6 +47,7 @@ our %special_prefix = (
DOMImplementation => "dom_implementation",
NamedNodeMap => "dom_namednodemap",
NodeList => "dom_nodelist",
+ HTMLCollection => "dom_html_collection",
CharacterData => "dom_characterdata",
CDATASection => "dom_cdata_section *",
);
@@ -54,6 +56,7 @@ our %unref_prefix = (
DOMString => "dom_string",
NamedNodeMap => "dom_namednodemap",
NodeList => "dom_nodelist",
+ HTMLCollection => "dom_html_collection",
);
our %special_method = (
@@ -79,6 +82,7 @@ our %override_suffix = (
DOMImplementation => "domimplementation",
NamedNodeMap => "domnamednodemap",
NodeList => "domnodelist",
+ HTMLCollection => "domhtmlcollection",
Collection => "list",
List => "list",
);
@@ -661,9 +665,9 @@ sub generate_method {
}
$method = to_cmethod($ats{'interface'}, $en);
-
+ my $cast = to_attribute_cast($ats{'interface'});
my $ns = $dd->find("parameters/param", $node);
- my $params = "$ats{'obj'}";
+ my $params = "${cast}$ats{'obj'}";
for ($count = 1; $count <= $ns->size; $count++) {
my $n = $ns->get_node($count);
my $p = $n->getAttribute("name");
@@ -788,7 +792,7 @@ sub generate_attribute_fetcher {
}
my $fetcher = to_attribute_fetcher($ats{'interface'}, "$en");
-
+ my $cast = to_attribute_cast($ats{'interface'});
my $unref = 0;
my $temp_node = 0;
# Deal with the situation like
@@ -807,14 +811,14 @@ sub generate_attribute_fetcher {
my $t = type_to_ctype($self->{'var'}->{$ats{'var'}});
$tnode_index ++;
print "\t$t tnode$tnode_index = NULL;\n";
- print "\texp = $fetcher($ats{'obj'}, \&tnode$tnode_index);\n";
+ print "\texp = $fetcher(${cast}$ats{'obj'}, \&tnode$tnode_index);\n";
# The ats{'obj'} must have been added to cleanup stack
$unref = 1;
# Indicate that we have created a temp node
$temp_node = 1;
} else {
$unref = $self->param_unref($ats{'var'});
- print "\texp = $fetcher($ats{'obj'}, \&$ats{'var'});\n";
+ print "\texp = $fetcher(${cast}$ats{'obj'}, \&$ats{'var'});\n";
}
@@ -1116,7 +1120,7 @@ sub generate_assertion {
case "assertURIEquals" {
my $actual = $ats->{actual};
- my ($scheme, $path, $host, $file, $query, $fragment, $isAbsolute) = qw(NULL NULL NULL NULL NULL NULL NULL);
+ my ($scheme, $path, $host, $file, $name, $query, $fragment, $isAbsolute) = qw(NULL NULL NULL NULL NULL NULL NULL NULL);
if (exists $ats->{scheme}) {
$scheme = $ats->{scheme};
}
@@ -1129,6 +1133,9 @@ sub generate_assertion {
if (exists $ats->{file}) {
$file = $ats->{file};
}
+ if (exists $ats->{name}) {
+ $name = $ats->{name};
+ }
if (exists $ats->{query}) {
$query = $ats->{query};
}
@@ -1139,7 +1146,7 @@ sub generate_assertion {
$isAbsolute = $ats->{isAbsolute};
}
- print "is_uri_equals($scheme, $path, $host, $file, $query, $fragment, $isAbsolute, $actual)"
+ print "is_uri_equals($scheme, $path, $host, $file, $name, $query, $fragment, $isAbsolute, $actual)"
}
}
@@ -1376,6 +1383,13 @@ sub to_attribute_accessor {
return $ret;
}
+sub to_attribute_cast {
+ my $type = shift;
+ my $ret = get_prefix($type);
+ $ret =~ s/h_t_m_l/html/;
+ return "(${ret} *)";
+}
+
sub get_prefix {
my $type = shift;
diff --git a/test/testcases/tests/level1/html/HTMLCollection02.xml.notimpl b/test/testcases/tests/level1/html/HTMLCollection02.xml.kfail
index 521d5ae..521d5ae 100644
--- a/test/testcases/tests/level1/html/HTMLCollection02.xml.notimpl
+++ b/test/testcases/tests/level1/html/HTMLCollection02.xml.kfail
diff --git a/test/testcases/tests/level1/html/HTMLCollection03.xml.notimpl b/test/testcases/tests/level1/html/HTMLCollection03.xml.kfail
index 36d489e..36d489e 100644
--- a/test/testcases/tests/level1/html/HTMLCollection03.xml.notimpl
+++ b/test/testcases/tests/level1/html/HTMLCollection03.xml.kfail
diff --git a/test/testcases/tests/level1/html/HTMLCollection10.xml.notimpl b/test/testcases/tests/level1/html/HTMLCollection10.xml.kfail
index 78f4c9a..78f4c9a 100644
--- a/test/testcases/tests/level1/html/HTMLCollection10.xml.notimpl
+++ b/test/testcases/tests/level1/html/HTMLCollection10.xml.kfail
diff --git a/test/testcases/tests/level1/html/HTMLCollection11.xml.notimpl b/test/testcases/tests/level1/html/HTMLCollection11.xml.kfail
index ebf217f..ebf217f 100644
--- a/test/testcases/tests/level1/html/HTMLCollection11.xml.notimpl
+++ b/test/testcases/tests/level1/html/HTMLCollection11.xml.kfail
diff --git a/test/testcases/tests/level1/html/HTMLCollection12.xml.notimpl b/test/testcases/tests/level1/html/HTMLCollection12.xml
index d7feb3d..d7feb3d 100644
--- a/test/testcases/tests/level1/html/HTMLCollection12.xml.notimpl
+++ b/test/testcases/tests/level1/html/HTMLCollection12.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement01.xml
index 057fac5..057fac5 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement02.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement02.xml
index 06abf8d..06abf8d 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement02.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement02.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement03.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement03.xml
index 50332f9..50332f9 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement03.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement03.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement04.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement04.xml
index 4077e36..4077e36 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement04.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement04.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement05.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement05.xml
index 54a3436..54a3436 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement05.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement05.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement06.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement06.xml
index fb1ca95..fb1ca95 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement06.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement06.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement07.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement07.xml
index 897b63d..897b63d 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement07.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement07.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement08.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement08.xml
index 1a691cb..1a691cb 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement08.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement08.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement09.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement09.xml
index 4f552d6..4f552d6 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement09.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement09.xml
diff --git a/test/testcases/tests/level1/html/HTMLFormElement10.xml.kfail b/test/testcases/tests/level1/html/HTMLFormElement10.xml
index 8d1f3b4..8d1f3b4 100644
--- a/test/testcases/tests/level1/html/HTMLFormElement10.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLFormElement10.xml
diff --git a/test/testcases/tests/level1/html/HTMLHeadElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLHeadElement01.xml
index a0fd82b..a0fd82b 100644
--- a/test/testcases/tests/level1/html/HTMLHeadElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLHeadElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLHtmlElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLHtmlElement01.xml
index 1ad206a..1ad206a 100644
--- a/test/testcases/tests/level1/html/HTMLHtmlElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLHtmlElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement01.xml
index c9e2d16..c9e2d16 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement02.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement02.xml
index ab0105a..ab0105a 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement02.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement02.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement03.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement03.xml
index fff36db..fff36db 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement03.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement03.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement04.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement04.xml
index 924d945..924d945 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement04.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement04.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement05.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement05.xml
index cec4f35..cec4f35 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement05.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement05.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement06.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement06.xml
index 400e8ed..400e8ed 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement06.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement06.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement07.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement07.xml
index 71bbd8d..71bbd8d 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement07.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement07.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement08.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement08.xml
index 657237d..657237d 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement08.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement08.xml
diff --git a/test/testcases/tests/level1/html/HTMLLinkElement09.xml.kfail b/test/testcases/tests/level1/html/HTMLLinkElement09.xml
index 6fb55a8..6fb55a8 100644
--- a/test/testcases/tests/level1/html/HTMLLinkElement09.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLinkElement09.xml
diff --git a/test/testcases/tests/level1/html/HTMLMetaElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLMetaElement01.xml
index 5ee3bcc..5ee3bcc 100644
--- a/test/testcases/tests/level1/html/HTMLMetaElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLMetaElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLMetaElement02.xml.kfail b/test/testcases/tests/level1/html/HTMLMetaElement02.xml
index 11e7a09..11e7a09 100644
--- a/test/testcases/tests/level1/html/HTMLMetaElement02.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLMetaElement02.xml
diff --git a/test/testcases/tests/level1/html/HTMLMetaElement03.xml.kfail b/test/testcases/tests/level1/html/HTMLMetaElement03.xml
index ab3afc7..ab3afc7 100644
--- a/test/testcases/tests/level1/html/HTMLMetaElement03.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLMetaElement03.xml
diff --git a/test/testcases/tests/level1/html/HTMLMetaElement04.xml.kfail b/test/testcases/tests/level1/html/HTMLMetaElement04.xml
index 14ce0eb..14ce0eb 100644
--- a/test/testcases/tests/level1/html/HTMLMetaElement04.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLMetaElement04.xml
diff --git a/test/testcases/tests/level1/html/HTMLTitleElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLTitleElement01.xml
index 9b95d95..9b95d95 100644
--- a/test/testcases/tests/level1/html/HTMLTitleElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLTitleElement01.xml
diff --git a/test/testutils/domtsasserts.c b/test/testutils/domtsasserts.c
index 92e8222..e5220e0 100644
--- a/test/testutils/domtsasserts.c
+++ b/test/testutils/domtsasserts.c
@@ -190,20 +190,148 @@ bool is_size_list(unsigned long size, list *list)
}
-bool is_uri_equals(char *scheme, char *path, char *host,
- char *file, char *query, char *fragment,
- bool isAbsolute, dom_string *actual)
+bool is_uri_equals(const char *scheme, const char *path, const char *host,
+ const char *file, const char *name, const char *query,
+ const char *fragment, const char *isAbsolute,
+ dom_string *actual)
{
- UNUSED(scheme);
- UNUSED(path);
- UNUSED(host);
- UNUSED(file);
- UNUSED(query);
- UNUSED(fragment);
- UNUSED(isAbsolute);
- UNUSED(actual);
+ const char *_ptr = actual != NULL ? dom_string_data(actual) : NULL;
+ const size_t slen = actual != NULL ? dom_string_byte_length(actual) : 0;
+ char *_sptr = actual != NULL ? domts_strndup(_ptr, slen) : NULL;
+ char *sptr = _sptr;
+ bool result = false;
+
+ /* Used farther down */
+ const char *firstColon = NULL;
+ const char *firstSlash = NULL;
+ char *actualPath = NULL;
+ char *actualScheme = NULL;
+ char *actualHost = NULL;
+ char *actualFile = NULL;
+ char *actualName = NULL;
+
+ assert(sptr != NULL);
+
+ /* Note, from here on down, this is essentially a semi-direct
+ * reimplementation of assertURIEquals in the Java DOMTS.
+ */
+
+ /* Attempt to check fragment */
+ {
+ char *fptr = strrchr(sptr, '#');
+ const char *cfptr = fptr + 1;
+ if (fptr != NULL) {
+ *fptr = '\0'; /* Remove fragment from sptr */
+ } else {
+ cfptr = "";
+ }
+ if (fragment != NULL) {
+ if (strcmp(fragment, cfptr) != 0)
+ goto out;
+ }
+ }
+ /* Attempt to check query string */
+ {
+ char *qptr = strrchr(sptr, '?');
+ const char *cqptr = qptr + 1;
+ if (qptr != NULL) {
+ *qptr = '\0'; /* Remove query from sptr */
+ } else {
+ cqptr = "";
+ }
+ if (query != NULL) {
+ if (strcmp(query, cqptr) != 0)
+ goto out;
+ }
+ }
+
+ /* Scheme and path */
+ firstColon = strchr(sptr, ':');
+ firstSlash = strchr(sptr, '/');
+ actualPath = strdup(sptr);
+ actualScheme = strdup("");
+ if (firstColon != NULL && firstColon < firstSlash) {
+ free(actualScheme);
+ free(actualPath);
+ actualScheme = domts_strndup(sptr, firstColon - sptr);
+ actualPath = strdup(firstColon + 1);
+ }
+ if (scheme != NULL) {
+ if (strcmp(scheme, actualScheme) != 0)
+ goto out;
+ }
+ if (path != NULL) {
+ if (strcmp(path, actualPath) != 0)
+ goto out;
+ }
+
+ /* host */
+ if (host != NULL) {
+ if (actualPath[0] == '/' &&
+ actualPath[1] == '/') {
+ const char *termslash = strchr(actualPath + 2, '/');
+ actualHost = domts_strndup(actualPath,
+ termslash - actualPath);
+ } else {
+ actualHost = strdup("");
+ }
+ if (strcmp(actualHost, host) != 0)
+ goto out;
+ }
+
+
+ /* file */
+ actualFile = strdup(actualPath);
+ if (file != NULL || name != NULL) {
+ const char *finalSlash = strrchr(actualPath, '/');
+ if (finalSlash != NULL) {
+ free(actualFile);
+ actualFile = strdup(finalSlash + 1);
+ }
+ if (file != NULL) {
+ if (strcmp(actualFile, file) != 0)
+ goto out;
+ }
+ }
+
+ /* name */
+ if (name != NULL) {
+ const char *finalPeriod = strrchr(actualFile, '.');
+ if (finalPeriod != NULL) {
+ actualName = domts_strndup(actualFile,
+ finalPeriod - actualFile);
+ } else {
+ actualName = strdup(actualFile);
+ }
+ if (strcmp(actualName, name) != 0)
+ goto out;
+ }
+
+ /* isAbsolute */
+ if (isAbsolute != NULL) {
+ bool startslash = *actualPath == '/';
+ bool isabsolute = strcasecmp(isAbsolute, "true") == 0;
+ isabsolute |= (strcasecmp(isAbsolute, "yes") == 0);
+ isabsolute |= (strcmp(isAbsolute, "1") == 0);
+ startslash |= (strncmp(actualPath, "file:/", 6) == 0);
+ if (isabsolute != startslash)
+ goto out;
+ }
- return false;
+ result = true;
+out:
+ if (actualPath != NULL)
+ free(actualPath);
+ if (actualScheme != NULL)
+ free(actualScheme);
+ if (actualHost != NULL)
+ free(actualHost);
+ if (actualFile != NULL)
+ free(actualFile);
+ if (actualName != NULL)
+ free(actualName);
+ free(_sptr);
+ return result;
}
diff --git a/test/testutils/domtsasserts.h b/test/testutils/domtsasserts.h
index c301d88..bc214e8 100644
--- a/test/testutils/domtsasserts.h
+++ b/test/testutils/domtsasserts.h
@@ -49,9 +49,10 @@ bool is_size_domnamednodemap(unsigned long size, dom_namednodemap *map);
bool is_size_domnodelist(unsigned long size, dom_nodelist *list);
bool is_size_list(unsigned long size, list *list);
-bool is_uri_equals(char *scheme, char *path, char *host,
- char *file, char *query, char *fragment,
- bool isAbsolute, dom_string *actual);
+bool is_uri_equals(const char *scheme, const char *path, const char *host,
+ const char *file, const char *name, const char *query,
+ const char *fragment, const char *isAbsolute,
+ dom_string *actual);
bool is_contenttype(const char *type);
diff --git a/test/testutils/utils.c b/test/testutils/utils.c
index 739933f..c876613 100644
--- a/test/testutils/utils.c
+++ b/test/testutils/utils.c
@@ -8,6 +8,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "utils.h"
@@ -31,4 +32,10 @@ void mymsg(uint32_t severity, void *ctx, const char *msg, ...)
fprintf(stderr, "\n");
}
-
+char *domts_strndup(const char *s, size_t len)
+{
+ size_t retlen = min(strlen(s), len);
+ char *ret = calloc(retlen + 1, 1);
+ memcpy(ret, s, retlen);
+ return ret;
+}
diff --git a/test/testutils/utils.h b/test/testutils/utils.h
index b57db36..560e909 100644
--- a/test/testutils/utils.h
+++ b/test/testutils/utils.h
@@ -31,5 +31,7 @@
void *myrealloc(void *ptr, size_t len, void *pw);
void mymsg(uint32_t severity, void *ctx, const char *msg, ...);
+char *domts_strndup(const char *s, size_t len);
+
#endif