Skip to content

Truly independent web browser

LibWeb: Splice appended text after block children

Aliaksandr Kalenikbf93caf64b2e
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
index bd407ca8652..65ebb6af658 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
@@ -1075,11 +1075,16 @@ impl ChildListInsertionReuse<'_, '_> {
has_unboxed_existing_text = true;
continue;
}
- let collapsed_whitespace_can_be_inserted = self.engine.tree().text_is_ascii_whitespace(child)
- && collapses_whitespace
- && !self.has_first_letter_owner
- && self.collapsing_whitespace_can_be_inserted(child);
- if !collapsed_whitespace_can_be_inserted {
+ if !self.engine.tree().text_is_ascii_whitespace(child) || !collapses_whitespace {
+ // Text that renders is inline-level content, which is appended as an inline element is.
+ if !parent_lays_out_block_children || will_insert_block_child {
+ return false;
+ }
+ will_insert_inline_child = true;
+ has_inserted_child = true;
+ continue;
+ }
+ if self.has_first_letter_owner || !self.collapsing_whitespace_can_be_inserted(child) {
return false;
}
inserted_whitespace_run_must_stay_last |= has_pending_collapsing_whitespace;
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.txt
index 813bac7cbb4..34d2f62c288 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
@@ -205,6 +205,25 @@ PASS: fall back when appending a list-item increment after a reversed list | inc
PASS: fall back when appending a subtree that opens a quote | rebuild parent
PASS: fall back when appending a subtree that opens a quote | layout tree builds=1
PASS: fall back when appending a subtree that opens a quote | incremental tree matches full rebuild
+PASS: append text after block child | preserve parent
+PASS: append text after block child | preserve before
+PASS: append text after block child | layout tree builds=1
+PASS: append text after block child | incremental tree matches full rebuild
+PASS: append text after anonymous inline run | preserve parent
+PASS: append text after anonymous inline run | preserve before
+PASS: append text after anonymous inline run | preserve inline
+PASS: append text after anonymous inline run | layout tree builds=1
+PASS: append text after anonymous inline run | incremental tree matches full rebuild
+PASS: append text and inline child after block child | preserve parent
+PASS: append text and inline child after block child | preserve before
+PASS: append text and inline child after block child | layout tree builds=1
+PASS: append text and inline child after block child | incremental tree matches full rebuild
+PASS: fall back for text before existing block child | rebuild parent
+PASS: fall back for text before existing block child | layout tree builds=1
+PASS: fall back for text before existing block child | incremental tree matches full rebuild
+PASS: fall back for text before appended block child | rebuild parent
+PASS: fall back for text before appended block child | layout tree builds=1
+PASS: fall back for text before appended block child | incremental tree matches full rebuild
PASS: fall back for block child before anonymous inline run | rebuild parent
PASS: fall back for block child before anonymous inline run | layout tree builds=1
PASS: fall back for block child before anonymous inline run | incremental tree matches full rebuild
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.txt
index 01ca795485b..6a9f93d95de 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
@@ -388,15 +388,15 @@ PASS: table parent | append whitespace | incremental tree matches full rebuild
PASS: insert in SVG parent | append whitespace | preserve
PASS: insert in SVG parent | append whitespace | layout tree builds=1
PASS: insert in SVG parent | append whitespace | incremental tree matches full rebuild
-PASS: rebuild for preserved whitespace | append whitespace | rebuild
-PASS: rebuild for preserved whitespace | append whitespace | layout tree builds=1
-PASS: rebuild for preserved whitespace | append whitespace | incremental tree matches full rebuild
-PASS: rebuild for non-ASCII whitespace | append no-break space | rebuild
-PASS: rebuild for non-ASCII whitespace | append no-break space | layout tree builds=1
-PASS: rebuild for non-ASCII whitespace | append no-break space | incremental tree matches full rebuild
-PASS: rebuild for non-whitespace text | append text | rebuild
-PASS: rebuild for non-whitespace text | append text | layout tree builds=1
-PASS: rebuild for non-whitespace text | append text | incremental tree matches full rebuild
+PASS: append preserved whitespace | append whitespace | preserve
+PASS: append preserved whitespace | append whitespace | layout tree builds=1
+PASS: append preserved whitespace | append whitespace | incremental tree matches full rebuild
+PASS: append non-ASCII whitespace | append no-break space | preserve
+PASS: append non-ASCII whitespace | append no-break space | layout tree builds=1
+PASS: append non-ASCII whitespace | append no-break space | incremental tree matches full rebuild
+PASS: append non-whitespace text | append text | preserve
+PASS: append non-whitespace text | append text | layout tree builds=1
+PASS: append non-whitespace text | append text | incremental tree matches full rebuild
PASS: rebuild under first-letter | append whitespace | rebuild
PASS: rebuild under first-letter | append whitespace | layout tree builds=1
PASS: rebuild under first-letter | append whitespace | incremental tree matches full rebuild
diff --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.html
index 6884af32d91..0fe048ccc17 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
@@ -368,6 +368,38 @@
tracked: ["parent"],
preserve: false,
},
+ {
+ name: "append text after block child",
+ markup: '<div class="parent"><i class="before child"></i></div>',
+ mutate: parent => parent.append("text"),
+ tracked: ["parent", "before"],
+ },
+ {
+ name: "append text after anonymous inline run",
+ markup: '<div class="parent"><i class="before child"></i><span class="inline">inline</span></div>',
+ mutate: parent => parent.append("text"),
+ tracked: ["parent", "before", "inline"],
+ },
+ {
+ name: "append text and inline child after block child",
+ markup: '<div class="parent"><i class="before child"></i></div>',
+ mutate: parent => parent.insertAdjacentHTML("beforeend", 'text <span class="target inline">inline</span> more text'),
+ tracked: ["parent", "before"],
+ },
+ {
+ name: "fall back for text before existing block child",
+ markup: '<div class="parent"><i class="before child"></i><i class="after child"></i></div>',
+ mutate: parent => parent.querySelector(".after").before("text"),
+ tracked: ["parent"],
+ preserve: false,
+ },
+ {
+ name: "fall back for text before appended block child",
+ markup: '<div class="parent"><i class="before child"></i></div>',
+ mutate: parent => parent.insertAdjacentHTML("beforeend", 'text<section class="target child"></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>',
diff --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.html
index 454787796e2..cd3e4f07f43 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
@@ -621,24 +621,24 @@
],
},
{
- name: "rebuild for preserved whitespace",
+ name: "append preserved whitespace",
markup: '<div class="parent preserve"><div class="tracked"></div><span>inline</span></div>',
steps: [
- { name: "append whitespace", mutate: parent => parent.append(" "), preserve: false },
+ { name: "append whitespace", mutate: parent => parent.append(" ") },
],
},
{
- name: "rebuild for non-ASCII whitespace",
+ name: "append non-ASCII whitespace",
markup: '<div class="parent"><div class="tracked"></div></div>',
steps: [
- { name: "append no-break space", mutate: parent => parent.append("\u00a0"), preserve: false },
+ { name: "append no-break space", mutate: parent => parent.append("\u00a0") },
],
},
{
- name: "rebuild for non-whitespace text",
+ name: "append non-whitespace text",
markup: '<div class="parent"><div class="tracked"></div></div>',
steps: [
- { name: "append text", mutate: parent => parent.append("text"), preserve: false },
+ { name: "append text", mutate: parent => parent.append("text") },
],
},
{