Truly independent web browser
LibWeb: Plan no descendant scopes for boxes painted on their lines
Aliaksandr Kalenik4d88e595ecbb
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex ba87ec44943..bc5aa8c3544 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -954,7 +954,20 @@ impl<'tree> Commit<'_, 'tree> {!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());+ let previous_content = self+ .arena_mut()+ .committed_side_data_mut(slot)+ .inline_content+ .replace(line_data.clone());+ if !previous_content+ .as_ref()+ .is_some_and(|previous| std::sync::Arc::ptr_eq(previous, line_data))+ {+ self.refresh_paint_order_inputs_that_disagree_with_the_atomic_inlines_of(+ previous_content.as_deref(),+ Some(line_data),+ );+ }if item_order_changed {self.arena_mut().note_paint_change(slot, RowPaintChange::ORDER);}@@ -986,7 +999,43 @@ impl<'tree> Commit<'_, 'tree> {/// 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() {- self.arena_mut().committed_side_data_mut(slot).inline_content = None;+ let previous_content = self.arena_mut().committed_side_data_mut(slot).inline_content.take();+ self.refresh_paint_order_inputs_that_disagree_with_the_atomic_inlines_of(previous_content.as_deref(), None);+ }+ }++ fn refresh_paint_order_inputs_that_disagree_with_the_atomic_inlines_of(+ &mut self,+ previous_content: Option<&crate::layout::inline_content::InlineContent>,+ content: Option<&crate::layout::inline_content::InlineContent>,+ ) {+ let atomic_inlines_before_and_after: Vec<NodeSlotId> = [previous_content, content]+ .into_iter()+ .flatten()+ .flat_map(|content| content.fragments.iter())+ .filter(|fragment| fragment.is_atomic_inline)+ .map(|fragment| fragment.layout_node)+ .collect();+ let is_atomic_inline_of_content = |node: NodeSlotId| {+ content.is_some_and(|content| {+ content+ .fragment_indices_of(node)+ .iter()+ .any(|&index| content.fragments[index as usize].is_atomic_inline)+ })+ };+ for node in atomic_inlines_before_and_after {+ let arena = self.arena();+ if !arena.slot_is_live(node) || !arena.paintable_row_is_populated(node) {+ continue;+ }+ let inputs_disagree = arena+ .committed_side_data(node)+ .prepared_order_inputs()+ .is_some_and(|inputs| inputs.is_atomic_inline_content() != is_atomic_inline_of_content(node));+ if inputs_disagree {+ self.arena_mut().refresh_paint_order_inputs(node);+ }}}diff --git a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rsindex a4a9eb59fb3..31276808e0b 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs@@ -175,6 +175,7 @@ enum PaintOrderFlag {CollapsedBorders,HiddenColumns,HasZIndex,+ AtomicInlineContent,}impl PaintOrderInputs {@@ -186,6 +187,10 @@ impl PaintOrderInputs {self.flags & (1 << flag as u32) != 0}+ pub(crate) fn is_atomic_inline_content(self) -> bool {+ self.has(PaintOrderFlag::AtomicInlineContent)+ }+fn z_index(self) -> Option<i32> {self.has(PaintOrderFlag::HasZIndex).then_some(self.z_index)}@@ -213,14 +218,25 @@ impl PaintOrderInputs {let display = style_queries::display(arena, row);let kind = arena.node_kind_if_live(row);let z_index = style_queries::z_index(arena, row);- let (collapsed_borders, hidden_columns) = arena.with_committed_fragment_link(row, |link| {- link.map_or((false, false), |link| {- (- link.fragment.collapsed_table_borders().is_some(),- link.placement.shown_as.facts.hidden_by_collapsed_columns,- )- })- });+ let (collapsed_borders, hidden_columns, committed_containing_block) =+ arena.with_committed_fragment_link(row, |link| {+ link.map_or((false, false, NodeSlotId::INVALID), |link| {+ (+ link.fragment.collapsed_table_borders().is_some(),+ link.placement.shown_as.facts.hidden_by_collapsed_columns,+ link.placement.containing_block,+ )+ })+ });+ let fragmented_inline = node_painting::is_fragmented_inline(arena, row);+ let containing_block = if committed_containing_block.is_invalid() {+ arena.paintable_data(row).containing_block+ } else {+ committed_containing_block+ };+ let atomic_inline_content = !fragmented_inline+ && display.is_inline_outside()+ && is_an_atomic_inline_fragment_of(arena, row, containing_block);use PaintOrderFlag::*;let decisions = [(@@ -231,7 +247,7 @@ impl PaintOrderInputs {(Floating, style_queries::is_floating(arena, row)),(Inline, display.is_inline_outside()),(FlexOrGridItem, style_queries::is_flex_or_grid_item(arena, row)),- (FragmentedInline, node_painting::is_fragmented_inline(arena, row)),+ (FragmentedInline, fragmented_inline),(Replaced, style_queries::is_replaced_box(arena, row)),(InlineLevelContext,@@ -247,6 +263,7 @@ impl PaintOrderInputs {(CollapsedBorders, collapsed_borders),(HiddenColumns, hidden_columns),(HasZIndex, z_index.is_some()),+ (AtomicInlineContent, atomic_inline_content),];// The high bit distinguishes the initial empty snapshot from a prepared row.let flags = decisions.iter().fold(1 << 31, |flags, &(flag, value)| {@@ -259,6 +276,16 @@ impl PaintOrderInputs {}}+fn is_an_atomic_inline_fragment_of(arena: &impl PaintRead, row: NodeSlotId, line_root: NodeSlotId) -> bool {+ if line_root.is_invalid() || !arena.paintable_row_is_populated(line_root) {+ return false;+ }+ let side = arena.committed_side_data(line_root);+ side.fragment_indices_of(row)+ .iter()+ .any(|&index| side.fragments()[index as usize].is_atomic_inline)+}+impl PaintScopePlan {/// Planning reads the snapshots kept on the rows, and gathers style and layout facts only/// for a row that has none.@@ -400,18 +427,7 @@ impl<R: PaintRead> PaintOrderBuilder<'_, R> {}fn is_atomic_inline_content(&self, paintable: NodeSlotId) -> bool {- if self.is_fragmented_inline(paintable) || !self.inputs(paintable).has(PaintOrderFlag::Inline) {- return false;- }- let block = self.layout_arena.paintable_data(paintable).containing_block;- !block.is_invalid()- && self.layout_arena.paintable_row_is_populated(block)- && self- .layout_arena- .committed_side_data(block)- .fragments()- .iter()- .any(|fragment| fragment.layout_node == paintable && fragment.is_atomic_inline)+ self.inputs(paintable).is_atomic_inline_content()}fn append_stacking_context(&mut self, owner: NodeSlotId) {@@ -643,6 +659,9 @@ impl<R: PaintRead> PaintOrderBuilder<'_, R> {}fn descendant_phase_is_empty(&self, child: NodeSlotId, phase: StackingContextPaintPhase) -> bool {+ if self.is_painted_at_its_place_on_a_line(child) {+ return true;+ }// Inline-blocks and inline-tables paint their backgrounds and internal floats// in the inline-level phase. Earlier passes through their parent do no work,// so there is no need to resolve, copy, or update an empty subtree capture.@@ -655,6 +674,12 @@ impl<R: PaintRead> PaintOrderBuilder<'_, R> {&& (phase == StackingContextPaintPhase::Floats || !self.is_pure_inline_box(child))}+ fn is_painted_at_its_place_on_a_line(&self, child: NodeSlotId) -> bool {+ !self.inputs(child).has(PaintOrderFlag::Floating)+ && !self.inputs(child).has(PaintOrderFlag::Positioned)+ && self.is_atomic_inline_content(child)+ }+fn append_descendant(&mut self, child: NodeSlotId, phase: StackingContextPaintPhase) {if self.has_stacking_context(child) {return;@@ -671,7 +696,7 @@ impl<R: PaintRead> PaintOrderBuilder<'_, R> {// These boxes are painted atomically at their fragment's position in the// containing line's foreground plan, including their internal floats.- if !floating && !positioned && self.is_atomic_inline_content(child) {+ if self.is_painted_at_its_place_on_a_line(child) {return;}diff --git a/Tests/LibWeb/Text/input/display_list/painted-as-stacking-context-capture-svg-mask-area-change.html b/Tests/LibWeb/Text/input/display_list/painted-as-stacking-context-capture-svg-mask-area-change.htmlindex 63e1c76fa02..0cf4dc4eee6 100644--- a/Tests/LibWeb/Text/input/display_list/painted-as-stacking-context-capture-svg-mask-area-change.html+++ b/Tests/LibWeb/Text/input/display_list/painted-as-stacking-context-capture-svg-mask-area-change.html@@ -47,9 +47,7 @@ displayListTest({BlockContainer<BODY>#body/scroll-metadata COPYBlockContainer<BODY>#body/background COPYBlockContainer<BODY>#body/border COPY- SVGSVGBox<svg>#svg/descendants(background-and-borders) ASSEMBLEBlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLE- SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) ASSEMBLEBlockContainer<HTML>#html/foreground COPYBlockContainer<BODY>#body/descendants(foreground) ASSEMBLESVGSVGBox<svg>#svg ASSEMBLE@@ -70,7 +68,6 @@ displayListTest({SVGGeometryBox<rect>#masked/svg RECORDSVGGeometryBox<rect>#masked/foreground RECORDBlockContainer<BODY>#body/foreground COPY- SVGSVGBox<svg>#svg/descendants(foreground) ASSEMBLEBlockContainer<BODY>#body/outline COPYBlockContainer<BODY>#body/overlay COPYBlockContainer<HTML>#html/outline COPYdiff --git a/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.html b/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.htmlindex b135c52b8d8..ee36004757c 100644--- a/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.html+++ b/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.html@@ -51,11 +51,9 @@ displayListTest({BlockContainer(anonymous)/scroll-metadata COPYBlockContainer(anonymous)/background COPYBlockContainer(anonymous)/border COPY- SVGSVGBox<svg>#svg/descendants(background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(background-and-borders) COPYBlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLEBlockContainer(anonymous)/descendants(inline-background-and-borders) ASSEMBLE- SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(inline-background-and-borders) COPYBlockContainer<HTML>#html/foreground COPYBlockContainer<BODY>#body/descendants(foreground) ASSEMBLE@@ -77,7 +75,6 @@ displayListTest({SVGGeometryBox<rect>#clip-rect/foreground RECORDSVGGeometryBox<rect>#clipped/foreground RECORDBlockContainer(anonymous)/foreground COPY- SVGSVGBox<svg>#svg/descendants(foreground) ASSEMBLEBlockContainer(anonymous)/outline COPYBlockContainer(anonymous)/overlay COPYBlockContainer<DIV>#other/descendants(foreground) COPYdiff --git a/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.html b/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.htmlindex 780bfa3890f..c6790dd7cf1 100644--- a/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.html+++ b/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.html@@ -53,11 +53,9 @@ displayListTest({BlockContainer(anonymous)/scroll-metadata COPYBlockContainer(anonymous)/background COPYBlockContainer(anonymous)/border COPY- SVGSVGBox<svg>#svg/descendants(background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(background-and-borders) COPYBlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLEBlockContainer(anonymous)/descendants(inline-background-and-borders) ASSEMBLE- SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(inline-background-and-borders) COPYBlockContainer<HTML>#html/foreground COPYBlockContainer<BODY>#body/descendants(foreground) ASSEMBLE@@ -81,7 +79,6 @@ displayListTest({SVGGeometryBox<rect>#masked/svg RECORDSVGGeometryBox<rect>#masked/foreground RECORDBlockContainer(anonymous)/foreground COPY- SVGSVGBox<svg>#svg/descendants(foreground) ASSEMBLEBlockContainer(anonymous)/outline COPYBlockContainer(anonymous)/overlay COPYBlockContainer<DIV>#other/descendants(foreground) COPY