diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/nodelist.c | 83 | ||||
-rw-r--r-- | src/core/nodelist.h | 4 | ||||
-rw-r--r-- | src/html/TODO | 57 | ||||
-rw-r--r-- | src/html/html_document.c | 166 | ||||
-rw-r--r-- | src/html/html_document.h | 19 | ||||
-rw-r--r-- | src/html/html_document_strings.h | 135 | ||||
-rw-r--r-- | src/html/html_element.c | 6 | ||||
-rw-r--r-- | src/html/html_element.h | 2 | ||||
-rw-r--r-- | src/html/html_form_element.c | 78 | ||||
-rw-r--r-- | src/html/html_form_element.h | 2 | ||||
-rw-r--r-- | src/html/html_head_element.c | 53 | ||||
-rw-r--r-- | src/html/html_head_element.h | 2 | ||||
-rw-r--r-- | src/html/html_html_element.c | 52 | ||||
-rw-r--r-- | src/html/html_html_element.h | 4 | ||||
-rw-r--r-- | src/html/html_link_element.c | 65 | ||||
-rw-r--r-- | src/html/html_link_element.h | 2 | ||||
-rw-r--r-- | src/html/html_meta_element.c | 61 | ||||
-rw-r--r-- | src/html/html_meta_element.h | 2 | ||||
-rw-r--r-- | src/html/html_title_element.c | 22 | ||||
-rw-r--r-- | src/html/html_title_element.h | 2 |
20 files changed, 676 insertions, 141 deletions
diff --git a/src/core/nodelist.c b/src/core/nodelist.c index 1100329..8ce9475 100644 --- a/src/core/nodelist.c +++ b/src/core/nodelist.c @@ -84,7 +84,8 @@ dom_exception _dom_nodelist_create(dom_document *doc, nodelist_type type, l->type = type; - if (type == DOM_NODELIST_BY_NAME) { + if (type == DOM_NODELIST_BY_NAME || + type == DOM_NODELIST_BY_NAME_CASELESS) { assert(tagname != NULL); l->data.n.any_name = false; if (dom_string_byte_length(tagname) == 1) { @@ -95,7 +96,8 @@ dom_exception _dom_nodelist_create(dom_document *doc, nodelist_type type, } l->data.n.name = dom_string_ref(tagname); - } else if (type == DOM_NODELIST_BY_NAMESPACE) { + } else if (type == DOM_NODELIST_BY_NAMESPACE || + type == DOM_NODELIST_BY_NAMESPACE_CASELESS) { l->data.ns.any_localname = false; l->data.ns.any_namespace = false; if (localname != NULL) { @@ -159,12 +161,14 @@ void dom_nodelist_unref(dom_nodelist *list) /* Nothing to do */ break; case DOM_NODELIST_BY_NAMESPACE: + case DOM_NODELIST_BY_NAMESPACE_CASELESS: if (list->data.ns.namespace != NULL) dom_string_unref(list->data.ns.namespace); if (list->data.ns.localname != NULL) dom_string_unref(list->data.ns.localname); break; case DOM_NODELIST_BY_NAME: + case DOM_NODELIST_BY_NAME_CASELESS: assert(list->data.n.name != NULL); dom_string_unref(list->data.n.name); break; @@ -210,7 +214,15 @@ dom_exception dom_nodelist_get_length(dom_nodelist *list, unsigned long *length) if (cur->type == DOM_ELEMENT_NODE) len++; } - } else { + } else if (list->type == DOM_NODELIST_BY_NAME_CASELESS) { + if (list->data.n.any_name == true || ( + cur->name != NULL && + dom_string_caseless_isequal(cur->name, + list->data.n.name))) { + if (cur->type == DOM_ELEMENT_NODE) + len++; + } + } else if (list->type == DOM_NODELIST_BY_NAMESPACE) { if (list->data.ns.any_namespace == true || dom_string_isequal(cur->namespace, list->data.ns.namespace)) { @@ -222,6 +234,22 @@ dom_exception dom_nodelist_get_length(dom_nodelist *list, unsigned long *length) len++; } } + } else if (list->type == DOM_NODELIST_BY_NAMESPACE_CASELESS) { + if (list->data.ns.any_namespace == true || + dom_string_caseless_isequal( + cur->namespace, + list->data.ns.namespace)) { + if (list->data.ns.any_localname == true || + (cur->name != NULL && + dom_string_caseless_isequal( + cur->name, + list->data.ns.localname))) { + if (cur->type == DOM_ELEMENT_NODE) + len++; + } + } + } else { + assert("Unknown list type" == NULL); } /* Now, find next node */ @@ -290,7 +318,15 @@ dom_exception _dom_nodelist_item(dom_nodelist *list, if (cur->type == DOM_ELEMENT_NODE) count++; } - } else { + } else if (list->type == DOM_NODELIST_BY_NAME_CASELESS) { + if (list->data.n.any_name == true || ( + cur->name != NULL && + dom_string_caseless_isequal(cur->name, + list->data.n.name))) { + if (cur->type == DOM_ELEMENT_NODE) + count++; + } + } else if (list->type == DOM_NODELIST_BY_NAMESPACE) { if (list->data.ns.any_namespace == true || (cur->namespace != NULL && dom_string_isequal(cur->namespace, @@ -303,6 +339,23 @@ dom_exception _dom_nodelist_item(dom_nodelist *list, count++; } } + } else if (list->type == DOM_NODELIST_BY_NAMESPACE_CASELESS) { + if (list->data.ns.any_namespace == true || + (cur->namespace != NULL && + dom_string_caseless_isequal( + cur->namespace, + list->data.ns.namespace))) { + if (list->data.ns.any_localname == true || + (cur->name != NULL && + dom_string_caseless_isequal( + cur->name, + list->data.ns.localname))) { + if (cur->type == DOM_ELEMENT_NODE) + count++; + } + } + } else { + assert("Unknown list type" == NULL); } /* Stop if this is the requested index */ @@ -366,20 +419,24 @@ bool _dom_nodelist_match(dom_nodelist *list, nodelist_type type, if (list->type != type) return false; - - if (list->type == DOM_NODELIST_CHILDREN) { + + switch (list->type) { + case DOM_NODELIST_CHILDREN: return true; - } - - if (list->type == DOM_NODELIST_BY_NAME) { + case DOM_NODELIST_BY_NAME: return dom_string_isequal(list->data.n.name, tagname); - } - - if (list->type == DOM_NODELIST_BY_NAMESPACE) { + case DOM_NODELIST_BY_NAMESPACE: return dom_string_isequal(list->data.ns.namespace, namespace) && dom_string_isequal(list->data.ns.localname, localname); + case DOM_NODELIST_BY_NAME_CASELESS: + return dom_string_caseless_isequal(list->data.n.name, tagname); + case DOM_NODELIST_BY_NAMESPACE_CASELESS: + return dom_string_caseless_isequal(list->data.ns.namespace, + namespace) && + dom_string_caseless_isequal(list->data.ns.localname, + localname); } - + return false; } diff --git a/src/core/nodelist.h b/src/core/nodelist.h index 6bc36d7..4fe5b61 100644 --- a/src/core/nodelist.h +++ b/src/core/nodelist.h @@ -22,7 +22,9 @@ struct dom_nodelist; typedef enum { DOM_NODELIST_CHILDREN, DOM_NODELIST_BY_NAME, - DOM_NODELIST_BY_NAMESPACE + DOM_NODELIST_BY_NAMESPACE, + DOM_NODELIST_BY_NAME_CASELESS, + DOM_NODELIST_BY_NAMESPACE_CASELESS } nodelist_type; /* Create a nodelist */ diff --git a/src/html/TODO b/src/html/TODO new file mode 100644 index 0000000..8ff489d --- /dev/null +++ b/src/html/TODO @@ -0,0 +1,57 @@ +The following is the status of the HTML Element and derived objects, at least +as far as the test suite is concerned. + +HTMLElement html_element DONE +HTMLHtmlElement html_html_element DONE +HTMLHeadElement html_head_element DONE +HTMLLinkElement html_link_element MISSING +HTMLTitleElement html_title_element DONE +HTMLMetaElement html_meta_element MISSING +HTMLBaseElement html_base_element MISSING +HTMLIsIndexElement html_isindex_element MISSING +HTMLStyleElement html_style_element MISSING +HTMLBodyElement html_body_element MISSING +HTMLFormElement html_form_element DONE +HTMLSelectElement html_select_element MISSING +HTMLOptGroupElement html_optgroup_element MISSING +HTMLOptionElement html_option_element MISSING +HTMLInputElement html_input_element MISSING +HTMLTextAreaElement html_textarea_element MISSING +HTMLButtonElement html_button_element MISSING +HTMLLabelElement html_label_element MISSING +HTMLFieldSetElement html_fieldset_element MISSING +HTMLLegendElement html_legend_element MISSING +HTMLUListElement html_ulist_element MISSING +HTMLOListElement html_olist_element MISSING +HTMLDListElement html_dlist_element MISSING +HTMLDirectoryElement html_directory_element MISSING +HTMLMenuElement html_menu_element MISSING +HTMLLIElement html_li_element MISSING +HTMLBlockquoteElement html_blockquote_element MISSING +HTMLDivElement html_div_element MISSING +HTMLParagraphElement html_paragraph_element MISSING +HTMLHeadingElement html_heading_element MISSING +HTMLQuoteElement html_quote_element MISSING +HTMLPreElement html_pre_element MISSING +HTMLBRElement html_br_element MISSING +HTMLBaseFontElement html_basefont_element MISSING +HTMLFontElement html_font_element MISSING +HTMLHRElement html_hr_element MISSING +HTMLModElement html_mod_element MISSING +HTMLAnchorElement html_anchor_element MISSING +HTMLImageElement html_image_element MISSING +HTMLObjectElement html_object_element MISSING +HTMLParamElement html_param_element MISSING +HTMLAppletElement html_applet_element MISSING +HTMLMapElement html_map_element MISSING +HTMLAreaElement html_area_element MISSING +HTMLScriptElement html_script_element MISSING +HTMLTableElement html_table_element MISSING +HTMLTableCaptionElement html_tablecaption_element MISSING +HTMLTableColElement html_tablecol_element MISSING +HTMLTableSectionElement html_tablesection_element MISSING +HTMLTableRowElement html_tablerow_element MISSING +HTMLTableCellElement html_tablecell_element MISSING +HTMLFrameSetElement html_frameset_element MISSING +HTMLFrameElement html_frame_element MISSING +HTMLIFrameElement html_iframe_element MISSING diff --git a/src/html/html_document.c b/src/html/html_document.c index a18218b..b266844 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -11,6 +11,12 @@ #include "html/html_document.h" #include "html/html_element.h" #include "html/html_collection.h" +#include "html/html_html_element.h" +#include "html/html_head_element.h" +#include "html/html_link_element.h" +#include "html/html_title_element.h" +#include "html/html_meta_element.h" +#include "html/html_form_element.h" #include "core/string.h" #include "utils/namespace.h" @@ -64,6 +70,7 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc, dom_events_default_action_fetcher daf) { dom_exception error; + int sidx; error = _dom_document_initialise(&doc->base, daf); if (error != DOM_NO_ERR) @@ -75,47 +82,55 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc, doc->url = NULL; doc->cookie = NULL; - doc->_memo_id = doc->_memo_title = doc->_memo_lang = - doc->_memo_dir = doc->_memo_class = NULL; + doc->memoised = calloc(sizeof(dom_string *), hds_COUNT); + if (doc->memoised == NULL) { + error = DOM_NO_MEM_ERR; + goto out; + } -#define MEMOISE(attr) \ - error = dom_string_create_interned((const uint8_t *) #attr, \ - SLEN(#attr), &doc->_memo_##attr); \ +#define HTML_DOCUMENT_STRINGS_ACTION(attr,str) \ + error = dom_string_create_interned((const uint8_t *) #str, \ + SLEN(#str), &doc->memoised[hds_##attr]); \ if (error != DOM_NO_ERR) { \ - if (doc->_memo_id != NULL) \ - dom_string_unref(doc->_memo_id); \ - if (doc->_memo_title != NULL) \ - dom_string_unref(doc->_memo_title); \ - if (doc->_memo_lang != NULL) \ - dom_string_unref(doc->_memo_lang); \ - if (doc->_memo_dir != NULL) \ - dom_string_unref(doc->_memo_dir); \ - return error; \ + goto out; \ + } + +#include "html_document_strings.h" +#undef HTML_DOCUMENT_STRINGS_ACTION + +out: + if (doc->memoised != NULL && error != DOM_NO_ERR) { + for(sidx = 0; sidx < hds_COUNT; ++sidx) { + if (doc->memoised[sidx] != NULL) { + dom_string_unref(doc->memoised[sidx]); + } + } + free(doc->memoised); + doc->memoised = NULL; } - - MEMOISE(id) - MEMOISE(title) - MEMOISE(lang) - MEMOISE(dir) - MEMOISE(class) - return error; } /* Finalise a HTMLDocument */ void _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); - dom_string_unref(doc->_memo_id); - dom_string_unref(doc->_memo_title); - dom_string_unref(doc->_memo_lang); - dom_string_unref(doc->_memo_dir); - dom_string_unref(doc->_memo_class); + if (doc->memoised != NULL) { + for(sidx = 0; sidx < hds_COUNT; ++sidx) { + if (doc->memoised[sidx] != NULL) { + dom_string_unref(doc->memoised[sidx]); + } + } + free(doc->memoised); + doc->memoised = NULL; + } _dom_document_finalise(&doc->base); } @@ -140,7 +155,43 @@ dom_exception _dom_html_document_copy(dom_node_internal *old, } /* Overloaded methods inherited from super class */ -/** \todo: dispatch on tag name to create correct HTMLElement subclass */ + +/** 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 *namespace, + dom_string *prefix, + dom_html_element **result) +{ + if (dom_string_caseless_isequal(tag_name, html->memoised[hds_HTML])) { + return _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, + (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, + (dom_html_title_element **) result); + } + + if (dom_string_caseless_isequal(tag_name, html->memoised[hds_FORM])) { + return _dom_html_form_element_create(html, namespace, prefix, + (dom_html_form_element **) result); + } + + if (dom_string_caseless_isequal(tag_name, html->memoised[hds_LINK])) { + return _dom_html_link_element_create(html, namespace, prefix, + (dom_html_link_element **) result); + } + + return _dom_html_element_create(html, tag_name, namespace, prefix, + result); +} dom_exception _dom_html_document_create_element(dom_document *doc, dom_string *tag_name, dom_element **result) @@ -150,8 +201,9 @@ dom_exception _dom_html_document_create_element(dom_document *doc, if (_dom_validate_name(tag_name) == false) return DOM_INVALID_CHARACTER_ERR; - return _dom_html_element_create(html, tag_name, NULL, NULL, - (dom_html_element **) result); + return _dom_html_document_create_element_internal(html, + tag_name, NULL, NULL, + (dom_html_element **)result); } dom_exception _dom_html_document_create_element_ns(dom_document *doc, @@ -178,8 +230,8 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc, } /* Attempt to create element */ - err = _dom_html_element_create(html, localname, namespace, prefix, - (dom_html_element **) result); + err = _dom_html_document_create_element_internal(html, localname, + namespace, prefix, (dom_html_element **)result); /* Tidy up */ if (localname != NULL) { @@ -193,6 +245,48 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc, return err; } +/** + * Retrieve a list of all elements with a given tag name + * + * \param doc The document to search in + * \param tagname The tag name to search for ("*" for all) + * \param result Pointer to location to receive result + * \return DOM_NO_ERR. + * + * The returned list will have its reference count increased. It is + * the responsibility of the caller to unref the list once it has + * finished with it. + */ +dom_exception _dom_html_document_get_elements_by_tag_name(dom_document *doc, + dom_string *tagname, dom_nodelist **result) +{ + return _dom_document_get_nodelist(doc, DOM_NODELIST_BY_NAME_CASELESS, + (dom_node_internal *) doc, tagname, NULL, NULL, + result); +} + +/** + * Retrieve a list of all elements with a given local name and namespace URI + * + * \param doc The document to search in + * \param namespace The namespace URI + * \param localname The local name + * \param result Pointer to location to receive result + * \return DOM_NO_ERR on success, appropriate dom_exception on failure. + * + * The returned list will have its reference count increased. It is + * the responsibility of the caller to unref the list once it has + * finished with it. + */ +dom_exception _dom_html_document_get_elements_by_tag_name_ns( + dom_document *doc, dom_string *namespace, + dom_string *localname, dom_nodelist **result) +{ + return _dom_document_get_nodelist(doc, DOM_NODELIST_BY_NAMESPACE_CASELESS, + (dom_node_internal *) doc, NULL, namespace, localname, + result); +} + /*-----------------------------------------------------------------------*/ /* The DOM spec public API */ @@ -218,20 +312,12 @@ dom_exception _dom_html_document_get_title(dom_html_document *doc, *title = dom_string_ref(doc->title); } else { dom_element *node; - dom_string *title_str; dom_nodelist *nodes; unsigned long len; - exc = dom_string_create_interned((uint8_t*)"title", - 5, &title_str); - if (exc != DOM_NO_ERR) { - return exc; - } - exc = dom_document_get_elements_by_tag_name(doc, - title_str, + doc->memoised[hds_TITLE], &nodes); - dom_string_unref(title_str); if (exc != DOM_NO_ERR) { return exc; } diff --git a/src/html/html_document.h b/src/html/html_document.h index 57ec1ec..fbe7155 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -24,14 +24,12 @@ struct dom_html_document { dom_string *url; /**< HTML document URL */ dom_string *cookie; /**< HTML document cookie */ - /* Cached strings for html objects to use */ - dom_string *_memo_id; /**< Memoised 'id' */ - dom_string *_memo_title;/**< Memoised 'title' */ - dom_string *_memo_lang; /**< Memoised 'lang' */ - dom_string *_memo_dir; /**< Memoised 'dir' */ - dom_string *_memo_class;/**< Memoised 'class' */ + /** Cached strings for html objects to use */ + dom_string **memoised; }; +#include "html_document_strings.h" + /* Create a HTMLDocument */ dom_exception _dom_html_document_create( dom_events_default_action_fetcher daf, @@ -115,6 +113,11 @@ dom_exception _dom_html_document_create_element(dom_document *doc, dom_exception _dom_html_document_create_element_ns(dom_document *doc, dom_string *namespace, dom_string *qname, dom_element **result); +dom_exception _dom_html_document_get_elements_by_tag_name(dom_document *doc, + dom_string *tagname, dom_nodelist **result); +dom_exception _dom_html_document_get_elements_by_tag_name_ns( + dom_document *doc, dom_string *namespace, + dom_string *localname, dom_nodelist **result); #define DOM_DOCUMENT_VTABLE_HTML \ _dom_document_get_doctype, \ @@ -128,11 +131,11 @@ dom_exception _dom_html_document_create_element_ns(dom_document *doc, _dom_document_create_processing_instruction, \ _dom_document_create_attribute, \ _dom_document_create_entity_reference, \ - _dom_document_get_elements_by_tag_name, \ + _dom_html_document_get_elements_by_tag_name, \ _dom_document_import_node, \ _dom_html_document_create_element_ns, \ _dom_document_create_attribute_ns, \ - _dom_document_get_elements_by_tag_name_ns, \ + _dom_html_document_get_elements_by_tag_name_ns, \ _dom_document_get_element_by_id, \ _dom_document_get_input_encoding, \ _dom_document_get_xml_encoding, \ diff --git a/src/html/html_document_strings.h b/src/html/html_document_strings.h new file mode 100644 index 0000000..632b686 --- /dev/null +++ b/src/html/html_document_strings.h @@ -0,0 +1,135 @@ +/* + * This file is part of libdom. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2012 Daniel Silverstone <dsilvers@netsurf-browser.org> + */ + +/* Note, this file deliberately lacks guards since it's included many times + * in many places in order to correctly handle the loading of the strings. + */ + +#ifndef HTML_DOCUMENT_STRINGS_ACTION +#define HTML_DOCUMENT_STRINGS_INTERNAL_ACTION 1 +#define HTML_DOCUMENT_STRINGS_PREFIX \ + typedef enum { +#define HTML_DOCUMENT_STRINGS_SUFFIX \ + hds_COUNT \ + } html_document_memo_string_e; +#define HTML_DOCUMENT_STRINGS_ACTION(tag,str) \ + hds_##tag, +#endif + +#define HTML_DOCUMENT_STRINGS_ACTION1(x) HTML_DOCUMENT_STRINGS_ACTION(x,x) + +#ifdef HTML_DOCUMENT_STRINGS_PREFIX +HTML_DOCUMENT_STRINGS_PREFIX +#endif + +/* Useful attributes for HTMLElement */ +HTML_DOCUMENT_STRINGS_ACTION1(id) +HTML_DOCUMENT_STRINGS_ACTION1(title) +HTML_DOCUMENT_STRINGS_ACTION1(lang) +HTML_DOCUMENT_STRINGS_ACTION1(dir) +HTML_DOCUMENT_STRINGS_ACTION1(class) +/* Useful attributes used by HTMLHtmlElement */ +HTML_DOCUMENT_STRINGS_ACTION1(version) +/* Useful attributes used by HTMLHeadElement */ +HTML_DOCUMENT_STRINGS_ACTION1(profile) +/* Useful attributes used by HTMLLinkElement */ +HTML_DOCUMENT_STRINGS_ACTION1(charset) +HTML_DOCUMENT_STRINGS_ACTION1(href) +HTML_DOCUMENT_STRINGS_ACTION1(hreflang) +HTML_DOCUMENT_STRINGS_ACTION1(media) +HTML_DOCUMENT_STRINGS_ACTION1(rel) +HTML_DOCUMENT_STRINGS_ACTION1(rev) +HTML_DOCUMENT_STRINGS_ACTION1(target) +HTML_DOCUMENT_STRINGS_ACTION1(type) +/* Useful attributes used by HTMLMetaElement */ +HTML_DOCUMENT_STRINGS_ACTION1(content) +HTML_DOCUMENT_STRINGS_ACTION(http_equiv,http-equiv) +HTML_DOCUMENT_STRINGS_ACTION1(name) +HTML_DOCUMENT_STRINGS_ACTION1(scheme) +/* Useful attributes used by HTMLFormElement */ +HTML_DOCUMENT_STRINGS_ACTION(accept_charset,accept-charset) +HTML_DOCUMENT_STRINGS_ACTION1(action) +HTML_DOCUMENT_STRINGS_ACTION1(enctype) +HTML_DOCUMENT_STRINGS_ACTION1(method) +/* HTML_DOCUMENT_STRINGS_ACTION1(target) */ +/* Names for elements which get specialised. */ +HTML_DOCUMENT_STRINGS_ACTION1(HTML) +HTML_DOCUMENT_STRINGS_ACTION1(HEAD) +HTML_DOCUMENT_STRINGS_ACTION1(LINK) +HTML_DOCUMENT_STRINGS_ACTION1(TITLE) +HTML_DOCUMENT_STRINGS_ACTION1(META) +HTML_DOCUMENT_STRINGS_ACTION1(BASE) +HTML_DOCUMENT_STRINGS_ACTION1(ISINDEX) +HTML_DOCUMENT_STRINGS_ACTION1(STYLE) +HTML_DOCUMENT_STRINGS_ACTION1(BODY) +HTML_DOCUMENT_STRINGS_ACTION1(FORM) +HTML_DOCUMENT_STRINGS_ACTION1(SELECT) +HTML_DOCUMENT_STRINGS_ACTION1(OPTGROUP) +HTML_DOCUMENT_STRINGS_ACTION1(OPTION) +HTML_DOCUMENT_STRINGS_ACTION1(INPUT) +HTML_DOCUMENT_STRINGS_ACTION1(TEXTAREA) +HTML_DOCUMENT_STRINGS_ACTION1(BUTTON) +HTML_DOCUMENT_STRINGS_ACTION1(LABEL) +HTML_DOCUMENT_STRINGS_ACTION1(FIELDSET) +HTML_DOCUMENT_STRINGS_ACTION1(LEGEND) +HTML_DOCUMENT_STRINGS_ACTION1(UL) +HTML_DOCUMENT_STRINGS_ACTION1(OL) +HTML_DOCUMENT_STRINGS_ACTION1(DL) +HTML_DOCUMENT_STRINGS_ACTION1(DIR) +HTML_DOCUMENT_STRINGS_ACTION1(MENU) +HTML_DOCUMENT_STRINGS_ACTION1(LI) +HTML_DOCUMENT_STRINGS_ACTION1(BLOCKQUOTE) +HTML_DOCUMENT_STRINGS_ACTION1(DIV) +HTML_DOCUMENT_STRINGS_ACTION1(P) +HTML_DOCUMENT_STRINGS_ACTION1(H1) +HTML_DOCUMENT_STRINGS_ACTION1(H2) +HTML_DOCUMENT_STRINGS_ACTION1(H3) +HTML_DOCUMENT_STRINGS_ACTION1(H4) +HTML_DOCUMENT_STRINGS_ACTION1(H5) +HTML_DOCUMENT_STRINGS_ACTION1(H6) +HTML_DOCUMENT_STRINGS_ACTION1(Q) +HTML_DOCUMENT_STRINGS_ACTION1(PRE) +HTML_DOCUMENT_STRINGS_ACTION1(BR) +HTML_DOCUMENT_STRINGS_ACTION1(BASEFONT) +HTML_DOCUMENT_STRINGS_ACTION1(FONT) +HTML_DOCUMENT_STRINGS_ACTION1(HR) +HTML_DOCUMENT_STRINGS_ACTION1(INS) +HTML_DOCUMENT_STRINGS_ACTION1(DEL) +HTML_DOCUMENT_STRINGS_ACTION1(A) +HTML_DOCUMENT_STRINGS_ACTION1(IMG) +HTML_DOCUMENT_STRINGS_ACTION1(OBJECT) +HTML_DOCUMENT_STRINGS_ACTION1(PARAM) +HTML_DOCUMENT_STRINGS_ACTION1(APPLET) +HTML_DOCUMENT_STRINGS_ACTION1(MAP) +HTML_DOCUMENT_STRINGS_ACTION1(AREA) +HTML_DOCUMENT_STRINGS_ACTION1(SCRIPT) +HTML_DOCUMENT_STRINGS_ACTION1(TABLE) +HTML_DOCUMENT_STRINGS_ACTION1(CAPTION) +HTML_DOCUMENT_STRINGS_ACTION1(COL) +HTML_DOCUMENT_STRINGS_ACTION1(COLGROUP) +HTML_DOCUMENT_STRINGS_ACTION1(THEAD) +HTML_DOCUMENT_STRINGS_ACTION1(TFOOT) +HTML_DOCUMENT_STRINGS_ACTION1(TBODY) +HTML_DOCUMENT_STRINGS_ACTION1(TR) +HTML_DOCUMENT_STRINGS_ACTION1(TH) +HTML_DOCUMENT_STRINGS_ACTION1(TD) +HTML_DOCUMENT_STRINGS_ACTION1(FRAMESET) +HTML_DOCUMENT_STRINGS_ACTION1(FRAME) +HTML_DOCUMENT_STRINGS_ACTION1(IFRAME) + +#ifdef HTML_DOCUMENT_STRINGS_SUFFIX +HTML_DOCUMENT_STRINGS_SUFFIX +#endif + +#undef HTML_DOCUMENT_STRINGS_ACTION1 + +#ifdef HTML_DOCUMENT_STRINGS_INTERNAL_ACTION +#undef HTML_DOCUMENT_STRINGS_INTERNAL_ACTION +#undef HTML_DOCUMENT_STRINGS_PREFIX +#undef HTML_DOCUMENT_STRINGS_SUFFIX +#undef HTML_DOCUMENT_STRINGS_ACTION +#endif diff --git a/src/html/html_element.c b/src/html/html_element.c index 18607d7..3642c6c 100644 --- a/src/html/html_element.c +++ b/src/html/html_element.c @@ -16,7 +16,7 @@ #include "core/document.h" #include "utils/utils.h" -static struct dom_html_element_vtable _dom_html_element_vtable = { +struct dom_html_element_vtable _dom_html_element_vtable = { { { { @@ -112,7 +112,7 @@ dom_exception _dom_html_element_get_##fattr(dom_html_element *element, \ \ _memo_##attr = \ ((struct dom_html_document *) \ - ((struct dom_node_internal *)element)->owner)->_memo_##attr; \ + ((struct dom_node_internal *)element)->owner)->memoised[hds_##attr]; \ \ ret = dom_element_get_attribute(element, _memo_##attr, fattr); \ \ @@ -127,7 +127,7 @@ dom_exception _dom_html_element_set_##fattr(dom_html_element *element, \ \ _memo_##attr = \ ((struct dom_html_document *) \ - ((struct dom_node_internal *)element)->owner)->_memo_##attr; \ + ((struct dom_node_internal *)element)->owner)->memoised[hds_##attr]; \ \ ret = dom_element_set_attribute(element, _memo_##attr, fattr); \ \ diff --git a/src/html/html_element.h b/src/html/html_element.h index 2766dab..4a81102 100644 --- a/src/html/html_element.h +++ b/src/html/html_element.h @@ -83,5 +83,7 @@ dom_exception dom_html_element_get_bool_property(dom_html_element *ele, dom_exception dom_html_element_set_bool_property(dom_html_element *ele, const char *name, unsigned long len, bool has); +extern struct dom_html_element_vtable _dom_html_element_vtable; + #endif diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c index b24a08e..d0a453d 100644 --- a/src/html/html_form_element.c +++ b/src/html/html_form_element.c @@ -8,6 +8,8 @@ #include <assert.h> #include <stdlib.h> +#include <dom/html/html_form_element.h> + #include "html/html_form_element.h" #include "html/html_collection.h" @@ -33,6 +35,7 @@ static bool _dom_is_form_control(struct dom_node_internal *node); * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element **ele) { struct dom_node_internal *node; @@ -43,10 +46,10 @@ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, /* Set up vtables */ node = (struct dom_node_internal *) *ele; - node->base.vtable = &_dom_element_vtable; + node->base.vtable = &_dom_html_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_form_element_initialise(doc, *ele); + return _dom_html_form_element_initialise(doc, namespace, prefix, *ele); } /** @@ -57,18 +60,15 @@ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element *ele) { - dom_string *name = NULL; dom_exception err; - err = dom_string_create((const uint8_t *) "FORM", SLEN("FORM"), &name); - if (err != DOM_NO_ERR) - return err; + err = _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_FORM], + namespace, prefix); - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - ele->col = NULL; return err; @@ -184,6 +184,48 @@ dom_exception dom_html_form_element_get_length(dom_html_form_element *ele, return dom_html_collection_get_length(ele->col, len); } +#define SIMPLE_GET_SET(attr) \ + dom_exception dom_html_form_element_get_##attr( \ + dom_html_form_element *element, \ + dom_string **attr) \ + { \ + dom_exception ret; \ + dom_string *_memo_##attr; \ + \ + _memo_##attr = \ + ((struct dom_html_document *) \ + ((struct dom_node_internal *)element)->owner)->\ + memoised[hds_##attr]; \ + \ + ret = dom_element_get_attribute(element, _memo_##attr, attr); \ + \ + return ret; \ + } \ + \ + dom_exception dom_html_form_element_set_##attr( \ + dom_html_form_element *element, \ + dom_string *attr) \ + { \ + dom_exception ret; \ + dom_string *_memo_##attr; \ + \ + _memo_##attr = \ + ((struct dom_html_document *) \ + ((struct dom_node_internal *)element)->owner)->\ + memoised[hds_##attr]; \ + \ + ret = dom_element_set_attribute(element, _memo_##attr, attr); \ + \ + return ret; \ + } + +SIMPLE_GET_SET(accept_charset) +SIMPLE_GET_SET(action) +SIMPLE_GET_SET(enctype) +SIMPLE_GET_SET(method) +SIMPLE_GET_SET(target) + + /** * Submit this form * @@ -231,11 +273,25 @@ dom_exception dom_html_form_element_reset(dom_html_form_element *ele) * src/html/html_collection.h for detail. */ static bool _dom_is_form_control(struct dom_node_internal *node) { - UNUSED(node); + struct dom_html_document *doc = + (struct dom_html_document *)(node->owner); assert(node->type == DOM_ELEMENT_NODE); - /** \todo: implement */ + /* Form controls are INPUT TEXTAREA SELECT and BUTTON */ + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_INPUT])) + return true; + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_TEXTAREA])) + return true; + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_SELECT])) + return true; + if (dom_string_caseless_isequal(node->name, + doc->memoised[hds_BUTTON])) + return true; + return false; } diff --git a/src/html/html_form_element.h b/src/html/html_form_element.h index dbf6267..1ee9878 100644 --- a/src/html/html_form_element.h +++ b/src/html/html_form_element.h @@ -23,10 +23,12 @@ struct dom_html_form_element { /* Create a dom_html_form_element object */ dom_exception _dom_html_form_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element **ele); /* Initialise a dom_html_form_element object */ dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_form_element *ele); /* Finalise a dom_html_form_element object */ diff --git a/src/html/html_head_element.c b/src/html/html_head_element.c index d74b8d1..00d4476 100644 --- a/src/html/html_head_element.c +++ b/src/html/html_head_element.c @@ -7,6 +7,7 @@ #include <stdlib.h> +#include "html/html_document.h" #include "html/html_head_element.h" #include "core/node.h" @@ -27,6 +28,7 @@ static struct dom_element_protected_vtable _protect_vtable = { * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_head_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_head_element **ele) { struct dom_node_internal *node; @@ -37,10 +39,10 @@ dom_exception _dom_html_head_element_create(struct dom_html_document *doc, /* Set up vtables */ node = (struct dom_node_internal *) *ele; - node->base.vtable = &_dom_element_vtable; + node->base.vtable = &_dom_html_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_head_element_initialise(doc, *ele); + return _dom_html_head_element_initialise(doc, namespace, prefix, *ele); } /** @@ -51,19 +53,12 @@ dom_exception _dom_html_head_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_head_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_head_element *ele) { - dom_string *name = NULL; - dom_exception err; - - err = dom_string_create((const uint8_t *) "HEAD", SLEN("HEAD"), &name); - if (err != DOM_NO_ERR) - return err; - - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - - return err; + return _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_HEAD], + namespace, prefix); } /** @@ -118,3 +113,35 @@ dom_exception _dom_html_head_element_copy(dom_node_internal *old, return _dom_html_element_copy(old, copy); } +/*-----------------------------------------------------------------------*/ +/* API functions */ + +dom_exception dom_html_head_element_get_profile(dom_html_head_element *element, + dom_string **profile) +{ + dom_exception ret; + dom_string *_memo_profile; + + _memo_profile = + ((struct dom_html_document *) + ((struct dom_node_internal *)element)->owner)->memoised[hds_profile]; + + ret = dom_element_get_attribute(element, _memo_profile, profile); + + return ret; +} + +dom_exception dom_html_head_element_set_profile(dom_html_head_element *element, + dom_string *profile) +{ + dom_exception ret; + dom_string *_memo_profile; + + _memo_profile = + ((struct dom_html_document *) + ((struct dom_node_internal *)element)->owner)->memoised[hds_profile]; + + ret = dom_element_set_attribute(element, _memo_profile, profile); + + return ret; +} diff --git a/src/html/html_head_element.h b/src/html/html_head_element.h index aa6e21a..deb2d6a 100644 --- a/src/html/html_head_element.h +++ b/src/html/html_head_element.h @@ -19,10 +19,12 @@ struct dom_html_head_element { /* Create a dom_html_head_element object */ dom_exception _dom_html_head_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_head_element **ele); /* Initialise a dom_html_head_element object */ dom_exception _dom_html_head_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_head_element *ele); /* Finalise a dom_html_head_element object */ diff --git a/src/html/html_html_element.c b/src/html/html_html_element.c index 1bdf590..ee26019 100644 --- a/src/html/html_html_element.c +++ b/src/html/html_html_element.c @@ -7,6 +7,7 @@ #include <stdlib.h> +#include "html/html_document.h" #include "html/html_html_element.h" #include "core/node.h" @@ -27,6 +28,7 @@ static struct dom_element_protected_vtable _protect_vtable = { * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_html_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_html_element **ele) { struct dom_node_internal *node; @@ -37,10 +39,10 @@ dom_exception _dom_html_html_element_create(struct dom_html_document *doc, /* Set up vtables */ node = (struct dom_node_internal *) *ele; - node->base.vtable = &_dom_element_vtable; + node->base.vtable = &_dom_html_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_html_element_initialise(doc, *ele); + return _dom_html_html_element_initialise(doc, namespace, prefix, *ele); } /** @@ -51,19 +53,11 @@ dom_exception _dom_html_html_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_html_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_html_element *ele) { - dom_string *name = NULL; - dom_exception err; - - err = dom_string_create((const uint8_t *) "HTML", SLEN("HTML"), &name); - if (err != DOM_NO_ERR) - return err; - - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - - return err; + return _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_HTML], namespace, prefix); } /** @@ -119,3 +113,35 @@ dom_exception _dom_html_html_element_copy(dom_node_internal *old, return _dom_html_element_copy(old, copy); } +/*-----------------------------------------------------------------------*/ +/* API functions */ + +dom_exception dom_html_html_element_get_version(dom_html_html_element *element, + dom_string **version) +{ + dom_exception ret; + dom_string *_memo_version; + + _memo_version = + ((struct dom_html_document *) + ((struct dom_node_internal *)element)->owner)->memoised[hds_version]; + + ret = dom_element_get_attribute(element, _memo_version, version); + + return ret; +} + +dom_exception dom_html_html_element_set_version(dom_html_html_element *element, + dom_string *version) +{ + dom_exception ret; + dom_string *_memo_version; + + _memo_version = + ((struct dom_html_document *) + ((struct dom_node_internal *)element)->owner)->memoised[hds_version]; + + ret = dom_element_set_attribute(element, _memo_version, version); + + return ret; +} diff --git a/src/html/html_html_element.h b/src/html/html_html_element.h index f943f7b..61eb626 100644 --- a/src/html/html_html_element.h +++ b/src/html/html_html_element.h @@ -19,10 +19,12 @@ struct dom_html_html_element { /* Create a dom_html_html_element object */ dom_exception _dom_html_html_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_html_element **ele); /* Initialise a dom_html_html_element object */ dom_exception _dom_html_html_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_html_element *ele); /* Finalise a dom_html_html_element object */ @@ -40,7 +42,7 @@ dom_exception _dom_html_html_element_copy(dom_node_internal *old, dom_node_internal **copy); #define DOM_HTML_HTML_ELEMENT_PROTECT_VTABLE \ - _dom_html_html_element_parse_attribute + _dom_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_HTML_ELEMENT \ _dom_virtual_html_html_element_destroy, \ diff --git a/src/html/html_link_element.c b/src/html/html_link_element.c index 92ca4f5..8e9a302 100644 --- a/src/html/html_link_element.c +++ b/src/html/html_link_element.c @@ -8,6 +8,7 @@ #include <assert.h> #include <stdlib.h> +#include "html/html_document.h" #include "html/html_link_element.h" #include "core/node.h" @@ -29,6 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_link_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_link_element **ele) { struct dom_node_internal *node; @@ -42,7 +44,7 @@ dom_exception _dom_html_link_element_create(struct dom_html_document *doc, node->base.vtable = &_dom_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_link_element_initialise(doc, *ele); + return _dom_html_link_element_initialise(doc, namespace, prefix, *ele); } /** @@ -53,19 +55,12 @@ dom_exception _dom_html_link_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_link_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_link_element *ele) { - dom_string *name = NULL; - dom_exception err; - - err = dom_string_create((const uint8_t *) "HEAD", SLEN("HEAD"), &name); - if (err != DOM_NO_ERR) - return err; - - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - - return err; + return _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_LINK], + namespace, prefix); } /** @@ -151,3 +146,49 @@ dom_exception _dom_html_link_element_copy(dom_node_internal *old, return _dom_html_element_copy(old, copy); } +/*-----------------------------------------------------------------------*/ +/* API functions */ + +#define SIMPLE_GET_SET(attr) \ + dom_exception dom_html_link_element_get_##attr( \ + dom_html_link_element *element, \ + dom_string **attr) \ + { \ + dom_exception ret; \ + dom_string *_memo_##attr; \ + \ + _memo_##attr = \ + ((struct dom_html_document *) \ + ((struct dom_node_internal *)element)->owner)->\ + memoised[hds_##attr]; \ + \ + ret = dom_element_get_attribute(element, _memo_##attr, attr); \ + \ + return ret; \ + } \ + \ + dom_exception dom_html_link_element_set_##attr( \ + dom_html_link_element *element, \ + dom_string *attr) \ + { \ + dom_exception ret; \ + dom_string *_memo_##attr; \ + \ + _memo_##attr = \ + ((struct dom_html_document *) \ + ((struct dom_node_internal *)element)->owner)->\ + memoised[hds_##attr]; \ + \ + ret = dom_element_set_attribute(element, _memo_##attr, attr); \ + \ + return ret; \ + } + +SIMPLE_GET_SET(charset) +SIMPLE_GET_SET(href) +SIMPLE_GET_SET(hreflang) +SIMPLE_GET_SET(media) +SIMPLE_GET_SET(rel) +SIMPLE_GET_SET(rev) +SIMPLE_GET_SET(target) +SIMPLE_GET_SET(type) diff --git a/src/html/html_link_element.h b/src/html/html_link_element.h index b281cfb..960dcdc 100644 --- a/src/html/html_link_element.h +++ b/src/html/html_link_element.h @@ -19,10 +19,12 @@ struct dom_html_link_element { /* Create a dom_html_link_element object */ dom_exception _dom_html_link_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_link_element **ele); /* Initialise a dom_html_link_element object */ dom_exception _dom_html_link_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_link_element *ele); /* Finalise a dom_html_link_element object */ diff --git a/src/html/html_meta_element.c b/src/html/html_meta_element.c index f1b6c3f..7a254e6 100644 --- a/src/html/html_meta_element.c +++ b/src/html/html_meta_element.c @@ -7,6 +7,7 @@ #include <stdlib.h> +#include "html/html_document.h" #include "html/html_meta_element.h" #include "core/node.h" @@ -27,6 +28,7 @@ static struct dom_element_protected_vtable _protect_vtable = { * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_meta_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_meta_element **ele) { struct dom_node_internal *node; @@ -40,7 +42,7 @@ dom_exception _dom_html_meta_element_create(struct dom_html_document *doc, node->base.vtable = &_dom_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_meta_element_initialise(doc, *ele); + return _dom_html_meta_element_initialise(doc, namespace, prefix, *ele); } /** @@ -51,19 +53,12 @@ dom_exception _dom_html_meta_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_meta_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_meta_element *ele) { - dom_string *name = NULL; - dom_exception err; - - err = dom_string_create((const uint8_t *) "META", SLEN("META"), &name); - if (err != DOM_NO_ERR) - return err; - - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - - return err; + return _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_META], + namespace, prefix); } /** @@ -118,3 +113,45 @@ dom_exception _dom_html_meta_element_copy(dom_node_internal *old, return _dom_html_element_copy(old, copy); } +/*-----------------------------------------------------------------------*/ +/* API functions */ + +#define SIMPLE_GET_SET(attr) \ + dom_exception dom_html_meta_element_get_##attr( \ + dom_html_meta_element *element, \ + dom_string **attr) \ + { \ + dom_exception ret; \ + dom_string *_memo_##attr; \ + \ + _memo_##attr = \ + ((struct dom_html_document *) \ + ((struct dom_node_internal *)element)->owner)->\ + memoised[hds_##attr]; \ + \ + ret = dom_element_get_attribute(element, _memo_##attr, attr); \ + \ + return ret; \ + } \ + \ + dom_exception dom_html_meta_element_set_##attr( \ + dom_html_meta_element *element, \ + dom_string *attr) \ + { \ + dom_exception ret; \ + dom_string *_memo_##attr; \ + \ + _memo_##attr = \ + ((struct dom_html_document *) \ + ((struct dom_node_internal *)element)->owner)->\ + memoised[hds_##attr]; \ + \ + ret = dom_element_set_attribute(element, _memo_##attr, attr); \ + \ + return ret; \ + } + +SIMPLE_GET_SET(content) +SIMPLE_GET_SET(http_equiv) +SIMPLE_GET_SET(name) +SIMPLE_GET_SET(scheme) diff --git a/src/html/html_meta_element.h b/src/html/html_meta_element.h index d302d24..d4a1076 100644 --- a/src/html/html_meta_element.h +++ b/src/html/html_meta_element.h @@ -19,10 +19,12 @@ struct dom_html_meta_element { /* Create a dom_html_meta_element object */ dom_exception _dom_html_meta_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_meta_element **ele); /* Initialise a dom_html_meta_element object */ dom_exception _dom_html_meta_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_meta_element *ele); /* Finalise a dom_html_meta_element object */ diff --git a/src/html/html_title_element.c b/src/html/html_title_element.c index ea4d24c..80da5e1 100644 --- a/src/html/html_title_element.c +++ b/src/html/html_title_element.c @@ -11,6 +11,7 @@ #include <dom/core/characterdata.h> #include <dom/core/text.h> +#include "html/html_document.h" #include "html/html_title_element.h" #include "core/node.h" @@ -31,6 +32,7 @@ static struct dom_element_protected_vtable _protect_vtable = { * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_title_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_title_element **ele) { struct dom_node_internal *node; @@ -41,10 +43,10 @@ dom_exception _dom_html_title_element_create(struct dom_html_document *doc, /* Set up vtables */ node = (struct dom_node_internal *) *ele; - node->base.vtable = &_dom_element_vtable; + node->base.vtable = &_dom_html_element_vtable; node->vtable = &_protect_vtable; - return _dom_html_title_element_initialise(doc, *ele); + return _dom_html_title_element_initialise(doc, namespace, prefix, *ele); } /** @@ -55,20 +57,12 @@ dom_exception _dom_html_title_element_create(struct dom_html_document *doc, * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_html_title_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_title_element *ele) { - dom_string *name = NULL; - dom_exception err; - - err = dom_string_create((const uint8_t *) "TITLE", SLEN("TITLE"), - &name); - if (err != DOM_NO_ERR) - return err; - - err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - dom_string_unref(name); - - return err; + return _dom_html_element_initialise(doc, &ele->base, + doc->memoised[hds_TITLE], + namespace, prefix); } /** diff --git a/src/html/html_title_element.h b/src/html/html_title_element.h index 958c3fe..51adaf9 100644 --- a/src/html/html_title_element.h +++ b/src/html/html_title_element.h @@ -19,10 +19,12 @@ struct dom_html_title_element { /* Create a dom_html_title_element object */ dom_exception _dom_html_title_element_create(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_title_element **ele); /* Initialise a dom_html_title_element object */ dom_exception _dom_html_title_element_initialise(struct dom_html_document *doc, + dom_string *namespace, dom_string *prefix, struct dom_html_title_element *ele); /* Finalise a dom_html_title_element object */ |