layout: dirty parent node with NodeDamage::ContentOrHeritage when text content changed (#38057)

This change aims to reduce the scope of incremental box tree
construction. Previously, when text content changed, the parent node
would always be marked as requiring box tree reconstruction; now, it is
adjusted to only mark the parent node as needing to recollect its box
tree children.

Testing: This should not change observable behavior and is thus covered
by existing WPT tests.

Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This commit is contained in:
JoeDow 2025-07-14 19:21:45 +08:00 committed by GitHub
parent bf0e3f84d0
commit f6b98d5c56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -817,7 +817,13 @@ impl Node {
match self.type_id() { match self.type_id() {
NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => { NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => {
self.parent_node.get().unwrap().dirty(damage) // For content changes in text nodes, we should accurately use
// [`NodeDamage::ContentOrHeritage`] to mark the parent node, thereby
// reducing the scope of incremental box tree construction.
self.parent_node
.get()
.unwrap()
.dirty(NodeDamage::ContentOrHeritage)
}, },
NodeTypeId::Element(_) => self.downcast::<Element>().unwrap().restyle(damage), NodeTypeId::Element(_) => self.downcast::<Element>().unwrap().restyle(damage),
NodeTypeId::DocumentFragment(DocumentFragmentTypeId::ShadowRoot) => self NodeTypeId::DocumentFragment(DocumentFragmentTypeId::ShadowRoot) => self