summaryrefslogtreecommitdiff
path: root/src/html/html_form_controls_collection.c
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-01-20 10:22:55 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-01-21 10:38:48 +0000
commite28c8c517ef1e89638de059c5f8da6cb8dab0adc (patch)
treec744435d4010a632b7fda19c01d03650f15e36dc /src/html/html_form_controls_collection.c
parent9158d4bedb8b16b8bc413c365a70321db6fbb1cd (diff)
downloadlibdom-e28c8c517ef1e89638de059c5f8da6cb8dab0adc.tar.gz
libdom-e28c8c517ef1e89638de059c5f8da6cb8dab0adc.tar.bz2
Add HTMLFormControlsCollection and RadioNodeListdsilvers/forms1
These are a necessary step on the way to libdom being able to manage the content and behaviours of web forms.
Diffstat (limited to 'src/html/html_form_controls_collection.c')
-rw-r--r--src/html/html_form_controls_collection.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/html/html_form_controls_collection.c b/src/html/html_form_controls_collection.c
new file mode 100644
index 0000000..f42f3f7
--- /dev/null
+++ b/src/html/html_form_controls_collection.c
@@ -0,0 +1,69 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2018 Daniel Silverstone <dsilvers@netsurf-browser.org>
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <libwapcaplet/libwapcaplet.h>
+
+#include "html/html_form_controls_collection.h"
+#include "html/html_document.h"
+#include "html/html_form_element.h"
+
+#include "html/html_input_element.h"
+#include "html/html_select_element.h"
+#include "html/html_text_area_element.h"
+#include "html/html_button_element.h"
+
+#include "core/node.h"
+#include "core/element.h"
+#include "core/string.h"
+
+/*-----------------------------------------------------------------------*/
+/* Internal functions */
+
+/* Callback function to test whether certain node is a form control, see
+ * src/html/html_collection.h for detail. */
+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;
+
+
+ assert(node->type == DOM_ELEMENT_NODE);
+
+ /* Form controls are INPUT TEXTAREA SELECT and BUTTON*/
+ if (dom_string_caseless_isequal(node->name,
+ doc->elements[DOM_HTML_ELEMENT_TYPE_INPUT]))
+ return ((dom_html_input_element *)node)->form == form;
+ if (dom_string_caseless_isequal(node->name,
+ doc->elements[DOM_HTML_ELEMENT_TYPE_TEXTAREA]))
+ return ((dom_html_text_area_element *)node)->form == form;
+ if (dom_string_caseless_isequal(node->name,
+ doc->elements[DOM_HTML_ELEMENT_TYPE_SELECT]))
+ return ((dom_html_select_element *)node)->form == form;
+ if (dom_string_caseless_isequal(node->name,
+ doc->elements[DOM_HTML_ELEMENT_TYPE_BUTTON])) {
+ return ((dom_html_button_element *)node)->form == form;
+ }
+
+ return false;
+}
+
+
+dom_exception _dom_html_form_controls_collection_create(struct dom_html_form_element *form,
+ dom_html_form_controls_collection **col)
+{
+ dom_html_document *doc = (dom_html_document *) dom_node_get_owner(form);
+
+ assert(doc != NULL);
+
+ return _dom_html_collection_create(doc,
+ (dom_node_internal *) doc,
+ _dom_is_form_control, form, col);
+}