diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2010-08-30 13:06:19 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2010-08-30 13:06:19 +0000 |
commit | 7b12b43398bd2beaebe9444ca76e5150b8410691 (patch) | |
tree | 4ce25caee01c0a2a2ebbe052999b5eb8a2fbe2e3 /src/html | |
parent | e1c80e0df81cec4ccf6a9dd378942d091a0f15dd (diff) | |
download | libdom-7b12b43398bd2beaebe9444ca76e5150b8410691.tar.gz libdom-7b12b43398bd2beaebe9444ca76e5150b8410691.tar.bz2 |
Merge branches/struggleyb/libdom-html to trunk.
A few additional fixes to reduce the number of regressions to single figures.
svn path=/trunk/dom/; revision=10724
Diffstat (limited to 'src/html')
113 files changed, 4187 insertions, 0 deletions
diff --git a/src/html/Makefile b/src/html/Makefile new file mode 100644 index 0000000..a154a99 --- /dev/null +++ b/src/html/Makefile @@ -0,0 +1,25 @@ +# Sources +DIR_SOURCES := \ + html_document.c html_collection.c html_options_collection.c \ + 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 + +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_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 \ + html_heading_element.c html_quote_element.c html_pre_element.c \ + html_br_element.c html_basefont_element.c html_font_element.c \ + html_hr_element.c html_mod_element.c html_anchor_element.c \ + html_image_element.c html_object_element.c html_param_element.c \ + html_applet_element.c html_map_element.c html_area_element.c \ + html_script_element.c html_table_element.c html_tablecaption_element.c \ + html_tablecol_element.c html_tablesection_element.c html_tablerow_element.c \ + html_tablecell_element.c html_frameset_element.c html_frame_element.c \ + html_iframe_element.c + +include build/makefiles/Makefile.subdir diff --git a/src/html/html_anchor_element.c b/src/html/html_anchor_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_anchor_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_anchor_element.h b/src/html/html_anchor_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_anchor_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_applet_element.c b/src/html/html_applet_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_applet_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_applet_element.h b/src/html/html_applet_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_applet_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_area_element.c b/src/html/html_area_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_area_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_area_element.h b/src/html/html_area_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_area_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_base_element.c b/src/html/html_base_element.c new file mode 100644 index 0000000..f8aa14e --- /dev/null +++ b/src/html/html_base_element.c @@ -0,0 +1,137 @@ +/* + * 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.com> + */ + +#include "html/html_base_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_BASE_ELEMENT + }, + DOM_HTML_BASE_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_base_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_base_element_create(struct dom_document *doc, + struct dom_html_base_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_base_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_base_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_base_element object + * + * \param doc The document object + * \param ele The dom_html_base_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_base_element_initialise(struct dom_document *doc, + struct dom_html_base_element *ele) +{ + const char *str = "BASE"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_base_element object + * + * \param doc The document object + * \param ele The dom_html_base_element object + */ +void _dom_html_base_element_finalise(struct dom_document *doc, + struct dom_html_base_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_base_element object + * + * \param doc The document object + * \param ele The dom_html_base_element object + */ +void _dom_html_base_element_destroy(struct dom_document *doc, + struct dom_html_base_element *ele) +{ + _dom_html_base_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_base_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_base_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_base_element_destroy(doc, (struct dom_html_base_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_base_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_base_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_base_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + diff --git a/src/html/html_base_element.h b/src/html/html_base_element.h new file mode 100644 index 0000000..7e58cc2 --- /dev/null +++ b/src/html/html_base_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_base_element_h_ +#define dom_internal_html_base_element_h_ + +#include <dom/html/html_base_element.h> + +#include "html/html_element.h" + +struct dom_html_base_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_base_element object */ +dom_exception _dom_html_base_element_create(struct dom_document *doc, + struct dom_html_base_element **ele); + +/* Initialise a dom_html_base_element object */ +dom_exception _dom_html_base_element_initialise(struct dom_document *doc, + struct dom_html_base_element *ele); + +/* Finalise a dom_html_base_element object */ +void _dom_html_base_element_finalise(struct dom_document *doc, + struct dom_html_base_element *ele); + +/* Destroy a dom_html_base_element object */ +void _dom_html_base_element_destroy(struct dom_document *doc, + struct dom_html_base_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_base_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_base_element_destroy(dom_node_internal *node); +dom_exception _dom_html_base_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_base_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_BASE_ELEMENT_PROTECT_VTABLE \ + _dom_html_base_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_BASE_ELEMENT \ + _dom_virtual_html_base_element_destroy, \ + _dom_html_base_element_alloc, \ + _dom_html_base_element_copy + +#endif + diff --git a/src/html/html_basefont_element.c b/src/html/html_basefont_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_basefont_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_basefont_element.h b/src/html/html_basefont_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_basefont_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_body_element.c b/src/html/html_body_element.c new file mode 100644 index 0000000..7512910 --- /dev/null +++ b/src/html/html_body_element.c @@ -0,0 +1,137 @@ +/* + * 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.com> + */ + +#include "html/html_body_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_BODY_ELEMENT + }, + DOM_HTML_BODY_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_body_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_body_element_create(struct dom_document *doc, + struct dom_html_body_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_body_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_body_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_body_element object + * + * \param doc The document object + * \param ele The dom_html_body_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_body_element_initialise(struct dom_document *doc, + struct dom_html_body_element *ele) +{ + const char *str = "BODY"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_body_element object + * + * \param doc The document object + * \param ele The dom_html_body_element object + */ +void _dom_html_body_element_finalise(struct dom_document *doc, + struct dom_html_body_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_body_element object + * + * \param doc The document object + * \param ele The dom_html_body_element object + */ +void _dom_html_body_element_destroy(struct dom_document *doc, + struct dom_html_body_element *ele) +{ + _dom_html_body_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_body_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_body_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_body_element_destroy(doc, (struct dom_html_body_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_body_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_body_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_body_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + diff --git a/src/html/html_body_element.h b/src/html/html_body_element.h new file mode 100644 index 0000000..e62ff78 --- /dev/null +++ b/src/html/html_body_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_body_element_h_ +#define dom_internal_html_body_element_h_ + +#include <dom/html/html_body_element.h> + +#include "html/html_element.h" + +struct dom_html_body_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_body_element object */ +dom_exception _dom_html_body_element_create(struct dom_document *doc, + struct dom_html_body_element **ele); + +/* Initialise a dom_html_body_element object */ +dom_exception _dom_html_body_element_initialise(struct dom_document *doc, + struct dom_html_body_element *ele); + +/* Finalise a dom_html_body_element object */ +void _dom_html_body_element_finalise(struct dom_document *doc, + struct dom_html_body_element *ele); + +/* Destroy a dom_html_body_element object */ +void _dom_html_body_element_destroy(struct dom_document *doc, + struct dom_html_body_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_body_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_body_element_destroy(dom_node_internal *node); +dom_exception _dom_html_body_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_body_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_BODY_ELEMENT_PROTECT_VTABLE \ + _dom_html_body_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_BODY_ELEMENT \ + _dom_virtual_html_body_element_destroy, \ + _dom_html_body_element_alloc, \ + _dom_html_body_element_copy + +#endif + diff --git a/src/html/html_br_element.c b/src/html/html_br_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_br_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_br_element.h b/src/html/html_br_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_br_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_button_element.c b/src/html/html_button_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_button_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_button_element.h b/src/html/html_button_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_button_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_collection.c b/src/html/html_collection.c new file mode 100644 index 0000000..e0c96b9 --- /dev/null +++ b/src/html/html_collection.c @@ -0,0 +1,300 @@ +/* + * 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> + */ + +#include <assert.h> + +#include <libwapcaplet/libwapcaplet.h> + +#include "html/html_collection.h" + +#include "core/node.h" +#include "core/document.h" +#include "core/element.h" +#include "core/string.h" + +/*-----------------------------------------------------------------------*/ +/* Constructor and destructor */ + +/** + * Create a dom_html_collection + * + * \param doc The document + * \param root The root element of the collection + * \param ic The callback function used to determin whether certain node + * belongs to the collection + * \param col The result collection object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_collection_create(struct dom_document *doc, + struct dom_node_internal *root, + dom_callback_is_in_collection ic, + struct dom_html_collection **col) +{ + *col = _dom_document_alloc(doc, NULL, sizeof(dom_html_collection)); + if (*col == NULL) + return DOM_NO_MEM_ERR; + + return _dom_html_collection_initialise(doc, *col, root, ic); +} + +/** + * Intialiase a dom_html_collection + * + * \param doc The document + * \param col The collection object to be initialised + * \param root The root element of the collection + * \param ic The callback function used to determin whether certain node + * belongs to the collection + * \return DOM_NO_ERR on success. + */ +dom_exception _dom_html_collection_initialise(struct dom_document *doc, + struct dom_html_collection *col, + struct dom_node_internal *root, + dom_callback_is_in_collection ic) +{ + assert(doc != NULL); + assert(ic != NULL); + assert(root != NULL); + + col->doc = doc; + dom_node_ref(doc); + + col->root = root; + dom_node_ref(root); + + col->ic = ic; + col->refcnt = 1; + + return DOM_NO_ERR; +} + +/** + * Finalise a dom_html_collection object + * + * \param col The dom_html_collection object + */ +void _dom_html_collection_finalise(struct dom_html_collection *col) +{ + dom_node_unref(col->doc); + col->doc = NULL; + + dom_node_unref(col->root); + col->root = NULL; + + col->ic = NULL; +} + +/** + * Destroy a dom_html_collection object + * \param col The dom_html_collection object + */ +void _dom_html_collection_destroy(struct dom_html_collection *col) +{ + struct dom_document *doc = col->doc; + _dom_html_collection_finalise(col); + + _dom_document_alloc(doc, col, 0); +} + + +/*-----------------------------------------------------------------------*/ +/* Public API */ + +/** + * Get the length of this dom_html_collection + * + * \param col The dom_html_collection object + * \param len The returned length of this collection + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_collection_get_length(dom_html_collection *col, + unsigned long *len) +{ + struct dom_node_internal *node = col->root; + *len = 0; + + while (node != NULL) { + if (node->type == DOM_ELEMENT_NODE && col->ic(node) == true) + (*len)++; + + /* Depth first iterating */ + if (node->first_child != NULL) { + node = node->first_child; + } else if (node->next != NULL) { + node = node->next; + } else { + /* No children and siblings */ + struct dom_node_internal *parent = node->parent; + + while (parent != col->root && + node == parent->last_child) { + node = parent; + parent = parent->parent; + } + + if (parent == col->root) + node = NULL; + else + node = node->next; + } + } + + return DOM_NO_ERR; +} + +/** + * Get the node with certain index + * + * \param col The dom_html_collection object + * \param index The index number based on zero + * \param node The returned node object + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_collection_item(dom_html_collection *col, + unsigned long index, struct dom_node **node) +{ + struct dom_node_internal *n = col->root; + unsigned long len = 0; + + while (n != NULL) { + if (n->type == DOM_ELEMENT_NODE && col->ic(n) == true) + len++; + + if (len == index + 1) { + dom_node_ref(n); + *node = (struct dom_node *) n; + return DOM_NO_ERR; + } + + /* Depth first iterating */ + if (n->first_child != NULL) { + n = n->first_child; + } else if (n->next != NULL) { + n = n->next; + } else { + /* No children and siblings */ + struct dom_node_internal *parent = n->parent; + + while (parent != col->root && + n == parent->last_child) { + n = parent; + parent = parent->parent; + } + + if (parent == col->root) + n = NULL; + else + n = n->next; + } + } + + /* Not find the node */ + *node = NULL; + return DOM_NO_ERR; +} + +/** + * Get the node in the collection according name + * + * \param col The collection + * \param name The name of target node + * \param node The returned node object + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_collection_named_item(dom_html_collection *col, + struct dom_string *name, struct dom_node **node) +{ + struct dom_node_internal *n = col->root; + dom_exception err; + lwc_string *str = NULL; + err = _dom_node_get_intern_string(n, name, &str); + if (err != DOM_NO_ERR) + return err; + + + while (node != NULL) { + if (n->type == DOM_ELEMENT_NODE && col->ic(n) == true) { + lwc_string *id = NULL; + err = _dom_element_get_id((struct dom_element *) n, + &id); + if (err != DOM_NO_ERR) { + _dom_node_unref_intern_string(n, id); + return err; + } + + /* Compare the lwc_string directly */ + if (str == id) { + *node = (struct dom_node *) n; + dom_node_ref(n); + _dom_node_unref_intern_string(n, id); + _dom_node_unref_intern_string(n, str); + + return DOM_NO_ERR; + } + + _dom_node_unref_intern_string(n, id); + } + + /* Depth first iterating */ + if (n->first_child != NULL) { + n = n->first_child; + } else if (n->next != NULL) { + n = n->next; + } else { + /* No children and siblings */ + struct dom_node_internal *parent = n->parent; + + while (parent != col->root && + n == parent->last_child) { + n = parent; + parent = parent->parent; + } + + if (parent == col->root) + n = NULL; + else + n = n->next; + } + } + + /* Not found the target node */ + *node = NULL; + _dom_node_unref_intern_string(n, str); + + return DOM_NO_ERR; +} + +/** + * Claim a reference on this collection + * + * \pram col The collection object + */ +void dom_html_collection_ref(dom_html_collection *col) +{ + if (col == NULL) + return; + + col->refcnt ++; +} + +/** + * Relese a reference on this collection + * + * \pram col The collection object + */ +void dom_html_collection_unref(dom_html_collection *col) +{ + if (col == NULL) + return; + + if (col->refcnt > 0) + col->refcnt --; + + if (col->refcnt == 0) + _dom_html_collection_destroy(col); +} + diff --git a/src/html/html_collection.h b/src/html/html_collection.h new file mode 100644 index 0000000..dc9e67d --- /dev/null +++ b/src/html/html_collection.h @@ -0,0 +1,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> + */ + +#ifndef dom_internal_html_collection_h_ +#define dom_internal_html_collection_h_ + +#include <dom/html/html_collection.h> + +struct dom_node_internal; + +typedef bool (*dom_callback_is_in_collection)(struct dom_node_internal *node); + +/** + * The html_collection structure + */ +struct dom_html_collection { + dom_callback_is_in_collection ic; + /**< The function pointer used to test + * whether some node is an element of + * this collection + */ + struct dom_document *doc; /**< The document created this + * collection + */ + struct dom_node_internal *root; + /**< The root node of this collection */ + uint32_t refcnt; + /**< Reference counting */ +}; + +dom_exception _dom_html_collection_create(struct dom_document *doc, + struct dom_node_internal *root, + dom_callback_is_in_collection ic, + struct dom_html_collection **col); + +dom_exception _dom_html_collection_initialise(struct dom_document *doc, + struct dom_html_collection *col, + struct dom_node_internal *root, + dom_callback_is_in_collection ic); + +void _dom_html_collection_finalise(struct dom_html_collection *col); + +void _dom_html_collection_destroy(struct dom_html_collection *col); + +#endif + diff --git a/src/html/html_directory_element.c b/src/html/html_directory_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_directory_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_directory_element.h b/src/html/html_directory_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_directory_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_div_element.c b/src/html/html_div_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_div_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_div_element.h b/src/html/html_div_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_div_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_dlist_element.c b/src/html/html_dlist_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_dlist_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_dlist_element.h b/src/html/html_dlist_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_dlist_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_document.c b/src/html/html_document.c new file mode 100644 index 0000000..d62714e --- /dev/null +++ b/src/html/html_document.c @@ -0,0 +1,118 @@ +/* + * 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> + */ + +#include <assert.h> + +#include "html/html_document.h" + +#include "core/string.h" +#include "utils/utils.h" + +/* Create a HTMLDocument */ +dom_exception dom_html_document_create(dom_alloc alloc, void *pw, dom_msg msg, + void *msg_pw, + dom_events_default_action_fetcher daf, dom_ui_handler ui, + dom_parser_type pt, dom_html_document **doc) +{ + assert(alloc != NULL); + *doc = alloc(NULL, sizeof(dom_html_document), pw); + if (*doc == NULL) + return DOM_NO_MEM_ERR; + + return _dom_html_document_initialise(*doc, alloc, pw, msg, msg_pw, + daf, ui, pt); +} + +/* Initialise a HTMLDocument */ +dom_exception _dom_html_document_initialise(dom_html_document *doc, + dom_alloc alloc, void *pw, dom_msg msg, void *msg_pw, + dom_events_default_action_fetcher daf, dom_ui_handler ui, + dom_parser_type pt) +{ + UNUSED(doc); + UNUSED(alloc); + UNUSED(pw); + UNUSED(msg); + UNUSED(msg_pw); + UNUSED(daf); + UNUSED(ui); + UNUSED(pt); + + return DOM_NO_ERR; +} + +/* Finalise a HTMLDocument */ +void _dom_html_document_finalise(dom_html_document *doc); +/* Destroy a HTMLDocument */ +void _dom_html_document_destroy(dom_html_document *doc); + +/* Parse a data chunk into the HTMLDocument */ +dom_exception dom_html_document_write_data(uint8_t *data, size_t len); + +/* Notify the HTMLDocument that it is completed */ +dom_exception dom_html_document_complete(void); + +/*-----------------------------------------------------------------------*/ +/* The DOM spec public API */ + +/** + * Get the title of this HTMLDocument + * \param doc The document object + * \param title The reutrned title string + * \return DOM_NO_ERR on success, appropriated dom_exception on failure. + * + * @note: this method find a title for the document as following: + * 1. If there is a title in the document object set by + * dom_html_document_set_title, then use it; + * 2. If there is no such one, find the <title> element and use its text + * as the returned title. + */ +dom_exception dom_html_document_get_title(dom_html_document *doc, + struct dom_string **title) +{ + UNUSED(doc); + UNUSED(title); + + return DOM_NO_ERR; +} + +dom_exception dom_html_document_set_title(dom_html_document *doc, + struct dom_string *title); +dom_exception dom_html_document_get_referer(dom_html_document *doc, + struct dom_string **referer); +dom_exception dom_html_document_get_domain(dom_html_document *doc, + struct dom_string **domain); +dom_exception dom_html_document_get_url(dom_html_document *doc, + struct dom_string **url); +dom_exception dom_html_document_get_body(dom_html_document *doc, + struct dom_html_element **body); +dom_exception dom_html_document_set_body(dom_html_document *doc, + struct dom_html_element *body); +dom_exception dom_html_document_get_images(dom_html_document *doc, + struct dom_html_collection **col); +dom_exception dom_html_document_get_applets(dom_html_document *doc, + struct dom_html_collection **col); +dom_exception dom_html_document_get_links(dom_html_document *doc, + struct dom_html_collection **col); +dom_exception dom_html_document_get_forms(dom_html_document *doc, + struct dom_html_collection **col); +dom_exception dom_html_document_get_anchors(dom_html_document *doc, + struct dom_html_collection **col); +dom_exception dom_html_document_get_cookie(dom_html_document *doc, + struct dom_string **cookie); +dom_exception dom_html_document_set_cookie(dom_html_document *doc, + struct dom_string *cookie); + +dom_exception dom_html_document_open(dom_html_document *doc); +dom_exception dom_html_document_close(dom_html_document *doc); +dom_exception dom_html_document_write(dom_html_document *doc, + struct dom_string *text); +dom_exception dom_html_document_writeln(dom_html_document *doc, + struct dom_string *text); +dom_exception dom_html_document_get_elements_by_name(dom_html_document *doc, + struct dom_string *name, struct dom_nodelist **list); + diff --git a/src/html/html_document.h b/src/html/html_document.h new file mode 100644 index 0000000..4abab09 --- /dev/null +++ b/src/html/html_document.h @@ -0,0 +1,47 @@ +/* + * 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> + */ + +#ifndef dom_internal_html_document_h_ +#define dom_internal_html_document_h_ + +#include <dom/html/html_document.h> + +#include "core/document.h" + +struct dom_hubbub_parser; +struct dom_xml_parser; + +/** + * The dom_html_document class + */ +struct dom_html_document { + struct dom_document base; /**< The base class */ + union { + struct dom_hubbub_parser *hp; + struct dom_xml_parser *xp; + } parser; + /**< The underlaying parser of this document */ + + struct dom_string *title; /**< HTML document title */ + struct dom_string *referer; /**< HTML document referer */ + struct dom_string *domain; /**< HTML document domain */ + struct dom_string *url; /**< HTML document URL */ + struct dom_string *cookie; /**< HTML document cookie */ +}; + +/* Initialise a HTMLDocument */ +dom_exception _dom_html_document_initialise(dom_html_document *doc, + dom_alloc alloc, void *pw, dom_msg msg, void *msg_pw, + dom_events_default_action_fetcher daf, dom_ui_handler ui, + dom_parser_type pt); +/* Finalise a HTMLDocument */ +void _dom_html_document_finalise(dom_html_document *doc); +/* Destroy a HTMLDocument */ +void _dom_html_document_destroy(dom_html_document *doc); + +#endif + diff --git a/src/html/html_element.c b/src/html/html_element.c new file mode 100644 index 0000000..4610c67 --- /dev/null +++ b/src/html/html_element.c @@ -0,0 +1,207 @@ +/* + * 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.com> + */ + +#include <assert.h> + +#include "html/html_element.h" + +#include "core/node.h" +#include "core/attr.h" +#include "core/document.h" +#include "utils/utils.h" + +dom_exception _dom_html_element_initialise(struct dom_document *doc, + struct dom_html_element *el, struct lwc_string_s *name, + struct lwc_string_s *namespace, struct lwc_string_s *prefix) +{ + dom_exception err; + + err = _dom_element_initialise(doc, &el->base, name, namespace, prefix); + if (err != DOM_NO_ERR) + return err; + + el->form = NULL; + return err; +} + +void _dom_html_element_finalise(struct dom_document *doc, + struct dom_html_element *ele) +{ + dom_node_unref(ele->form); + ele->form = NULL; + + _dom_element_finalise(doc, &ele->base); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual destroy function, see src/core/node.c for detail */ +void _dom_virtual_html_element_destroy(dom_node_internal *node) +{ + UNUSED(node); + assert("Should never be here" == NULL); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(doc); + UNUSED(n); + UNUSED(ret); + + assert("Should never be here" == NULL); + + return DOM_NO_MEM_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_element_copy(new, old); +} + +/*-----------------------------------------------------------------------*/ +/* Common functions */ + +/** + * Get the a bool property + * + * \param ele The dom_html_element object + * \param name The name of the attribute + * \param len The length of ::name + * \param has The returned status + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_element_get_bool_property(dom_html_element *ele, + const char *name, unsigned long len, bool *has) +{ + dom_document *doc = dom_node_get_owner(ele); + dom_string *str = NULL; + dom_attr *a = NULL; + dom_exception err; + + err = _dom_document_create_string(doc, (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) { + *has = true; + } else { + *has = false; + } + + dom_node_unref(a); + +cleanup1: + dom_string_unref(str); + +fail: + return err; +} + +/** + * Set a bool property + * + * \param ele The dom_html_element object + * \param name The name of the attribute + * \param len The length of ::name + * \param has The status + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_element_set_bool_property(dom_html_element *ele, + const char *name, unsigned long len, bool has) +{ + dom_document *doc = dom_node_get_owner(ele); + dom_string *str = NULL; + dom_attr *a = NULL; + dom_exception err; + + err = _dom_document_create_string(doc, (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 && has == false) { + dom_attr *res = NULL; + + err = dom_element_remove_attribute_node(ele, a, &res); + if (err != DOM_NO_ERR) + goto cleanup2; + + dom_node_unref(res); + } else if (a == NULL && has == true) { + dom_attr *res = NULL; + lwc_string *lstr = NULL; + + err = _dom_string_intern(str, &lstr); + if (err != DOM_NO_ERR) + goto cleanup1; + + err = _dom_attr_create(doc, lstr, NULL, NULL, true, &a); + if (err != DOM_NO_ERR) { + lwc_string_unref(lstr); + goto cleanup1; + } + lwc_string_unref(lstr); + + err = dom_element_set_attribute_node(ele, a, &res); + if (err != DOM_NO_ERR) + goto cleanup2; + + dom_node_unref(res); + } + +cleanup2: + dom_node_unref(a); + +cleanup1: + dom_string_unref(str); + +fail: + return err; +} + +/** + * Get the form element if this element is a form control + * + * \param ele The element object + * \param form The form object + */ +void _dom_html_element_get_form(dom_html_element *ele, + struct dom_html_form_element **form) +{ + *form = ele->form; + dom_node_ref(*form); +} + +/** + * Set the form element if this element is a form control + * + * \param ele The element object + * \param form The form object + */ +void _dom_html_element_associate_form(dom_html_element *ele, + struct dom_html_form_element *form) +{ + /* Unref the form if there is any */ + dom_node_unref(form); + ele->form = form; + dom_node_ref(form); +} + diff --git a/src/html/html_element.h b/src/html/html_element.h new file mode 100644 index 0000000..430dac4 --- /dev/null +++ b/src/html/html_element.h @@ -0,0 +1,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> + */ + +#ifndef dom_internal_html_element_h_ +#define dom_internal_html_element_h_ + +#include <dom/html/html_element.h> + +#include "core/element.h" + +struct dom_html_form_element; + +/** + * The dom_html_element class + * + * Note: For now, there is no new members and methods in this class, + * but in future, we may add common abstracted functions from child class + * to here. + */ +struct dom_html_element { + struct dom_element base; + /**< The base class */ + struct dom_html_form_element *form; + /**< The form element which contains this element if + * this element is a form control + */ +}; + +dom_exception _dom_html_element_initialise(struct dom_document *doc, + struct dom_html_element *el, struct lwc_string_s *name, + struct lwc_string_s *namespace, struct lwc_string_s *prefix); + +void _dom_html_element_finalise(struct dom_document *doc, + struct dom_html_element *ele); + +/* The protected virtual functions */ +void _dom_virtual_html_element_destroy(dom_node_internal *node); +dom_exception _dom_html_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +/* Some common functions used by all child classes */ +dom_exception dom_html_element_get_bool_property(dom_html_element *ele, + const char *name, unsigned long len, bool *has); +dom_exception dom_html_element_set_bool_property(dom_html_element *ele, + const char *name, unsigned long len, bool has); +void _dom_html_element_get_form(dom_html_element *ele, + struct dom_html_form_element **form); +void _dom_html_element_associate_form(dom_html_element *ele, + struct dom_html_form_element *form); + +#endif + diff --git a/src/html/html_fieldset_element.c b/src/html/html_fieldset_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_fieldset_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_fieldset_element.h b/src/html/html_fieldset_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_fieldset_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_font_element.c b/src/html/html_font_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_font_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_font_element.h b/src/html/html_font_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_font_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c new file mode 100644 index 0000000..7c0e9af --- /dev/null +++ b/src/html/html_form_element.c @@ -0,0 +1,256 @@ +/* + * 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.com> + */ + +#include <assert.h> + +#include "html/html_form_element.h" + +#include "html/html_collection.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_FORM_ELEMENT + }, + DOM_HTML_FORM_ELEMENT_PROTECT_VTABLE +}; + +static bool _dom_is_form_control(struct dom_node_internal *node); + +/** + * Create a dom_html_form_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_form_element_create(struct dom_document *doc, + struct dom_html_form_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_form_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_form_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_form_element object + * + * \param doc The document object + * \param ele The dom_html_form_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_form_element_initialise(struct dom_document *doc, + struct dom_html_form_element *ele) +{ + const char *str = "FORM"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + ele->col = NULL; + + return err; +} + +/** + * Finalise a dom_html_form_element object + * + * \param doc The document object + * \param ele The dom_html_form_element object + */ +void _dom_html_form_element_finalise(struct dom_document *doc, + struct dom_html_form_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_form_element object + * + * \param doc The document object + * \param ele The dom_html_form_element object + */ +void _dom_html_form_element_destroy(struct dom_document *doc, + struct dom_html_form_element *ele) +{ + _dom_html_form_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_form_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_form_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_form_element_destroy(doc, (struct dom_html_form_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_form_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_form_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_form_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + +/*-----------------------------------------------------------------------*/ +/* Public APIs */ + +/** + * Get the form controls under this form element + * + * \param ele The form object + * \param col The collection of form controls + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_form_element_get_elements(dom_html_form_element *ele, + struct dom_html_collection **col) +{ + dom_exception err; + + if (ele->col == NULL) { + dom_document *doc = dom_node_get_owner(ele); + assert(doc != NULL); + err = _dom_html_collection_create(doc, + (dom_node_internal *) ele, + _dom_is_form_control, col); + if (err != DOM_NO_ERR) + return err; + + ele->col = *col; + } + + *col = ele->col; + dom_html_collection_ref(*col); + + return DOM_NO_ERR; +} + +/** + * Get the number of form controls under this form element + * + * \param ele The form object + * \param len The number of controls + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_form_element_get_length(dom_html_form_element *ele, + unsigned long *len) +{ + dom_exception err; + + if (ele->col == NULL) { + dom_document *doc = dom_node_get_owner(ele); + assert(doc != NULL); + err = _dom_html_collection_create(doc, + (dom_node_internal *) ele, + _dom_is_form_control, &ele->col); + if (err != DOM_NO_ERR) + return err; + } + + return dom_html_collection_get_length(ele->col, len); +} + +/** + * Submit this form + * + * \param ele The form object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_form_element_submit(dom_html_form_element *ele) +{ + struct dom_document *doc = dom_node_get_owner(ele); + bool success = false; + assert(doc != NULL); + + /* Dispatch an event and let the default action handler to deal with + * the submit action, and a 'submit' event is bubbling and cancelable + */ + return _dom_dispatch_generic_event(doc, (dom_event_target *) ele, + (const uint8_t *) "submit", SLEN("submit"), true, + true, &success); +} + +/** + * Reset this form + * + * \param ele The form object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_form_element_reset(dom_html_form_element *ele) +{ + struct dom_document *doc = dom_node_get_owner(ele); + bool success = false; + assert(doc != NULL); + + /* Dispatch an event and let the default action handler to deal with + * the reset action, and a 'reset' event is bubbling and cancelable + */ + return _dom_dispatch_generic_event(doc, (dom_event_target *) ele, + (const uint8_t *) "reset", SLEN("reset"), true, + true, &success); +} + +/*-----------------------------------------------------------------------*/ +/* Internal functions */ + +/* 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) +{ + assert(node->type == DOM_ELEMENT_NODE); + dom_html_element *ele = (dom_html_element *) node; + + return ele->form != NULL; +} + diff --git a/src/html/html_form_element.h b/src/html/html_form_element.h new file mode 100644 index 0000000..9b8105d --- /dev/null +++ b/src/html/html_form_element.h @@ -0,0 +1,59 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_form_element_h_ +#define dom_internal_html_form_element_h_ + +#include <dom/html/html_form_element.h> + +#include "html/html_element.h" + +struct dom_html_collection; + +struct dom_html_form_element { + struct dom_html_element base; + /**< The base class */ + struct dom_html_collection *col; + /**< The collection of form controls */ +}; + +/* Create a dom_html_form_element object */ +dom_exception _dom_html_form_element_create(struct dom_document *doc, + struct dom_html_form_element **ele); + +/* Initialise a dom_html_form_element object */ +dom_exception _dom_html_form_element_initialise(struct dom_document *doc, + struct dom_html_form_element *ele); + +/* Finalise a dom_html_form_element object */ +void _dom_html_form_element_finalise(struct dom_document *doc, + struct dom_html_form_element *ele); + +/* Destroy a dom_html_form_element object */ +void _dom_html_form_element_destroy(struct dom_document *doc, + struct dom_html_form_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_form_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_form_element_destroy(dom_node_internal *node); +dom_exception _dom_html_form_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_form_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_FORM_ELEMENT_PROTECT_VTABLE \ + _dom_html_form_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_FORM_ELEMENT \ + _dom_virtual_html_form_element_destroy, \ + _dom_html_form_element_alloc, \ + _dom_html_form_element_copy + +#endif + diff --git a/src/html/html_frame_element.c b/src/html/html_frame_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_frame_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_frame_element.h b/src/html/html_frame_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_frame_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_frameset_element.c b/src/html/html_frameset_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_frameset_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_frameset_element.h b/src/html/html_frameset_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_frameset_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_head_element.c b/src/html/html_head_element.c new file mode 100644 index 0000000..9ab53b6 --- /dev/null +++ b/src/html/html_head_element.c @@ -0,0 +1,137 @@ +/* + * 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.com> + */ + +#include "html/html_head_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_HEAD_ELEMENT + }, + DOM_HTML_HEAD_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_head_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_head_element_create(struct dom_document *doc, + struct dom_html_head_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_head_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_head_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_head_element object + * + * \param doc The document object + * \param ele The dom_html_head_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_head_element_initialise(struct dom_document *doc, + struct dom_html_head_element *ele) +{ + const char *str = "HEAD"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_head_element object + * + * \param doc The document object + * \param ele The dom_html_head_element object + */ +void _dom_html_head_element_finalise(struct dom_document *doc, + struct dom_html_head_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_head_element object + * + * \param doc The document object + * \param ele The dom_html_head_element object + */ +void _dom_html_head_element_destroy(struct dom_document *doc, + struct dom_html_head_element *ele) +{ + _dom_html_head_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_head_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_head_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_head_element_destroy(doc, (struct dom_html_head_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_head_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_head_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_head_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + diff --git a/src/html/html_head_element.h b/src/html/html_head_element.h new file mode 100644 index 0000000..d92c656 --- /dev/null +++ b/src/html/html_head_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_head_element_h_ +#define dom_internal_html_head_element_h_ + +#include <dom/html/html_head_element.h> + +#include "html/html_element.h" + +struct dom_html_head_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_head_element object */ +dom_exception _dom_html_head_element_create(struct dom_document *doc, + struct dom_html_head_element **ele); + +/* Initialise a dom_html_head_element object */ +dom_exception _dom_html_head_element_initialise(struct dom_document *doc, + struct dom_html_head_element *ele); + +/* Finalise a dom_html_head_element object */ +void _dom_html_head_element_finalise(struct dom_document *doc, + struct dom_html_head_element *ele); + +/* Destroy a dom_html_head_element object */ +void _dom_html_head_element_destroy(struct dom_document *doc, + struct dom_html_head_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_head_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_head_element_destroy(dom_node_internal *node); +dom_exception _dom_html_head_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_head_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_HEAD_ELEMENT_PROTECT_VTABLE \ + _dom_html_head_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_HEAD_ELEMENT \ + _dom_virtual_html_head_element_destroy, \ + _dom_html_head_element_alloc, \ + _dom_html_head_element_copy + +#endif + diff --git a/src/html/html_heading_element.c b/src/html/html_heading_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_heading_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_heading_element.h b/src/html/html_heading_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_heading_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_hr_element.c b/src/html/html_hr_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_hr_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_hr_element.h b/src/html/html_hr_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_hr_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_html_element.c b/src/html/html_html_element.c new file mode 100644 index 0000000..8e08382 --- /dev/null +++ b/src/html/html_html_element.c @@ -0,0 +1,137 @@ +/* + * 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.com> + */ + +#include "html/html_html_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_HTML_ELEMENT + }, + DOM_HTML_HTML_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_html_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_html_element_create(struct dom_document *doc, + struct dom_html_html_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_html_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_html_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_html_element object + * + * \param doc The document object + * \param ele The dom_html_html_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_html_element_initialise(struct dom_document *doc, + struct dom_html_html_element *ele) +{ + const char *str = "HTML"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_html_element object + * + * \param doc The document object + * \param ele The dom_html_html_element object + */ +void _dom_html_html_element_finalise(struct dom_document *doc, + struct dom_html_html_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_html_element object + * + * \param doc The document object + * \param ele The dom_html_html_element object + */ +void _dom_html_html_element_destroy(struct dom_document *doc, + struct dom_html_html_element *ele) +{ + _dom_html_html_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_html_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_html_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_html_element_destroy(doc, (struct dom_html_html_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_html_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_html_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_html_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + diff --git a/src/html/html_html_element.h b/src/html/html_html_element.h new file mode 100644 index 0000000..4e81d18 --- /dev/null +++ b/src/html/html_html_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_html_element_h_ +#define dom_internal_html_html_element_h_ + +#include <dom/html/html_html_element.h> + +#include "html/html_element.h" + +struct dom_html_html_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_html_element object */ +dom_exception _dom_html_html_element_create(struct dom_document *doc, + struct dom_html_html_element **ele); + +/* Initialise a dom_html_html_element object */ +dom_exception _dom_html_html_element_initialise(struct dom_document *doc, + struct dom_html_html_element *ele); + +/* Finalise a dom_html_html_element object */ +void _dom_html_html_element_finalise(struct dom_document *doc, + struct dom_html_html_element *ele); + +/* Destroy a dom_html_html_element object */ +void _dom_html_html_element_destroy(struct dom_document *doc, + struct dom_html_html_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_html_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_html_element_destroy(dom_node_internal *node); +dom_exception _dom_html_html_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_html_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_HTML_ELEMENT_PROTECT_VTABLE \ + _dom_html_html_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_HTML_ELEMENT \ + _dom_virtual_html_html_element_destroy, \ + _dom_html_html_element_alloc, \ + _dom_html_html_element_copy + +#endif + diff --git a/src/html/html_iframe_element.c b/src/html/html_iframe_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_iframe_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_iframe_element.h b/src/html/html_iframe_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_iframe_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_image_element.c b/src/html/html_image_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_image_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_image_element.h b/src/html/html_image_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_image_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_input_element.c b/src/html/html_input_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_input_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_input_element.h b/src/html/html_input_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_input_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_isindex_element.c b/src/html/html_isindex_element.c new file mode 100644 index 0000000..42db2e5 --- /dev/null +++ b/src/html/html_isindex_element.c @@ -0,0 +1,162 @@ +/* + * 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.com> + */ + +#include "html/html_isindex_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_ISINDEX_ELEMENT + }, + DOM_HTML_ISINDEX_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_isindex_element object + * + * \param doc The document object + * \param form The form element which contains this element + * \param ele The returned element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_isindex_element_create(struct dom_document *doc, + struct dom_html_form_element *form, + struct dom_html_isindex_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_isindex_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_isindex_element_initialise(doc, form, *ele); +} + +/** + * Initialise a dom_html_isindex_element object + * + * \param doc The document object + * \param form The form element which contains this element + * \param ele The dom_html_isindex_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_isindex_element_initialise(struct dom_document *doc, + struct dom_html_form_element *form, + struct dom_html_isindex_element *ele) +{ + const char *str = "ISINDEX"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + ele->base.form = form; + dom_node_ref(form); + + return err; +} + +/** + * Finalise a dom_html_isindex_element object + * + * \param doc The document object + * \param ele The dom_html_isindex_element object + */ +void _dom_html_isindex_element_finalise(struct dom_document *doc, + struct dom_html_isindex_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_isindex_element object + * + * \param doc The document object + * \param ele The dom_html_isindex_element object + */ +void _dom_html_isindex_element_destroy(struct dom_document *doc, + struct dom_html_isindex_element *ele) +{ + _dom_html_isindex_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_isindex_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_isindex_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_isindex_element_destroy(doc, (struct dom_html_isindex_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_isindex_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_isindex_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_isindex_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + + +/*-----------------------------------------------------------------------*/ +/* Public APIs */ + +/** + * Get the form element which contains this element + * + * \param ele The dom_html_isindex_element + * \param form The form element + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_isindex_element_get_form(dom_html_isindex_element *ele, + struct dom_html_form_element **form) +{ + _dom_html_element_get_form(&ele->base, form); + + return DOM_NO_ERR; +} diff --git a/src/html/html_isindex_element.h b/src/html/html_isindex_element.h new file mode 100644 index 0000000..3aad119 --- /dev/null +++ b/src/html/html_isindex_element.h @@ -0,0 +1,57 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_isindex_element_h_ +#define dom_internal_html_isindex_element_h_ + +#include <dom/html/html_isindex_element.h> + +#include "html/html_element.h" + +struct dom_html_isindex_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_isindex_element object */ +dom_exception _dom_html_isindex_element_create(struct dom_document *doc, + struct dom_html_form_element *form, + struct dom_html_isindex_element **ele); + +/* Initialise a dom_html_isindex_element object */ +dom_exception _dom_html_isindex_element_initialise(struct dom_document *doc, + struct dom_html_form_element *form, + struct dom_html_isindex_element *ele); + +/* Finalise a dom_html_isindex_element object */ +void _dom_html_isindex_element_finalise(struct dom_document *doc, + struct dom_html_isindex_element *ele); + +/* Destroy a dom_html_isindex_element object */ +void _dom_html_isindex_element_destroy(struct dom_document *doc, + struct dom_html_isindex_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_isindex_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_isindex_element_destroy(dom_node_internal *node); +dom_exception _dom_html_isindex_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_isindex_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_ISINDEX_ELEMENT_PROTECT_VTABLE \ + _dom_html_isindex_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_ISINDEX_ELEMENT \ + _dom_virtual_html_isindex_element_destroy, \ + _dom_html_isindex_element_alloc, \ + _dom_html_isindex_element_copy + +#endif + diff --git a/src/html/html_label_element.c b/src/html/html_label_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_label_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_label_element.h b/src/html/html_label_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_label_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_legend_element.c b/src/html/html_legend_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_legend_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_legend_element.h b/src/html/html_legend_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_legend_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_li_element.c b/src/html/html_li_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_li_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_li_element.h b/src/html/html_li_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_li_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_link_element.c b/src/html/html_link_element.c new file mode 100644 index 0000000..ce0d6ac --- /dev/null +++ b/src/html/html_link_element.c @@ -0,0 +1,171 @@ +/* + * 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.com> + */ + +#include <assert.h> + +#include "html/html_link_element.h" + +#include "core/node.h" +#include "core/attr.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_LINK_ELEMENT + }, + DOM_HTML_LINK_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_link_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_link_element_create(struct dom_document *doc, + struct dom_html_link_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_link_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_link_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_link_element object + * + * \param doc The document object + * \param ele The dom_html_link_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_link_element_initialise(struct dom_document *doc, + struct dom_html_link_element *ele) +{ + const char *str = "LINK"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_link_element object + * + * \param doc The document object + * \param ele The dom_html_link_element object + */ +void _dom_html_link_element_finalise(struct dom_document *doc, + struct dom_html_link_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_link_element object + * + * \param doc The document object + * \param ele The dom_html_link_element object + */ +void _dom_html_link_element_destroy(struct dom_document *doc, + struct dom_html_link_element *ele) +{ + _dom_html_link_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*-----------------------------------------------------------------------*/ +/* Public APIs */ + +/** + * Get the disabled property + * + * \param ele The dom_html_link_element object + * \param disabled The returned status + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_link_element_get_disabled(dom_html_link_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_link_element object + * \param disabled The status + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_link_element_set_disabled(dom_html_link_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_link_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_link_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_link_element_destroy(doc, (struct dom_html_link_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_link_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_link_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_link_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + diff --git a/src/html/html_link_element.h b/src/html/html_link_element.h new file mode 100644 index 0000000..4c6fe55 --- /dev/null +++ b/src/html/html_link_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_link_element_h_ +#define dom_internal_html_link_element_h_ + +#include <dom/html/html_link_element.h> + +#include "html/html_element.h" + +struct dom_html_link_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_link_element object */ +dom_exception _dom_html_link_element_create(struct dom_document *doc, + struct dom_html_link_element **ele); + +/* Initialise a dom_html_link_element object */ +dom_exception _dom_html_link_element_initialise(struct dom_document *doc, + struct dom_html_link_element *ele); + +/* Finalise a dom_html_link_element object */ +void _dom_html_link_element_finalise(struct dom_document *doc, + struct dom_html_link_element *ele); + +/* Destroy a dom_html_link_element object */ +void _dom_html_link_element_destroy(struct dom_document *doc, + struct dom_html_link_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_link_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_link_element_destroy(dom_node_internal *node); +dom_exception _dom_html_link_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_link_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_LINK_ELEMENT_PROTECT_VTABLE \ + _dom_html_link_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_LINK_ELEMENT \ + _dom_virtual_html_link_element_destroy, \ + _dom_html_link_element_alloc, \ + _dom_html_link_element_copy + +#endif + diff --git a/src/html/html_map_element.c b/src/html/html_map_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_map_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_map_element.h b/src/html/html_map_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_map_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_menu_element.c b/src/html/html_menu_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_menu_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_menu_element.h b/src/html/html_menu_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_menu_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_meta_element.c b/src/html/html_meta_element.c new file mode 100644 index 0000000..a525e13 --- /dev/null +++ b/src/html/html_meta_element.c @@ -0,0 +1,137 @@ +/* + * 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.com> + */ + +#include "html/html_meta_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_META_ELEMENT + }, + DOM_HTML_META_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_meta_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_meta_element_create(struct dom_document *doc, + struct dom_html_meta_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_meta_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_meta_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_meta_element object + * + * \param doc The document object + * \param ele The dom_html_meta_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_meta_element_initialise(struct dom_document *doc, + struct dom_html_meta_element *ele) +{ + const char *str = "META"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_meta_element object + * + * \param doc The document object + * \param ele The dom_html_meta_element object + */ +void _dom_html_meta_element_finalise(struct dom_document *doc, + struct dom_html_meta_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_meta_element object + * + * \param doc The document object + * \param ele The dom_html_meta_element object + */ +void _dom_html_meta_element_destroy(struct dom_document *doc, + struct dom_html_meta_element *ele) +{ + _dom_html_meta_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_meta_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_meta_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_meta_element_destroy(doc, (struct dom_html_meta_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_meta_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_meta_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_meta_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + diff --git a/src/html/html_meta_element.h b/src/html/html_meta_element.h new file mode 100644 index 0000000..2f50719 --- /dev/null +++ b/src/html/html_meta_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_meta_element_h_ +#define dom_internal_html_meta_element_h_ + +#include <dom/html/html_meta_element.h> + +#include "html/html_element.h" + +struct dom_html_meta_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_meta_element object */ +dom_exception _dom_html_meta_element_create(struct dom_document *doc, + struct dom_html_meta_element **ele); + +/* Initialise a dom_html_meta_element object */ +dom_exception _dom_html_meta_element_initialise(struct dom_document *doc, + struct dom_html_meta_element *ele); + +/* Finalise a dom_html_meta_element object */ +void _dom_html_meta_element_finalise(struct dom_document *doc, + struct dom_html_meta_element *ele); + +/* Destroy a dom_html_meta_element object */ +void _dom_html_meta_element_destroy(struct dom_document *doc, + struct dom_html_meta_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_meta_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_meta_element_destroy(dom_node_internal *node); +dom_exception _dom_html_meta_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_meta_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_META_ELEMENT_PROTECT_VTABLE \ + _dom_html_meta_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_META_ELEMENT \ + _dom_virtual_html_meta_element_destroy, \ + _dom_html_meta_element_alloc, \ + _dom_html_meta_element_copy + +#endif + diff --git a/src/html/html_mod_element.c b/src/html/html_mod_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_mod_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_mod_element.h b/src/html/html_mod_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_mod_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_object_element.c b/src/html/html_object_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_object_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_object_element.h b/src/html/html_object_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_object_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_olist_element.c b/src/html/html_olist_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_olist_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_olist_element.h b/src/html/html_olist_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_olist_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_optgroup_element.c b/src/html/html_optgroup_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_optgroup_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_optgroup_element.h b/src/html/html_optgroup_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_optgroup_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_option_element.c b/src/html/html_option_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_option_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_option_element.h b/src/html/html_option_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_option_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_options_collection.c b/src/html/html_options_collection.c new file mode 100644 index 0000000..8b4c7bb --- /dev/null +++ b/src/html/html_options_collection.c @@ -0,0 +1,177 @@ +/* + * 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> + */ + +#include <assert.h> + +#include <libwapcaplet/libwapcaplet.h> + +#include "html/html_options_collection.h" + +#include "core/node.h" +#include "core/document.h" +#include "core/element.h" +#include "core/string.h" +#include "utils/utils.h" + +/*-----------------------------------------------------------------------*/ +/* Constructor and destructor */ + +/** + * Create a dom_html_options_collection + * + * \param doc The document + * \param root The root element of the collection + * \param ic The callback function used to determin whether certain node + * belongs to the collection + * \param col The result collection object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_options_collection_create(struct dom_document *doc, + struct dom_node_internal *root, + dom_callback_is_in_collection ic, + struct dom_html_options_collection **col) +{ + *col = _dom_document_alloc(doc, NULL, + sizeof(dom_html_options_collection)); + if (*col == NULL) + return DOM_NO_MEM_ERR; + + return _dom_html_options_collection_initialise(doc, *col, root, ic); +} + +/** + * Intialiase a dom_html_options_collection + * + * \param doc The document + * \param col The collection object to be initialised + * \param root The root element of the collection + * \param ic The callback function used to determin whether certain node + * belongs to the collection + * \return DOM_NO_ERR on success. + */ +dom_exception _dom_html_options_collection_initialise(struct dom_document *doc, + struct dom_html_options_collection *col, + struct dom_node_internal *root, + dom_callback_is_in_collection ic) +{ + return _dom_html_collection_initialise(doc, &col->base, root, ic); +} + +/** + * Finalise a dom_html_options_collection object + * + * \param col The dom_html_options_collection object + */ +void _dom_html_options_collection_finalise(struct dom_html_options_collection *col) +{ + _dom_html_collection_finalise(&col->base); +} + +/** + * Destroy a dom_html_options_collection object + * \param col The dom_html_options_collection object + */ +void _dom_html_options_collection_destroy(struct dom_html_options_collection *col) +{ + struct dom_document *doc = col->base.doc; + _dom_html_options_collection_finalise(col); + + _dom_document_alloc(doc, col, 0); +} + + +/*-----------------------------------------------------------------------*/ +/* Public API */ + +/** + * Get the length of this dom_html_options_collection + * + * \param col The dom_html_options_collection object + * \param len The returned length of this collection + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_options_collection_get_length(dom_html_options_collection *col, + unsigned long *len) +{ + return dom_html_collection_get_length(&col->base, len); +} + +/** + * Set the length of this dom_html_options_collection + * + * \param col The dom_html_options_collection object + * \param len The length of this collection to be set + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_options_collection_set_length( + dom_html_options_collection *col, unsigned long len) +{ + UNUSED(col); + UNUSED(len); + + /* TODO: how to deal with this */ + return DOM_NOT_SUPPORTED_ERR; +} + +/** + * Get the node with certain index + * + * \param col The dom_html_options_collection object + * \param index The index number based on zero + * \param node The returned node object + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_options_collection_item(dom_html_options_collection *col, + unsigned long index, struct dom_node **node) +{ + return dom_html_collection_item(&col->base, index, node); +} + +/** + * Get the node in the collection according name + * + * \param col The collection + * \param name The name of target node + * \param node The returned node object + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_options_collection_named_item(dom_html_options_collection *col, + struct dom_string *name, struct dom_node **node) +{ + return dom_html_collection_named_item(&col->base, name, node); +} + +/** + * Claim a reference on this collection + * + * \pram col The collection object + */ +void dom_html_options_collection_ref(dom_html_options_collection *col) +{ + if (col == NULL) + return; + + col->base.refcnt ++; +} + +/** + * Relese a reference on this collection + * + * \pram col The collection object + */ +void dom_html_options_collection_unref(dom_html_options_collection *col) +{ + if (col == NULL) + return; + + if (col->base.refcnt > 0) + col->base.refcnt --; + + if (col->base.refcnt == 0) + _dom_html_options_collection_destroy(col); +} + diff --git a/src/html/html_options_collection.h b/src/html/html_options_collection.h new file mode 100644 index 0000000..e82cc5c --- /dev/null +++ b/src/html/html_options_collection.h @@ -0,0 +1,42 @@ +/* + * 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> + */ + +#ifndef dom_internal_html_options_collection_h_ +#define dom_internal_html_options_collection_h_ + +#include <dom/html/html_options_collection.h> + +#include "html/html_collection.h" + +struct dom_node_internal; + +/** + * The html_options_collection structure + */ +struct dom_html_options_collection { + struct dom_html_collection base; + /**< The base class */ +}; + +dom_exception _dom_html_options_collection_create(struct dom_document *doc, + struct dom_node_internal *root, + dom_callback_is_in_collection ic, + struct dom_html_options_collection **col); + +dom_exception _dom_html_options_collection_initialise(struct dom_document *doc, + struct dom_html_options_collection *col, + struct dom_node_internal *root, + dom_callback_is_in_collection ic); + +void _dom_html_options_collection_finalise( + struct dom_html_options_collection *col); + +void _dom_html_options_collection_destroy( + struct dom_html_options_collection *col); + +#endif + diff --git a/src/html/html_paragraph_element.c b/src/html/html_paragraph_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_paragraph_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_paragraph_element.h b/src/html/html_paragraph_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_paragraph_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_param_element.c b/src/html/html_param_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_param_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_param_element.h b/src/html/html_param_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_param_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_pre_element.c b/src/html/html_pre_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_pre_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_pre_element.h b/src/html/html_pre_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_pre_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_quote_element.c b/src/html/html_quote_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_quote_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_quote_element.h b/src/html/html_quote_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_quote_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_script_element.c b/src/html/html_script_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_script_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_script_element.h b/src/html/html_script_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_script_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c new file mode 100644 index 0000000..f4e54cb --- /dev/null +++ b/src/html/html_select_element.c @@ -0,0 +1,344 @@ +/* + * 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> + */ + +#include <assert.h> + +#include "html/html_select_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_SELECT_ELEMENT + }, + DOM_HTML_SELECT_ELEMENT_PROTECT_VTABLE +}; + +static bool is_option(struct dom_node_internal *node); +/** + * Create a dom_html_select_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_select_element_create(struct dom_document *doc, + struct dom_html_select_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_select_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_select_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_select_element object + * + * \param doc The document object + * \param ele The dom_html_select_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_select_element_initialise(struct dom_document *doc, + struct dom_html_select_element *ele) +{ + const char *str = "SELECT"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + ele->selected = -1; + ele->options = NULL; + + return err; +} + +/** + * Finalise a dom_html_select_element object + * + * \param doc The document object + * \param ele The dom_html_select_element object + */ +void _dom_html_select_element_finalise(struct dom_document *doc, + struct dom_html_select_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_select_element object + * + * \param doc The document object + * \param ele The dom_html_select_element object + */ +void _dom_html_select_element_destroy(struct dom_document *doc, + struct dom_html_select_element *ele) +{ + _dom_html_select_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_select_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_select_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_select_element_destroy(doc, (struct dom_html_select_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_select_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_select_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_select_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + +/*-----------------------------------------------------------------------*/ +/* Public APIs */ + +/** + * Get the ordinal index of the selected option + * + * \param ele The element object + * \param index The returned index + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_get_selected_index( + dom_html_select_element *ele, unsigned long *index) +{ + *index = ele->selected; + + return DOM_NO_ERR; +} + +/** + * Set the ordinal index of the selected option + * + * \param ele The element object + * \param index The new index + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_set_selected_index( + dom_html_select_element *ele, unsigned long index) +{ + ele->selected = index; + + return DOM_NO_ERR; +} + +/** + * Get the number of options in this select element + * + * \param ele The element object + * \param len The returned len + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_get_length( + dom_html_select_element *ele, unsigned long *len) +{ + dom_exception err; + dom_document *doc = dom_node_get_owner(ele); + assert(doc != NULL); + + if (ele->options == NULL) { + err = _dom_html_options_collection_create(doc, + (dom_node_internal *) ele, + is_option, &ele->options); + if (err != DOM_NO_ERR) + return err; + } + + return dom_html_options_collection_get_length(ele->options, len); +} + +/** + * Set the number of options in this select element + * + * \param ele The element object + * \param len The new len + * \return DOM_NOT_SUPPORTED_ERR. + * + * todo: how to deal with set the len of the children option objects? + */ +dom_exception dom_html_select_element_set_length( + dom_html_select_element *ele, unsigned long len) +{ + UNUSED(ele); + UNUSED(len); + + return DOM_NOT_SUPPORTED_ERR; +} + +/** + * The collection of OPTION elements of this element + * + * \param ele The element object + * \param col THe returned collection object + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_get_options( + dom_html_select_element *ele, + struct dom_html_options_collection **col) +{ + dom_exception err; + dom_document *doc = dom_node_get_owner(ele); + assert(doc != NULL); + + if (ele->options == NULL) { + err = _dom_html_options_collection_create(doc, + (dom_node_internal *) ele, + is_option, &ele->options); + if (err != DOM_NO_ERR) + return err; + + *col = ele->options; + return DOM_NO_ERR; + } + + dom_html_options_collection_ref(ele->options); + *col = ele->options; + + return DOM_NO_ERR; +} + +/** + * Whether this element is disabled + * + * \param ele The element object + * \param disabled The returned status + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_get_disabled( + dom_html_select_element *ele, bool *disabled) +{ + return dom_html_element_get_bool_property(&ele->base, + "disabled", SLEN("disabled"), disabled); +} + +/** + * Set the disabled status of this element + * + * \param ele The element object + * \param disabled The disabled status + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_set_disabled( + dom_html_select_element *ele, bool disabled) +{ + return dom_html_element_set_bool_property(&ele->base, + "disabled", SLEN("disabled"), disabled); +} + +/** + * Whether this element can be multiple selected + * + * \param ele The element object + * \param multiple The returned status + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_get_multiple( + dom_html_select_element *ele, bool *multiple) +{ + return dom_html_element_get_bool_property(&ele->base, + "multiple", SLEN("multiple"), multiple); +} + +/** + * Set whether this element can be multiple selected + * + * \param ele The element object + * \param multiple The status + * \return DOM_NO_ERR on success. + */ +dom_exception dom_html_select_element_set_multiple( + dom_html_select_element *ele, bool multiple) +{ + return dom_html_element_set_bool_property(&ele->base, + "multiple", SLEN("multiple"), multiple); +} + +dom_exception dom_html_select_element_get_size( + dom_html_select_element *ele, unsigned long *size); +dom_exception dom_html_select_element_set_size( + dom_html_select_element *ele, unsigned long size); +dom_exception dom_html_select_element_get_tab_index( + dom_html_select_element *ele, unsigned long *tab_index); +dom_exception dom_html_select_element_set_tab_index( + dom_html_select_element *ele, unsigned long tab_index); + +/* Functions */ +dom_exception dom_html_select_element_add(struct dom_html_element *ele, + struct dom_html_element *before); +dom_exception dom_html_element_blur(struct dom_html_select_element *ele); +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) +{ + lwc_string *name = NULL; + bool ret = false; + dom_exception err; + + err = _dom_node_create_lwcstring(node, (const uint8_t *) "OPTION", + SLEN("OPTION"), &name); + assert(err == DOM_NO_ERR); + + if (name == node->name) + ret = true; + + _dom_node_unref_intern_string(node, name); + + return ret; +} diff --git a/src/html/html_select_element.h b/src/html/html_select_element.h new file mode 100644 index 0000000..28b4956 --- /dev/null +++ b/src/html/html_select_element.h @@ -0,0 +1,60 @@ +/* + * 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> + */ + +#ifndef dom_internal_html_select_element_h_ +#define dom_internal_html_select_element_h_ + +#include <dom/html/html_select_element.h> + +#include "html/html_element.h" +#include "html/html_options_collection.h" + +struct dom_html_select_element { + struct dom_html_element base; + /**< The base class */ + long selected; + /**< The selected element's index */ + dom_html_options_collection *options; + /**< The options objects */ +}; + +/* Create a dom_html_select_element object */ +dom_exception _dom_html_select_element_create(struct dom_document *doc, + struct dom_html_select_element **ele); + +/* Initialise a dom_html_select_element object */ +dom_exception _dom_html_select_element_initialise(struct dom_document *doc, + struct dom_html_select_element *ele); + +/* Finalise a dom_html_select_element object */ +void _dom_html_select_element_finalise(struct dom_document *doc, + struct dom_html_select_element *ele); + +/* Destroy a dom_html_select_element object */ +void _dom_html_select_element_destroy(struct dom_document *doc, + struct dom_html_select_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_select_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_select_element_destroy(dom_node_internal *node); +dom_exception _dom_html_select_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_select_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_SELECT_ELEMENT_PROTECT_VTABLE \ + _dom_html_select_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_SELECT_ELEMENT \ + _dom_virtual_html_select_element_destroy, \ + _dom_html_select_element_alloc, \ + _dom_html_select_element_copy + +#endif + diff --git a/src/html/html_style_element.c b/src/html/html_style_element.c new file mode 100644 index 0000000..288b1cf --- /dev/null +++ b/src/html/html_style_element.c @@ -0,0 +1,168 @@ +/* + * 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.com> + */ + +#include "html/html_style_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_STYLE_ELEMENT + }, + DOM_HTML_STYLE_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_style_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_style_element_create(struct dom_document *doc, + struct dom_html_style_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_style_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_style_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_style_element object + * + * \param doc The document object + * \param ele The dom_html_style_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_style_element_initialise(struct dom_document *doc, + struct dom_html_style_element *ele) +{ + const char *str = "STYLE"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_style_element object + * + * \param doc The document object + * \param ele The dom_html_style_element object + */ +void _dom_html_style_element_finalise(struct dom_document *doc, + struct dom_html_style_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_style_element object + * + * \param doc The document object + * \param ele The dom_html_style_element object + */ +void _dom_html_style_element_destroy(struct dom_document *doc, + struct dom_html_style_element *ele) +{ + _dom_html_style_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_style_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_style_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_style_element_destroy(doc, (struct dom_html_style_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_style_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_style_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_style_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + +/*-----------------------------------------------------------------------*/ +/* Public APIs */ + +/** + * Get the disabled property + * + * \param ele The dom_html_style_element object + * \param disabled The returned status + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_style_element_get_disabled(dom_html_style_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_style_element object + * \param disabled The status + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception dom_html_style_element_set_disabled(dom_html_style_element *ele, + bool disabled) +{ + return dom_html_element_set_bool_property(&ele->base, "disabled", + SLEN("disabled"), disabled); +} + diff --git a/src/html/html_style_element.h b/src/html/html_style_element.h new file mode 100644 index 0000000..3ac8cf5 --- /dev/null +++ b/src/html/html_style_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_style_element_h_ +#define dom_internal_html_style_element_h_ + +#include <dom/html/html_style_element.h> + +#include "html/html_element.h" + +struct dom_html_style_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_style_element object */ +dom_exception _dom_html_style_element_create(struct dom_document *doc, + struct dom_html_style_element **ele); + +/* Initialise a dom_html_style_element object */ +dom_exception _dom_html_style_element_initialise(struct dom_document *doc, + struct dom_html_style_element *ele); + +/* Finalise a dom_html_style_element object */ +void _dom_html_style_element_finalise(struct dom_document *doc, + struct dom_html_style_element *ele); + +/* Destroy a dom_html_style_element object */ +void _dom_html_style_element_destroy(struct dom_document *doc, + struct dom_html_style_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_style_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_style_element_destroy(dom_node_internal *node); +dom_exception _dom_html_style_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_style_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_STYLE_ELEMENT_PROTECT_VTABLE \ + _dom_html_style_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_STYLE_ELEMENT \ + _dom_virtual_html_style_element_destroy, \ + _dom_html_style_element_alloc, \ + _dom_html_style_element_copy + +#endif + diff --git a/src/html/html_table_element.c b/src/html/html_table_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_table_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_table_element.h b/src/html/html_table_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_table_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablecaption_element.c b/src/html/html_tablecaption_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablecaption_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablecaption_element.h b/src/html/html_tablecaption_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablecaption_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablecell_element.c b/src/html/html_tablecell_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablecell_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablecell_element.h b/src/html/html_tablecell_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablecell_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablecol_element.c b/src/html/html_tablecol_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablecol_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablecol_element.h b/src/html/html_tablecol_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablecol_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablerow_element.c b/src/html/html_tablerow_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablerow_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablerow_element.h b/src/html/html_tablerow_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablerow_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablesection_element.c b/src/html/html_tablesection_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablesection_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_tablesection_element.h b/src/html/html_tablesection_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_tablesection_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_textarea_element.c b/src/html/html_textarea_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_textarea_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_textarea_element.h b/src/html/html_textarea_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_textarea_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_title_element.c b/src/html/html_title_element.c new file mode 100644 index 0000000..c914d4a --- /dev/null +++ b/src/html/html_title_element.c @@ -0,0 +1,187 @@ +/* + * 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.com> + */ + +#include <assert.h> + +#include <dom/core/characterdata.h> +#include <dom/core/text.h> + +#include "html/html_title_element.h" + +#include "core/node.h" +#include "core/document.h" +#include "utils/utils.h" + +static struct dom_element_protected_vtable _protect_vtable = { + { + DOM_NODE_PROTECT_VTABLE_HTML_TITLE_ELEMENT + }, + DOM_HTML_TITLE_ELEMENT_PROTECT_VTABLE +}; + +/** + * Create a dom_html_title_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_title_element_create(struct dom_document *doc, + struct dom_html_title_element **ele) +{ + *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_title_element)); + if (*ele == NULL) + return DOM_NO_MEM_ERR; + + /* Set up vtables */ + struct dom_node_internal *node = (struct dom_node_internal *) *ele; + node->base.vtable = &_dom_element_vtable; + node->vtable = &_protect_vtable; + + return _dom_html_title_element_initialise(doc, *ele); +} + +/** + * Initialise a dom_html_title_element object + * + * \param doc The document object + * \param ele The dom_html_title_element object + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + */ +dom_exception _dom_html_title_element_initialise(struct dom_document *doc, + struct dom_html_title_element *ele) +{ + const char *str = "TITLE"; + lwc_string *name = NULL; + dom_exception err; + + err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + &name); + if (err != DOM_NO_ERR) + return err; + + err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); + _dom_document_unref_lwcstring(doc, name); + + return err; +} + +/** + * Finalise a dom_html_title_element object + * + * \param doc The document object + * \param ele The dom_html_title_element object + */ +void _dom_html_title_element_finalise(struct dom_document *doc, + struct dom_html_title_element *ele) +{ + _dom_html_element_finalise(doc, &ele->base); +} + +/** + * Destroy a dom_html_title_element object + * + * \param doc The document object + * \param ele The dom_html_title_element object + */ +void _dom_html_title_element_destroy(struct dom_document *doc, + struct dom_html_title_element *ele) +{ + _dom_html_title_element_finalise(doc, ele); + _dom_document_alloc(doc, ele, 0); +} + +/*------------------------------------------------------------------------*/ +/* The protected virtual functions */ + +/* The virtual function used to parse attribute value, see src/core/element.c + * for detail */ +dom_exception _dom_html_title_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct 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_title_element_destroy(dom_node_internal *node) +{ + struct dom_document *doc = dom_node_get_owner(node); + _dom_html_title_element_destroy(doc, (struct dom_html_title_element *) node); +} + +/* The virtual allocation function, see src/core/node.c for detail */ +dom_exception _dom_html_title_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret) +{ + UNUSED(n); + + *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_title_element)); + if (*ret == NULL) + return DOM_NO_MEM_ERR; + + return DOM_NO_ERR; +} + +/* The virtual copy function, see src/core/node.c for detail */ +dom_exception _dom_html_title_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old) +{ + return _dom_html_element_copy(new, old); +} + +/*-----------------------------------------------------------------------*/ +/* Public APIs */ + +/** + * Get the text of title + * + * \param ele The title element + * \param text The returned text + * \return DOM_NO_ERR on success, appropriated dom_exception on failure. + */ +dom_exception dom_html_title_element_get_text(dom_html_title_element *ele, + struct dom_string **text) +{ + dom_node_internal *node = (dom_node_internal *) ele; + dom_node_internal *n = node->first_child; + + /* There should be only one child of title element */ + assert(node->first_child == node->last_child); + /* And it should be a text node */ + assert(n->type == DOM_TEXT_NODE); + + return dom_characterdata_get_data(n, text); +} + +/** + * Set the text of title + * + * \param ele The title element + * \param text The text data to be set + * \return DOM_NO_ERR on success, appropriated dom_exception on failure. + */ +dom_exception dom_html_title_element_set_text(dom_html_title_element *ele, + struct dom_string *text) +{ + dom_node_internal *node = (dom_node_internal *) ele; + dom_node_internal *n = node->first_child; + + /* There should be only one child of title element */ + assert(node->first_child == node->last_child); + /* And it should be a text node */ + assert(n->type == DOM_TEXT_NODE); + + return dom_characterdata_set_data(n, text); +} + diff --git a/src/html/html_title_element.h b/src/html/html_title_element.h new file mode 100644 index 0000000..1433189 --- /dev/null +++ b/src/html/html_title_element.h @@ -0,0 +1,55 @@ +/* + * 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.com> + */ + +#ifndef dom_internal_html_title_element_h_ +#define dom_internal_html_title_element_h_ + +#include <dom/html/html_title_element.h> + +#include "html/html_element.h" + +struct dom_html_title_element { + struct dom_html_element base; + /**< The base class */ +}; + +/* Create a dom_html_title_element object */ +dom_exception _dom_html_title_element_create(struct dom_document *doc, + struct dom_html_title_element **ele); + +/* Initialise a dom_html_title_element object */ +dom_exception _dom_html_title_element_initialise(struct dom_document *doc, + struct dom_html_title_element *ele); + +/* Finalise a dom_html_title_element object */ +void _dom_html_title_element_finalise(struct dom_document *doc, + struct dom_html_title_element *ele); + +/* Destroy a dom_html_title_element object */ +void _dom_html_title_element_destroy(struct dom_document *doc, + struct dom_html_title_element *ele); + +/* The protected virtual functions */ +dom_exception _dom_html_title_element_parse_attribute(dom_element *ele, + struct dom_string *name, struct dom_string *value, + struct dom_string **parsed); +void _dom_virtual_html_title_element_destroy(dom_node_internal *node); +dom_exception _dom_html_title_element_alloc(struct dom_document *doc, + struct dom_node_internal *n, struct dom_node_internal **ret); +dom_exception _dom_html_title_element_copy(struct dom_node_internal *new, + struct dom_node_internal *old); + +#define DOM_HTML_TITLE_ELEMENT_PROTECT_VTABLE \ + _dom_html_title_element_parse_attribute + +#define DOM_NODE_PROTECT_VTABLE_HTML_TITLE_ELEMENT \ + _dom_virtual_html_title_element_destroy, \ + _dom_html_title_element_alloc, \ + _dom_html_title_element_copy + +#endif + diff --git a/src/html/html_ulist_element.c b/src/html/html_ulist_element.c new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_ulist_element.c @@ -0,0 +1,7 @@ +/* + * 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> + */ + diff --git a/src/html/html_ulist_element.h b/src/html/html_ulist_element.h new file mode 100644 index 0000000..2e182d5 --- /dev/null +++ b/src/html/html_ulist_element.h @@ -0,0 +1,7 @@ +/* + * 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> + */ + |