summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dom/html/html_opt_group_element.h28
-rw-r--r--src/html/html_document.c6
-rw-r--r--src/html/html_document_strings.h2
-rw-r--r--src/html/html_opt_group_element.c186
-rw-r--r--src/html/html_opt_group_element.h46
5 files changed, 265 insertions, 3 deletions
diff --git a/include/dom/html/html_opt_group_element.h b/include/dom/html/html_opt_group_element.h
index 2e182d5..a356275 100644
--- a/include/dom/html/html_opt_group_element.h
+++ b/include/dom/html/html_opt_group_element.h
@@ -2,6 +2,32 @@
* This file is part of libdom.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2012 Daniel Silverstone <dsilvers@netsurf-browser.org>
*/
+#ifndef dom_html_opt_group_element_h_
+#define dom_html_opt_group_element_h_
+
+#include <stdbool.h>
+#include <dom/core/exceptions.h>
+#include <dom/core/string.h>
+#include <dom/html/html_form_element.h>
+
+typedef struct dom_html_opt_group_element dom_html_opt_group_element;
+
+dom_exception dom_html_opt_group_element_get_form(
+ dom_html_opt_group_element *opt_group, dom_html_form_element **form);
+
+dom_exception dom_html_opt_group_element_get_disabled(
+ dom_html_opt_group_element *opt_group, bool *disabled);
+
+dom_exception dom_html_opt_group_element_set_disabled(
+ dom_html_opt_group_element *opt_group, bool disabled);
+
+dom_exception dom_html_opt_group_element_get_label(
+ dom_html_opt_group_element *opt_group, dom_string **label);
+
+dom_exception dom_html_opt_group_element_set_label(
+ dom_html_opt_group_element *opt_group, dom_string *label);
+
+#endif
diff --git a/src/html/html_document.c b/src/html/html_document.c
index ec88ebc..a2a7ed5 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -20,6 +20,7 @@
#include "html/html_button_element.h"
#include "html/html_input_element.h"
#include "html/html_text_area_element.h"
+#include "html/html_opt_group_element.h"
#include "core/string.h"
#include "utils/namespace.h"
@@ -207,6 +208,11 @@ _dom_html_document_create_element_internal(dom_html_document *html,
(dom_html_text_area_element **) result);
}
+ if (dom_string_caseless_isequal(tag_name, html->memoised[hds_OPTGROUP])) {
+ return _dom_html_opt_group_element_create(html, namespace, prefix,
+ (dom_html_opt_group_element **) result);
+ }
+
return _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 f1ff04d..f7ecf4e 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -79,6 +79,8 @@ HTML_DOCUMENT_STRINGS_ACTION(use_map,usemap)
/* HTML_DOCUMENT_STRINGS_ACTION1(value) */
/* HTMLTextAreaElement type */
HTML_DOCUMENT_STRINGS_ACTION1(textarea)
+/* HTMLOptGroupElement attributes */
+HTML_DOCUMENT_STRINGS_ACTION1(label)
/* Names for elements which get specialised. */
HTML_DOCUMENT_STRINGS_ACTION1(HTML)
HTML_DOCUMENT_STRINGS_ACTION1(HEAD)
diff --git a/src/html/html_opt_group_element.c b/src/html/html_opt_group_element.c
index 2e182d5..cb0c207 100644
--- a/src/html/html_opt_group_element.c
+++ b/src/html/html_opt_group_element.c
@@ -2,6 +2,190 @@
* This file is part of libdom.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2012 Daniel Silverstone <dsilvers@netsurf-browser.org>
*/
+#include <assert.h>
+#include <stdlib.h>
+
+#include <dom/html/html_opt_group_element.h>
+
+#include "html/html_document.h"
+#include "html/html_opt_group_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_OPT_GROUP_ELEMENT
+ },
+ DOM_HTML_OPT_GROUP_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_opt_group_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_opt_group_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_opt_group_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_opt_group_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_opt_group_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_opt_group_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_opt_group_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_opt_group_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_opt_group_element *ele)
+{
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_OPTGROUP],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_opt_group_element object
+ *
+ * \param ele The dom_html_opt_group_element object
+ */
+void _dom_html_opt_group_element_finalise(struct dom_html_opt_group_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_opt_group_element object
+ *
+ * \param ele The dom_html_opt_group_element object
+ */
+void _dom_html_opt_group_element_destroy(struct dom_html_opt_group_element *ele)
+{
+ _dom_html_opt_group_element_finalise(ele);
+ free(ele);
+}
+
+/*-----------------------------------------------------------------------*/
+/* Public APIs */
+
+/**
+ * Get the disabled property
+ *
+ * \param ele The dom_html_opt_group_element object
+ * \param disabled The returned status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_opt_group_element_get_disabled(dom_html_opt_group_element *ele,
+ bool *disabled)
+{
+ return dom_html_element_get_bool_property(&ele->base, "disabled",
+ SLEN("disabled"), disabled);
+}
+
+/**
+ * Set the disabled property
+ *
+ * \param ele The dom_html_opt_group_element object
+ * \param disabled The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_opt_group_element_set_disabled(dom_html_opt_group_element *ele,
+ bool disabled)
+{
+ return dom_html_element_set_bool_property(&ele->base, "disabled",
+ SLEN("disabled"), disabled);
+}
+
+/*------------------------------------------------------------------------*/
+/* The protected virtual functions */
+
+/* The virtual function used to parse attribute value, see src/core/element.c
+ * for detail */
+dom_exception _dom_html_opt_group_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_opt_group_element_destroy(dom_node_internal *node)
+{
+ _dom_html_opt_group_element_destroy((struct dom_html_opt_group_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_opt_group_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_opt_group_element_get_##attr( \
+ dom_html_opt_group_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_opt_group_element_set_##attr( \
+ dom_html_opt_group_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(label);
diff --git a/src/html/html_opt_group_element.h b/src/html/html_opt_group_element.h
index 2e182d5..c7f8c13 100644
--- a/src/html/html_opt_group_element.h
+++ b/src/html/html_opt_group_element.h
@@ -2,6 +2,50 @@
* This file is part of libdom.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
+ * Copyright 2012 Daniel Silverstone <dsilvers@netsurf-browser.org>
*/
+#ifndef dom_internal_html_opt_group_element_h_
+#define dom_internal_html_opt_group_element_h_
+
+#include <dom/html/html_opt_group_element.h>
+
+#include "html/html_element.h"
+
+struct dom_html_opt_group_element {
+ struct dom_html_element base;
+ /**< The base class */
+};
+
+/* Create a dom_html_opt_group_element object */
+dom_exception _dom_html_opt_group_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_opt_group_element **ele);
+
+/* Initialise a dom_html_opt_group_element object */
+dom_exception _dom_html_opt_group_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_opt_group_element *ele);
+
+/* Finalise a dom_html_opt_group_element object */
+void _dom_html_opt_group_element_finalise(struct dom_html_opt_group_element *ele);
+
+/* Destroy a dom_html_opt_group_element object */
+void _dom_html_opt_group_element_destroy(struct dom_html_opt_group_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_opt_group_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_opt_group_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_opt_group_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_OPT_GROUP_ELEMENT_PROTECT_VTABLE \
+ _dom_html_opt_group_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_OPT_GROUP_ELEMENT \
+ _dom_virtual_html_opt_group_element_destroy, \
+ _dom_html_opt_group_element_copy
+
+#endif