summaryrefslogtreecommitdiff
path: root/src/html/html_document.c
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2012-03-25 09:22:22 +0000
committerDaniel Silverstone <dsilvers@netsurf-browser.org>2012-03-25 09:22:22 +0000
commitfc4f4aff6c4c7d99314dc2a1ef57fe3176d974fb (patch)
tree67a2b7f8be0ec11c63baab4728d30e79f4e8ef45 /src/html/html_document.c
parentd22c5dd55aba0164ecc407521b6d5b290957e5d8 (diff)
downloadlibdom-fc4f4aff6c4c7d99314dc2a1ef57fe3176d974fb.tar.gz
libdom-fc4f4aff6c4c7d99314dc2a1ef57fe3176d974fb.tar.bz2
Implement HTMLDocument.getTitle for non-explicit titles
svn path=/trunk/libdom/; revision=13656
Diffstat (limited to 'src/html/html_document.c')
-rw-r--r--src/html/html_document.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/html/html_document.c b/src/html/html_document.c
index 52e0b9c..2ae6488 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -180,13 +180,54 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc,
dom_exception _dom_html_document_get_title(dom_html_document *doc,
dom_string **title)
{
+ dom_exception exc = DOM_NO_ERR;
+ *title = NULL;
+
if (doc->title != NULL) {
*title = dom_string_ref(doc->title);
} else {
- /** \todo Search for title element */
+ 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) {
+ dom_node_unref(node);
+ return exc;
+ }
+
+ exc = dom_document_get_elements_by_tag_name(doc,
+ title_str,
+ &nodes);
+ dom_string_unref(title_str);
+ if (exc != DOM_NO_ERR) {
+ return exc;
+ }
+
+ exc = dom_nodelist_get_length(nodes, &len);
+ if (exc != DOM_NO_ERR) {
+ dom_nodelist_unref(nodes);
+ return exc;
+ }
+
+ if (len == 0) {
+ dom_nodelist_unref(nodes);
+ return DOM_NO_ERR;
+ }
+
+ exc = dom_nodelist_item(nodes, 0, &node);
+ dom_nodelist_unref(nodes);
+ if (exc != DOM_NO_ERR) {
+ return exc;
+ }
+
+ exc = dom_node_get_text_content(node, title);
+ dom_node_unref(node);
}
- return DOM_NO_ERR;
+ return exc;
}
dom_exception _dom_html_document_set_title(dom_html_document *doc,