From 067d862e55500d89e8e96637a4678cf25cae478b Mon Sep 17 00:00:00 2001 From: Rupinder Singh Khokhar Date: Mon, 9 Jun 2014 09:33:23 +0530 Subject: HTMLCollection --- src/html/html_collection.c | 25 +++++++++++++++++++++---- src/html/html_document.c | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/html') diff --git a/src/html/html_collection.c b/src/html/html_collection.c index 2b4d8aa..43a26c5 100644 --- a/src/html/html_collection.c +++ b/src/html/html_collection.c @@ -11,6 +11,7 @@ #include #include "html/html_collection.h" +#include "html/html_document.h" #include "core/node.h" #include "core/element.h" @@ -182,7 +183,7 @@ dom_exception dom_html_collection_item(dom_html_collection *col, /* No children and siblings */ struct dom_node_internal *parent = n->parent; - while (parent != col->root && + while (n != col->root && n == parent->last_child) { n = parent; parent = parent->parent; @@ -212,8 +213,8 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col, dom_string *name, struct dom_node **node) { struct dom_node_internal *n = col->root; + dom_html_document *doc = (dom_html_document *)dom_node_get_owner(n); dom_exception err; - while (n != NULL) { if (n->type == DOM_ELEMENT_NODE && col->ic(n, col->ctx) == true) { @@ -235,6 +236,22 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col, if (id != NULL) dom_string_unref(id); + + /* Check for Name attr if id not matched/found */ + dom_string *id_name = NULL; + err = _dom_element_get_attribute((dom_element *)n, + doc->memoised[hds_name], &id_name); + if(err != DOM_NO_ERR) { + return err; + } + if (id_name != NULL && dom_string_isequal(name, id_name)) { + *node = (struct dom_node *) n; + dom_node_ref(n); + dom_string_unref(id_name); + + return DOM_NO_ERR; + } + } /* Depth first iterating */ @@ -246,13 +263,13 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col, /* No children and siblings */ struct dom_node_internal *parent = n->parent; - while (parent != col->root && + while (n != col->root && n == parent->last_child) { n = parent; parent = parent->parent; } - if (parent == col->root) + if (n == col->root) n = NULL; else n = n->next; diff --git a/src/html/html_document.c b/src/html/html_document.c index 83c4801..cd062a2 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -907,6 +907,7 @@ dom_exception _dom_html_document_set_cookie(dom_html_document *doc, { UNUSED(doc); UNUSED(cookie); + /*todo implement this after updating client interface */ return DOM_NOT_SUPPORTED_ERR; } -- cgit v1.2.3