summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2024-02-04 19:31:14 +0000
committerJohn-Mark Bell <jmb@netsurf-browser.org>2024-02-04 22:38:58 +0000
commit1c8b11727a7d4e1300d58671e4101cd4ce727b17 (patch)
treeb52a7e23ac6a2864bac49514943d83da261c07d3
parent60d232cc848997789bbe97aaf09748ad7aedc224 (diff)
downloadnetsurf-1c8b11727a7d4e1300d58671e4101cd4ce727b17.tar.gz
netsurf-1c8b11727a7d4e1300d58671e4101cd4ce727b17.tar.bz2
HTML: more granualar change tracking
-rw-r--r--content/handlers/html/box/manager.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/content/handlers/html/box/manager.c b/content/handlers/html/box/manager.c
index 02db4ef48..49e6453c5 100644
--- a/content/handlers/html/box/manager.c
+++ b/content/handlers/html/box/manager.c
@@ -8,12 +8,22 @@
/* Flags for DOM Element nodes */
-#define BM_DOM_FLAG_STRUCTURE_CHANGED 0x00000001
-/* Document structure has changed at this node: recompute style information
+#define BM_DOM_FLAG_NODE_INSERTED 0x00000001
+/* This node has been inserted into the DOM tree */
+#define BM_DOM_FLAG_PREVIOUS_NODE_REMOVED 0x00000002
+/* The node preceding this one was removed from the DOM tree */
+#define BM_DOM_FLAG_ID_ATTRIBUTE_CHANGED 0x00000004
+/* This node's @id has changed */
+#define BM_DOM_FLAG_CLASS_ATTRIBUTE_CHANGED 0x00000008
+/* This node's @class has changed */
+#define BM_DOM_FLAG_ATTRIBUTE_CHANGED 0x00000010
+/* A (non-@class/@id) attribute on this node has changed */
+
+/* If any of the above flags are set on a node: recompute style information
* for it, its descendants, its subsequent siblings, and their descendants.
* If styles have changed, rebuild box subtree */
-#define BM_DOM_FLAG_TEXT_CONTENTS_CHANGED 0x00000002
+#define BM_DOM_FLAG_TEXT_CONTENTS_CHANGED 0x00000100
/* Text contents of this node have changed: rebuild box subtree */
@@ -270,6 +280,22 @@ _set_node_flags(dom_node *node, void *pw)
return exc;
}
+static uintptr_t
+_attr_name_to_flag(dom_string *attr_name)
+{
+ uintptr_t flag = 0;
+
+ if (dom_string_isequal(attr_name, corestring_dom_class)) {
+ flag = BM_DOM_FLAG_CLASS_ATTRIBUTE_CHANGED;
+ } else if (dom_string_isequal(attr_name, corestring_dom_id)) {
+ flag = BM_DOM_FLAG_ID_ATTRIBUTE_CHANGED;
+ } else {
+ flag = BM_DOM_FLAG_ATTRIBUTE_CHANGED;
+ }
+
+ return flag;
+}
+
static void
box_manager_handle_dom_event(dom_event *evt, void *pw)
{
@@ -337,11 +363,24 @@ box_manager_handle_dom_event(dom_event *evt, void *pw)
/* Node removed: subsequent sibling element */
exc = _next_element_sibling((dom_node *) target,
_set_node_flags,
- (void *) BM_DOM_FLAG_STRUCTURE_CHANGED);
- } else {
- /* Just target itself */
+ (void *) BM_DOM_FLAG_PREVIOUS_NODE_REMOVED);
+ } else if (computed_type == corestring_dom_DOMNodeInserted) {
+ /* Node inserted: target itself */
exc = _set_node_flags((dom_node *) target,
- (void *) BM_DOM_FLAG_STRUCTURE_CHANGED);
+ (void *) BM_DOM_FLAG_NODE_INSERTED);
+ } else {
+ /* Attribute modified: target itself */
+ dom_string *attr_name = NULL;
+
+ exc = dom_mutation_event_get_attr_name(evt,
+ &attr_name);
+ if (exc == DOM_NO_ERR && attr_name != NULL) {
+ exc = _set_node_flags((dom_node *) target,
+ (void *) _attr_name_to_flag(
+ attr_name));
+
+ dom_string_unref(attr_name);
+ }
}
} else if (target_type == DOM_TEXT_NODE) {
/* Mark parent as text content changed */