summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2016-01-28 17:13:28 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2016-01-28 17:13:28 +0000
commitcedfbbce5ee148d04cfa87c3e459eea26ba397ef (patch)
tree89635134eed70c1df176a98aebd54eeab811ab20
parentfa2111088b5bb6b24b4acca53c95e1dc0284682e (diff)
downloadlibdom-cedfbbce5ee148d04cfa87c3e459eea26ba397ef.tar.gz
libdom-cedfbbce5ee148d04cfa87c3e459eea26ba397ef.tar.bz2
Add function to get html element's tag type.
-rw-r--r--Makefile1
-rw-r--r--include/dom/html/html_element.h18
-rw-r--r--src/html/html_element.c18
-rw-r--r--src/html/html_element.h5
4 files changed, 41 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index ddbdbd2..d287455 100644
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,7 @@ I := /$(INCLUDEDIR)/dom/html
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_document.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_collection.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_elements.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_html_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_head_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_link_element.h
diff --git a/include/dom/html/html_element.h b/include/dom/html/html_element.h
index dc1def1..49a7d59 100644
--- a/include/dom/html/html_element.h
+++ b/include/dom/html/html_element.h
@@ -9,6 +9,7 @@
#define dom_html_element_h_
#include <dom/core/element.h>
+#include <dom/html/html_elements.h>
typedef struct dom_html_element dom_html_element;
@@ -45,6 +46,12 @@ typedef struct dom_html_element_vtable {
dom_exception (*dom_html_element_set_class_name)(
struct dom_html_element *element,
dom_string *class_name);
+
+ /* This is for providing clients with a convienent way to deal
+ * with html elements with a specific tag name. */
+ dom_exception (*dom_html_element_get_tag_type)(
+ const struct dom_html_element *element,
+ dom_html_element_type *type);
} dom_html_element_vtable;
static inline dom_exception dom_html_element_get_id(
@@ -139,5 +146,16 @@ static inline dom_exception dom_html_element_set_class_name(
dom_html_element_set_class_name((dom_html_element *) (e), \
(class_name))
+static inline dom_exception dom_html_element_get_tag_type(
+ const struct dom_html_element *element,
+ dom_html_element_type *type)
+{
+ return ((dom_html_element_vtable *) ((dom_node *) element)->vtable)->
+ dom_html_element_get_tag_type(element, type);
+}
+#define dom_html_element_get_tag_type(e, type) \
+ dom_html_element_get_tag_type((const dom_html_element *) (e), \
+ (type))
+
#endif
diff --git a/src/html/html_element.c b/src/html/html_element.c
index 39aabda..85380ff 100644
--- a/src/html/html_element.c
+++ b/src/html/html_element.c
@@ -282,6 +282,24 @@ dom_exception _dom_html_element_get_elements_by_tag_name_ns(
return err;
}
+/**
+ * Retrieve an HTML element's tag type.
+ *
+ * \param element The element to get the tag type of.
+ * \param type Updated to the tag type of the element.
+ * \return DOM_NO_ERR
+ *
+ * Elements with non-standard tags will be DOM_HTML_ELEMENT_TYPE__UNKNOWN.
+ */
+dom_exception _dom_html_element_get_tag_type(
+ const struct dom_html_element *element,
+ dom_html_element_type *type)
+{
+ *type = element->type;
+
+ return DOM_NO_ERR;
+}
+
/*-----------------------------------------------------------------------*/
/* Common functions */
diff --git a/src/html/html_element.h b/src/html/html_element.h
index 7d86727..92c96ab 100644
--- a/src/html/html_element.h
+++ b/src/html/html_element.h
@@ -124,6 +124,8 @@ dom_exception _dom_html_element_get_class_name(dom_html_element *element,
dom_string **class_name);
dom_exception _dom_html_element_set_class_name(dom_html_element *element,
dom_string *class_name);
+dom_exception _dom_html_element_get_tag_type(const dom_html_element *element,
+ dom_html_element_type *type);
#define DOM_HTML_ELEMENT_VTABLE \
_dom_html_element_get_id, \
@@ -135,7 +137,8 @@ dom_exception _dom_html_element_set_class_name(dom_html_element *element,
_dom_html_element_get_dir, \
_dom_html_element_set_dir, \
_dom_html_element_get_class_name, \
- _dom_html_element_set_class_name
+ _dom_html_element_set_class_name, \
+ _dom_html_element_get_tag_type
/* Some common functions used by all child classes */
dom_exception dom_html_element_get_bool_property(dom_html_element *ele,