From bb1f7872c8dd7721b2bde9f0924b8284b5f7c3f0 Mon Sep 17 00:00:00 2001 From: rsk1994 Date: Tue, 20 May 2014 05:21:14 +0530 Subject: TableCell Element Rev.2 --- src/html/html_tablecell_element.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/html/html_tablecell_element.c') diff --git a/src/html/html_tablecell_element.c b/src/html/html_tablecell_element.c index 6317686..b5d406f 100644 --- a/src/html/html_tablecell_element.c +++ b/src/html/html_tablecell_element.c @@ -185,9 +185,13 @@ dom_exception dom_html_table_cell_element_get_cell_index( dom_node_internal *n = ((dom_node_internal *)table_cell)->parent; dom_html_document *doc = (dom_html_document *)(n->owner); int32_t cnt = 0; - - for (n = n->first_child; n != NULL; n = n->next) { - + while(n != NULL) { + if(dom_string_caseless_isequal(doc->memoised[hds_TR],n->name)) { + break; + } + n = n->parent; + } + while(n != NULL) { if(n == (dom_node_internal *)table_cell) { break; } else if((n->type == DOM_ELEMENT_NODE) && @@ -195,7 +199,27 @@ dom_exception dom_html_table_cell_element_get_cell_index( dom_string_caseless_isequal(doc->memoised[hds_TH],n->name))) { cnt += 1; } - + 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 !=NULL) { + if(n == parent->last_child) { + n = parent; + parent = parent->parent; + } else { + break; + } + + } + if(parent == NULL) { + n = NULL; + } + } } table_cell->id = cnt; } -- cgit v1.2.3