summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrsk1994 <rsk1coder99@gmail.com>2014-05-31 09:07:42 +0530
committerRupinder Singh Khokhar <rsk1coder99@gmail.com>2014-06-11 04:27:11 +0530
commitf0a3c95cfc4a5595f930cd5dd14d6cbbf1f85312 (patch)
tree5f74ee26934ca2c29dcf9b61061c035ff5dce801 /src
parentca30ba7de4c3b0b17a61e1f07032575a01f2cd25 (diff)
downloadlibdom-f0a3c95cfc4a5595f930cd5dd14d6cbbf1f85312.tar.gz
libdom-f0a3c95cfc4a5595f930cd5dd14d6cbbf1f85312.tar.bz2
tableSectionElement Rev.2 && tableCellElement Rev.4 && tableElement Rev.1 && tableRowElement Rev.1 && DOMTSHandler(Test Suite) Revised and implemented inefficient ways to produce correct .c's && other minor bg fixes in HTMLCollection... Tests expecting 2nd attribute of dom_html_collection_get_length to be of type int32_t aren't enabled yet. Will be done in a later commit.
Diffstat (limited to 'src')
-rw-r--r--src/html/Makefile6
-rw-r--r--src/html/TODO4
-rw-r--r--src/html/html_collection.c2
-rw-r--r--src/html/html_document.c10
-rw-r--r--src/html/html_document_strings.h5
-rw-r--r--src/html/html_table_element.c740
-rw-r--r--src/html/html_table_element.h56
-rw-r--r--src/html/html_tablecell_element.c19
-rw-r--r--src/html/html_tablerow_element.c368
-rw-r--r--src/html/html_tablerow_element.h46
-rw-r--r--src/html/html_tablesection_element.c77
-rw-r--r--src/html/html_tablesection_element.h2
12 files changed, 1262 insertions, 73 deletions
diff --git a/src/html/Makefile b/src/html/Makefile
index 8fc029d..8c20362 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -16,11 +16,11 @@ DIR_SOURCES := \
html_basefont_element.c html_image_element.c html_object_element.c \
html_param_element.c html_applet_element.c html_area_element.c \
html_map_element.c html_script_element.c html_tablecaption_element.c \
- html_tablecell_element.c html_tablecol_element.c html_tablesection_element.c
+ html_tablecell_element.c html_tablecol_element.c html_tablesection_element.c \
+ html_table_element.c html_tablerow_element.c
UNINMPLEMENTED_SOURCES := \
- html_table_element.c \
- html_tablerow_element.c html_frameset_element.c \
+ html_frameset_element.c \
html_frame_element.c html_iframe_element.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/html/TODO b/src/html/TODO
index 50e905c..0a75535 100644
--- a/src/html/TODO
+++ b/src/html/TODO
@@ -46,11 +46,11 @@ HTMLAppletElement html_applet_element DONE
HTMLMapElement html_map_element DONE
HTMLAreaElement html_area_element DONE
HTMLScriptElement html_script_element DONE
-HTMLTableElement html_table_element MISSING
+HTMLTableElement html_table_element DONE
HTMLTableCaptionElement html_tablecaption_element DONE
HTMLTableColElement html_tablecol_element DONE
HTMLTableSectionElement html_tablesection_element DONE
-HTMLTableRowElement html_tablerow_element MISSING
+HTMLTableRowElement html_tablerow_element DONE
HTMLTableCellElement html_tablecell_element DONE
HTMLFrameSetElement html_frameset_element MISSING
HTMLFrameElement html_frame_element MISSING
diff --git a/src/html/html_collection.c b/src/html/html_collection.c
index fb801d9..2b4d8aa 100644
--- a/src/html/html_collection.c
+++ b/src/html/html_collection.c
@@ -132,7 +132,7 @@ dom_exception dom_html_collection_get_length(dom_html_collection *col,
/* No children and siblings */
struct dom_node_internal *parent = node->parent;
- while (parent != col->root &&
+ while (node != col->root &&
node == parent->last_child) {
node = parent;
parent = parent->parent;
diff --git a/src/html/html_document.c b/src/html/html_document.c
index 692dd98..25abca3 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -54,6 +54,8 @@
#include "html/html_tablecell_element.h"
#include "html/html_tablecol_element.h"
#include "html/html_tablesection_element.h"
+#include "html/html_table_element.h"
+#include "html/html_tablerow_element.h"
#include "core/attr.h"
#include "core/string.h"
@@ -350,9 +352,15 @@ _dom_html_document_create_element_internal(dom_html_document *html,
(dom_html_table_col_element **) result);
} else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_THEAD])||
dom_string_caseless_isequal(tag_name, html->memoised[hds_TBODY])||
- dom_string_caseless_isequal(tag_name, html->memoised[hds_TBODY])) {
+ dom_string_caseless_isequal(tag_name, html->memoised[hds_TFOOT])) {
exc = _dom_html_table_section_element_create(html, tag_name, namespace, prefix,
(dom_html_table_section_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TABLE])) {
+ exc = _dom_html_table_element_create(html, namespace, prefix,
+ (dom_html_table_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TD])) {
+ exc = _dom_html_table_row_element_create(html, namespace, prefix,
+ (dom_html_table_row_element **) result);
} else {
exc = _dom_html_element_create(html, tag_name, namespace,
prefix, result);
diff --git a/src/html/html_document_strings.h b/src/html/html_document_strings.h
index 38b0004..8ded892 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -102,6 +102,9 @@ HTML_DOCUMENT_STRINGS_ACTION1(abbr)
HTML_DOCUMENT_STRINGS_ACTION1(axis)
HTML_DOCUMENT_STRINGS_ACTION1(headers)
HTML_DOCUMENT_STRINGS_ACTION1(scope)
+HTML_DOCUMENT_STRINGS_ACTION1(frame)
+HTML_DOCUMENT_STRINGS_ACTION1(rules)
+HTML_DOCUMENT_STRINGS_ACTION1(summary)
HTML_DOCUMENT_STRINGS_ACTION(tab_index,tabindex)
HTML_DOCUMENT_STRINGS_ACTION(html_for,for)
HTML_DOCUMENT_STRINGS_ACTION(date_time,datetime)
@@ -112,6 +115,8 @@ HTML_DOCUMENT_STRINGS_ACTION(value_type,valuetype)
HTML_DOCUMENT_STRINGS_ACTION(v_align,valign)
HTML_DOCUMENT_STRINGS_ACTION(ch,char)
HTML_DOCUMENT_STRINGS_ACTION(ch_off,charoff)
+HTML_DOCUMENT_STRINGS_ACTION(cell_padding,cellpadding)
+HTML_DOCUMENT_STRINGS_ACTION(cell_spacing,cellspacing)
/* HTML_DOCUMENT_STRINGS_ACTION1(type) */
HTML_DOCUMENT_STRINGS_ACTION(use_map,usemap)
/* HTML_DOCUMENT_STRINGS_ACTION1(value) */
diff --git a/src/html/html_table_element.c b/src/html/html_table_element.c
index 2e182d5..0f27fd3 100644
--- a/src/html/html_table_element.c
+++ b/src/html/html_table_element.c
@@ -3,5 +3,745 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar<rsk1coder99@gmail.com>
*/
+#include <assert.h>
+#include <stdlib.h>
+
+#include <dom/html/html_table_element.h>
+
+#include "html/html_document.h"
+#include "html/html_table_element.h"
+#include "html/html_tablecaption_element.h"
+#include "html/html_tablesection_element.h"
+#include "html/html_tablerow_element.h"
+#include "html/html_collection.h"
+
+#include "core/node.h"
+#include "core/attr.h"
+#include "utils/utils.h"
+
+static struct dom_element_protected_vtable _protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_HTML_TABLE_ELEMENT
+ },
+ DOM_HTML_TABLE_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_table_element object
+ *
+ * \param doc The document object
+ * \param ele The returned element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_table_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_table_element));
+ if (*ele == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Set up vtables */
+ node = (struct dom_node_internal *) *ele;
+ node->base.vtable = &_dom_html_element_vtable;
+ node->vtable = &_protect_vtable;
+
+ return _dom_html_table_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_table_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_table_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_table_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_element *ele)
+{
+ ele->caption = NULL;
+ ele->t_head = NULL;
+ ele->t_foot = NULL;
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_TABLE],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_table_element object
+ *
+ * \param ele The dom_html_table_element object
+ */
+void _dom_html_table_element_finalise(struct dom_html_table_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_table_element object
+ *
+ * \param ele The dom_html_table_element object
+ */
+void _dom_html_table_element_destroy(struct dom_html_table_element *ele)
+{
+ _dom_html_table_element_finalise(ele);
+ free(ele);
+}
+
+/*------------------------------------------------------------------------*/
+/* The protected virtual functions */
+
+/* The virtual function used to parse attribute value, see src/core/element.c
+ * for detail */
+dom_exception _dom_html_table_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed)
+{
+ UNUSED(ele);
+ UNUSED(name);
+
+ dom_string_ref(value);
+ *parsed = value;
+
+ return DOM_NO_ERR;
+}
+
+/* The virtual destroy function, see src/core/node.c for detail */
+void _dom_virtual_html_table_element_destroy(dom_node_internal *node)
+{
+ _dom_html_table_element_destroy((struct dom_html_table_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_table_element_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ return _dom_html_element_copy(old, copy);
+}
+
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+#define SIMPLE_GET(attr) \
+ dom_exception dom_html_table_element_get_##attr( \
+ dom_html_table_element *element, \
+ dom_string **attr) \
+{ \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)-> \
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_get_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+}
+#define SIMPLE_SET(attr) \
+ dom_exception dom_html_table_element_set_##attr( \
+ dom_html_table_element *element, \
+ dom_string *attr) \
+{ \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)-> \
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_set_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+}
+
+#define SIMPLE_GET_SET(attr) SIMPLE_GET(attr) SIMPLE_SET(attr)
+SIMPLE_GET_SET(align);
+SIMPLE_GET_SET(bg_color);
+SIMPLE_GET_SET(border);
+SIMPLE_GET_SET(cell_padding);
+SIMPLE_GET_SET(cell_spacing);
+SIMPLE_GET_SET(frame);
+SIMPLE_GET_SET(rules);
+SIMPLE_GET_SET(summary);
+SIMPLE_GET_SET(width);
+
+/**
+ * Get the caption Attribute
+ *
+ * \param table The dom_html_table_element object
+ */
+dom_exception dom_html_table_element_get_caption(
+ dom_html_table_element *table, dom_html_table_caption_element **caption)
+{
+ dom_node_internal *node_tmp = ((dom_node_internal *)table);
+ dom_html_document *doc = (dom_html_document *)(node_tmp->owner);
+
+ if(table->caption == NULL) {
+ for (node_tmp = node_tmp->first_child; node_tmp != NULL; node_tmp = node_tmp->next) {
+ if((node_tmp->type == DOM_ELEMENT_NODE) &&
+ dom_string_caseless_isequal(doc->memoised[hds_CAPTION],node_tmp->name)) {
+ break;
+ }
+ }
+ table->caption = (dom_html_table_caption_element *)node_tmp;
+ }
+ *caption = (table->caption);
+ return DOM_NO_ERR;
+}
+
+/**
+ * Set the caption Attribute
+ *
+ * \param table The dom_html_table_element object
+ * \param table The dom_html_table_element object
+ */
+dom_exception dom_html_table_element_set_caption(
+ dom_html_table_element *table, dom_html_table_caption_element *caption)
+{
+ dom_node_internal *check_node = ((dom_node_internal *)caption);
+ dom_html_document *doc = (dom_html_document *)(((dom_node_internal *)table)->owner);
+ if(check_node == NULL) {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ if(!dom_string_caseless_isequal(doc->memoised[hds_CAPTION],check_node->name)) {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ table->caption = caption;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get the t_head Attribute
+ *
+ * \param table The dom_html_table_element object
+ */
+dom_exception dom_html_table_element_get_t_head(
+ dom_html_table_element *table, dom_html_table_section_element **t_head)
+{
+ dom_node_internal *node_tmp = ((dom_node_internal *)table);
+ dom_html_document *doc = (dom_html_document *)(node_tmp->owner);
+
+ if(table->t_head == NULL) {
+ for (node_tmp = node_tmp->first_child; node_tmp != NULL; node_tmp = node_tmp->next) {
+ if((node_tmp->type == DOM_ELEMENT_NODE) &&
+ dom_string_caseless_isequal(doc->memoised[hds_THEAD],node_tmp->name)) {
+ break;
+ }
+ }
+ table->t_head = (dom_html_table_section_element *)node_tmp;
+ }
+ *t_head = table->t_head;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Set the t_head Attribute
+ *
+ * \param table The dom_html_table_element object
+ * \param table The dom_html_table_element object
+ */
+dom_exception dom_html_table_element_set_t_head(
+ dom_html_table_element *table, dom_html_table_section_element *t_head)
+{
+ dom_node_internal *check_node = ((dom_node_internal *)t_head);
+ dom_html_document *doc = (dom_html_document *)(((dom_node_internal *)table)->owner);
+ if(check_node == NULL) {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ if(!dom_string_caseless_isequal(doc->memoised[hds_CAPTION],check_node->name)) {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ table->t_head = t_head;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get the t_foot Attribute
+ *
+ * \param table The dom_html_table_element object
+ */
+dom_exception dom_html_table_element_get_t_foot(
+ dom_html_table_element *table, dom_html_table_section_element **t_foot)
+{
+ dom_node_internal *node_tmp = ((dom_node_internal *)table);
+ dom_html_document *doc = (dom_html_document *)(node_tmp->owner);
+
+ if(table->t_foot == NULL) {
+ for (node_tmp = node_tmp->first_child; node_tmp != NULL; node_tmp = node_tmp->next) {
+ if((node_tmp->type == DOM_ELEMENT_NODE) &&
+ dom_string_caseless_isequal(doc->memoised[hds_TFOOT],node_tmp->name)) {
+ break;
+ }
+ }
+ table->t_foot = (dom_html_table_section_element *)node_tmp;
+ }
+ *t_foot = (table->t_foot);
+ return DOM_NO_ERR;
+}
+
+/**
+ * Set the t_foot Attribute
+ *
+ * \param table The dom_html_table_element object
+ */
+dom_exception dom_html_table_element_set_t_foot(
+ dom_html_table_element *table, dom_html_table_section_element *t_foot)
+{
+ dom_node_internal *check_node = ((dom_node_internal *)t_foot); /*< temporary node to check for raised exceptions */
+ dom_html_document *doc = (dom_html_document *)(((dom_node_internal *)table)->owner);
+ if(check_node == NULL) {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ if(!dom_string_caseless_isequal(doc->memoised[hds_TFOOT],check_node->name)) {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ table->t_foot = t_foot;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Callback for creating the rows collection
+ *
+ * \param node The dom_html_table_element object
+ * \param ctx The dom_html_document object (void *)
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+bool table_rows_callback(struct dom_node_internal *node, void *ctx)
+{
+ if(node->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(node->name,
+ ((dom_html_document *)ctx)->memoised[hds_TR])) {
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Get the rows collection
+ *
+ * \param element The dom_html_table_element object
+ * \param rows The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_get_rows(
+ dom_html_table_element *element,
+ dom_html_collection **rows)
+{
+ dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) element)->owner;
+ return _dom_html_collection_create(doc, (dom_node_internal *)element,
+ table_rows_callback, (void *)doc, rows);
+}
+
+/**
+ * Callback for creating the tbodies collection
+ *
+ * \param node The dom_html_table_element object
+ * \param ctx The dom_html_document object (void *)
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+bool table_t_bodies_callback(struct dom_node_internal *node, void *ctx)
+{
+ if(node->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(node->name,
+ ((dom_html_document *)ctx)->memoised[hds_TBODY])) {
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Get the tBodies collection
+ *
+ * \param element The dom_html_table_element object
+ * \param t_bodies The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_get_t_bodies(
+ dom_html_table_element *element,
+ dom_html_collection **t_bodies)
+{
+ dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) element)->owner;
+ return _dom_html_collection_create(doc, (dom_node_internal *)element,
+ table_t_bodies_callback, (void *)doc, t_bodies);
+}
+
+/**
+ * Get or Create the table caption
+ *
+ * \param element The dom_html_table_element object
+ * \param caption The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_create_caption(
+ dom_html_table_element *element,
+ dom_html_element **caption)
+{
+ dom_exception exp;
+ if((exp = dom_html_table_element_get_caption(element,
+ (dom_html_table_caption_element **)caption)) != DOM_NO_ERR) {
+ return exp;
+ }
+ if((*caption) == NULL) {
+ dom_html_document *doc = (dom_html_document *)
+ ((dom_node_internal *) element)->owner;
+ exp = _dom_html_table_caption_element_create(doc,
+ ((dom_node_internal *)element)->namespace,
+ ((dom_node_internal *)element)->prefix,
+ (dom_html_table_caption_element **)caption);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+ _dom_node_append_child((dom_node_internal *)element,
+ (dom_node_internal *)*caption,
+ (dom_node_internal **)caption);
+ element->caption = (dom_html_table_caption_element *)*caption;
+
+ }
+ return DOM_NO_ERR;
+}
+
+/**
+ * Delete the table caption, if one exists
+ *
+ * \param element The dom_html_table_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_delete_caption(
+ dom_html_table_element *element)
+{
+ dom_html_table_caption_element *caption;
+ dom_html_table_element_get_caption(element, &caption);
+ _dom_node_remove_child((dom_node_internal *)element,
+ (dom_node_internal *)caption,
+ (dom_node_internal **)&caption);
+ element->caption = NULL;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get or Create the table Foot
+ *
+ * \param element The dom_html_table_element object
+ * \param t_foot The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_create_t_foot(
+ dom_html_table_element *element,
+ dom_html_element **t_foot)
+{
+ dom_exception exp;
+ exp = dom_html_table_element_get_t_foot(element,
+ (dom_html_table_section_element **)t_foot);
+ if(exp !=DOM_NO_ERR) {
+ return exp;
+ }
+ if((*t_foot) == NULL) {
+ dom_html_document *doc = (dom_html_document *)
+ ((dom_node_internal *) element)->owner;
+ exp = _dom_html_table_section_element_create(doc,
+ doc->memoised[hds_TFOOT],
+ ((dom_node_internal *)element)->namespace,
+ ((dom_node_internal *)element)->prefix,
+ (dom_html_table_section_element **)t_foot);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+ _dom_node_append_child((dom_node_internal *)element,
+ (dom_node_internal *)*t_foot,
+ (dom_node_internal **)t_foot);
+ element->t_foot = (dom_html_table_section_element *)*t_foot;
+
+ }
+ return DOM_NO_ERR;
+}
+
+/**
+ * Delete the table Foot, if one exists
+ *
+ * \param element The dom_html_table_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_delete_t_foot(
+ dom_html_table_element *element)
+{
+ dom_html_table_section_element *t_foot;
+ dom_html_table_element_get_t_foot(element, &t_foot);
+ _dom_node_remove_child((dom_node_internal *)element,
+ (dom_node_internal *)t_foot,
+ (dom_node_internal **)&t_foot);
+ element->t_foot = NULL;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get or Create the table Head
+ *
+ * \param element The dom_html_table_element object
+ * \param t_head The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_create_t_head(
+ dom_html_table_element *element,
+ dom_html_element **t_head)
+{
+ dom_html_table_element_get_t_head(element,
+ (dom_html_table_section_element **)t_head);
+ if((*t_head) == NULL) {
+ dom_exception exp;
+ dom_html_document *doc = (dom_html_document *)
+ ((dom_node_internal *) element)->owner;
+ exp = _dom_html_table_section_element_create(doc,
+ doc->memoised[hds_THEAD],
+ ((dom_node_internal *)element)->namespace,
+ ((dom_node_internal *)element)->prefix,
+ (dom_html_table_section_element **)t_head);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+ _dom_node_append_child((dom_node_internal *)element,
+ (dom_node_internal *)*t_head,
+ (dom_node_internal **)t_head);
+ element->t_head = (dom_html_table_section_element *)*t_head;
+
+ }
+ return DOM_NO_ERR;
+}
+
+/**
+ * Delete the table Head, if one exists
+ *
+ * \param element The dom_html_table_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_delete_t_head(
+ dom_html_table_element *element)
+{
+ dom_html_table_section_element *t_head;
+ dom_html_table_element_get_t_head(element, &t_head);
+ _dom_node_remove_child((dom_node_internal *)element,
+ (dom_node_internal *)t_head,
+ (dom_node_internal **)&t_head);
+ element->t_head = NULL;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get or Create the table Body
+ *
+ * \param element The dom_html_table_element object
+ * \param t_head The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_create_t_body(
+ dom_html_table_element *element,
+ dom_html_table_section_element **t_body)
+{
+ dom_html_collection *t_bodies;
+ uint32_t len;
+ dom_html_table_element_get_t_bodies(element,
+ &t_bodies);
+ dom_html_collection_get_length(t_bodies,
+ &len);
+
+ if(len == 0) {
+ dom_exception exp;
+ dom_html_document *doc = (dom_html_document *)
+ ((dom_node_internal *) element)->owner;
+ exp = _dom_html_table_section_element_create(doc,
+ doc->memoised[hds_TBODY],
+ ((dom_node_internal *)element)->namespace,
+ ((dom_node_internal *)element)->prefix,
+ t_body);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+ return _dom_node_append_child((dom_node_internal *)element,
+ (dom_node_internal *)*t_body,
+ (dom_node_internal **)t_body);
+
+ } else {
+ return dom_html_collection_item(t_bodies,
+ 0, (dom_node **)t_body);
+ }
+ return DOM_NO_ERR;
+}
+/**
+ * Insert a new Row into the table
+ *
+ * \param element The dom_html_table_element object
+ * \param index The Index to insert the Row
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_insert_row(
+ dom_html_table_element *element,
+ int32_t index,
+ dom_html_element **row)
+{
+ dom_exception exp;
+ dom_html_collection* rows;
+ uint32_t len;
+ dom_html_document *doc = (dom_html_document *)
+ ((dom_node_internal *) element)->owner;
+
+ exp = dom_html_table_element_get_rows(element,
+ &rows);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+ exp = dom_html_collection_get_length(rows,
+ &len);
+
+ exp = _dom_html_table_row_element_create(doc,
+ ((dom_node_internal *)element)->namespace,
+ ((dom_node_internal *)element)->prefix,
+ (dom_html_table_row_element **)row);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+
+ if(index > (int32_t)len || index < -1) {
+ return DOM_INDEX_SIZE_ERR;
+ } else if(len == 0) {
+ dom_html_table_section_element *new_body;
+ exp = dom_html_table_element_create_t_body(element,
+ &new_body);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+
+ return _dom_node_append_child((dom_node_internal *)new_body,
+ (dom_node_internal *)*row,
+ (dom_node_internal **)row);
+
+ } else {
+ if(index ==-1) {
+ index = (int32_t)len;
+ }
+
+ dom_html_collection* rows;
+ dom_html_table_section_element *t_head;
+ dom_html_table_section_element *t_foot;
+ uint32_t window_len = 0, section_len;
+
+ dom_html_table_element_get_t_head(element, &t_head);
+ dom_html_table_section_element_get_rows(t_head, &rows);
+ dom_html_collection_get_length(rows, &section_len);
+
+ if(window_len + section_len > (uint32_t)index ||
+ window_len + section_len == len) {
+ return dom_html_table_section_element_insert_row(t_head,
+ index-window_len, row);
+ }
+
+ window_len += section_len;
+
+ dom_node_internal *n = (dom_node_internal *)element;
+
+ for (n = n->first_child; n != NULL; n = n->next) {
+ if((n->type == DOM_ELEMENT_NODE) &&
+ dom_string_caseless_isequal(doc->memoised[hds_TBODY],n->name)) {
+
+ dom_html_table_section_element_get_rows((dom_html_table_section_element *)n, &rows);
+ dom_html_collection_get_length(rows, &section_len);
+
+ if(window_len + section_len > (uint32_t)index ||
+ window_len + section_len == len) {
+ return dom_html_table_section_element_insert_row(
+ (dom_html_table_section_element *)n,
+ index-window_len, row);
+ }
+
+ window_len += section_len;
+ }
+ }
+ dom_html_table_element_get_t_foot(element, &t_foot);
+ dom_html_table_section_element_get_rows(t_foot, &rows);
+ dom_html_collection_get_length(rows, &section_len);
+ if(window_len + section_len > (uint32_t)index ||
+ window_len +section_len == len) {
+ return dom_html_table_section_element_insert_row(t_foot,
+ index-window_len, row);
+ }
+ return DOM_INDEX_SIZE_ERR;
+ }
+}
+/**
+ * Delete the table Head, if one exists
+ *
+ * \param element The dom_html_table_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_element_delete_row(
+ dom_html_table_element *element,
+ int32_t index)
+{
+ dom_exception exp;
+ dom_html_collection* rows;
+ uint32_t len;
+ dom_html_document *doc = (dom_html_document *)
+ ((dom_node_internal *) element)->owner;
+
+ exp = dom_html_table_element_get_rows(element,
+ &rows);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+ exp = dom_html_collection_get_length(rows,
+ &len);
+
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+
+ if(index >= (int32_t)len || index < -1 || len ==0) {
+ return DOM_INDEX_SIZE_ERR;
+ } else {
+ if(index ==-1) {
+ index = (int32_t)len-1;
+ }
+ dom_html_collection* rows;
+ dom_html_table_section_element *t_head;
+ dom_html_table_section_element *t_foot;
+ uint32_t window_len = 0, section_len;
+ dom_html_table_element_get_t_head(element, &t_head);
+ dom_html_table_section_element_get_rows(t_head, &rows);
+ dom_html_collection_get_length(rows, &section_len);
+ if(window_len + section_len > (uint32_t)index) {
+ return dom_html_table_section_element_delete_row(t_head,
+ index-window_len);
+ }
+ window_len += section_len;
+ dom_node_internal *n = (dom_node_internal *)element;
+ for (n = n->first_child; n != NULL; n = n->next) {
+ if((n->type == DOM_ELEMENT_NODE) &&
+ dom_string_caseless_isequal(doc->memoised[hds_TBODY],n->name)) {
+ dom_html_table_section_element_get_rows((dom_html_table_section_element *)n, &rows);
+ dom_html_collection_get_length(rows, &section_len);
+ if(window_len + section_len > (uint32_t)index) {
+ return dom_html_table_section_element_delete_row(
+ (dom_html_table_section_element *)n,
+ index-window_len);
+ }
+ window_len += section_len;
+ }
+ }
+ exp = dom_html_table_element_get_t_foot(element, &t_foot);
+ dom_html_table_section_element_get_rows(t_foot, &rows);
+ dom_html_collection_get_length(rows, &section_len);
+ if(window_len + section_len > (uint32_t)index) {
+ return dom_html_table_section_element_delete_row(t_foot,
+ index-window_len);
+ }
+ return DOM_INDEX_SIZE_ERR;
+ }
+
+}
diff --git a/src/html/html_table_element.h b/src/html/html_table_element.h
index 2e182d5..caabbe8 100644
--- a/src/html/html_table_element.h
+++ b/src/html/html_table_element.h
@@ -3,5 +3,61 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar <rsk1coder99@gmail.com>
*/
+#ifndef dom_internal_html_table_element_h_
+#define dom_internal_html_table_element_h_
+
+#include <dom/html/html_table_element.h>
+#include "html/html_element.h"
+
+struct dom_html_table_element {
+ struct dom_html_element base;
+ /**< The base class */
+ dom_html_table_caption_element* caption;
+ /**< The caption associated with the table*/
+ dom_html_table_section_element* t_head;
+ /**< The thead element associated with the table*/
+ dom_html_table_section_element* t_foot;
+ /**< The tfoot element associated with the table*/
+};
+
+/* Create a dom_html_table_element object */
+dom_exception _dom_html_table_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_element **ele);
+
+/* Initialise a dom_html_table_element object */
+dom_exception _dom_html_table_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_element *ele);
+
+/* Finalise a dom_html_table_element object */
+void _dom_html_table_element_finalise(struct dom_html_table_element *ele);
+
+/* Destroy a dom_html_table_element object */
+void _dom_html_table_element_destroy(struct dom_html_table_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_table_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_table_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_table_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_TABLE_ELEMENT_PROTECT_VTABLE \
+ _dom_html_table_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_TABLE_ELEMENT \
+ _dom_virtual_html_table_element_destroy, \
+ _dom_html_table_element_copy
+
+#endif
+
+bool table_rows_callback(struct dom_node_internal *node, void *ctx);
+bool table_t_bodies_callback(struct dom_node_internal *node, void *ctx);
+dom_exception dom_html_table_element_create_t_body(
+ dom_html_table_element *element,
+ dom_html_table_section_element **t_body);
diff --git a/src/html/html_tablecell_element.c b/src/html/html_tablecell_element.c
index f8eaf01..cc596c1 100644
--- a/src/html/html_tablecell_element.c
+++ b/src/html/html_tablecell_element.c
@@ -191,6 +191,7 @@ dom_exception dom_html_table_cell_element_get_cell_index(
}
n = n->parent;
}
+ dom_node_internal *root = n;
while(n != NULL) {
if(n == (dom_node_internal *)table_cell) {
break;
@@ -207,18 +208,16 @@ dom_exception dom_html_table_cell_element_get_cell_index(
} 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;
- }
-
+ while (n == parent->last_child &&
+ n != root) {
+ n = parent;
+ parent = parent->parent;
}
- if(parent == NULL) {
+
+ if(n == root) {
n = NULL;
+ } else {
+ n = n->next;
}
}
}
diff --git a/src/html/html_tablerow_element.c b/src/html/html_tablerow_element.c
index 2e182d5..fb3e27b 100644
--- a/src/html/html_tablerow_element.c
+++ b/src/html/html_tablerow_element.c
@@ -3,5 +3,373 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar <rsk1coder99@gmail.com>
*/
+#include <assert.h>
+#include <stdlib.h>
+
+#include <dom/html/html_tablerow_element.h>
+#include <dom/html/html_table_element.h>
+
+#include "html/html_document.h"
+#include "html/html_tablerow_element.h"
+#include "html/html_collection.h"
+
+#include "core/node.h"
+#include "core/attr.h"
+#include "utils/utils.h"
+
+static struct dom_element_protected_vtable _protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_HTML_TABLE_ROW_ELEMENT
+ },
+ DOM_HTML_TABLE_ROW_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_table_row_element table_row
+ *
+ * \param doc The document table_row
+ * \param ele The returned element table_row
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_table_row_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_row_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_table_row_element));
+ if (*ele == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Set up vtables */
+ node = (struct dom_node_internal *) *ele;
+ node->base.vtable = &_dom_html_element_vtable;
+ node->vtable = &_protect_vtable;
+
+ return _dom_html_table_row_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_table_row_element table_row
+ *
+ * \param doc The document table_row
+ * \param ele The dom_html_table_row_element table_row
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_table_row_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_row_element *ele)
+{
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_TR],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_table_row_element table_row
+ *
+ * \param ele The dom_html_table_row_element table_row
+ */
+void _dom_html_table_row_element_finalise(struct dom_html_table_row_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_table_row_element table_row
+ *
+ * \param ele The dom_html_table_row_element table_row
+ */
+void _dom_html_table_row_element_destroy(struct dom_html_table_row_element *ele)
+{
+ _dom_html_table_row_element_finalise(ele);
+ free(ele);
+}
+
+/*------------------------------------------------------------------------*/
+/* The protected virtual functions */
+
+/* The virtual function used to parse attribute value, see src/core/element.c
+ * for detail */
+dom_exception _dom_html_table_row_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed)
+{
+ UNUSED(ele);
+ UNUSED(name);
+
+ dom_string_ref(value);
+ *parsed = value;
+
+ return DOM_NO_ERR;
+}
+
+/* The virtual destroy function, see src/core/node.c for detail */
+void _dom_virtual_html_table_row_element_destroy(dom_node_internal *node)
+{
+ _dom_html_table_row_element_destroy((struct dom_html_table_row_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_table_row_element_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ return _dom_html_element_copy(old, copy);
+}
+
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+#define SIMPLE_GET(attr) \
+ dom_exception dom_html_table_row_element_get_##attr( \
+ dom_html_table_row_element *element, \
+ dom_string **attr) \
+{ \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_get_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+}
+#define SIMPLE_SET(attr) \
+ dom_exception dom_html_table_row_element_set_##attr( \
+ dom_html_table_row_element *element, \
+ dom_string *attr) \
+{ \
+ dom_exception ret; \
+ dom_string *_memo_##attr; \
+ \
+ _memo_##attr = \
+ ((struct dom_html_document *) \
+ ((struct dom_node_internal *)element)->owner)->\
+ memoised[hds_##attr]; \
+ \
+ ret = dom_element_set_attribute(element, _memo_##attr, attr); \
+ \
+ return ret; \
+}
+
+#define SIMPLE_GET_SET(attr) SIMPLE_GET(attr) SIMPLE_SET(attr)
+
+SIMPLE_GET_SET(align);
+SIMPLE_GET_SET(bg_color);
+SIMPLE_GET_SET(ch);
+SIMPLE_GET_SET(ch_off);
+SIMPLE_GET_SET(v_align);
+
+/**
+ * Get the index of the Row in logical order
+ *
+ * \param element The dom_html_table_row_element object
+ * \param index The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_row_element_get_row_index(
+ dom_html_table_row_element *table_row, int32_t *row_index)
+{
+ dom_node_internal *n = ((dom_node_internal *)table_row)->parent;
+ dom_node_internal *parent = n;
+ dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) table_row)->owner;
+ uint32_t count = 0;
+ for(n = n->first_child; n != (dom_node_internal *)table_row;
+ n = n->next) {
+ if(n->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(n->name,doc->memoised[hds_TR])) {
+ count += 1;
+ }
+ }
+
+ if(dom_string_caseless_isequal((parent->parent)->name, doc->memoised[hds_TABLE]) &&
+ dom_string_caseless_isequal(parent->name, doc->memoised[hds_THEAD])
+ ) {
+ *row_index = count;
+ }else if(dom_string_caseless_isequal((parent->parent)->name, doc->memoised[hds_TABLE]) &&
+ (dom_string_caseless_isequal(parent->name, doc->memoised[hds_TBODY]) ||
+ dom_string_caseless_isequal(parent->name, doc->memoised[hds_TFOOT]))) {
+ uint32_t len;
+ n = parent->parent;
+ dom_html_table_section_element *t_head;
+ dom_html_collection *rows;
+ dom_html_table_element_get_t_head(
+ (dom_html_table_element *)(parent->parent),
+ &t_head);
+ dom_html_table_section_element_get_rows(t_head,
+ &rows);
+ dom_html_collection_get_length(rows,
+ &len);
+ count += len;
+ for(n = n->first_child;n != parent && n != NULL;
+ n = n->next) {
+ if(dom_string_caseless_isequal(n->name, doc->memoised[hds_TBODY])) {
+ dom_html_table_section_element_get_rows(
+ (dom_html_table_section_element *)n,
+ &rows);
+ dom_html_collection_get_length(rows, &len);
+ count += len;
+ }
+ }
+ *row_index = (int32_t)count;
+
+ } else {
+ return DOM_HIERARCHY_REQUEST_ERR;
+ }
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get the index of a row within its Section
+ *
+ * \param element The dom_html_table_row_element object
+ * \param index The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_row_element_get_section_row_index(
+ dom_html_table_row_element *table_row, int32_t *section_row_index)
+{
+ dom_node_internal *n = ((dom_node_internal *)table_row)->parent;
+ dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) table_row)->owner;
+ int32_t count = 0;
+ for(n = n->first_child; n != (dom_node_internal *)table_row;
+ n = n->next) {
+ if(n->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(n->name, doc->memoised[hds_TR])) {
+ count += 1;
+ }
+ }
+ *section_row_index = count;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Callback for creating the Cells collection
+ *
+ * \param node The dom_node_internal object
+ * \param ctx The dom_html_document object (void *)
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+bool table_cells_callback(struct dom_node_internal *node, void *ctx)
+{
+ if(node->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(node->name,
+ ((dom_html_document *)ctx)->memoised[hds_TD])) {
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Get the Cells collection
+ *
+ * \param element The dom_html_table_element object
+ * \param t_bodies The Status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_row_element_get_cells(
+ dom_html_table_row_element *element,
+ dom_html_collection **cells)
+{
+ dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) element)->owner;
+ return _dom_html_collection_create(doc, (dom_node_internal *)element,
+ table_cells_callback, (void *)doc, cells);
+}
+
+/**
+ * Insert Cell before the given Index
+ *
+ * \param element The dom_html_table_row_element object
+ * \param index The Index of the Cell node to be inserted
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_row_element_insert_cell(
+ dom_html_table_row_element *element,
+ int32_t index, dom_html_element **cell) {
+ dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) element)->owner;
+
+ dom_node *node; /*< The node at the (index)th position*/
+
+ dom_html_collection *cells; /*< The collection of cells in input table_row_element*/
+ uint32_t len; /*< The size of the cell collection */
+ dom_exception exp; /*< Variable for getting the exceptions*/
+ exp = _dom_html_element_create(doc, doc->memoised[hds_TD],
+ ((dom_node_internal *)element)->namespace,
+ ((dom_node_internal *)element)->prefix,
+ cell);
+ if(exp != DOM_NO_ERR)
+ return exp;
+
+ exp = dom_html_table_row_element_get_cells(element, &cells);
+ if(exp != DOM_NO_ERR)
+ return exp;
+
+ exp = dom_html_collection_get_length(cells, &len);
+ if(exp != DOM_NO_ERR)
+ return exp;
+
+ if(index < -1 || index > (int32_t)len) {
+ /* Check for index validity */
+ return DOM_INDEX_SIZE_ERR;
+ } else if(index == -1 || index == (int32_t)len) {
+ return _dom_node_append_child((dom_node_internal *)element,
+ (dom_node_internal *)*cell,
+ (dom_node_internal **)cell);
+ } else {
+ dom_html_collection_item(cells,
+ index, &node);
+ return _dom_node_insert_before((dom_node_internal *)element,
+ (dom_node_internal *)*cell, (dom_node_internal *)node,
+ (dom_node_internal **)cell);
+ }
+}
+
+/**
+ * Delete Cell at given Index
+ *
+ * \param element The dom_html_table_row_element object
+ * \param index The Index of the Cell node to be deleted
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_row_element_delete_cell(
+ dom_html_table_row_element *element,
+ int32_t index) {
+ dom_node *node; /*< The node at the (index)th position*/
+
+ dom_html_collection *cells; /*< The collection of rows in input table_row_element*/
+ uint32_t len; /*< The size of the row collection */
+
+ dom_exception exp; /*< Temporary variable to store & check the exceptions*/
+
+ exp = dom_html_table_row_element_get_cells(element, &cells);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+
+ exp = dom_html_collection_get_length(cells, &len);
+ if(exp != DOM_NO_ERR) {
+ return exp;
+ }
+
+ if(index < -1 || index >= (int32_t)len || len ==0) {
+ /* Check for index validity */
+ return DOM_INDEX_SIZE_ERR;
+ } else if(index == -1) {
+ exp = dom_html_collection_item(cells,
+ len-1, &node);
+ } else {
+ exp = dom_html_collection_item(cells,
+ index, &node);
+ }
+ return _dom_node_remove_child((dom_node_internal *)element,
+ (dom_node_internal *)node,
+ (dom_node_internal **)&node);
+
+}
+
diff --git a/src/html/html_tablerow_element.h b/src/html/html_tablerow_element.h
index 2e182d5..2401790 100644
--- a/src/html/html_tablerow_element.h
+++ b/src/html/html_tablerow_element.h
@@ -3,5 +3,51 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2014 Rupinder Singh Khokhar <rsk1coder99@gmail.com>
*/
+#ifndef dom_internal_html_table_row_element_h_
+#define dom_internal_html_table_row_element_h_
+
+#include <dom/html/html_tablerow_element.h>
+#include "html/html_element.h"
+
+struct dom_html_table_row_element {
+ struct dom_html_element base;
+ /**< The base class */
+};
+
+/* Create a dom_html_table_row_element object */
+dom_exception _dom_html_table_row_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_row_element **ele);
+
+/* Initialise a dom_html_table_row_element object */
+dom_exception _dom_html_table_row_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_row_element *ele);
+
+/* Finalise a dom_html_table_row_element object */
+void _dom_html_table_row_element_finalise(struct dom_html_table_row_element *ele);
+
+/* Destroy a dom_html_table_row_element object */
+void _dom_html_table_row_element_destroy(struct dom_html_table_row_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_table_row_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_table_row_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_table_row_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_TABLE_ROW_ELEMENT_PROTECT_VTABLE \
+ _dom_html_table_row_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_TABLE_ROW_ELEMENT \
+ _dom_virtual_html_table_row_element_destroy, \
+ _dom_html_table_row_element_copy
+
+#endif
+bool table_cells_callback(struct dom_node_internal *node, void *ctx);
+
diff --git a/src/html/html_tablesection_element.c b/src/html/html_tablesection_element.c
index 7468d01..b35cfb4 100644
--- a/src/html/html_tablesection_element.c
+++ b/src/html/html_tablesection_element.c
@@ -12,6 +12,7 @@
#include "html/html_document.h"
#include "html/html_tablesection_element.h"
+#include "html/html_tablerow_element.h"
#include "html/html_collection.h"
#include "html/html_element.h"
@@ -169,8 +170,7 @@ bool table_section_callback(struct dom_node_internal *node, void *ctx)
{
if(node->type == DOM_ELEMENT_NODE &&
dom_string_caseless_isequal(node->name,
- ((dom_html_document *)ctx)->memoised[hds_TR]))
- {
+ ((dom_html_document *)ctx)->memoised[hds_TR])) {
return true;
}
return false;
@@ -179,7 +179,7 @@ bool table_section_callback(struct dom_node_internal *node, void *ctx)
/**
* Get the rows collection
*
- * \param element The dom_html_section_element object
+ * \param element The dom_html_table_section_element object
* \param rows The Status
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
@@ -188,21 +188,20 @@ dom_exception dom_html_table_section_element_get_rows(
dom_html_collection **rows)
{
dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) element)->owner;
- _dom_html_collection_create(doc, (dom_node_internal *)element,
+ return _dom_html_collection_create(doc, (dom_node_internal *)element,
table_section_callback, (void *)doc, rows);
- return DOM_NO_ERR;
}
/**
* Insert Row before the given Index
*
- * \param element The dom_html_section_element object
+ * \param element The dom_html_table_section_element object
* \param index The Index of the Row node to be inserted
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception dom_html_table_section_element_insert_row(
dom_html_table_section_element *element,
- int32_t index, dom_html_element **newRow) {
+ int32_t index, dom_html_element **new_row) {
dom_html_document *doc = (dom_html_document *) ((dom_node_internal *) element)->owner;
dom_node *node; /*< The node at the (index)th position*/
@@ -210,10 +209,10 @@ dom_exception dom_html_table_section_element_insert_row(
dom_html_collection *rows; /*< The collection of rows in input table_section_element*/
uint32_t len; /*< The size of the row collection */
dom_exception exp; /*< Variable for getting the exceptions*/
- exp = _dom_html_element_create(doc, doc->memoised[hds_TR],
+ exp = _dom_html_table_row_element_create(doc,
((dom_node_internal *)element)->namespace,
((dom_node_internal *)element)->prefix,
- newRow);
+ (dom_html_table_row_element **)new_row);
if(exp != DOM_NO_ERR)
return exp;
@@ -225,47 +224,26 @@ dom_exception dom_html_table_section_element_insert_row(
if(exp != DOM_NO_ERR)
return exp;
- if(index < -1 || (uint32_t)index > len) {
+ if(index < -1 || index > (int32_t)len) {
/* Check for index validity */
return DOM_INDEX_SIZE_ERR;
- } else if((index == -1 || (uint32_t)index == len)
- &&len != 0) {
- dom_html_collection_item(rows,
- len-1, &node);
-
- dom_node_internal *internal_node = (dom_node_internal *)node; /*< The dom_node_internal row object at the (len-1)th position*/
-
- ((dom_node_internal *) *newRow)->next = internal_node->next;
- ((dom_node_internal *) *newRow)->previous = internal_node;
- internal_node->next = (dom_node_internal *)*newRow;
- } else if(len != 0) {
+ } else if(index == -1 || index == (int32_t)len) {
+ return _dom_node_append_child((dom_node_internal *)element,
+ (dom_node_internal *)*new_row,
+ (dom_node_internal **)new_row);
+ } else {
dom_html_collection_item(rows,
index, &node);
-
- dom_node_internal *internal_node = (dom_node_internal *)node; /*< The dom_node_internal row object at the (index)th position*/
-
- ((dom_node_internal *) *newRow)->next = internal_node;
- ((dom_node_internal *) *newRow)->previous = internal_node->previous;
- if(internal_node->previous != NULL) {
- (internal_node->previous)->next = (dom_node_internal *)*newRow;
- internal_node->previous = (dom_node_internal *)*newRow;
- }
+ return _dom_node_insert_before((dom_node_internal *)element,
+ (dom_node_internal *)*new_row, (dom_node_internal *)node,
+ (dom_node_internal **)new_row);
}
-
- /*Adjust parent's pointers*/
- ((dom_node_internal *) *newRow)->parent = (dom_node_internal *)element;
- if(index == 0)
- ((dom_node_internal *)element)->first_child = (dom_node_internal *)*newRow;
- if((uint32_t)index == len)
- ((dom_node_internal *)element)->last_child = (dom_node_internal *)*newRow;
-
- return DOM_NO_ERR;
}
/**
* Delete Row at given Index
*
- * \param element The dom_html_section_element object
+ * \param element The dom_html_table_section_element object
* \param index The Index of the Row node to be deleted
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
@@ -289,7 +267,7 @@ dom_exception dom_html_table_section_element_delete_row(
return exp;
}
- if(index < -1 || (uint32_t)index >= len) {
+ if(index < -1 || index >= (int32_t)len) {
/* Check for index validity */
return DOM_INDEX_SIZE_ERR;
} else if(index == -1) {
@@ -299,20 +277,9 @@ dom_exception dom_html_table_section_element_delete_row(
exp = dom_html_collection_item(rows,
index, &node);
}
- if(exp != DOM_NO_ERR)
- return exp;
-
- dom_node_internal *internal_node = (dom_node_internal *)node;
-
- /*Fixing the sibling pointers*/
- if(internal_node->previous != NULL) {
- (internal_node->previous)->next = internal_node->next;
- }
- if(internal_node->next != NULL) {
- (internal_node->next)->previous = internal_node->previous;
- }
-
- _dom_html_element_destroy(internal_node);
+ exp = _dom_node_remove_child((dom_node_internal *)element,
+ (dom_node_internal *)node,
+ (dom_node_internal **)&node);
return DOM_NO_ERR;
}
diff --git a/src/html/html_tablesection_element.h b/src/html/html_tablesection_element.h
index fcab1cb..387882a 100644
--- a/src/html/html_tablesection_element.h
+++ b/src/html/html_tablesection_element.h
@@ -10,8 +10,8 @@
#define dom_internal_html_table_section_element_h_
#include <dom/html/html_tablesection_element.h>
-#include "html/html_element.h"
+#include "html/html_element.h"
struct dom_html_table_section_element {
struct dom_html_element base;