Truly independent web browser
LibWeb: Splice appended out-of-flow blocks after pending whitespace
Aliaksandr Kalenik4b75b2670298
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 6fecc38b6d6..b00b5814043 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -1024,9 +1024,15 @@ 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.+ let mut inserted_whitespace_run_must_stay_last = false;for child in self.dom_children() {let child_layout_node = self.box_of(child);if !child_layout_node.is_invalid() {+ if inserted_whitespace_run_must_stay_last {+ return false;+ }has_pending_collapsing_whitespace = false;has_existing_child_after_insertion |= has_inserted_child;if self.layout.parent(child_layout_node) != self.layout_node {@@ -1106,7 +1112,7 @@ impl ChildListInsertionReuse<'_, '_> {}if parent_lays_out_block_children && child_display.is_block_outside() {if has_pending_collapsing_whitespace && !child_is_in_flow {- return false;+ inserted_whitespace_run_must_stay_last = true;}has_pending_collapsing_whitespace = false;has_inserted_child = true;diff --git a/Tests/LibWeb/Text/expected/layout-tree-update/direct-child-list-preservation.txt b/Tests/LibWeb/Text/expected/layout-tree-update/direct-child-list-preservation.txtindex 0f339a368ca..f73004a4adc 100644--- a/Tests/LibWeb/Text/expected/layout-tree-update/direct-child-list-preservation.txt+++ b/Tests/LibWeb/Text/expected/layout-tree-update/direct-child-list-preservation.txt@@ -148,6 +148,30 @@ PASS: append relative item after whitespace in flex | preserve parentPASS: append relative item after whitespace in flex | preserve beforePASS: append relative item after whitespace in flex | layout tree builds=1PASS: append relative item after whitespace in flex | incremental tree matches full rebuild+PASS: append absolute block child after whitespace | preserve parent+PASS: append absolute block child after whitespace | preserve before+PASS: append absolute block child after whitespace | layout tree builds=1+PASS: append absolute block child after whitespace | incremental tree matches full rebuild+PASS: append floated block child after whitespace | preserve parent+PASS: append floated block child after whitespace | preserve before+PASS: append floated block child after whitespace | layout tree builds=1+PASS: append floated block child after whitespace | incremental tree matches full rebuild+PASS: append absolute block child between whitespace and blocks | preserve parent+PASS: append absolute block child between whitespace and blocks | preserve before+PASS: append absolute block child between whitespace and blocks | layout tree builds=1+PASS: append absolute block child between whitespace and blocks | incremental tree matches full rebuild+PASS: append block and whitespace ending in absolute block child | preserve parent+PASS: append block and whitespace ending in absolute block child | preserve before+PASS: append block and whitespace ending in absolute block child | layout tree builds=1+PASS: append block and whitespace ending in absolute block child | incremental tree matches full rebuild+PASS: append absolute block child after whitespace and anonymous inline run | preserve parent+PASS: append absolute block child after whitespace and anonymous inline run | preserve before+PASS: append absolute block child after whitespace and anonymous inline run | preserve inline+PASS: append absolute block child after whitespace and anonymous inline run | layout tree builds=1+PASS: append absolute block child after whitespace and anonymous inline run | incremental tree matches full rebuild+PASS: fall back for absolute block child after whitespace before existing child | rebuild parent+PASS: fall back for absolute block child after whitespace before existing child | layout tree builds=1+PASS: fall back for absolute block child after whitespace before existing child | incremental tree matches full rebuildPASS: fall back for block child before anonymous inline run | rebuild parentPASS: fall back for block child before anonymous inline run | layout tree builds=1PASS: fall back for block child before anonymous inline run | incremental tree matches full rebuilddiff --git a/Tests/LibWeb/Text/input/layout-tree-update/direct-child-list-preservation.html b/Tests/LibWeb/Text/input/layout-tree-update/direct-child-list-preservation.htmlindex 32165d76182..2423f5d977c 100644--- a/Tests/LibWeb/Text/input/layout-tree-update/direct-child-list-preservation.html+++ b/Tests/LibWeb/Text/input/layout-tree-update/direct-child-list-preservation.html@@ -269,6 +269,43 @@mutate: parent => parent.insertAdjacentHTML("beforeend", '\n<section class="target child" style="position: relative"><b></b></section>'),tracked: ["parent", "before"],},+ {+ name: "append absolute block child after whitespace",+ markup: '<div class="parent"><i class="before child"></i></div>',+ mutate: parent => parent.insertAdjacentHTML("beforeend", '\n<section class="target child absolute"><b></b></section>'),+ tracked: ["parent", "before"],+ },+ {+ name: "append floated block child after whitespace",+ markup: '<div class="parent"><i class="before child"></i></div>',+ mutate: parent => parent.insertAdjacentHTML("beforeend", '\n<section class="target child float"><b></b></section>'),+ tracked: ["parent", "before"],+ },+ {+ name: "append absolute block child between whitespace and blocks",+ markup: '<div class="parent"><i class="before child"></i></div>',+ mutate: parent => parent.insertAdjacentHTML("beforeend", '\n<section class="target child absolute"><b></b></section>\n<section class="target child"></section>\n<section class="target child absolute"></section>\n<section class="target child"></section>'),+ tracked: ["parent", "before"],+ },+ {+ name: "append block and whitespace ending in absolute block child",+ markup: '<div class="parent"><i class="before child"></i></div>',+ mutate: parent => parent.insertAdjacentHTML("beforeend", '<section class="target child"></section>\n<section class="target child absolute"><b></b></section>'),+ tracked: ["parent", "before"],+ },+ {+ name: "append absolute block child after whitespace and anonymous inline run",+ markup: '<div class="parent"><i class="before child"></i><span class="inline">inline</span></div>',+ mutate: parent => parent.insertAdjacentHTML("beforeend", '\n<section class="target child absolute"><b></b></section>'),+ tracked: ["parent", "before", "inline"],+ },+ {+ name: "fall back for absolute block child after whitespace before existing child",+ markup: '<div class="parent"><i class="before child"></i><i class="after child"></i></div>',+ mutate: parent => parent.querySelector(".after").insertAdjacentHTML("beforebegin", '\n<section class="target child absolute"><b></b></section>'),+ tracked: ["parent"],+ preserve: false,+ },{name: "fall back for block child before anonymous inline run",markup: '<div class="parent"><i class="before child"></i><span class="inline">inline</span></div>',