Truly independent web browser
LibWeb: Keep display: contents pseudo-element boxes inline on restyle
Aliaksandr Kalenik5508033feae0
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex b44db6ac818..42ebfc400d0 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -3815,10 +3815,32 @@ impl LayoutNodeArena {self.update_layout_style(host_calls, node, LayoutStyle::reset_table_properties);}+ pub(crate) fn make_display_contents_pseudo_element_box_inline(&self, host_calls: HostCalls<'_>, node: NodeSlotId) {+ self.update_layout_style(host_calls, node, |style| {+ style.set_display(crate::layout::FfiDisplay::outside_and_inside(+ crate::css::css_enums::display_outside::INLINE,+ crate::css::css_enums::display_inside::FLOW,+ false,+ ));+ });+ }++ fn is_display_contents_pseudo_element_box_holding_its_published_display(&self, node: NodeSlotId) -> bool {+ let data = self.data(node);+ data.kind.get() == NodeKind::InlineNode+ && super::node_facts::has_flag(data, NodeFlag::IsPseudoElementPrincipalBox)+ && self+ .style_payloads(node)+ .is_some_and(|payloads| ComputedValuesView::new(&payloads.groups).display().is_contents())+ }+pub(crate) fn reinherit_anonymous_descendants(&self, host_calls: HostCalls<'_>, node: NodeSlotId) {if self.node_style_record(node) == 0 {return;}+ if self.is_display_contents_pseudo_element_box_holding_its_published_display(node) {+ self.make_display_contents_pseudo_element_box_inline(host_calls, node);+ }let parent = self.data(node).parent.get();let parent_is_table_wrapper_of_this_table_box = !parent.is_invalid()&& self.data(parent).kind.get() == NodeKind::TableWrapperdiff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 4280ad1789e..cbbb811ae97 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -3174,13 +3174,8 @@ fn stamp_pseudo_element_box_row(host.arena().stamp_pseudo_element_row(slot, kind, generator, generated_for);if decision == FfiPseudoElementDecision::Contents {- host.arena().update_layout_style(host.host_calls(), slot, |style| {- style.set_display(FfiDisplay::outside_and_inside(- crate::css::css_enums::display_outside::INLINE,- crate::css::css_enums::display_inside::FLOW,- false,- ));- });+ host.arena()+ .make_display_contents_pseudo_element_box_inline(host.host_calls(), slot);}if is_list_item_marker {host.arena()diff --git a/Tests/LibWeb/Text/expected/display-contents-pseudo-element-keeps-generated-text-after-restyle.txt b/Tests/LibWeb/Text/expected/display-contents-pseudo-element-keeps-generated-text-after-restyle.txtnew file mode 100644index 00000000000..bf17e67584f--- /dev/null+++ b/Tests/LibWeb/Text/expected/display-contents-pseudo-element-keeps-generated-text-after-restyle.txt@@ -0,0 +1,2 @@+generated text kept: true+width matches the box built recolored: truediff --git a/Tests/LibWeb/Text/input/display-contents-pseudo-element-keeps-generated-text-after-restyle.html b/Tests/LibWeb/Text/input/display-contents-pseudo-element-keeps-generated-text-after-restyle.htmlnew file mode 100644index 00000000000..66f3bbbe58a--- /dev/null+++ b/Tests/LibWeb/Text/input/display-contents-pseudo-element-keeps-generated-text-after-restyle.html@@ -0,0 +1,43 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ .container {+ position: relative;+ height: 50px;+ font-size: 32px;+ }+ .shrink-to-fit {+ position: absolute;+ top: 0;+ }+ .generator::before {+ display: contents;+ content: "generated text";+ }+ .recolored {+ color: green;+ }+</style>+<div class="container">+ <div id="mutated" class="shrink-to-fit"><span id="restyled" class="generator">a</span><span id="sibling">b</span></div>+</div>+<div class="container">+ <div id="reference" class="shrink-to-fit"><span id="built-recolored" class="generator recolored">a</span><span>c</span></div>+</div>+<script>+ asyncTest(async done => {+ await animationFrame();++ restyled.classList.add("recolored");+ await animationFrame();+ sibling.textContent = "c";+ await animationFrame();+ await animationFrame();++ const generatorWidth = restyled.getBoundingClientRect().width;+ const referenceGeneratorWidth = document.getElementById("built-recolored").getBoundingClientRect().width;+ println(`generated text kept: ${generatorWidth === referenceGeneratorWidth}`);+ println(`width matches the box built recolored: ${mutated.getBoundingClientRect().width === reference.getBoundingClientRect().width}`);+ done();+ });+</script>