summaryrefslogtreecommitdiff
path: root/src/html/html_options_collection.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2012-09-19 14:06:09 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2012-09-19 14:06:09 +0100
commitd621b4cc86289f23b11f2050d5dcfbf025a3218f (patch)
treed43a13ad6c765c00ff32759d5995d460afad54d2 /src/html/html_options_collection.c
parent83ace96a3046ec0f6bdbd258280b50292a4e8caf (diff)
parent55e606196f97c2b2ded75933f7643d3acf57033f (diff)
downloadlibdom-d621b4cc86289f23b11f2050d5dcfbf025a3218f.tar.gz
libdom-d621b4cc86289f23b11f2050d5dcfbf025a3218f.tar.bz2
Merge branch 'tlsa/selectstuff'
Conflicts: include/dom/html/html_select_element.h src/html/html_select_element.c src/html/html_select_element.h
Diffstat (limited to 'src/html/html_options_collection.c')
-rw-r--r--src/html/html_options_collection.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/html/html_options_collection.c b/src/html/html_options_collection.c
index 0583d9c..85001ad 100644
--- a/src/html/html_options_collection.c
+++ b/src/html/html_options_collection.c
@@ -142,7 +142,73 @@ dom_exception dom_html_options_collection_item(dom_html_options_collection *col,
dom_exception dom_html_options_collection_named_item(dom_html_options_collection *col,
dom_string *name, struct dom_node **node)
{
- return dom_html_collection_named_item(&col->base, name, node);
+ struct dom_node_internal *n = col->base.root;
+ dom_string *kname;
+ dom_exception err;
+
+ /* Search for an element with an appropriate ID */
+ err = dom_html_collection_named_item(&col->base, name, node);
+ if (err == DOM_NO_ERR && *node != NULL)
+ return err;
+
+ /* Didn't find one, so consider name attribute */
+ err = dom_string_create_interned((const uint8_t *) "name", SLEN("name"),
+ &kname);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ while (n != NULL) {
+ if (n->type == DOM_ELEMENT_NODE &&
+ col->base.ic(n, col->base.ctx) == true) {
+ dom_string *nval = NULL;
+
+ err = dom_element_get_attribute(n, kname, &nval);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(kname);
+ return err;
+ }
+
+ if (nval != NULL && dom_string_isequal(name, nval)) {
+ *node = (struct dom_node *) n;
+ dom_node_ref(n);
+ dom_string_unref(nval);
+ dom_string_unref(kname);
+
+ return DOM_NO_ERR;
+ }
+
+ if (nval != NULL)
+ dom_string_unref(nval);
+ }
+
+ /* Depth first iterating */
+ if (n->first_child != NULL) {
+ n = n->first_child;
+ } else if (n->next != NULL) {
+ n = n->next;
+ } else {
+ /* No children and siblings */
+ struct dom_node_internal *parent = n->parent;
+
+ while (parent != col->base.root &&
+ n == parent->last_child) {
+ n = parent;
+ parent = parent->parent;
+ }
+
+ if (parent == col->base.root)
+ n = NULL;
+ else
+ n = n->next;
+ }
+ }
+
+ dom_string_unref(kname);
+
+ /* Not found the target node */
+ *node = NULL;
+
+ return DOM_NO_ERR;
}
/**