summaryrefslogtreecommitdiff
path: root/src/html/html_document.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2012-02-05 21:01:43 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2012-02-05 21:01:43 +0000
commit967540245c4e577e8a26959a88ae7703f760cc61 (patch)
tree4179a08dad87ae02ef86d2bac69bba16901f7116 /src/html/html_document.c
parentca2566cbd69530e91f80b763beef011481d6cf94 (diff)
downloadlibdom-967540245c4e577e8a26959a88ae7703f760cc61.tar.gz
libdom-967540245c4e577e8a26959a88ae7703f760cc61.tar.bz2
Make HTMLDocument use dynamic dispatch like everything else.
Fix variable misuse in HTMLDocument constructor. Overload Document.createElement and Document.createElementNS for HTMLDocuments Re-enable decision to create HTMLDocument instead of Document in DOMImplementation.createDocument svn path=/trunk/libdom/; revision=13425
Diffstat (limited to 'src/html/html_document.c')
-rw-r--r--src/html/html_document.c223
1 files changed, 188 insertions, 35 deletions
diff --git a/src/html/html_document.c b/src/html/html_document.c
index 673615e..52e0b9c 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -9,9 +9,12 @@
#include <stdlib.h>
#include "html/html_document.h"
+#include "html/html_element.h"
#include "core/string.h"
+#include "utils/namespace.h"
#include "utils/utils.h"
+#include "utils/validate.h"
static struct dom_html_document_vtable html_document_vtable = {
{
@@ -21,8 +24,9 @@ static struct dom_html_document_vtable html_document_vtable = {
},
DOM_NODE_VTABLE,
},
- DOM_DOCUMENT_VTABLE
- }
+ DOM_DOCUMENT_VTABLE_HTML
+ },
+ DOM_HTML_DOCUMENT_VTABLE
};
static struct dom_node_protect_vtable html_document_protect_vtable = {
@@ -44,7 +48,7 @@ dom_exception _dom_html_document_create(
result->base.base.base.vtable = &html_document_vtable;
result->base.base.vtable = &html_document_protect_vtable;
- error = _dom_html_document_initialise(*doc, daf);
+ error = _dom_html_document_initialise(result, daf);
if (error != DOM_NO_ERR) {
free(result);
return error;
@@ -104,6 +108,60 @@ dom_exception _dom_html_document_copy(dom_node_internal *old,
return DOM_NOT_SUPPORTED_ERR;
}
+/* Overloaded methods inherited from super class */
+/** \todo: dispatch on tag name to create correct HTMLElement subclass */
+
+dom_exception _dom_html_document_create_element(dom_document *doc,
+ dom_string *tag_name, dom_element **result)
+{
+ dom_html_document *html = (dom_html_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);
+}
+
+dom_exception _dom_html_document_create_element_ns(dom_document *doc,
+ dom_string *namespace, dom_string *qname,
+ dom_element **result)
+{
+ dom_html_document *html = (dom_html_document *) doc;
+ dom_string *prefix, *localname;
+ dom_exception err;
+
+ if (_dom_validate_name(qname) == false)
+ return DOM_INVALID_CHARACTER_ERR;
+
+ /* Validate qname */
+ err = _dom_namespace_validate_qname(qname, namespace);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ /* Divide QName into prefix/localname pair */
+ err = _dom_namespace_split_qname(qname, &prefix, &localname);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ /* Attempt to create element */
+ err = _dom_html_element_create(html, localname, namespace, prefix,
+ (dom_html_element **) result);
+
+ /* Tidy up */
+ if (localname != NULL) {
+ dom_string_unref(localname);
+ }
+
+ if (prefix != NULL) {
+ dom_string_unref(prefix);
+ }
+
+ return err;
+}
+
/*-----------------------------------------------------------------------*/
/* The DOM spec public API */
@@ -119,7 +177,7 @@ dom_exception _dom_html_document_copy(dom_node_internal *old,
* 2. If there is no such one, find the <title> element and use its text
* as the returned title.
*/
-dom_exception dom_html_document_get_title(dom_html_document *doc,
+dom_exception _dom_html_document_get_title(dom_html_document *doc,
dom_string **title)
{
if (doc->title != NULL) {
@@ -131,7 +189,7 @@ dom_exception dom_html_document_get_title(dom_html_document *doc,
return DOM_NO_ERR;
}
-dom_exception dom_html_document_set_title(dom_html_document *doc,
+dom_exception _dom_html_document_set_title(dom_html_document *doc,
dom_string *title)
{
if (doc->title != NULL)
@@ -142,7 +200,7 @@ dom_exception dom_html_document_set_title(dom_html_document *doc,
return DOM_NO_ERR;
}
-dom_exception dom_html_document_get_referer(dom_html_document *doc,
+dom_exception _dom_html_document_get_referer(dom_html_document *doc,
dom_string **referer)
{
*referer = dom_string_ref(doc->referer);
@@ -150,7 +208,7 @@ dom_exception dom_html_document_get_referer(dom_html_document *doc,
return DOM_NO_ERR;
}
-dom_exception dom_html_document_get_domain(dom_html_document *doc,
+dom_exception _dom_html_document_get_domain(dom_html_document *doc,
dom_string **domain)
{
*domain = dom_string_ref(doc->domain);
@@ -158,7 +216,7 @@ dom_exception dom_html_document_get_domain(dom_html_document *doc,
return DOM_NO_ERR;
}
-dom_exception dom_html_document_get_url(dom_html_document *doc,
+dom_exception _dom_html_document_get_url(dom_html_document *doc,
dom_string **url)
{
*url = dom_string_ref(doc->url);
@@ -166,31 +224,126 @@ dom_exception dom_html_document_get_url(dom_html_document *doc,
return DOM_NO_ERR;
}
-dom_exception dom_html_document_get_body(dom_html_document *doc,
- struct dom_html_element **body);
-dom_exception dom_html_document_set_body(dom_html_document *doc,
- struct dom_html_element *body);
-dom_exception dom_html_document_get_images(dom_html_document *doc,
- struct dom_html_collection **col);
-dom_exception dom_html_document_get_applets(dom_html_document *doc,
- struct dom_html_collection **col);
-dom_exception dom_html_document_get_links(dom_html_document *doc,
- struct dom_html_collection **col);
-dom_exception dom_html_document_get_forms(dom_html_document *doc,
- struct dom_html_collection **col);
-dom_exception dom_html_document_get_anchors(dom_html_document *doc,
- struct dom_html_collection **col);
-dom_exception dom_html_document_get_cookie(dom_html_document *doc,
- dom_string **cookie);
-dom_exception dom_html_document_set_cookie(dom_html_document *doc,
- dom_string *cookie);
-
-dom_exception dom_html_document_open(dom_html_document *doc);
-dom_exception dom_html_document_close(dom_html_document *doc);
-dom_exception dom_html_document_write(dom_html_document *doc,
- dom_string *text);
-dom_exception dom_html_document_writeln(dom_html_document *doc,
- dom_string *text);
-dom_exception dom_html_document_get_elements_by_name(dom_html_document *doc,
- dom_string *name, struct dom_nodelist **list);
+dom_exception _dom_html_document_get_body(dom_html_document *doc,
+ struct dom_html_element **body)
+{
+ UNUSED(doc);
+ UNUSED(body);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_set_body(dom_html_document *doc,
+ struct dom_html_element *body)
+{
+ UNUSED(doc);
+ UNUSED(body);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_images(dom_html_document *doc,
+ struct dom_html_collection **col)
+{
+ UNUSED(doc);
+ UNUSED(col);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_applets(dom_html_document *doc,
+ struct dom_html_collection **col)
+{
+ UNUSED(doc);
+ UNUSED(col);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_links(dom_html_document *doc,
+ struct dom_html_collection **col)
+{
+ UNUSED(doc);
+ UNUSED(col);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_forms(dom_html_document *doc,
+ struct dom_html_collection **col)
+{
+ UNUSED(doc);
+ UNUSED(col);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_anchors(dom_html_document *doc,
+ struct dom_html_collection **col)
+{
+ UNUSED(doc);
+ UNUSED(col);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_cookie(dom_html_document *doc,
+ dom_string **cookie)
+{
+ UNUSED(doc);
+ UNUSED(cookie);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_set_cookie(dom_html_document *doc,
+ dom_string *cookie)
+{
+ UNUSED(doc);
+ UNUSED(cookie);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_open(dom_html_document *doc)
+{
+ UNUSED(doc);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_close(dom_html_document *doc)
+{
+ UNUSED(doc);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_write(dom_html_document *doc,
+ dom_string *text)
+{
+ UNUSED(doc);
+ UNUSED(text);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_writeln(dom_html_document *doc,
+ dom_string *text)
+{
+ UNUSED(doc);
+ UNUSED(text);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}
+
+dom_exception _dom_html_document_get_elements_by_name(dom_html_document *doc,
+ dom_string *name, struct dom_nodelist **list)
+{
+ UNUSED(doc);
+ UNUSED(name);
+ UNUSED(list);
+
+ return DOM_NOT_SUPPORTED_ERR;
+}