diff options
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/html_document.c | 91 | ||||
-rw-r--r-- | src/html/html_document.h | 2 | ||||
-rw-r--r-- | src/html/html_element.c | 67 | ||||
-rw-r--r-- | src/html/html_element.h | 34 |
4 files changed, 146 insertions, 48 deletions
diff --git a/src/html/html_document.c b/src/html/html_document.c index a2a7ed5..7644fde 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -116,15 +116,20 @@ out: } /* Finalise a HTMLDocument */ -void _dom_html_document_finalise(dom_html_document *doc) +bool _dom_html_document_finalise(dom_html_document *doc) { int sidx; - dom_string_unref(doc->cookie); - dom_string_unref(doc->url); - dom_string_unref(doc->domain); - dom_string_unref(doc->referrer); - dom_string_unref(doc->title); + if (doc->cookie != NULL) + dom_string_unref(doc->cookie); + if (doc->url != NULL) + dom_string_unref(doc->url); + if (doc->domain != NULL) + dom_string_unref(doc->domain); + if (doc->referrer != NULL) + dom_string_unref(doc->referrer); + if (doc->title != NULL) + dom_string_unref(doc->title); if (doc->memoised != NULL) { for(sidx = 0; sidx < hds_COUNT; ++sidx) { @@ -136,7 +141,7 @@ void _dom_html_document_finalise(dom_html_document *doc) doc->memoised = NULL; } - _dom_document_finalise(&doc->base); + return _dom_document_finalise(&doc->base); } /* Destroy a HTMLDocument */ @@ -144,9 +149,8 @@ void _dom_html_document_destroy(dom_node_internal *node) { dom_html_document *doc = (dom_html_document *) node; - _dom_html_document_finalise(doc); - - free(doc); + if (_dom_html_document_finalise(doc) == true) + free(doc); } dom_exception _dom_html_document_copy(dom_node_internal *old, @@ -163,58 +167,53 @@ dom_exception _dom_html_document_copy(dom_node_internal *old, /** Internal method to support both kinds of create method */ static dom_exception _dom_html_document_create_element_internal(dom_html_document *html, - dom_string *tag_name, + dom_string *in_tag_name, dom_string *namespace, dom_string *prefix, dom_html_element **result) { + dom_exception exc; + dom_string *tag_name; + + exc = dom_string_toupper(in_tag_name, true, &tag_name); + if (exc != DOM_NO_ERR) + return exc; + if (dom_string_caseless_isequal(tag_name, html->memoised[hds_HTML])) { - return _dom_html_html_element_create(html, namespace, prefix, + exc = _dom_html_html_element_create(html, namespace, prefix, (dom_html_html_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_HEAD])) { - return _dom_html_head_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_HEAD])) { + exc = _dom_html_head_element_create(html, namespace, prefix, (dom_html_head_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TITLE])) { - return _dom_html_title_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TITLE])) { + exc = _dom_html_title_element_create(html, namespace, prefix, (dom_html_title_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_FORM])) { - return _dom_html_form_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_FORM])) { + exc = _dom_html_form_element_create(html, namespace, prefix, (dom_html_form_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_LINK])) { - return _dom_html_link_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_LINK])) { + exc = _dom_html_link_element_create(html, namespace, prefix, (dom_html_link_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_BUTTON])) { - return _dom_html_button_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_BUTTON])) { + exc = _dom_html_button_element_create(html, namespace, prefix, (dom_html_button_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_INPUT])) { - return _dom_html_input_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_INPUT])) { + exc = _dom_html_input_element_create(html, namespace, prefix, (dom_html_input_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TEXTAREA])) { - return _dom_html_text_area_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_TEXTAREA])) { + exc = _dom_html_text_area_element_create(html, namespace, prefix, (dom_html_text_area_element **) result); - } - - if (dom_string_caseless_isequal(tag_name, html->memoised[hds_OPTGROUP])) { - return _dom_html_opt_group_element_create(html, namespace, prefix, + } else if (dom_string_caseless_isequal(tag_name, html->memoised[hds_OPTGROUP])) { + exc = _dom_html_opt_group_element_create(html, namespace, prefix, (dom_html_opt_group_element **) result); + } else { + exc = _dom_html_element_create(html, tag_name, namespace, + prefix, result); } - return _dom_html_element_create(html, tag_name, namespace, prefix, - result); + dom_string_unref(tag_name); + + return exc; } dom_exception _dom_html_document_create_element(dom_document *doc, diff --git a/src/html/html_document.h b/src/html/html_document.h index fbe7155..bb1a0d2 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -38,7 +38,7 @@ dom_exception _dom_html_document_create( dom_exception _dom_html_document_initialise(dom_html_document *doc, dom_events_default_action_fetcher daf); /* Finalise a HTMLDocument */ -void _dom_html_document_finalise(dom_html_document *doc); +bool _dom_html_document_finalise(dom_html_document *doc); void _dom_html_document_destroy(dom_node_internal *node); dom_exception _dom_html_document_copy(dom_node_internal *old, diff --git a/src/html/html_element.c b/src/html/html_element.c index 21f3d1e..c2a4899 100644 --- a/src/html/html_element.c +++ b/src/html/html_element.c @@ -26,7 +26,7 @@ struct dom_html_element_vtable _dom_html_element_vtable = { }, DOM_NODE_VTABLE_ELEMENT, }, - DOM_ELEMENT_VTABLE + DOM_ELEMENT_VTABLE_HTML_ELEMENT, }, DOM_HTML_ELEMENT_VTABLE }; @@ -142,6 +142,71 @@ SIMPLE_GET_SET(lang,lang) SIMPLE_GET_SET(dir,dir) SIMPLE_GET_SET(class_name,class) +/** + * Retrieve a list of descendant elements of an element which match a given + * tag name (caselessly) + * + * \param element The root of the subtree to search + * \param name The tag name to match (or "*" for all tags) + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned nodelist will have its reference count increased. It is + * the responsibility of the caller to unref the nodelist once it has + * finished with it. + */ +dom_exception _dom_html_element_get_elements_by_tag_name( + struct dom_element *element, dom_string *name, + struct dom_nodelist **result) +{ + dom_exception err; + dom_node_internal *base = (dom_node_internal *) element; + + assert(base->owner != NULL); + + err = _dom_document_get_nodelist(base->owner, + DOM_NODELIST_BY_NAME_CASELESS, + (struct dom_node_internal *) element, name, NULL, + NULL, result); + + return err; +} + +/** + * Retrieve a list of descendant elements of an element which match a given + * namespace/localname pair, caselessly. + * + * \param element The root of the subtree to search + * \param namespace The namespace URI to match (or "*" for all) + * \param localname The local name to match (or "*" for all) + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, + * DOM_NOT_SUPPORTED_ERR if the implementation does not support + * the feature "XML" and the language exposed + * through the Document does not support + * Namespaces. + * + * The returned nodelist will have its reference count increased. It is + * the responsibility of the caller to unref the nodelist once it has + * finished with it. + */ +dom_exception _dom_html_element_get_elements_by_tag_name_ns( + struct dom_element *element, dom_string *namespace, + dom_string *localname, struct dom_nodelist **result) +{ + dom_exception err; + + /** \todo ensure XML feature is supported */ + + err = _dom_document_get_nodelist(element->base.owner, + DOM_NODELIST_BY_NAMESPACE_CASELESS, + (struct dom_node_internal *) element, NULL, + namespace, localname, + result); + + return err; +} + /*-----------------------------------------------------------------------*/ /* Common functions */ diff --git a/src/html/html_element.h b/src/html/html_element.h index ebf47ba..2ac4b17 100644 --- a/src/html/html_element.h +++ b/src/html/html_element.h @@ -33,11 +33,45 @@ dom_exception _dom_html_element_initialise(struct dom_html_document *doc, void _dom_html_element_finalise(struct dom_html_element *ele); +/* Virtual functions */ +dom_exception _dom_html_element_get_elements_by_tag_name( + struct dom_element *element, dom_string *name, + struct dom_nodelist **result); + +dom_exception _dom_html_element_get_elements_by_tag_name_ns( + struct dom_element *element, dom_string *namespace, + dom_string *localname, struct dom_nodelist **result); + + /* The protected virtual functions */ void _dom_html_element_destroy(dom_node_internal *node); dom_exception _dom_html_element_copy(dom_node_internal *old, dom_node_internal **copy); +#define DOM_ELEMENT_VTABLE_HTML_ELEMENT \ + _dom_element_get_tag_name, \ + _dom_element_get_attribute, \ + _dom_element_set_attribute, \ + _dom_element_remove_attribute, \ + _dom_element_get_attribute_node, \ + _dom_element_set_attribute_node, \ + _dom_element_remove_attribute_node, \ + _dom_html_element_get_elements_by_tag_name, \ + _dom_element_get_attribute_ns, \ + _dom_element_set_attribute_ns, \ + _dom_element_remove_attribute_ns, \ + _dom_element_get_attribute_node_ns, \ + _dom_element_set_attribute_node_ns, \ + _dom_html_element_get_elements_by_tag_name_ns, \ + _dom_element_has_attribute, \ + _dom_element_has_attribute_ns, \ + _dom_element_get_schema_type_info, \ + _dom_element_set_id_attribute, \ + _dom_element_set_id_attribute_ns, \ + _dom_element_set_id_attribute_node, \ + _dom_element_get_classes, \ + _dom_element_has_class + #define DOM_HTML_ELEMENT_PROTECT_VTABLE \ _dom_html_element_destroy, \ _dom_html_element_copy |