Truly independent web browser
LibWeb: Replan tall plain text when its fragment count changes
Andreas Kling3ca44a63db64
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex 55a56ef35f4..b3587c1098f 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -512,16 +512,13 @@ impl<'tree> Commit<'_, 'tree> {if !keeps_committed_subtree {self.arena_mut().forget_committed_out_of_flow_facts(node);}- let previous_fragmented_content = (has_more_fragments+ let previous_inline_content = previous+ .as_ref()+ .and_then(|previous| previous.previous_inline_content.clone());+ let is_or_was_fragmented = has_more_fragments|| previous.as_ref()- .is_some_and(|previous| previous.previous_fragments.len() > 1))- .then(|| {- previous- .as_ref()- .and_then(|previous| previous.previous_inline_content.clone())- })- .flatten();+ .is_some_and(|previous| previous.previous_fragments.len() > 1);let prepared_row = self.prepare_node(node, true, keeps_committed_subtree, enclosing_line_root_changes);self.committed_anew.push(node);if let Some(previous) = previous {@@ -588,7 +585,8 @@ impl<'tree> Commit<'_, 'tree> {let line_data_changes = self.set_line_data(node,line_data,- previous_fragmented_content,+ previous_inline_content,+ is_or_was_fragmented,link.fragment.sides.content_size,);line_root_changes_for_children = line_root_changes_for_children.union(line_data_changes);@@ -912,7 +910,8 @@ impl<'tree> Commit<'_, 'tree> {&mut self,slot: NodeSlotId,line_data: &std::sync::Arc<crate::layout::inline_content::InlineContent>,- previous_fragmented_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,+ previous_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,+ is_or_was_fragmented: bool,content_size: used_values::FfiCssPixelSize,) -> LineRootChanges {if !node_painting::has_lines(self.arena(), slot) {@@ -928,16 +927,16 @@ impl<'tree> Commit<'_, 'tree> {&physical_line_data};let has_pieces = !line_data.inline_box_pieces.is_empty();- let (content_changed, item_order_changed) = previous_fragmented_content.map_or((false, false), |previous| {- if std::sync::Arc::ptr_eq(&previous, line_data) || *previous == **line_data {+ // NB: The link of a box in one fragment says how its content changed, but compares the content as layout made+ // it. The plan of the foreground reads the content the row holds, which is merged and in the physical+ // plane, so that is what says whether the plan changed.+ let (content_changed, item_order_changed) = previous_content.map_or((false, false), |previous| {+ if std::sync::Arc::ptr_eq(&previous, line_data) {return (false, false);}- let fragments_became_or_stopped_being_producers =- crate::painting::paint_order_plan::text_fragments_of_content_are_producers(&previous)- != crate::painting::paint_order_plan::text_fragments_of_content_are_producers(line_data);(- true,- !previous.has_same_item_order(line_data) || fragments_became_or_stopped_being_producers,+ is_or_was_fragmented && *previous != **line_data,+ !crate::painting::paint_order_plan::content_plans_same_foreground(&previous, line_data),)});self.arena_mut().committed_side_data_mut(slot).inline_content = Some(line_data.clone());diff --git a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rsindex 1d4f9ad0c8f..a4a9eb59fb3 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs@@ -117,6 +117,23 @@ pub(crate) fn text_fragments_of_content_are_producers(content: &crate::layout::i&& bottom - top > crate::css::css_pixels::CssPixels::from_integer(TALLEST_TEXT_PLANNED_IN_ONE_PIECE)}+/// Whether the foreground of a box with lines is planned the same for `content` as it was for `previous`, both as the+/// box's row holds them: the same producers, in the same order.+pub(crate) fn content_plans_same_foreground(+ previous: &crate::layout::inline_content::InlineContent,+ content: &crate::layout::inline_content::InlineContent,+) -> bool {+ let text_fragments_are_producers = text_fragments_of_content_are_producers(content);+ if text_fragments_are_producers != text_fragments_of_content_are_producers(previous) {+ return false;+ }+ // NB: Plain text has no items. Where its text fragments are producers, the plan lists every one of them.+ if text_fragments_are_producers && content.items.is_empty() && content.fragments.len() != previous.fragments.len() {+ return false;+ }+ previous.has_same_item_order(content)+}+pub(crate) fn text_fragments_are_producers(rows: &impl PaintRead, root: NodeSlotId) -> bool {rows.committed_side_data(root).inline_contentdiff --git a/Tests/LibWeb/Ref/expected/tall-plain-text-changes-line-count-then-repaint-ref.html b/Tests/LibWeb/Ref/expected/tall-plain-text-changes-line-count-then-repaint-ref.htmlnew file mode 100644index 00000000000..2693fc496e0--- /dev/null+++ b/Tests/LibWeb/Ref/expected/tall-plain-text-changes-line-count-then-repaint-ref.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<style>+ div {+ float: left;+ width: 0;+ margin-right: 100px;+ font: 20px monospace;+ line-height: 300px;+ }+ .vertical {+ writing-mode: vertical-rl;+ width: auto;+ height: 800px;+ line-height: 30px;+ }+ .columns {+ columns: 2;+ column-gap: 100px;+ height: 700px;+ }+</style>+<div>a b</div>+<div>a b c</div>+<div>a</div>+<div>a b c</div>+<div class="vertical">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>+<div class="vertical">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>+<div class="columns">a b c</div>+<div class="columns">a b c d e f</div>diff --git a/Tests/LibWeb/Ref/input/tall-plain-text-changes-line-count-then-repaint.html b/Tests/LibWeb/Ref/input/tall-plain-text-changes-line-count-then-repaint.htmlnew file mode 100644index 00000000000..dc41d1ecdf8--- /dev/null+++ b/Tests/LibWeb/Ref/input/tall-plain-text-changes-line-count-then-repaint.html@@ -0,0 +1,51 @@+<!DOCTYPE html>+<html class="reftest-wait">+<link rel="match" href="../expected/tall-plain-text-changes-line-count-then-repaint-ref.html">+<style>+ div {+ float: left;+ width: 0;+ margin-right: 100px;+ font: 20px monospace;+ line-height: 300px;+ }+ .vertical {+ writing-mode: vertical-rl;+ width: auto;+ height: 800px;+ line-height: 30px;+ }+ .columns {+ columns: 2;+ column-gap: 100px;+ height: 700px;+ }+</style>+<div id="shrinks">a b c</div>+<div id="grows">a b</div>+<div id="becomes-short">a b c</div>+<div id="becomes-tall">a</div>+<div id="vertical-shrinks" class="vertical">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>+<div id="vertical-grows" class="vertical">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>+<div id="columns-shrinks" class="columns">a b c d e f</div>+<div id="columns-grows" class="columns">a b c</div>+<script>+ window.onload = () => {+ requestAnimationFrame(() => {+ requestAnimationFrame(() => {+ const setText = (id, text) => (document.getElementById(id).firstChild.data = text);+ const word = "a".repeat(60);+ setText("shrinks", "a b");+ setText("grows", "a b c");+ setText("becomes-short", "a");+ setText("becomes-tall", "a b c");+ setText("vertical-shrinks", `${word} ${word}`);+ setText("vertical-grows", `${word} ${word} ${word}`);+ setText("columns-shrinks", "a b c");+ setText("columns-grows", "a b c d e f");+ document.documentElement.classList.remove("reftest-wait");+ });+ });+ };+</script>+</html>