summaryrefslogtreecommitdiff
path: root/src/html
diff options
context:
space:
mode:
Diffstat (limited to 'src/html')
-rw-r--r--src/html/Makefile5
-rw-r--r--src/html/html_button_element.c232
-rw-r--r--src/html/html_button_element.h54
-rw-r--r--src/html/html_collection.c15
-rw-r--r--src/html/html_collection.h7
-rw-r--r--src/html/html_document.c9
-rw-r--r--src/html/html_document_strings.h5
-rw-r--r--src/html/html_element.c102
-rw-r--r--src/html/html_element.h5
-rw-r--r--src/html/html_form_element.c28
-rw-r--r--src/html/html_options_collection.c8
-rw-r--r--src/html/html_options_collection.h3
-rw-r--r--src/html/html_select_element.c12
13 files changed, 454 insertions, 31 deletions
diff --git a/src/html/Makefile b/src/html/Makefile
index 203f828..2210ece 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -4,11 +4,12 @@ DIR_SOURCES := \
html_element.c html_html_element.c html_head_element.c \
html_link_element.c html_title_element.c html_meta_element.c \
html_base_element.c html_isindex_element.c html_style_element.c \
- html_body_element.c html_form_element.c html_select_element.c
+ html_body_element.c html_form_element.c html_select_element.c \
+ html_button_element.c
UNINMPLEMENTED_SOURCES := html_optgroup_element.c \
html_option_element.c html_input_element.c html_textarea_element.c \
- html_button_element.c html_label_element.c html_fieldset_element.c \
+ html_label_element.c html_fieldset_element.c \
html_legend_element.c html_ulist_element.c html_olist_element.c \
html_dlist_element.c html_directory_element.c html_menu_element.c \
html_li_element.c html_div_element.c html_paragraph_element.c \
diff --git a/src/html/html_button_element.c b/src/html/html_button_element.c
index 2e182d5..d914ae3 100644
--- a/src/html/html_button_element.c
+++ b/src/html/html_button_element.c
@@ -2,6 +2,236 @@
* 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_button_element.h>
+
+#include "html/html_document.h"
+#include "html/html_button_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_BUTTON_ELEMENT
+ },
+ DOM_HTML_BUTTON_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_button_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_button_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_button_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_button_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_button_element_initialise(doc, namespace, prefix, *ele);
+}
+
+/**
+ * Initialise a dom_html_button_element object
+ *
+ * \param doc The document object
+ * \param ele The dom_html_button_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_button_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_button_element *ele)
+{
+ return _dom_html_element_initialise(doc, &ele->base,
+ doc->memoised[hds_BUTTON],
+ namespace, prefix);
+}
+
+/**
+ * Finalise a dom_html_button_element object
+ *
+ * \param ele The dom_html_button_element object
+ */
+void _dom_html_button_element_finalise(struct dom_html_button_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_button_element object
+ *
+ * \param ele The dom_html_button_element object
+ */
+void _dom_html_button_element_destroy(struct dom_html_button_element *ele)
+{
+ _dom_html_button_element_finalise(ele);
+ free(ele);
+}
+
+/*-----------------------------------------------------------------------*/
+/* Public APIs */
+
+/**
+ * Get the disabled property
+ *
+ * \param ele The dom_html_button_element object
+ * \param disabled The returned status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_button_element_get_disabled(dom_html_button_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_button_element object
+ * \param disabled The status
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_button_element_set_disabled(dom_html_button_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_button_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_button_element_destroy(dom_node_internal *node)
+{
+ _dom_html_button_element_destroy((struct dom_html_button_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_button_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_button_element_get_##attr( \
+ dom_html_button_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_button_element_set_##attr( \
+ dom_html_button_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(name);
+SIMPLE_GET(type);
+SIMPLE_GET_SET(value);
+
+dom_exception dom_html_button_element_get_tab_index(
+ dom_html_button_element *button, unsigned long *tab_index)
+{
+ return dom_html_element_get_long_property(&button->base, "tabindex",
+ SLEN("tabindex"), tab_index);
+}
+
+dom_exception dom_html_button_element_set_tab_index(
+ dom_html_button_element *button, unsigned long tab_index)
+{
+ return dom_html_element_set_long_property(&button->base, "tabindex",
+ SLEN("tabindex"), tab_index);
+}
+
+dom_exception dom_html_button_element_get_form(
+ dom_html_button_element *button, dom_html_form_element **form)
+{
+ *form = button->form;
+
+ if (*form != NULL)
+ dom_node_ref(*form);
+
+ return DOM_NO_ERR;
+}
+
+dom_exception _dom_html_button_element_set_form(
+ dom_html_button_element *button, dom_html_form_element *form)
+{
+ if (button->form == form)
+ return DOM_NO_ERR;
+
+ if (button->form != NULL)
+ dom_node_unref(button->form);
+
+ button->form = form;
+
+ if (button->form != NULL)
+ dom_node_ref(button->form);
+
+ return DOM_NO_ERR;
+}
+
diff --git a/src/html/html_button_element.h b/src/html/html_button_element.h
index 2e182d5..18d0250 100644
--- a/src/html/html_button_element.h
+++ b/src/html/html_button_element.h
@@ -2,6 +2,58 @@
* 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_button_element_h_
+#define dom_internal_html_button_element_h_
+
+#include <dom/html/html_button_element.h>
+
+#include "html/html_element.h"
+
+struct dom_html_button_element {
+ struct dom_html_element base;
+ /**< The base class */
+ struct dom_html_form_element *form;
+ /**< The form associated with the button */
+};
+
+/* Create a dom_html_button_element object */
+dom_exception _dom_html_button_element_create(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_button_element **ele);
+
+/* Initialise a dom_html_button_element object */
+dom_exception _dom_html_button_element_initialise(struct dom_html_document *doc,
+ dom_string *namespace, dom_string *prefix,
+ struct dom_html_button_element *ele);
+
+/* Finalise a dom_html_button_element object */
+void _dom_html_button_element_finalise(struct dom_html_button_element *ele);
+
+/* Destroy a dom_html_button_element object */
+void _dom_html_button_element_destroy(struct dom_html_button_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_button_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+void _dom_virtual_html_button_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_button_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_BUTTON_ELEMENT_PROTECT_VTABLE \
+ _dom_html_button_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_BUTTON_ELEMENT \
+ _dom_virtual_html_button_element_destroy, \
+ _dom_html_button_element_copy
+
+/* Internal function for bindings */
+
+dom_exception _dom_html_button_element_set_form(
+ dom_html_button_element *button, dom_html_form_element *form);
+
+#endif
+
diff --git a/src/html/html_collection.c b/src/html/html_collection.c
index 7fe6d06..1e43940 100644
--- a/src/html/html_collection.c
+++ b/src/html/html_collection.c
@@ -32,13 +32,14 @@
dom_exception _dom_html_collection_create(struct dom_html_document *doc,
struct dom_node_internal *root,
dom_callback_is_in_collection ic,
+ void *ctx,
struct dom_html_collection **col)
{
*col = malloc(sizeof(dom_html_collection));
if (*col == NULL)
return DOM_NO_MEM_ERR;
- return _dom_html_collection_initialise(doc, *col, root, ic);
+ return _dom_html_collection_initialise(doc, *col, root, ic, ctx);
}
/**
@@ -54,7 +55,7 @@ dom_exception _dom_html_collection_create(struct dom_html_document *doc,
dom_exception _dom_html_collection_initialise(struct dom_html_document *doc,
struct dom_html_collection *col,
struct dom_node_internal *root,
- dom_callback_is_in_collection ic)
+ dom_callback_is_in_collection ic, void *ctx)
{
assert(doc != NULL);
assert(ic != NULL);
@@ -67,6 +68,7 @@ dom_exception _dom_html_collection_initialise(struct dom_html_document *doc,
dom_node_ref(root);
col->ic = ic;
+ col->ctx = ctx;
col->refcnt = 1;
return DOM_NO_ERR;
@@ -117,7 +119,8 @@ dom_exception dom_html_collection_get_length(dom_html_collection *col,
*len = 0;
while (node != NULL) {
- if (node->type == DOM_ELEMENT_NODE && col->ic(node) == true)
+ if (node->type == DOM_ELEMENT_NODE &&
+ col->ic(node, col->ctx) == true)
(*len)++;
/* Depth first iterating */
@@ -160,7 +163,8 @@ dom_exception dom_html_collection_item(dom_html_collection *col,
unsigned long len = 0;
while (n != NULL) {
- if (n->type == DOM_ELEMENT_NODE && col->ic(n) == true)
+ if (n->type == DOM_ELEMENT_NODE &&
+ col->ic(n, col->ctx) == true)
len++;
if (len == index + 1) {
@@ -213,7 +217,8 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col,
while (*node != NULL) {
assert(n != NULL);
- if (n->type == DOM_ELEMENT_NODE && col->ic(n) == true) {
+ if (n->type == DOM_ELEMENT_NODE &&
+ col->ic(n, col->ctx) == true) {
dom_string *id = NULL;
err = _dom_element_get_id((struct dom_element *) n,
diff --git a/src/html/html_collection.h b/src/html/html_collection.h
index 634d2d3..23d149b 100644
--- a/src/html/html_collection.h
+++ b/src/html/html_collection.h
@@ -12,7 +12,8 @@
struct dom_node_internal;
-typedef bool (*dom_callback_is_in_collection)(struct dom_node_internal *node);
+typedef bool (*dom_callback_is_in_collection)(
+ struct dom_node_internal *node, void *ctx);
/**
* The html_collection structure
@@ -23,6 +24,7 @@ struct dom_html_collection {
* whether some node is an element of
* this collection
*/
+ void *ctx; /**< Context for the callback */
struct dom_html_document *doc; /**< The document created this
* collection
*/
@@ -35,12 +37,13 @@ struct dom_html_collection {
dom_exception _dom_html_collection_create(struct dom_html_document *doc,
struct dom_node_internal *root,
dom_callback_is_in_collection ic,
+ void *ctx,
struct dom_html_collection **col);
dom_exception _dom_html_collection_initialise(struct dom_html_document *doc,
struct dom_html_collection *col,
struct dom_node_internal *root,
- dom_callback_is_in_collection ic);
+ dom_callback_is_in_collection ic, void *ctx);
void _dom_html_collection_finalise(struct dom_html_collection *col);
diff --git a/src/html/html_document.c b/src/html/html_document.c
index b36ca7d..217e582 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -426,10 +426,13 @@ dom_exception _dom_html_document_get_links(dom_html_document *doc,
return DOM_NOT_SUPPORTED_ERR;
}
-static bool __dom_html_document_node_is_form(dom_node_internal *node)
+static bool __dom_html_document_node_is_form(dom_node_internal *node,
+ void *ctx)
{
dom_html_document *doc = (dom_html_document *)node->owner;
-
+
+ UNUSED(ctx);
+
return dom_string_caseless_isequal(node->name,
doc->memoised[hds_FORM]);
}
@@ -446,7 +449,7 @@ dom_exception _dom_html_document_get_forms(dom_html_document *doc,
return err;
err = _dom_html_collection_create(doc, (dom_node_internal *) root,
- __dom_html_document_node_is_form, &result);
+ __dom_html_document_node_is_form, NULL, &result);
if (err != DOM_NO_ERR) {
dom_node_unref(root);
return err;
diff --git a/src/html/html_document_strings.h b/src/html/html_document_strings.h
index 632b686..2f5be32 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -56,6 +56,11 @@ HTML_DOCUMENT_STRINGS_ACTION1(action)
HTML_DOCUMENT_STRINGS_ACTION1(enctype)
HTML_DOCUMENT_STRINGS_ACTION1(method)
/* HTML_DOCUMENT_STRINGS_ACTION1(target) */
+/* Useful attributes used by HTMLButtonElement */
+HTML_DOCUMENT_STRINGS_ACTION(access_key,accesskey)
+/* HTML_DOCUMENT_STRINGS_ACTION1(name) */
+/* HTML_DOCUMENT_STRINGS_ACTION1(type) */
+HTML_DOCUMENT_STRINGS_ACTION1(value)
/* Names for elements which get specialised. */
HTML_DOCUMENT_STRINGS_ACTION1(HTML)
HTML_DOCUMENT_STRINGS_ACTION1(HEAD)
diff --git a/src/html/html_element.c b/src/html/html_element.c
index 3642c6c..21f3d1e 100644
--- a/src/html/html_element.c
+++ b/src/html/html_element.c
@@ -7,6 +7,8 @@
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
#include "html/html_document.h"
#include "html/html_element.h"
@@ -240,3 +242,103 @@ fail:
return err;
}
+static char *_strndup(const char *s, size_t n)
+{
+ size_t len;
+ char *s2;
+
+ for (len = 0; len != n && s[len] != '\0'; len++)
+ continue;
+
+ s2 = malloc(len + 1);
+ if (s2 == NULL)
+ return NULL;
+
+ memcpy(s2, s, len);
+ s2[len] = '\0';
+ return s2;
+}
+
+/**
+ * Get the a long property
+ *
+ * \param ele The dom_html_element object
+ * \param name The name of the attribute
+ * \param len The length of ::name
+ * \param value The returned value
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_element_get_long_property(dom_html_element *ele,
+ const char *name, unsigned long len, unsigned long *value)
+{
+ dom_string *str = NULL, *s2 = NULL;
+ dom_attr *a = NULL;
+ dom_exception err;
+
+ err = dom_string_create((const uint8_t *) name, len, &str);
+ if (err != DOM_NO_ERR)
+ goto fail;
+
+ err = dom_element_get_attribute_node(ele, str, &a);
+ if (err != DOM_NO_ERR)
+ goto cleanup1;
+
+ if (a != NULL) {
+ err = dom_node_get_text_content(a, &s2);
+ if (err == DOM_NO_ERR) {
+ char *s3 = _strndup(dom_string_data(s2),
+ dom_string_byte_length(s2));
+ *value = strtoul(s3, NULL, 0);
+ free(s3);
+ dom_string_unref(s2);
+ }
+ } else {
+ *value = 0;
+ }
+
+ dom_node_unref(a);
+
+cleanup1:
+ dom_string_unref(str);
+
+fail:
+ return err;
+}
+
+/**
+ * Set a long property
+ *
+ * \param ele The dom_html_element object
+ * \param name The name of the attribute
+ * \param len The length of ::name
+ * \param value The value
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception dom_html_element_set_long_property(dom_html_element *ele,
+ const char *name, unsigned long len, unsigned long value)
+{
+ dom_string *str = NULL, *svalue = NULL;
+ dom_exception err;
+ char numbuffer[32];
+
+ err = dom_string_create((const uint8_t *) name, len, &str);
+ if (err != DOM_NO_ERR)
+ goto fail;
+
+ if (snprintf(numbuffer, 32, "%lu", value) == 32)
+ numbuffer[31] = '\0';
+
+ err = dom_string_create((const uint8_t *) numbuffer,
+ strlen(numbuffer), &svalue);
+ if (err != DOM_NO_ERR)
+ goto cleanup;
+
+ err = dom_element_set_attribute(ele, svalue, str);
+
+ dom_string_unref(svalue);
+cleanup:
+ dom_string_unref(str);
+
+fail:
+ return err;
+}
diff --git a/src/html/html_element.h b/src/html/html_element.h
index 4a81102..ebf47ba 100644
--- a/src/html/html_element.h
+++ b/src/html/html_element.h
@@ -83,6 +83,11 @@ dom_exception dom_html_element_get_bool_property(dom_html_element *ele,
dom_exception dom_html_element_set_bool_property(dom_html_element *ele,
const char *name, unsigned long len, bool has);
+dom_exception dom_html_element_get_long_property(dom_html_element *ele,
+ const char *name, unsigned long len, unsigned long *value);
+dom_exception dom_html_element_set_long_property(dom_html_element *ele,
+ const char *name, unsigned long len, unsigned long value);
+
extern struct dom_html_element_vtable _dom_html_element_vtable;
#endif
diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c
index d0a453d..fcdf42e 100644
--- a/src/html/html_form_element.c
+++ b/src/html/html_form_element.c
@@ -11,6 +11,7 @@
#include <dom/html/html_form_element.h>
#include "html/html_form_element.h"
+#include "html/html_button_element.h"
#include "html/html_collection.h"
#include "html/html_document.h"
@@ -25,7 +26,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
DOM_HTML_FORM_ELEMENT_PROTECT_VTABLE
};
-static bool _dom_is_form_control(struct dom_node_internal *node);
+static bool _dom_is_form_control(struct dom_node_internal *node, void *ctx);
/**
* Create a dom_html_form_element object
@@ -145,8 +146,8 @@ dom_exception dom_html_form_element_get_elements(dom_html_form_element *ele,
dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
assert(doc != NULL);
err = _dom_html_collection_create(doc,
- (dom_node_internal *) ele,
- _dom_is_form_control, col);
+ (dom_node_internal *) doc,
+ _dom_is_form_control, ele, col);
if (err != DOM_NO_ERR)
return err;
@@ -175,8 +176,8 @@ dom_exception dom_html_form_element_get_length(dom_html_form_element *ele,
dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
assert(doc != NULL);
err = _dom_html_collection_create(doc,
- (dom_node_internal *) ele,
- _dom_is_form_control, &ele->col);
+ (dom_node_internal *) doc,
+ _dom_is_form_control, ele, &ele->col);
if (err != DOM_NO_ERR)
return err;
}
@@ -271,11 +272,13 @@ dom_exception dom_html_form_element_reset(dom_html_form_element *ele)
/* Callback function to test whether certain node is a form control, see
* src/html/html_collection.h for detail. */
-static bool _dom_is_form_control(struct dom_node_internal *node)
+static bool _dom_is_form_control(struct dom_node_internal *node, void *ctx)
{
struct dom_html_document *doc =
(struct dom_html_document *)(node->owner);
+ struct dom_html_form_element *form = ctx, *form2;
+
assert(node->type == DOM_ELEMENT_NODE);
/* Form controls are INPUT TEXTAREA SELECT and BUTTON */
@@ -289,8 +292,17 @@ static bool _dom_is_form_control(struct dom_node_internal *node)
doc->memoised[hds_SELECT]))
return true;
if (dom_string_caseless_isequal(node->name,
- doc->memoised[hds_BUTTON]))
- return true;
+ doc->memoised[hds_BUTTON])) {
+ dom_html_button_element *button =
+ (dom_html_button_element *) node;
+ dom_exception err =
+ dom_html_button_element_get_form(button, &form2);
+ if (err == DOM_NO_ERR) {
+ return form == form2;
+ }
+ /* Couldn't get the form, assume it's not ours. */
+ return false;
+ }
return false;
}
diff --git a/src/html/html_options_collection.c b/src/html/html_options_collection.c
index 918d693..26926bf 100644
--- a/src/html/html_options_collection.c
+++ b/src/html/html_options_collection.c
@@ -33,13 +33,15 @@
dom_exception _dom_html_options_collection_create(struct dom_html_document *doc,
struct dom_node_internal *root,
dom_callback_is_in_collection ic,
+ void *ctx,
struct dom_html_options_collection **col)
{
*col = malloc(sizeof(dom_html_options_collection));
if (*col == NULL)
return DOM_NO_MEM_ERR;
- return _dom_html_options_collection_initialise(doc, *col, root, ic);
+ return _dom_html_options_collection_initialise(doc, *col, root,
+ ic, ctx);
}
/**
@@ -55,9 +57,9 @@ dom_exception _dom_html_options_collection_create(struct dom_html_document *doc,
dom_exception _dom_html_options_collection_initialise(struct dom_html_document *doc,
struct dom_html_options_collection *col,
struct dom_node_internal *root,
- dom_callback_is_in_collection ic)
+ dom_callback_is_in_collection ic, void *ctx)
{
- return _dom_html_collection_initialise(doc, &col->base, root, ic);
+ return _dom_html_collection_initialise(doc, &col->base, root, ic, ctx);
}
/**
diff --git a/src/html/html_options_collection.h b/src/html/html_options_collection.h
index bbaaba4..637d38f 100644
--- a/src/html/html_options_collection.h
+++ b/src/html/html_options_collection.h
@@ -25,12 +25,13 @@ struct dom_html_options_collection {
dom_exception _dom_html_options_collection_create(struct dom_html_document *doc,
struct dom_node_internal *root,
dom_callback_is_in_collection ic,
+ void *ctx,
struct dom_html_options_collection **col);
dom_exception _dom_html_options_collection_initialise(struct dom_html_document *doc,
struct dom_html_options_collection *col,
struct dom_node_internal *root,
- dom_callback_is_in_collection ic);
+ dom_callback_is_in_collection ic, void *ctx);
void _dom_html_options_collection_finalise(
struct dom_html_options_collection *col);
diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c
index 6a05edd..6e79034 100644
--- a/src/html/html_select_element.c
+++ b/src/html/html_select_element.c
@@ -21,7 +21,7 @@ static struct dom_element_protected_vtable _protect_vtable = {
DOM_HTML_SELECT_ELEMENT_PROTECT_VTABLE
};
-static bool is_option(struct dom_node_internal *node);
+static bool is_option(struct dom_node_internal *node, void *ctx);
/**
* Create a dom_html_select_element object
@@ -176,7 +176,7 @@ dom_exception dom_html_select_element_get_length(
if (ele->options == NULL) {
err = _dom_html_options_collection_create(doc,
(dom_node_internal *) ele,
- is_option, &ele->options);
+ is_option, NULL, &ele->options);
if (err != DOM_NO_ERR)
return err;
}
@@ -220,7 +220,7 @@ dom_exception dom_html_select_element_get_options(
if (ele->options == NULL) {
err = _dom_html_options_collection_create(doc,
(dom_node_internal *) ele,
- is_option, &ele->options);
+ is_option, NULL, &ele->options);
if (err != DOM_NO_ERR)
return err;
@@ -310,12 +310,14 @@ dom_exception dom_html_element_focus(struct dom_html_select_element *ele);
/* Helper functions */
/* Test whether certain node is an option node */
-bool is_option(struct dom_node_internal *node)
+bool is_option(struct dom_node_internal *node, void *ctx)
{
dom_string *name = NULL;
bool ret = false;
dom_exception err;
-
+
+ UNUSED(ctx);
+
err = dom_string_create((const uint8_t *) "OPTION", SLEN("OPTION"),
&name);
if (err != DOM_NO_ERR)