Skip to content

Truly independent web browser

LibWeb: Don’t give a pseudo-element list item a marker it can’t show

sideshowbarkerbc3ccca7c6d2
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
index 9bfb29b0983..4555f464005 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
@@ -3565,7 +3565,10 @@ fn stamp_nested_list_marker_row(
generator: StyleNodeID,
pseudo_element: FfiPseudoElement,
list_item_box: NodeSlotId,
-) -> NodeSlotId {
+) -> Option<NodeSlotId> {
+ let list_item_shows_its_type = host
+ .style(list_item_box)
+ .is_some_and(|style| !style.list_style_type_is_none());
let derived = host.arena_mut().with_style_engine(|engine| {
// The generator's own `::marker` record, which the engine derives for this read alone where the generator
// holds none. It answers one for every list item; should it not, the marker takes the generator's style.
@@ -3581,10 +3584,18 @@ fn stamp_nested_list_marker_row(
})
.or_else(|| engine.element_published_style_record(generator))
.expect("a list item the build reaches has published its style");
+ // As for an element's ::marker, the marker shows its own list-style-image, or else the list item's
+ // list-style-type, which shows nothing where it's none. Where neither shows anything, there's no marker.
+ let marker_shows_its_image = engine
+ .style_record_view(record)
+ .is_some_and(|view| ComputedValuesView::of(view.payloads).list_style_image_is_set());
+ if !marker_shows_its_image && !list_item_shows_its_type {
+ return None;
+ }
// NB: Republishing the generator's own `::marker` record can retire its animation record while the nested
// marker still refers to it. The marker takes a record of its own, copied from it.
- LayoutStyle::from_record(engine, record).intern(engine)
- });
+ Some(LayoutStyle::from_record(engine, record).intern(engine))
+ })?;
let slot = host.arena.allocate_unbound();
host.arena_mut()
.stamp_anonymous_box(slot, NodeKind::ListItemMarkerBox, derived);
@@ -3602,7 +3613,7 @@ fn stamp_nested_list_marker_row(
owns_content_replacement_image: false,
},
);
- slot
+ Some(slot)
}
/// The row one item of a pseudo-element's generated content is built in, and its layout node. An
@@ -3761,8 +3772,10 @@ fn create_pseudo_element(
let owner = resolve_counters(host, element_identity, pseudo_element);
// FIXME: This code actually computes style for element::marker, and shouldn't for element::pseudo::marker.
- if layout_node_kind == NodeKind::ListItemBox {
- let marker_slot = stamp_nested_list_marker_row(host, element_identity, pseudo_element, layout_node);
+ let nested_marker_slot = (layout_node_kind == NodeKind::ListItemBox)
+ .then(|| stamp_nested_list_marker_row(host, element_identity, pseudo_element, layout_node))
+ .flatten();
+ if let Some(marker_slot) = nested_marker_slot {
let marker = host.created(marker_slot);
let first_child = host.first_child(layout_node);
host.attach_child(layout_node, marker, first_child);
diff --git a/Tests/LibWeb/Crash/CSS/pseudo-element-list-item-with-own-list-style-image.html b/Tests/LibWeb/Crash/CSS/pseudo-element-list-item-with-own-list-style-image.html
new file mode 100644
index 00000000000..47a89077321
--- /dev/null
+++ b/Tests/LibWeb/Crash/CSS/pseudo-element-list-item-with-own-list-style-image.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<style>
+.own::before { display: list-item; content: "own"; list-style-type: none; list-style-image: linear-gradient(red, blue); }
+.inherited { list-style-image: linear-gradient(red, blue); }
+.inherited::before { display: list-item; content: "inherited"; list-style-type: none; }
+</style>
+<div class="own">a</div>
+<div class="inherited">b</div>
diff --git a/Tests/LibWeb/Layout/expected/css-pseudo-element-display-list-item-without-marker.txt b/Tests/LibWeb/Layout/expected/css-pseudo-element-display-list-item-without-marker.txt
new file mode 100644
index 00000000000..f08d043b8f2
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/css-pseudo-element-display-list-item-without-marker.txt
@@ -0,0 +1,73 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 245.5 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 229.5 0+0+8] children: not-inline
+ BlockContainer <div.own> at [8,8] [0+0+0 784 0+0+0] [0+0+0 32 0+0+0] children: not-inline
+ ListItemBox <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 3, rect: [8,8 31.1875x16] baseline: 12.796875
+ "own"
+ GeneratedTextNode <(anonymous)> (not painted)
+ BlockContainer <(anonymous)> at [8,24] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,24 9.34375x16] baseline: 12.796875
+ "a"
+ TextNode <#text> (not painted)
+ BlockContainer <ul.inherited> at [48,56] [0+0+40 744 0+0+0] [16+0+0 32 0+0+16] children: not-inline
+ ListItemBox <li> at [48,56] [0+0+0 744 0+0+0] [0+0+0 32 0+0+0] children: not-inline
+ ListItemBox <(anonymous)> at [48,56] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 9, rect: [48,56 69.015625x16] baseline: 12.796875
+ "inherited"
+ GeneratedTextNode <(anonymous)> (not painted)
+ BlockContainer <(anonymous)> at [48,72] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [48,72 9.46875x16] baseline: 12.796875
+ "b"
+ TextNode <#text> (not painted)
+ ListItemBox <div.item> at [8,104] [0+0+0 784 0+0+0] [0+0+0 32 0+0+0] children: not-inline
+ ListItemMarkerBox <(anonymous)> at [-6,104] [0+0+0 13.84375 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 2, rect: [-6,104 13.84375x16] baseline: 12.796875
+ "• "
+ GeneratedTextNode <(anonymous)> (not painted)
+ ListItemBox <(anonymous)> at [8,104] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 6, rect: [8,104 51.109375x16] baseline: 12.796875
+ "nested"
+ GeneratedTextNode <(anonymous)> (not painted)
+ BlockContainer <(anonymous)> at [8,120] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,120 8.890625x16] baseline: 12.796875
+ "c"
+ TextNode <#text> (not painted)
+ BlockContainer <div.shown> at [8,136] [0+0+0 784 0+0+0] [0+0+0 34.75 0+0+0] children: not-inline
+ ListItemBox <(anonymous)> at [8,136] [0+0+0 784 0+0+0] [0+0+0 18.75 0+0+0] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 5, rect: [8,138 49.828125x16] baseline: 12.796875
+ "shown"
+ ListItemMarkerBox <(anonymous)> at [-33,135.953125] [0+0+0 40.625 0+0+0] [0+0+0 18.75 0+0+0] [BFC] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 2, rect: [-33,138 40.625x16] baseline: 12.796875
+ "▪ "
+ GeneratedTextNode <(anonymous)> (not painted)
+ GeneratedTextNode <(anonymous)> (not painted)
+ BlockContainer <(anonymous)> at [8,154.75] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,154.75 7.859375x16] baseline: 12.796875
+ "d"
+ TextNode <#text> (not painted)
+ BlockContainer <div#hides.toggled.off> at [8,170.75] [0+0+0 784 0+0+0] [0+0+0 32 0+0+0] children: not-inline
+ ListItemBox <(anonymous)> at [8,170.75] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 7, rect: [8,170.75 53.15625x16] baseline: 12.796875
+ "toggled"
+ GeneratedTextNode <(anonymous)> (not painted)
+ BlockContainer <(anonymous)> at [8,186.75] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,186.75 8.71875x16] baseline: 12.796875
+ "e"
+ TextNode <#text> (not painted)
+ BlockContainer <div#shows.toggled> at [8,202.75] [0+0+0 784 0+0+0] [0+0+0 34.75 0+0+0] children: not-inline
+ ListItemBox <(anonymous)> at [8,202.75] [0+0+0 784 0+0+0] [0+0+0 18.75 0+0+0] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 7, rect: [8,204.75 53.15625x16] baseline: 12.796875
+ "toggled"
+ ListItemMarkerBox <(anonymous)> at [-33,202.703125] [0+0+0 40.625 0+0+0] [0+0+0 18.75 0+0+0] [BFC] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 2, rect: [-33,204.75 40.625x16] baseline: 12.796875
+ "▪ "
+ GeneratedTextNode <(anonymous)> (not painted)
+ GeneratedTextNode <(anonymous)> (not painted)
+ BlockContainer <(anonymous)> at [8,221.5] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,221.5 6.4375x16] baseline: 12.796875
+ "f"
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x245.5] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/css-pseudo-element-display-list-item-without-marker.html b/Tests/LibWeb/Layout/input/css-pseudo-element-display-list-item-without-marker.html
new file mode 100644
index 00000000000..f40ce960e49
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/css-pseudo-element-display-list-item-without-marker.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<style>
+.own::before { display: list-item; content: "own"; list-style-type: none; }
+ul.inherited { list-style-type: none; }
+ul.inherited li::before { display: list-item; content: "inherited"; }
+.item { display: list-item; list-style-type: disc; }
+.item::before { display: list-item; content: "nested"; list-style-type: none; }
+.shown::before { display: list-item; content: "shown"; list-style-type: square; }
+.toggled::before { display: list-item; content: "toggled"; list-style-type: square; }
+.toggled.off::before { list-style-type: none; }
+</style>
+<div class="own">a</div>
+<ul class="inherited"><li>b</li></ul>
+<div class="item">c</div>
+<div class="shown">d</div>
+<div class="toggled" id="hides">e</div>
+<div class="toggled off" id="shows">f</div>
+<script>
+ document.body.offsetWidth;
+ hides.classList.add("off");
+ shows.classList.remove("off");
+</script>