Truly independent web browser
LibWeb: Splice whitespace runs separated by boxless siblings
Aliaksandr Kalenik98ae4fa91509
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex fe5558cc81d..bd407ca8652 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -893,8 +893,12 @@ impl ChildListInsertionReuse<'_, '_> {fn pending_children_can_preserve_parent(&self) -> bool {let collapses_whitespace = self.parent_collapses_whitespace();let mut has_pending_collapsing_whitespace = false;+ let mut inserted_whitespace_run_must_stay_last = false;for child in self.dom_children() {if !self.box_of(child).is_invalid() {+ if inserted_whitespace_run_must_stay_last {+ return false;+ }has_pending_collapsing_whitespace = false;if self.needs_layout_tree_update(child) || self.arena().child_needs_layout_tree_update(Some(child)) {return false;@@ -910,9 +914,7 @@ impl ChildListInsertionReuse<'_, '_> {&& !self.has_first_letter_owner&& self.collapsing_whitespace_can_be_inserted(child){- if has_pending_collapsing_whitespace {- return false;- }+ inserted_whitespace_run_must_stay_last |= has_pending_collapsing_whitespace;has_pending_collapsing_whitespace = true;continue;}@@ -1034,8 +1036,9 @@ impl ChildListInsertionReuse<'_, '_> {let mut all_indirect_existing_children_are_in_text_run_wrappers =self.layout.data(self.layout_node).kind.get() != NodeKind::FieldSetBox;let mut has_pending_collapsing_whitespace = false;- // An appended out-of-flow block joins the anonymous wrapper its preceding whitespace starts, as in a full- // build, only while that wrapper stays the parent's last child.+ // In a full build, an out-of-flow block or more whitespace after inserted whitespace joins the anonymous wrapper+ // that whitespace starts. The incremental insertion finds that wrapper only while it stays the parent's last+ // child.let mut inserted_whitespace_run_must_stay_last = false;// Counters are resolved from the boxes before a box, so an inserted subtree that touches one changes only what// comes after it.@@ -1076,9 +1079,10 @@ impl ChildListInsertionReuse<'_, '_> {&& collapses_whitespace&& !self.has_first_letter_owner&& self.collapsing_whitespace_can_be_inserted(child);- if !collapsed_whitespace_can_be_inserted || has_pending_collapsing_whitespace {+ if !collapsed_whitespace_can_be_inserted {return false;}+ inserted_whitespace_run_must_stay_last |= has_pending_collapsing_whitespace;has_pending_collapsing_whitespace = true;continue;}diff --git a/Tests/LibWeb/Text/expected/layout-tree-update/whitespace-child-insertion-preservation.txt b/Tests/LibWeb/Text/expected/layout-tree-update/whitespace-child-insertion-preservation.txtindex a76cfd58875..01ca795485b 100644--- a/Tests/LibWeb/Text/expected/layout-tree-update/whitespace-child-insertion-preservation.txt+++ b/Tests/LibWeb/Text/expected/layout-tree-update/whitespace-child-insertion-preservation.txt@@ -100,6 +100,18 @@ PASS: insert adjacent whitespace nodes between grid items | rebuild when extendiPASS: insert whitespace interleaved with hidden nodes | rebuild for interleaved batch | rebuildPASS: insert whitespace interleaved with hidden nodes | rebuild for interleaved batch | layout tree builds=1PASS: insert whitespace interleaved with hidden nodes | rebuild for interleaved batch | incremental tree matches full rebuild+PASS: append whitespace runs separated by boxless siblings | append whitespace, hidden element and whitespace | preserve+PASS: append whitespace runs separated by boxless siblings | append whitespace, hidden element and whitespace | layout tree builds=1+PASS: append whitespace runs separated by boxless siblings | append whitespace, hidden element and whitespace | incremental tree matches full rebuild+PASS: append whitespace runs separated by boxless siblings | append whitespace, script, whitespace and block | preserve+PASS: append whitespace runs separated by boxless siblings | append whitespace, script, whitespace and block | layout tree builds=1+PASS: append whitespace runs separated by boxless siblings | append whitespace, script, whitespace and block | incremental tree matches full rebuild+PASS: append whitespace runs separated by boxless siblings | append adjacent whitespace nodes | preserve+PASS: append whitespace runs separated by boxless siblings | append adjacent whitespace nodes | layout tree builds=1+PASS: append whitespace runs separated by boxless siblings | append adjacent whitespace nodes | incremental tree matches full rebuild+PASS: append whitespace runs separated by boxless siblings to flex items | append whitespace, hidden element, whitespace and item | preserve+PASS: append whitespace runs separated by boxless siblings to flex items | append whitespace, hidden element, whitespace and item | layout tree builds=1+PASS: append whitespace runs separated by boxless siblings to flex items | append whitespace, hidden element, whitespace and item | incremental tree matches full rebuildPASS: trailing inline run changes block insertion | create trailing run | preservePASS: trailing inline run changes block insertion | create trailing run | layout tree builds=1PASS: trailing inline run changes block insertion | create trailing run | incremental tree matches full rebuilddiff --git a/Tests/LibWeb/Text/input/layout-tree-update/whitespace-child-insertion-preservation.html b/Tests/LibWeb/Text/input/layout-tree-update/whitespace-child-insertion-preservation.htmlindex 8a7e328bc48..454787796e2 100644--- a/Tests/LibWeb/Text/input/layout-tree-update/whitespace-child-insertion-preservation.html+++ b/Tests/LibWeb/Text/input/layout-tree-update/whitespace-child-insertion-preservation.html@@ -227,6 +227,39 @@},],},+ {+ name: "append whitespace runs separated by boxless siblings",+ markup: '<div class="parent"><div class="tracked"></div></div>',+ steps: [+ {+ name: "append whitespace, hidden element and whitespace",+ mutate: parent => {+ const hidden = document.createElement("span");+ hidden.className = "hidden";+ parent.append(" ", hidden, "\n");+ },+ },+ {+ name: "append whitespace, script, whitespace and block",+ mutate: parent => parent.insertAdjacentHTML("beforeend", '\n<script type="text/plain">x<\/script>\n<p>after</p>'),+ },+ { name: "append adjacent whitespace nodes", mutate: parent => parent.append(" ", "\t") },+ ],+ },+ {+ name: "append whitespace runs separated by boxless siblings to flex items",+ markup: '<div class="parent flex"><div class="tracked"></div></div>',+ steps: [+ {+ name: "append whitespace, hidden element, whitespace and item",+ mutate: parent => {+ const hidden = document.createElement("span");+ hidden.className = "hidden";+ parent.append(" ", hidden, "\n", document.createElement("div"));+ },+ },+ ],+ },{name: "trailing inline run changes block insertion",markup: '<div class="parent"><div class="tracked"></div><div class="after"></div></div>',