summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrsk1994 <rsk1coder99@gmail.com>2014-05-19 06:52:56 +0530
committerRupinder Singh Khokhar <rsk1coder99@gmail.com>2014-06-11 04:27:10 +0530
commit1dd1c7617aae1a4bd285d83a3c73d5d2f53761d7 (patch)
tree9f939c0616a1761e4db2a0ec5ab788b224713641 /src
parent3c9d9494222d81c207cc09a7686cca50db109c0b (diff)
downloadlibdom-1dd1c7617aae1a4bd285d83a3c73d5d2f53761d7.tar.gz
libdom-1dd1c7617aae1a4bd285d83a3c73d5d2f53761d7.tar.bz2
TableCell Element & possible bug fix on TableCaption ELement
Diffstat (limited to 'src')
-rw-r--r--src/html/Makefile5
-rw-r--r--src/html/TODO2
-rw-r--r--src/html/html_document.c6
-rw-r--r--src/html/html_document_strings.h7
-rw-r--r--src/html/html_tablecell_element.c282
-rw-r--r--src/html/html_tablecell_element.h47
6 files changed, 346 insertions, 3 deletions
diff --git a/src/html/Makefile b/src/html/Makefile
index 1de0190..fcf326f 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -15,11 +15,12 @@ DIR_SOURCES := \
html_font_element.c html_mod_element.c html_anchor_element.c \
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_map_element.c html_script_element.c html_tablecaption_element.c \
+ html_tablecell_element.c
UNINMPLEMENTED_SOURCES := \
html_table_element.c html_tablecol_element.c html_tablesection_element.c \
- html_tablerow_element.c html_tablecell_element.c html_frameset_element.c \
+ html_tablerow_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 52dfafe..584de0e 100644
--- a/src/html/TODO
+++ b/src/html/TODO
@@ -51,7 +51,7 @@ HTMLTableCaptionElement html_tablecaption_element DONE
HTMLTableColElement html_tablecol_element MISSING
HTMLTableSectionElement html_tablesection_element MISSING
HTMLTableRowElement html_tablerow_element MISSING
-HTMLTableCellElement html_tablecell_element MISSING
+HTMLTableCellElement html_tablecell_element DONE
HTMLFrameSetElement html_frameset_element MISSING
HTMLFrameElement html_frame_element MISSING
HTMLIFrameElement html_iframe_element MISSING
diff --git a/src/html/html_document.c b/src/html/html_document.c
index 6eda5e8..939b031 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -51,6 +51,7 @@
#include "html/html_area_element.h"
#include "html/html_script_element.h"
#include "html/html_tablecaption_element.h"
+#include "html/html_tablecell_element.h"
#include "core/attr.h"
#include "core/string.h"
@@ -335,6 +336,11 @@ _dom_html_document_create_element_internal(dom_html_document *html,
} else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_CAPTION])) {
exc = _dom_html_table_caption_element_create(html, namespace, prefix,
(dom_html_table_caption_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TD]) ||
+ dom_string_caseless_isequal(tag_name, html->memoised[hds_TH])
+ ) {
+ exc = _dom_html_table_cell_element_create(html, tag_name, namespace, prefix,
+ (dom_html_table_cell_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 8ed3bb2..38b0004 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -98,6 +98,10 @@ HTML_DOCUMENT_STRINGS_ACTION1(standby)
HTML_DOCUMENT_STRINGS_ACTION1(object)
HTML_DOCUMENT_STRINGS_ACTION1(event)
HTML_DOCUMENT_STRINGS_ACTION1(defer)
+HTML_DOCUMENT_STRINGS_ACTION1(abbr)
+HTML_DOCUMENT_STRINGS_ACTION1(axis)
+HTML_DOCUMENT_STRINGS_ACTION1(headers)
+HTML_DOCUMENT_STRINGS_ACTION1(scope)
HTML_DOCUMENT_STRINGS_ACTION(tab_index,tabindex)
HTML_DOCUMENT_STRINGS_ACTION(html_for,for)
HTML_DOCUMENT_STRINGS_ACTION(date_time,datetime)
@@ -105,6 +109,9 @@ HTML_DOCUMENT_STRINGS_ACTION(long_desc,longdesc)
HTML_DOCUMENT_STRINGS_ACTION(code_base,codebase)
HTML_DOCUMENT_STRINGS_ACTION(code_type,codetype)
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_ACTION1(type) */
HTML_DOCUMENT_STRINGS_ACTION(use_map,usemap)
/* HTML_DOCUMENT_STRINGS_ACTION1(value) */
diff --git a/src/html/html_tablecell_element.c b/src/html/html_tablecell_element.c
index 2e182d5..6317686 100644
--- a/src/html/html_tablecell_element.c
+++ b/src/html/html_tablecell_element.c
@@ -3,5 +3,287 @@
* 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_tablecell_element.h>
+
+#include "html/html_document.h"
+#include "html/html_tablecell_element.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_CELL_ELEMENT
+ },
+ DOM_HTML_TABLE_CELL_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_table_cell_element table_cell
+ *
+ * \param doc The document table_cell
+ * \param ele The returned element table_cell
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_table_cell_element_create(struct dom_html_document *doc,
+ dom_string *tag_name, dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_cell_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_table_cell_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_cell_element_initialise(doc, tag_name, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_table_cell_element table_cell
+ *
+ * \param doc The document table_cell
+ * \param ele The dom_html_table_cell_element table_cell
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_table_cell_element_initialise(struct dom_html_document *doc,
+ dom_string *tag_name, dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_cell_element *ele)
+{
+ ele->id = -1;
+ return _dom_html_element_initialise(doc, &ele->base,
+ tag_name,
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_table_cell_element table_cell
+ *
+ * \param ele The dom_html_table_cell_element table_cell
+ */
+void _dom_html_table_cell_element_finalise(struct dom_html_table_cell_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_table_cell_element table_cell
+ *
+ * \param ele The dom_html_table_cell_element table_cell
+ */
+void _dom_html_table_cell_element_destroy(struct dom_html_table_cell_element *ele)
+{
+ _dom_html_table_cell_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_cell_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_cell_element_destroy(dom_node_internal *node)
+{
+ _dom_html_table_cell_element_destroy((struct dom_html_table_cell_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_table_cell_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_cell_element_get_##attr( \
+ dom_html_table_cell_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_cell_element_set_##attr( \
+ dom_html_table_cell_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(abbr);
+SIMPLE_GET_SET(align);
+SIMPLE_GET_SET(axis);
+SIMPLE_GET_SET(bg_color);
+SIMPLE_GET_SET(ch);
+SIMPLE_GET_SET(ch_off);
+SIMPLE_GET_SET(headers);
+SIMPLE_GET_SET(height);
+SIMPLE_GET_SET(scope);
+SIMPLE_GET_SET(v_align);
+SIMPLE_GET_SET(width);
+
+/**
+ * Get the cell_index property
+ *
+ * \param table_cell The dom_html_table_cell_element object
+ * \param cell_index The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_get_cell_index(
+ dom_html_table_cell_element *table_cell, int32_t *cell_index)
+{
+ if(table_cell->id == -1) {
+ 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) {
+
+ if(n == (dom_node_internal *)table_cell) {
+ break;
+ } else if((n->type == DOM_ELEMENT_NODE) &&
+ (dom_string_caseless_isequal(doc->memoised[hds_TD],n->name) ||
+ dom_string_caseless_isequal(doc->memoised[hds_TH],n->name))) {
+ cnt += 1;
+ }
+
+ }
+ table_cell->id = cnt;
+ }
+ *cell_index = table_cell->id;
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get the col_span property
+ *
+ * \param table_cell The dom_html_table_cell_element object
+ * \param no_wrap The returned status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_get_col_span(
+ dom_html_table_cell_element *table_cell, int32_t *col_span)
+{
+ return dom_html_element_get_int32_t_property(&table_cell->base, "colspan",
+ SLEN("colspan"), col_span);
+}
+
+/**
+ * Set the col_span property
+ *
+ * \param table_cell The dom_html_table_cell_element object
+ * \param no_wrap The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_set_col_span(
+ dom_html_table_cell_element *table_cell, uint32_t col_span)
+{
+ return dom_html_element_set_int32_t_property(&table_cell->base, "colspan",
+ SLEN("colspan"), col_span);
+}
+
+/**
+ * Get the row_span property
+ *
+ * \param table_cell The dom_html_table_cell_element object
+ * \param no_wrap The returned status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_get_row_span(
+ dom_html_table_cell_element *table_cell, int32_t *row_span)
+{
+ return dom_html_element_get_int32_t_property(&table_cell->base, "rowspan",
+ SLEN("rowspan"), row_span);
+}
+
+/**
+ * Set the row_span property
+ *
+ * \param table_cell The dom_html_table_cell_element object
+ * \param no_wrap The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_set_row_span(
+ dom_html_table_cell_element *table_cell, uint32_t row_span)
+{
+ return dom_html_element_set_int32_t_property(&table_cell->base, "rowspan",
+ SLEN("rowspan"), row_span);
+}
+
+/**
+ * Get the no_wrap property
+ *
+ * \param ele The dom_html_table_cell_element object
+ * \param no_wrap The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_get_no_wrap(dom_html_table_cell_element *ele,
+ bool *no_wrap)
+{
+ return dom_html_element_get_bool_property(&ele->base, "nowrap",
+ SLEN("nowrap"), no_wrap);
+}
+
+/**
+ * Set the no_wrap property
+ *
+ * \param ele The dom_html_table_cell_element object
+ * \param no_wrap The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_table_cell_element_set_no_wrap(dom_html_table_cell_element *ele,
+ bool no_wrap)
+{
+ return dom_html_element_set_bool_property(&ele->base, "nowrap",
+ SLEN("nowrap"), no_wrap);
+}
+
diff --git a/src/html/html_tablecell_element.h b/src/html/html_tablecell_element.h
index 2e182d5..801c3c0 100644
--- a/src/html/html_tablecell_element.h
+++ b/src/html/html_tablecell_element.h
@@ -3,5 +3,52 @@
* 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_cell_element_h_
+#define dom_internal_html_table_cell_element_h_
+
+#include <dom/html/html_tablecell_element.h>
+#include "html/html_element.h"
+
+
+struct dom_html_table_cell_element {
+ struct dom_html_element base;
+ /**< The base class */
+ int32_t id;
+ /**< The Index Associated with the cell*/
+};
+
+/* Create a dom_html_table_cell_element object */
+dom_exception _dom_html_table_cell_element_create(struct dom_html_document *doc,
+ dom_string *tag_name, dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_cell_element **ele);
+
+/* Initialise a dom_html_table_cell_element object */
+dom_exception _dom_html_table_cell_element_initialise(struct dom_html_document *doc,
+ dom_string *tag_name, dom_string *namespace, dom_string *prefix,
+ struct dom_html_table_cell_element *ele);
+
+/* Finalise a dom_html_table_cell_element object */
+void _dom_html_table_cell_element_finalise(struct dom_html_table_cell_element *ele);
+
+/* Destroy a dom_html_table_cell_element object */
+void _dom_html_table_cell_element_destroy(struct dom_html_table_cell_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_table_cell_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_table_cell_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_table_cell_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_TABLE_CELL_ELEMENT_PROTECT_VTABLE \
+ _dom_html_table_cell_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_TABLE_CELL_ELEMENT \
+ _dom_virtual_html_table_cell_element_destroy, \
+ _dom_html_table_cell_element_copy
+
+#endif