summaryrefslogtreecommitdiff
path: root/include/dom
diff options
context:
space:
mode:
Diffstat (limited to 'include/dom')
-rw-r--r--include/dom/core/node.h10
-rw-r--r--include/dom/core/tokenlist.h43
-rw-r--r--include/dom/dom.h1
-rw-r--r--include/dom/html/html_elements.h9
-rw-r--r--include/dom/walk.h65
5 files changed, 123 insertions, 5 deletions
diff --git a/include/dom/core/node.h b/include/dom/core/node.h
index 9600e6d..90026a1 100644
--- a/include/dom/core/node.h
+++ b/include/dom/core/node.h
@@ -77,7 +77,7 @@ typedef struct dom_node_internal dom_node_internal;
* DOM node type
*/
typedef struct dom_node {
- void *vtable;
+ const void *vtable;
uint32_t refcnt;
} dom_node;
@@ -169,8 +169,8 @@ typedef struct dom_node_vtable {
dom_exception (*dom_node_set_user_data)(dom_node_internal *node,
dom_string *key, void *data,
dom_user_data_handler handler, void **result);
- dom_exception (*dom_node_get_user_data)(dom_node_internal *node,
- dom_string *key, void **result);
+ dom_exception (*dom_node_get_user_data)(const dom_node_internal *node,
+ const dom_string *key, void **result);
} dom_node_vtable;
/* The ref/unref methods define */
@@ -567,8 +567,8 @@ static inline dom_exception dom_node_set_user_data(struct dom_node *node,
(dom_node *) (n), (k), (void *) (d), \
(dom_user_data_handler) h, (void **) (r))
-static inline dom_exception dom_node_get_user_data(struct dom_node *node,
- dom_string *key, void **result)
+static inline dom_exception dom_node_get_user_data(const struct dom_node *node,
+ const dom_string *key, void **result)
{
return ((dom_node_vtable *) node->vtable)->dom_node_get_user_data(
(dom_node_internal *) node, key, result);
diff --git a/include/dom/core/tokenlist.h b/include/dom/core/tokenlist.h
new file mode 100644
index 0000000..718d3a5
--- /dev/null
+++ b/include/dom/core/tokenlist.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2022 Daniel Silverstone <dsilvers@netsurf-browser.org>
+ */
+
+#ifndef dom_core_tokenlist_h_
+#define dom_core_tokenlist_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_element;
+struct dom_string;
+
+typedef struct dom_tokenlist dom_tokenlist;
+
+void dom_tokenlist_ref(struct dom_tokenlist *list);
+void dom_tokenlist_unref(struct dom_tokenlist *list);
+
+dom_exception dom_tokenlist_create(struct dom_element *ele, struct dom_string *attr, dom_tokenlist **list);
+
+dom_exception dom_tokenlist_get_length(struct dom_tokenlist *list,
+ uint32_t *length);
+dom_exception _dom_tokenlist_item(struct dom_tokenlist *list,
+ uint32_t index, struct dom_string **value);
+
+#define dom_tokenlist_item(l, i, n) _dom_tokenlist_item((dom_tokenlist *) (l), \
+ (uint32_t) (i), (struct dom_string **) (n))
+
+dom_exception dom_tokenlist_get_value(struct dom_tokenlist *list,
+ struct dom_string **value);
+
+dom_exception dom_tokenlist_set_value(struct dom_tokenlist *list,
+ struct dom_string *value);
+
+dom_exception dom_tokenlist_contains(struct dom_tokenlist *list, struct dom_string *value, bool *contains);
+
+dom_exception dom_tokenlist_add(struct dom_tokenlist *list, struct dom_string *value);
+
+dom_exception dom_tokenlist_remove(struct dom_tokenlist *list, struct dom_string *value);
+
+#endif
diff --git a/include/dom/dom.h b/include/dom/dom.h
index c10e5a6..00bf3d9 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -32,6 +32,7 @@
#include <dom/core/doc_fragment.h>
#include <dom/core/entity_ref.h>
#include <dom/core/nodelist.h>
+#include <dom/core/tokenlist.h>
#include <dom/core/string.h>
#include <dom/core/text.h>
#include <dom/core/pi.h>
diff --git a/include/dom/html/html_elements.h b/include/dom/html/html_elements.h
index 5b54bbe..6e954c5 100644
--- a/include/dom/html/html_elements.h
+++ b/include/dom/html/html_elements.h
@@ -12,6 +12,7 @@
DOM_HTML_ELEMENT_STRINGS_ENTRY(_UNKNOWN) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(A) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(ABBR) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(ACRONYM) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(ADDRESS) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(APPLET) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(AREA) \
@@ -23,6 +24,8 @@
DOM_HTML_ELEMENT_STRINGS_ENTRY(BASEFONT) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(BDI) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(BDO) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(BGSOUND) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(BIG) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(BLOCKQUOTE) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(BODY) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(BR) \
@@ -81,11 +84,14 @@
DOM_HTML_ELEMENT_STRINGS_ENTRY(MAIN) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(MAP) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(MARK) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(MARQUEE) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(MENU) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(MENUITEM) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(META) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(METER) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(NAV) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(NOBR) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(NOFRAMES) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(NOSCRIPT) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(OBJECT) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(OL) \
@@ -108,7 +114,9 @@
DOM_HTML_ELEMENT_STRINGS_ENTRY(SELECT) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(SMALL) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(SOURCE) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(SPACER) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(SPAN) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(STRIKE) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(STRONG) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(STYLE) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(SUB) \
@@ -126,6 +134,7 @@
DOM_HTML_ELEMENT_STRINGS_ENTRY(TITLE) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(TR) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(TRACK) \
+ DOM_HTML_ELEMENT_STRINGS_ENTRY(TT) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(U) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(UL) \
DOM_HTML_ELEMENT_STRINGS_ENTRY(VAR) \
diff --git a/include/dom/walk.h b/include/dom/walk.h
new file mode 100644
index 0000000..5de3546
--- /dev/null
+++ b/include/dom/walk.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+/** \file
+ * This is an API for walking a loaded DOM.
+ */
+
+#ifndef dom_walk_h_
+#define dom_walk_h_
+
+enum dom_walk_stage {
+ DOM_WALK_STAGE_ENTER,
+ DOM_WALK_STAGE_LEAVE,
+};
+
+enum dom_walk_enable {
+ DOM_WALK_ENABLE_ENTER = (1 << DOM_WALK_STAGE_ENTER),
+ DOM_WALK_ENABLE_LEAVE = (1 << DOM_WALK_STAGE_LEAVE),
+ DOM_WALK_ENABLE_ALL = DOM_WALK_ENABLE_ENTER | DOM_WALK_ENABLE_LEAVE,
+};
+
+enum dom_walk_cmd {
+ DOM_WALK_CMD_CONTINUE, /**< Continue the tree walk. */
+ DOM_WALK_CMD_ABORT, /**< Early termination of the tree walk. */
+ DOM_WALK_CMD_SKIP, /**< Skip children (only for \ref DOM_WALK_ENABLE_ENTER). */
+};
+
+/**
+ * DOM walking callback.
+ *
+ * Client callback for DOM walk.
+ *
+ * \param[in] stage Whether the \ref node is being entered or left.
+ * \param[in] node The node being walked. Client must take ref itself.
+ * \param[in] type The node type.
+ * \param[in] pw Client private data.
+ * \return Tree walking client command.
+ */
+typedef enum dom_walk_cmd (*dom_walk_cb)(
+ enum dom_walk_stage stage,
+ dom_node_type type,
+ dom_node *node,
+ void *pw);
+
+
+/**
+ * Walk a DOM subtree.
+ *
+ * \param[in] mask Mask of stages to enable callback for.
+ * \param[in] cb The client callback function.
+ * \param[in] root Node to start walk from.
+ * \param[in] pw The client's private data.
+ * \return false for early termination of walk, true otherwise.
+ */
+dom_exception libdom_treewalk(
+ enum dom_walk_enable mask,
+ dom_walk_cb cb,
+ dom_node *root,
+ void *pw);
+
+#endif