From 7783b83d261de624ea7a74d4d8c12f085ea8cc91 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 7 Jul 2012 16:28:04 +0100 Subject: HTMLFormElement: Initial support, 2 tests now pass --- src/html/html_document.c | 6 ++++++ src/html/html_form_element.c | 34 +++++++++++++++++++++++----------- src/html/html_form_element.h | 2 ++ 3 files changed, 31 insertions(+), 11 deletions(-) (limited to 'src/html') diff --git a/src/html/html_document.c b/src/html/html_document.c index 11ee899..288de82 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -14,6 +14,7 @@ #include "html/html_html_element.h" #include "html/html_head_element.h" #include "html/html_title_element.h" +#include "html/html_form_element.h" #include "core/string.h" #include "utils/namespace.h" @@ -176,6 +177,11 @@ _dom_html_document_create_element_internal(dom_html_document *html, (dom_html_title_element **) result); } + if (dom_string_caseless_isequal(tag_name, html->memoised[hds_FORM])) { + return _dom_html_form_element_create(html, namespace, prefix, + (dom_html_form_element **) result); + } + return _dom_html_element_create(html, tag_name, namespace, prefix, result); } diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c index b24a08e..83af37a 100644 --- a/src/html/html_form_element.c +++ b/src/html/html_form_element.c @@ -33,6 +33,7 @@ static bool _dom_is_form_control(struct dom_node_internal *node); * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element **ele) { struct dom_node_internal *node; @@ -43,10 +44,10 @@ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, /* Set up vtables */ node = (struct dom_node_internal *) *ele; - node->base.vtable = &_dom_element_vtable; + node->base.vtable = &_dom_html_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_form_element_initialise(doc, *ele); + return _dom_html_form_element_initialise(doc, namespace, prefix, *ele); } /** @@ -57,18 +58,15 @@ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element *ele) { - dom_string *name = NULL; dom_exception err; - err = dom_string_create((const uint8_t *) "FORM", SLEN("FORM"), &name); - if (err != DOM_NO_ERR) - return err; + err = _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_FORM], + namespace, prefix); - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - ele->col = NULL; return err; @@ -231,11 +229,25 @@ dom_exception dom_html_form_element_reset(dom_html_form_element *ele) * src/html/html_collection.h for detail. */ static bool _dom_is_form_control(struct dom_node_internal *node) { - UNUSED(node); + struct dom_html_document *doc = + (struct dom_html_document *)(node->owner); assert(node->type == DOM_ELEMENT_NODE); - /** \todo: implement */ + /* Form controls are INPUT TEXTAREA SELECT and BUTTON */ + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_INPUT])) + return true; + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_TEXTAREA])) + return true; + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_SELECT])) + return true; + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_BUTTON])) + return true; + return false; } diff --git a/src/html/html_form_element.h b/src/html/html_form_element.h index dbf6267..1ee9878 100644 --- a/src/html/html_form_element.h +++ b/src/html/html_form_element.h @@ -23,10 +23,12 @@ struct dom_html_form_element { /* Create a dom_html_form_element object */ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element **ele); /* Initialise a dom_html_form_element object */ dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element *ele); /* Finalise a dom_html_form_element object */ -- cgit v1.2.3