r13656 dsilvers - /trunk/libdom/src/html/html_document.c

netsurf at semichrome.net netsurf at semichrome.net
Sun Mar 25 10:22:22 BST 2012


Author: dsilvers
Date: Sun Mar 25 04:22:22 2012
New Revision: 13656

URL: http://source.netsurf-browser.org?rev=13656&view=rev
Log:
Implement HTMLDocument.getTitle for non-explicit titles

Modified:
    trunk/libdom/src/html/html_document.c

Modified: trunk/libdom/src/html/html_document.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/html/html_document.c?rev=13656&r1=13655&r2=13656&view=diff
==============================================================================
--- trunk/libdom/src/html/html_document.c (original)
+++ trunk/libdom/src/html/html_document.c Sun Mar 25 04:22:22 2012
@@ -180,13 +180,54 @@
 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 */
-	}
-
-	return DOM_NO_ERR;
+		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 exc;
 }
 
 dom_exception _dom_html_document_set_title(dom_html_document *doc,




More information about the netsurf-commits mailing list