r13755 tlsa - in /trunk/libdom: include/dom/core/element.h src/core/element.c

netsurf at semichrome.net netsurf at semichrome.net
Wed Mar 28 13:48:10 BST 2012


Author: tlsa
Date: Wed Mar 28 07:48:09 2012
New Revision: 13755

URL: http://source.netsurf-browser.org?rev=13755&view=rev
Log:
Add some functions to implement some of LibCSS's selection callbacks, as an experiment in clawing back performance.  May well get reverted.

Modified:
    trunk/libdom/include/dom/core/element.h
    trunk/libdom/src/core/element.c

Modified: trunk/libdom/include/dom/core/element.h
URL: http://source.netsurf-browser.org/trunk/libdom/include/dom/core/element.h?rev=13755&r1=13754&r2=13755&view=diff
==============================================================================
--- trunk/libdom/include/dom/core/element.h (original)
+++ trunk/libdom/include/dom/core/element.h Wed Mar 28 07:48:09 2012
@@ -352,4 +352,16 @@
 		dom_element_has_class((dom_element *) (e), \
 		(lwc_string *) (n), (bool *) (m))
 
+
+/* Functions for implementing some libcss selection callbacks.
+ * Note that they don't take a reference to the returned element, as such they
+ * are UNSAFE if you require the returned element to live beyond the next time
+ * the DOM gets a chance to change. */
+dom_exception dom_element_named_ancestor_node(dom_element *element,
+		lwc_string *name, dom_element **ancestor);
+dom_exception dom_element_named_parent_node(dom_element *element,
+		lwc_string *name, dom_element **parent);
+dom_exception dom_element_parent_node(dom_element *element,
+		dom_element **parent);
+
 #endif

Modified: trunk/libdom/src/core/element.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/core/element.c?rev=13755&r1=13754&r2=13755&view=diff
==============================================================================
--- trunk/libdom/src/core/element.c (original)
+++ trunk/libdom/src/core/element.c Wed Mar 28 07:48:09 2012
@@ -1225,6 +1225,92 @@
 	return DOM_NO_ERR;
 }
 
+/**
+ * Get a named ancestor node
+ *
+ * \param element   Element to consider
+ * \param name      Node name to look for
+ * \param ancestor  Pointer to location to receive node pointer
+ * \return DOM_NO_ERR.
+ */
+dom_exception dom_element_named_ancestor_node(dom_element *element,
+		lwc_string *name, dom_element **ancestor)
+{
+	dom_node_internal *node = (dom_node_internal *)element;
+
+	*ancestor = NULL;
+
+	for (node = node->parent; node != NULL; node = node->parent) {
+		if (node->type != DOM_ELEMENT_NODE)
+			continue;
+
+		assert(node->name != NULL);
+
+		if (dom_string_caseless_lwc_isequal(node->name, name)) {
+			*ancestor = (dom_element *)node;
+			break;
+		}
+	}
+
+	return DOM_NO_ERR;
+}
+
+/**
+ * Get a named parent node
+ *
+ * \param element  Element to consider
+ * \param name     Node name to look for
+ * \param parent   Pointer to location to receive node pointer
+ * \return DOM_NO_ERR.
+ */
+dom_exception dom_element_named_parent_node(dom_element *element,
+		lwc_string *name, dom_element **parent)
+{
+	dom_node_internal *node = (dom_node_internal *)element;
+
+	*parent = NULL;
+
+	for (node = node->parent; node != NULL; node = node->parent) {
+		if (node->type != DOM_ELEMENT_NODE)
+			continue;
+
+		assert(node->name != NULL);
+
+		if (dom_string_caseless_lwc_isequal(node->name, name)) {
+			*parent = (dom_element *)node;
+		}
+		break;
+	}
+
+	return DOM_NO_ERR;
+}
+
+/**
+ * Get a named parent node
+ *
+ * \param element  Element to consider
+ * \param name     Node name to look for
+ * \param parent   Pointer to location to receive node pointer
+ * \return DOM_NO_ERR.
+ */
+dom_exception dom_element_parent_node(dom_element *element,
+		dom_element **parent)
+{
+	dom_node_internal *node = (dom_node_internal *)element;
+
+	*parent = NULL;
+
+	for (node = node->parent; node != NULL; node = node->parent) {
+		if (node->type != DOM_ELEMENT_NODE)
+			continue;
+
+		*parent = (dom_element *)node;
+		break;
+	}
+
+	return DOM_NO_ERR;
+}
+
 /*------------- The overload virtual functions ------------------------*/
 
 /* Overload function of Node, please refer src/core/node.c for detail */




More information about the netsurf-commits mailing list