Skip to content

Truly independent web browser

LibWeb: Keep the ink overflow of inline boxes whose pieces only moved

Aliaksandr Kalenikd099af16c22d
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index b3587c1098f..ba87ec44943 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -262,6 +262,7 @@ struct Commit<'arena, 'tree> {
out_of_flow_boxes: Vec<(Node, std::sync::Arc<crate::layout::abspos_inputs::AbsposLayoutInputs>)>,
pass_level_links: Vec<Node>,
line_roots: Vec<(Node, LineRootChanges)>,
+ pieces_only_moved_by_inline_box_slot_index: Vec<bool>,
}
impl<'tree> Commit<'_, 'tree> {
@@ -670,8 +671,7 @@ impl<'tree> Commit<'_, 'tree> {
if row_existed_before_this_commit
&& line_root_changes_repaint_inline_box(self.arena(), node, enclosing_line_root_changes)
{
- self.arena_mut()
- .note_paint_change(node, RowPaintChange::EVERYTHING_IT_PAINTS);
+ self.note_paint_change_of_inline_box(node, RowPaintChange::EVERYTHING_IT_PAINTS);
}
if row_existed_before_this_commit && enclosing_line_root_changes.fragment_changed {
self.arena_mut()
@@ -763,10 +763,13 @@ impl<'tree> Commit<'_, 'tree> {
paint_change |= RowPaintChange::ORDER;
}
fragment_content_changed |= enclosing_line_root_changes.fragment_changed;
- } else if offset_changed {
- paint_change |= RowPaintChange::PLACE;
+ self.note_paint_change_of_inline_box(node, paint_change);
+ } else {
+ if offset_changed {
+ paint_change |= RowPaintChange::PLACE;
+ }
+ self.arena_mut().note_paint_change(node, paint_change);
}
- self.arena_mut().note_paint_change(node, paint_change);
if offset_changed {
self.arena_mut()
.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::MovedWithDescendants);
@@ -927,6 +930,18 @@ impl<'tree> Commit<'_, 'tree> {
&physical_line_data
};
let has_pieces = !line_data.inline_box_pieces.is_empty();
+ if let Some(previous) = previous_content.as_ref()
+ && !is_or_was_fragmented
+ && !std::sync::Arc::ptr_eq(previous, line_data)
+ {
+ for inline_box in line_data.inline_boxes_whose_pieces_only_moved_since(previous) {
+ let index = inline_box.slot_index() as usize;
+ if self.pieces_only_moved_by_inline_box_slot_index.len() <= index {
+ self.pieces_only_moved_by_inline_box_slot_index.resize(index + 1, false);
+ }
+ self.pieces_only_moved_by_inline_box_slot_index[index] = true;
+ }
+ }
// 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.
@@ -953,6 +968,21 @@ impl<'tree> Commit<'_, 'tree> {
}
}
+ fn note_paint_change_of_inline_box(&mut self, inline_box: Node, change: RowPaintChange) {
+ if self
+ .pieces_only_moved_by_inline_box_slot_index
+ .get(inline_box.slot_index() as usize)
+ .copied()
+ .unwrap_or(false)
+ && !crate::painting::fragment_ownership::is_self_painting_inline(&self.arena().paintable_rows(), inline_box)
+ {
+ self.arena_mut()
+ .note_paint_change_keeping_own_ink_overflow(inline_box, change);
+ } else {
+ self.arena_mut().note_paint_change(inline_box, change);
+ }
+ }
+
/// Clears the inline content of a row whose new fragment has none.
fn clear_line_data(&mut self, slot: NodeSlotId) {
if self.arena().committed_side_data(slot).inline_content.is_some() {
@@ -1229,6 +1259,7 @@ pub(crate) fn commit_replacing(
out_of_flow_boxes: Vec::new(),
pass_level_links: Vec::new(),
line_roots: Vec::new(),
+ pieces_only_moved_by_inline_box_slot_index: Vec::new(),
}
.finish(pass_fragments)
}
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_content.rs b/Libraries/LibWeb/Rust/src/layout/inline_content.rs
index 039447e83f5..4167fcdaad7 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_content.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_content.rs
@@ -448,6 +448,31 @@ pub struct InlineBoxPieceRecord {
pub is_geometry_only_placeholder: bool,
}
+fn pieces_only_moved<'a>(
+ previous_pieces: impl ExactSizeIterator<Item = &'a InlineBoxPieceRecord>,
+ pieces: impl ExactSizeIterator<Item = &'a InlineBoxPieceRecord>,
+) -> bool {
+ if previous_pieces.len() != pieces.len() {
+ return false;
+ }
+ let mut offset_of_every_piece = None;
+ for (previous_piece, piece) in previous_pieces.zip(pieces) {
+ let (previous_rect, rect) = (previous_piece.border_box_rect, piece.border_box_rect);
+ if previous_piece.is_geometry_only_placeholder
+ || piece.is_geometry_only_placeholder
+ || previous_piece.present_edges != piece.present_edges
+ || (previous_rect.width, previous_rect.height) != (rect.width, rect.height)
+ {
+ return false;
+ }
+ let offset = (rect.x - previous_rect.x, rect.y - previous_rect.y);
+ if *offset_of_every_piece.get_or_insert(offset) != offset {
+ return false;
+ }
+ }
+ offset_of_every_piece.is_some()
+}
+
#[derive(Clone, Copy, PartialEq)]
pub(crate) struct ClampedInlineBoxRect {
pub node: NodeSlotId,
@@ -634,6 +659,30 @@ impl InlineContent {
})
}
+ /// The inline boxes whose pieces all lie as they did in `previous`, moved by one offset and drawn at the same size.
+ pub(crate) fn inline_boxes_whose_pieces_only_moved_since<'a>(
+ &'a self,
+ previous: &'a InlineContent,
+ ) -> impl Iterator<Item = NodeSlotId> + 'a {
+ let mut previous_boxes = previous.inline_boxes.boxes().peekable();
+ self.inline_boxes.boxes().filter_map(move |(node, piece_indices)| {
+ while previous_boxes
+ .next_if(|(previous_node, _)| inline_box_order(*previous_node) < inline_box_order(node))
+ .is_some()
+ {}
+ let (_, previous_piece_indices) = previous_boxes.next_if(|(previous_node, _)| *previous_node == node)?;
+ pieces_only_moved(
+ previous_piece_indices
+ .iter()
+ .map(|&index| &previous.inline_box_pieces[index as usize]),
+ piece_indices
+ .iter()
+ .map(|&index| &self.inline_box_pieces[index as usize]),
+ )
+ .then_some(node)
+ })
+ }
+
/// Indexes the pieces of each inline box again, after they were renumbered or given to other boxes.
pub(crate) fn index_inline_boxes(&mut self) {
self.inline_boxes = InlineBoxIndex::of(&self.inline_box_pieces);
diff --git a/Libraries/LibWeb/Rust/src/painting/record/change_ticks.rs b/Libraries/LibWeb/Rust/src/painting/record/change_ticks.rs
index 05f7a370840..06880295132 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/change_ticks.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/change_ticks.rs
@@ -162,6 +162,12 @@ impl PaintGenerations {
}
}
+#[derive(Clone, Copy, PartialEq)]
+enum OwnInkOverflow {
+ MayChange,
+ Kept,
+}
+
impl LayoutNodeArena {
pub(crate) fn take_paint_generation(&mut self) -> PaintGeneration {
let generations = &mut self.paintable_rows.paint_generations;
@@ -201,6 +207,15 @@ impl LayoutNodeArena {
}
pub(crate) fn note_paint_change(&mut self, row: NodeSlotId, change: RowPaintChange) {
+ self.note_paint_change_to_row(row, change, OwnInkOverflow::MayChange);
+ }
+
+ /// Notes a change that leaves the ink overflow of the row itself, relative to its padding box, as it was.
+ pub(crate) fn note_paint_change_keeping_own_ink_overflow(&mut self, row: NodeSlotId, change: RowPaintChange) {
+ self.note_paint_change_to_row(row, change, OwnInkOverflow::Kept);
+ }
+
+ fn note_paint_change_to_row(&mut self, row: NodeSlotId, change: RowPaintChange, own_ink_overflow: OwnInkOverflow) {
if change.is_empty() || !self.paintable_row_is_populated(row) {
return;
}
@@ -208,7 +223,9 @@ impl LayoutNodeArena {
self.note_hit_test_items_changed();
}
if change.intersects(RowPaintChange::DRAWING | RowPaintChange::PLACE | RowPaintChange::ORDER) {
- self.request_ink_overflow_recalculation(row);
+ if own_ink_overflow == OwnInkOverflow::MayChange {
+ self.request_ink_overflow_recalculation(row);
+ }
self.request_inline_ink_overflow_recalculation(row);
if change.intersects(RowPaintChange::PLACE) {
self.request_containing_block_ink_overflow_recalculation(row);