summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsk1994 <rsk1coder99@gmail.com>2014-05-09 15:17:13 (GMT)
committer Rupinder Singh Khokhar <rsk1coder99@gmail.com>2014-06-10 22:57:05 (GMT)
commit75f10df52d1edd40fda31cabc359da35680389d0 (patch)
tree744dd65c582e91d95612f0340ca1485d77cff8df
parent1ea759971d89fdb7bb8f20206cef27c2ea0c15b9 (diff)
downloadlibdom-75f10df52d1edd40fda31cabc359da35680389d0.tar.gz
libdom-75f10df52d1edd40fda31cabc359da35680389d0.tar.bz2
Label Element
-rw-r--r--Makefile1
-rw-r--r--include/dom/dom.h1
-rw-r--r--include/dom/html/html_label_element.h26
-rw-r--r--src/html/Makefile4
-rw-r--r--src/html/TODO4
-rw-r--r--src/html/html_document.c4
-rw-r--r--src/html/html_document_strings.h1
-rw-r--r--src/html/html_label_element.c187
-rw-r--r--src/html/html_label_element.h47
-rw-r--r--test/testcases/tests/level1/html/HTMLLabelElement01.xml (renamed from test/testcases/tests/level1/html/HTMLLabelElement01.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLabelElement02.xml (renamed from test/testcases/tests/level1/html/HTMLLabelElement02.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLabelElement03.xml (renamed from test/testcases/tests/level1/html/HTMLLabelElement03.xml.kfail)0
-rw-r--r--test/testcases/tests/level1/html/HTMLLabelElement04.xml (renamed from test/testcases/tests/level1/html/HTMLLabelElement04.xml.kfail)0
13 files changed, 271 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index a9b7388..de937e9 100644
--- a/Makefile
+++ b/Makefile
@@ -108,6 +108,7 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_heading_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_quote_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_pre_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_br_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_label_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR)/pkgconfig:lib$(COMPONENT).pc.in
INSTALL_ITEMS := $(INSTALL_ITEMS) /$(LIBDIR):$(OUTPUT)
diff --git a/include/dom/dom.h b/include/dom/dom.h
index 4c5ba09..8035622 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -67,6 +67,7 @@
#include <dom/html/html_quote_element.h>
#include <dom/html/html_pre_element.h>
#include <dom/html/html_br_element.h>
+#include <dom/html/html_label_element.h>
/* DOM Events header */
#include <dom/events/events.h>
diff --git a/include/dom/html/html_label_element.h b/include/dom/html/html_label_element.h
index 2e182d5..6aca45d 100644
--- a/include/dom/html/html_label_element.h
+++ b/include/dom/html/html_label_element.h
@@ -5,3 +5,29 @@
* Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
*/
+#ifndef dom_html_label_element_h_
+#define dom_html_label_element_h_
+
+#include <stdbool.h>
+
+#include <dom/core/exceptions.h>
+
+#include <dom/html/html_form_element.h>
+
+typedef struct dom_html_label_element dom_html_label_element;
+
+dom_exception dom_html_label_element_get_access_key(
+ dom_html_label_element *ele, dom_string **access_key);
+dom_exception dom_html_label_element_set_access_key(
+ dom_html_label_element *ele, dom_string *access_key);
+
+dom_exception dom_html_label_element_get_html_for(
+ dom_html_label_element *ele, dom_string **html_for);
+dom_exception dom_html_label_element_set_html_for(
+ dom_html_label_element *ele, dom_string *html_for);
+
+dom_exception dom_html_label_element_get_form(
+ dom_html_label_element *ele, dom_html_form_element **form);
+
+#endif
+
diff --git a/src/html/Makefile b/src/html/Makefile
index 632e581..a682418 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -10,10 +10,10 @@ DIR_SOURCES := \
html_dlist_element.c html_directory_element.c html_menu_element.c \
html_fieldset_element.c html_legend_element.c html_div_element.c \
html_paragraph_element.c html_heading_element.c html_quote_element.c \
- html_pre_element.c html_br_element.c
+ html_pre_element.c html_br_element.c html_label_element.c
UNINMPLEMENTED_SOURCES := \
- html_label_element.c html_ulist_element.c html_olist_element.c \
+ html_ulist_element.c html_olist_element.c \
html_li_element.c html_basefont_element.c html_font_element.c \
html_mod_element.c html_anchor_element.c \
html_image_element.c html_object_element.c html_param_element.c \
diff --git a/src/html/TODO b/src/html/TODO
index 8753087..19be8a4 100644
--- a/src/html/TODO
+++ b/src/html/TODO
@@ -18,7 +18,7 @@ HTMLOptionElement html_option_element MISSING
HTMLInputElement html_input_element MISSING
HTMLTextAreaElement html_textarea_element MISSING
HTMLButtonElement html_button_element MISSING
-HTMLLabelElement html_label_element MISSING
+HTMLLabelElement html_label_element DONE
HTMLFieldSetElement html_fieldset_element DONE
HTMLLegendElement html_legend_element DONE
HTMLUListElement html_ulist_element MISSING
@@ -33,7 +33,7 @@ HTMLParagraphElement html_paragraph_element MISSING
HTMLHeadingElement html_heading_element DONE
HTMLQuoteElement html_quote_element DONE
HTMLPreElement html_pre_element DONE
-HTMLBRElement html_br_element MISSING
+HTMLBRElement html_br_element DONE
HTMLBaseFontElement html_basefont_element MISSING
HTMLFontElement html_font_element MISSING
HTMLHRElement html_hr_element DONE
diff --git a/src/html/html_document.c b/src/html/html_document.c
index e2ac1f3..07f155e 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -35,6 +35,7 @@
#include "html/html_quote_element.h"
#include "html/html_pre_element.h"
#include "html/html_br_element.h"
+#include "html/html_label_element.h"
#include "core/attr.h"
#include "core/string.h"
@@ -270,6 +271,9 @@ _dom_html_document_create_element_internal(dom_html_document *html,
} else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_BR])) {
exc = _dom_html_br_element_create(html, namespace, prefix,
(dom_html_br_element **) result);
+ } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_LABEL])) {
+ exc = _dom_html_label_element_create(html, namespace, prefix,
+ (dom_html_label_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 e7af1b9..d160971 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -86,6 +86,7 @@ HTML_DOCUMENT_STRINGS_ACTION1(width)
HTML_DOCUMENT_STRINGS_ACTION1(compact)
HTML_DOCUMENT_STRINGS_ACTION1(cite)
HTML_DOCUMENT_STRINGS_ACTION(tab_index,tabindex)
+HTML_DOCUMENT_STRINGS_ACTION(html_for,for)
/* HTML_DOCUMENT_STRINGS_ACTION1(type) */
HTML_DOCUMENT_STRINGS_ACTION(use_map,usemap)
/* HTML_DOCUMENT_STRINGS_ACTION1(value) */
diff --git a/src/html/html_label_element.c b/src/html/html_label_element.c
index 2e182d5..1ffbf71 100644
--- a/src/html/html_label_element.c
+++ b/src/html/html_label_element.c
@@ -3,5 +3,192 @@
* 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 "html/html_document.h"
+#include "html/html_label_element.h"
+
+#include "core/node.h"
+#include "utils/utils.h"
+
+static struct dom_element_protected_vtable _protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_HTML_LABEL_ELEMENT
+ },
+ DOM_HTML_LABEL_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_label_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_label_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_label_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_label_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_label_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_label_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_label_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_label_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_label_element *ele)
+{
+ ele->form = NULL;
+
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_LABEL],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_label_element object
+ *
+ * \param ele The dom_html_label_element object
+ */
+void _dom_html_label_element_finalise(struct dom_html_label_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_label_element object
+ *
+ * \param ele The dom_html_label_element object
+ */
+void _dom_html_label_element_destroy(struct dom_html_label_element *ele)
+{
+ _dom_html_label_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_label_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_label_element_destroy(dom_node_internal *node)
+{
+ _dom_html_label_element_destroy((struct dom_html_label_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_label_element_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ return _dom_html_element_copy(old, copy);
+}
+
+/**
+ * Get the dom_html_form_element object
+ *
+ * \param label The dom_html_label_element object
+ * \param form The returned dom_htmlform_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_label_element_get_form(
+ dom_html_label_element *label, dom_html_form_element **form)
+{
+ dom_html_document *doc
+ = (dom_html_document *) ((dom_node_internal *) label)->owner;
+ dom_node_internal *form_tmp = ((dom_node_internal *) label)->parent;
+
+ /* Search ancestor chain for FIELDSET element */
+ while (form_tmp != NULL) {
+ if (form_tmp->type == DOM_ELEMENT_NODE &&
+ dom_string_caseless_isequal(form_tmp->name,
+ doc->memoised[hds_FORM]))
+ break;
+
+ form_tmp = form_tmp->parent;
+ }
+
+ if (form_tmp != NULL) {
+ *form = (dom_html_form_element *) form_tmp;
+ return DOM_NO_ERR;
+ }
+
+ *form = NULL;
+
+ return DOM_NO_ERR;
+}
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+#define SIMPLE_GET(attr) \
+ dom_exception dom_html_label_element_get_##attr( \
+ dom_html_label_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_label_element_set_##attr( \
+ dom_html_label_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(access_key);
+SIMPLE_GET_SET(html_for);
+
diff --git a/src/html/html_label_element.h b/src/html/html_label_element.h
index 2e182d5..b5ec3f4 100644
--- a/src/html/html_label_element.h
+++ b/src/html/html_label_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_label_element_h_
+#define dom_internal_html_label_element_h_
+
+#include <dom/html/html_label_element.h>
+#include "html/html_element.h"
+
+
+struct dom_html_label_element {
+ struct dom_html_element base;
+ /**< The base class */
+ dom_html_form_element *form;
+ /**< The form associated with label */
+};
+
+/* Create a dom_html_label_element object */
+dom_exception _dom_html_label_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_label_element **ele);
+
+/* Initialise a dom_html_label_element object */
+dom_exception _dom_html_label_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_label_element *ele);
+
+/* Finalise a dom_html_label_element object */
+void _dom_html_label_element_finalise(struct dom_html_label_element *ele);
+
+/* Destroy a dom_html_label_element object */
+void _dom_html_label_element_destroy(struct dom_html_label_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_label_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_label_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_label_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_LABEL_ELEMENT_PROTECT_VTABLE \
+ _dom_html_label_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_LABEL_ELEMENT \
+ _dom_virtual_html_label_element_destroy, \
+ _dom_html_label_element_copy
+
+#endif
diff --git a/test/testcases/tests/level1/html/HTMLLabelElement01.xml.kfail b/test/testcases/tests/level1/html/HTMLLabelElement01.xml
index 2111d6e..2111d6e 100644
--- a/test/testcases/tests/level1/html/HTMLLabelElement01.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLabelElement01.xml
diff --git a/test/testcases/tests/level1/html/HTMLLabelElement02.xml.kfail b/test/testcases/tests/level1/html/HTMLLabelElement02.xml
index 444a753..444a753 100644
--- a/test/testcases/tests/level1/html/HTMLLabelElement02.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLabelElement02.xml
diff --git a/test/testcases/tests/level1/html/HTMLLabelElement03.xml.kfail b/test/testcases/tests/level1/html/HTMLLabelElement03.xml
index b4daacf..b4daacf 100644
--- a/test/testcases/tests/level1/html/HTMLLabelElement03.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLabelElement03.xml
diff --git a/test/testcases/tests/level1/html/HTMLLabelElement04.xml.kfail b/test/testcases/tests/level1/html/HTMLLabelElement04.xml
index ae22b88..ae22b88 100644
--- a/test/testcases/tests/level1/html/HTMLLabelElement04.xml.kfail
+++ b/test/testcases/tests/level1/html/HTMLLabelElement04.xml