diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2024-01-21 21:41:50 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2024-01-21 21:41:50 +0000 |
commit | 2baf7aa6094f95da5c63c819344fcca44d1b9c60 (patch) | |
tree | 48f26ddf34d5e1c95e005d0cff9af675de2e6ee3 | |
parent | 81c13e2110d39e28221f253157b927a471fc20ce (diff) | |
download | netsurf-2baf7aa6094f95da5c63c819344fcca44d1b9c60.tar.gz netsurf-2baf7aa6094f95da5c63c819344fcca44d1b9c60.tar.bz2 |
HTML/Docs: observe text content changes, too
-rw-r--r-- | content/handlers/html/box/manager.c | 27 | ||||
-rw-r--r-- | docs/ideas/boxes.txt | 23 | ||||
-rw-r--r-- | utils/corestringlist.h | 1 |
3 files changed, 48 insertions, 3 deletions
diff --git a/content/handlers/html/box/manager.c b/content/handlers/html/box/manager.c index 08d88b281..2d8df9c5e 100644 --- a/content/handlers/html/box/manager.c +++ b/content/handlers/html/box/manager.c @@ -227,6 +227,9 @@ box_manager_handle_dom_event(dom_event *evt, void *pw) } else if (dom_string_isequal(evt_type, corestring_dom_DOMAttrModified)) { computed_type = corestring_dom_DOMAttrModified; + } else if (dom_string_isequal(evt_type, + corestring_dom_DOMCharacterDataModified)) { + computed_type = corestring_dom_DOMCharacterDataModified; } } dom_string_unref(evt_type); @@ -240,9 +243,10 @@ box_manager_handle_dom_event(dom_event *evt, void *pw) return; } - /* 3. The event target must be an Element node */ + /* 3. The event target must be an Element or Text node */ exc = dom_node_get_node_type(target, &node_type); - if (exc != DOM_NO_ERR || node_type != DOM_ELEMENT_NODE) { + if (exc != DOM_NO_ERR || (node_type != DOM_ELEMENT_NODE && + node_type != DOM_TEXT_NODE)) { dom_node_unref(target); return; } @@ -284,10 +288,14 @@ box_manager_create(dom_document *doc, box_manager **manager) /* Register event listener. * - * We listen for AttrModified, NodeInserted, and NodeRemoved events. + * We listen for AttrModified, CharacterDataModified, NodeInserted, + * and NodeRemoved events. * * In all cases (where the event target is an Element), the affected * subtree is rooted at the Element's *parent* Element. + * + * Where the event target is a Text node, the affected Element is the + * closest Element ancestor of the Text node. */ exc = dom_event_listener_create(box_manager_handle_dom_event, mgr, &mgr->listener); @@ -332,6 +340,19 @@ box_manager_create(dom_document *doc, box_manager **manager) return NSERROR_DOM; } + exc = dom_event_target_add_event_listener(doc, + corestring_dom_DOMCharacterDataModified, + mgr->listener, + true); + if (exc != DOM_NO_ERR) { + /* Remove all instances of this listener */ + dom_event_target_remove_event_listener(doc, NULL, + mgr->listener, true); + dom_event_listener_unref(mgr->listener); + free(mgr); + return NSERROR_DOM; + } + mgr->doc = (dom_document *) dom_node_ref(doc); mgr->have_styles = false; mgr->callback_pending = false; diff --git a/docs/ideas/boxes.txt b/docs/ideas/boxes.txt index 8b7773e28..85e34361a 100644 --- a/docs/ideas/boxes.txt +++ b/docs/ideas/boxes.txt @@ -204,6 +204,29 @@ descendants. Note, however, that all dirty nodes in a tree need to be processed, so event processing should not try to short circuit here. +In addition to DOM changes which might affect the application of styling, we +are also interested in changes to text content which may cause the creation, +destruction, modification, or invalidation of boxes intended to contain the +content. To do this, we will use the following events, marking the containing +Element as requiring reflow (this is distinct from marking it dirty for the +purposes of style selection): + + 1. DOMCharacterDataModified + - Dispatched after the modification has happened + - The event target is the Text (or other, uninteresting) node + - The relatedNode field identifies the parent node (which may not be an + Element) + - Its parent Element must be searched for + 2. DOMNodeInserted + - Dispatched after the insertion is complete + - The event target is the inserted node (which may not be a Text node) + - The relatedNode field identifies the parent node (again, may not be + an Element) + 3. DOMNodeRemoved + - Dispatched before the removal has begun + - The event target is the removed node (which may not be a Text node) + - The relatedNode field identifies the parent node (again, may not be + an Element) Detecting changes to pseudo classes ----------------------------------- diff --git a/utils/corestringlist.h b/utils/corestringlist.h index 0e157a11b..ff8e49a35 100644 --- a/utils/corestringlist.h +++ b/utils/corestringlist.h @@ -227,6 +227,7 @@ CORESTRING_DOM_STRING(data); CORESTRING_DOM_STRING(dblclick); CORESTRING_DOM_STRING(defer); CORESTRING_DOM_STRING(DOMAttrModified); +CORESTRING_DOM_STRING(DOMCharacterDataModified); CORESTRING_DOM_STRING(DOMNodeInserted); CORESTRING_DOM_STRING(DOMNodeInsertedIntoDocument); CORESTRING_DOM_STRING(DOMNodeRemoved); |