diff options
-rw-r--r-- | content/handlers/html/box/manager.c | 53 |
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 */ |