summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dom/html/html_element.h39
-rw-r--r--src/html/html_element.c47
-rw-r--r--src/html/html_element.h11
3 files changed, 83 insertions, 14 deletions
diff --git a/include/dom/html/html_element.h b/include/dom/html/html_element.h
index 8c41664..ed7aa69 100644
--- a/include/dom/html/html_element.h
+++ b/include/dom/html/html_element.h
@@ -8,19 +8,36 @@
#ifndef dom_html_element_h_
#define dom_html_element_h_
+#include <dom/core/element.h>
+
typedef struct dom_html_element dom_html_element;
-/**
- * Note: DOM HTML spec is used to provide a more convenient way to
- * access Element's attribute through property. But, for implementation like
- * C, such propery provide no more convenience than Element.get(set)Attribute
- * function, so we ignore all the propety whose type is DOMString in this
- * implementation, clients can always access these property through
- * get(set)Attribute methods.
- *
- * For the readonly property, an readonly Attr node should be created, so once
- * these Attr nodes are created, they can not be changed any more.
- */
+typedef struct dom_html_element_vtable {
+ struct dom_element_vtable base;
+
+ dom_exception (*dom_html_element_get_id)(struct dom_html_element *element,
+ struct dom_string **id);
+ dom_exception (*dom_html_element_set_id)(struct dom_html_element *element,
+ struct dom_string *id);
+};
+
+static inline dom_exception dom_html_element_get_id(struct dom_html_element *element,
+ struct dom_string **id)
+{
+ return ((dom_html_element_vtable *) ((dom_node *) element)->vtable)->
+ dom_html_element_get_id(element, id);
+}
+#define dom_html_element_get_id(e, id) dom_html_element_get_id( \
+ (dom_html_element *) (e), (struct dom_string **) (id))
+
+static inline dom_exception dom_html_element_set_id(struct dom_html_element *element,
+ struct dom_string *id)
+{
+ return ((dom_html_element_vtable *) ((dom_node *) element)->vtable)->
+ dom_html_element_set_id(element, id);
+}
+#define dom_html_element_set_id(e, id) dom_html_element_set_id( \
+ (dom_html_element *) (e), (struct dom_string *) (id))
#endif
diff --git a/src/html/html_element.c b/src/html/html_element.c
index 4610c67..0101ee8 100644
--- a/src/html/html_element.c
+++ b/src/html/html_element.c
@@ -68,6 +68,53 @@ dom_exception _dom_html_element_copy(struct dom_node_internal *new,
}
/*-----------------------------------------------------------------------*/
+/* API functions */
+
+dom_exception _dom_html_element_get_id(dom_html_element *element,
+ struct dom_string **id)
+{
+ dom_exception ret;
+ dom_document *doc;
+ dom_string *idstr;
+
+ ret = dom_node_get_owner_document(element, &doc);
+ if (ret != DOM_NO_ERR)
+ return ret;
+
+ ret = dom_document_create_string(doc, "id", SLEN("id"), &idstr);
+ if (ret != DOM_NO_ERR)
+ return ret;
+
+ ret = dom_element_get_attribute(element, idstr, id);
+
+ dom_string_unref(idstr);
+
+ return ret;
+}
+
+dom_exception _dom_html_element_set_id(dom_html_element *element,
+ struct dom_string *id)
+{
+ dom_exception ret;
+ dom_document *doc;
+ dom_string *idstr;
+
+ ret = dom_node_get_owner_document(element, &doc);
+ if (ret != DOM_NO_ERR)
+ return ret;
+
+ ret = dom_document_create_string(doc, "id", SLEN("id"), &idstr);
+ if (ret != DOM_NO_ERR)
+ return ret;
+
+ ret = dom_element_set_attribute(element, idstr, id);
+
+ dom_string_unref(idstr);
+
+ return ret;
+}
+
+/*-----------------------------------------------------------------------*/
/* Common functions */
/**
diff --git a/src/html/html_element.h b/src/html/html_element.h
index 430dac4..d0691d6 100644
--- a/src/html/html_element.h
+++ b/src/html/html_element.h
@@ -17,9 +17,6 @@ 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;
@@ -44,6 +41,12 @@ dom_exception _dom_html_element_alloc(struct dom_document *doc,
dom_exception _dom_html_element_copy(struct dom_node_internal *new,
struct dom_node_internal *old);
+/* The API functions */
+dom_exception _dom_html_element_get_id(dom_html_element *element,
+ struct dom_string **id);
+dom_exception _dom_html_element_set_id(dom_html_element *element,
+ struct dom_string *id);
+
/* 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);
@@ -54,5 +57,7 @@ void _dom_html_element_get_form(dom_html_element *ele,
void _dom_html_element_associate_form(dom_html_element *ele,
struct dom_html_form_element *form);
+
+
#endif