Truly independent web browser
LibWeb: Keep an inside marker ahead of its list item’s block children
sideshowbarkere479099ae2e9
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 9469369a64c..852d2a53e94 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -4571,34 +4571,49 @@ fn is_out_of_flow_table_internal_child_of_table_root(&& is_table_non_root_box_with_display(host.display_before_box_type_transformation(child))}-fn create_anonymous_wrapper(host: &mut TreeBuilderHost<'_>, parent: LayoutNode) -> LayoutNode {+fn create_anonymous_wrapper(host: &mut TreeBuilderHost<'_>, parent: LayoutNode, before: LayoutNode) -> LayoutNode {let wrapper = host.create_anonymous_wrapper_box(parent);let wrapper_slot = wrapper.slot();- host.attach_child(parent, wrapper, NodeSlotId::INVALID);+ host.attach_child(parent, wrapper, before);wrapper_slot}-fn last_child_creating_anonymous_wrapper_if_needed(host: &mut TreeBuilderHost<'_>, parent: LayoutNode) -> LayoutNode {- let last_child = host.last_child(parent);- if last_child.is_invalid() {- return create_anonymous_wrapper(host, parent);+/// The anonymous wrapper at the end of the parent's children that an inline-level node joins, or at their start if+/// the node is being prepended (as an inside ::marker is) — creating one there if the child at that end isn't one.+fn edge_child_creating_anonymous_wrapper_if_needed(+ host: &mut TreeBuilderHost<'_>,+ parent: LayoutNode,+ mode: FfiInsertionMode,+) -> LayoutNode {+ let (edge_child, insert_wrapper_before) = if mode == FfiInsertionMode::Prepend {+ let first_child = host.first_child(parent);+ (first_child, first_child)+ } else {+ (host.last_child(parent), NodeSlotId::INVALID)+ };+ if edge_child.is_invalid() {+ return create_anonymous_wrapper(host, parent, insert_wrapper_before);}- let data = host.data(last_child);+ let data = host.data(edge_child);if !node_facts::has_flag(data, NodeFlag::Anonymous)|| !node_facts::has_flag(data, NodeFlag::ChildrenAreInline)|| node_is_generated_for_pseudo_element(data){- return create_anonymous_wrapper(host, parent);+ return create_anonymous_wrapper(host, parent, insert_wrapper_before);}- last_child+ edge_child}// The insertion_parent_for_*() functions maintain the invariant that the in-flow children of// block-level boxes must be either all block-level or all inline-level.-fn insertion_parent_for_inline_node(host: &mut TreeBuilderHost<'_>, parent: LayoutNode) -> LayoutNode {+fn insertion_parent_for_inline_node(+ host: &mut TreeBuilderHost<'_>,+ parent: LayoutNode,+ mode: FfiInsertionMode,+) -> LayoutNode {let data = host.data(parent);if matches!(data.kind.get(), NodeKind::FieldSetBox | NodeKind::SVGForeignObjectBox) {- return last_child_creating_anonymous_wrapper_if_needed(host, parent);+ return edge_child_creating_anonymous_wrapper_if_needed(host, parent, mode);}// SVG layout ignores the inline/block distinction, and an anonymous wrapper would only hide@@ -4613,7 +4628,7 @@ fn insertion_parent_for_inline_node(host: &mut TreeBuilderHost<'_>, parent: Layo}if parent_display.is_some_and(|display| display.is_flex_inside() || display.is_grid_inside()) {- return last_child_creating_anonymous_wrapper_if_needed(host, parent);+ return edge_child_creating_anonymous_wrapper_if_needed(host, parent, mode);}if !has_in_flow_block_children(host, parent) || node_facts::has_flag(data, NodeFlag::ChildrenAreInline) {@@ -4621,7 +4636,7 @@ fn insertion_parent_for_inline_node(host: &mut TreeBuilderHost<'_>, parent: Layo}// Parent has block-level children, insert into an anonymous wrapper block (and create it first if needed)- last_child_creating_anonymous_wrapper_if_needed(host, parent)+ edge_child_creating_anonymous_wrapper_if_needed(host, parent, mode)}fn nearest_rebuildable_container(host: &TreeBuilderHost<'_>, node: LayoutNode) -> LayoutNode {@@ -4966,7 +4981,7 @@ fn insert_node_into_inline_or_block_ancestor(|| is_inline_level_absolutely_positioned_box_in_flow_layout(host, nearest_insertion_ancestor, node_slot);let insertion_point = if is_inline_outside {- insertion_parent_for_inline_node(host, nearest_insertion_ancestor)+ insertion_parent_for_inline_node(host, nearest_insertion_ancestor, mode)} else {insertion_parent_for_block_node(host, state, nearest_insertion_ancestor, node_slot, mode, identity)};diff --git a/Tests/LibWeb/Layout/expected/list-item-inside-marker-before-block-child.txt b/Tests/LibWeb/Layout/expected/list-item-inside-marker-before-block-child.txtnew file mode 100644index 00000000000..f15d14c2032--- /dev/null+++ b/Tests/LibWeb/Layout/expected/list-item-inside-marker-before-block-child.txt@@ -0,0 +1,66 @@+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 184 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 160 0+0+8] children: not-inline+ BlockContainer <details> at [8,8] [0+0+0 784 0+0+0] [0+0+0 32 0+0+0] children: not-inline+ ListItemBox <summary> at [8,8] [0+0+0 784 0+0+0] [0+0+0 32 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [8,8 13.84375x16] baseline: 13+ ListItemMarkerBox <(anonymous)> at [8,8] [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: [8,8 13.84375x16] baseline: 13+ "► "+ GeneratedTextNode <(anonymous)> (not painted)+ ListItemBox <li> at [8,24] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [8,24 13.84375x16] baseline: 13+ frag 1 from TextNode start: 0, length: 5, rect: [21.84375,24 36.84375x16] baseline: 13+ "hello"+ ListItemMarkerBox <(anonymous)> at [8,24] [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: [8,24 13.84375x16] baseline: 13+ "► "+ GeneratedTextNode <(anonymous)> (not painted)+ TextNode <#text> (not painted)+ BlockContainer <slot> at [8,40] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline+ BlockContainer <ul> at [48,56] [0+0+40 744 0+0+0] [16+0+0 112 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+ BlockContainer <(anonymous)> at [48,56] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [48,56 13.84375x16] baseline: 13+ ListItemMarkerBox <(anonymous)> at [48,56] [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: [48,56 13.84375x16] baseline: 13+ "• "+ GeneratedTextNode <(anonymous)> (not painted)+ BlockContainer <div> 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: 11, rect: [48,72 84.703125x16] baseline: 13+ "block first"+ TextNode <#text> (not painted)+ ListItemBox <li> at [48,88] [0+0+0 744 0+0+0] [0+0+0 32 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [48,88] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [48,88 13.84375x16] baseline: 13+ frag 1 from TextNode start: 0, length: 12, rect: [61.84375,88 85.328125x16] baseline: 13+ "inline first"+ ListItemMarkerBox <(anonymous)> at [48,88] [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: [48,88 13.84375x16] baseline: 13+ "• "+ GeneratedTextNode <(anonymous)> (not painted)+ TextNode <#text> (not painted)+ BlockContainer <div> at [48,104] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 12, rect: [48,104 100.5x16] baseline: 13+ "then a block"+ TextNode <#text> (not painted)+ ListItemBox <li> at [48,120] [0+0+0 744 0+0+0] [0+0+0 48 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [48,120] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [48,120 13.84375x16] baseline: 13+ ListItemMarkerBox <(anonymous)> at [48,120] [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: [48,120 13.84375x16] baseline: 13+ "• "+ GeneratedTextNode <(anonymous)> (not painted)+ BlockContainer <div> at [48,136] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 11, rect: [48,136 84.703125x16] baseline: 13+ "block first"+ TextNode <#text> (not painted)+ BlockContainer <(anonymous)> at [48,152] [0+0+0 744 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 11, rect: [48,152 83.78125x16] baseline: 13+ "then inline"+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x184] (z-index: auto)+ SC for BlockContainer<SLOT> [8,40 784x0] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/list-item-marker-tree-linkage.txt b/Tests/LibWeb/Layout/expected/list-item-marker-tree-linkage.txtindex 577bf6e91a6..47ef6fea870 100644--- a/Tests/LibWeb/Layout/expected/list-item-marker-tree-linkage.txt+++ b/Tests/LibWeb/Layout/expected/list-item-marker-tree-linkage.txt@@ -3,16 +3,16 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 48 0+0+0] children: not-inlineBlockContainer <ul> at [40,0] [0+0+40 760 0+0+0] [0+0+0 48 0+0+0] children: not-inlineListItemBox <li.inside> at [40,0] [0+0+0 760 0+0+0] [0+0+0 32 0+0+0] children: not-inline- BlockContainer <div> at [40,0] [0+0+0 760 0+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 13, rect: [40,0 109.578125x16] baseline: 13- "block content"- TextNode <#text> (not painted)- BlockContainer <(anonymous)> at [40,16] [0+0+0 760 0+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [40,16 13.84375x16] baseline: 13- ListItemMarkerBox <(anonymous)> at [40,16] [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: [40,16 13.84375x16] baseline: 13+ BlockContainer <(anonymous)> at [40,0] [0+0+0 760 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [40,0 13.84375x16] baseline: 13+ ListItemMarkerBox <(anonymous)> at [40,0] [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: [40,0 13.84375x16] baseline: 13"• "GeneratedTextNode <(anonymous)> (not painted)+ BlockContainer <div> at [40,16] [0+0+0 760 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 13, rect: [40,16 109.578125x16] baseline: 13+ "block content"+ TextNode <#text> (not painted)ListItemBox <li.without-marker> at [40,32] [0+0+0 760 0+0+0] [0+0+0 16 0+0+0] children: not-inlineListItemBox <div.nested> at [40,32] [0+0+0 760 0+0+0] [0+0+0 16 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 16, rect: [40,32 124.453125x16] baseline: 13diff --git a/Tests/LibWeb/Layout/input/list-item-inside-marker-before-block-child.html b/Tests/LibWeb/Layout/input/list-item-inside-marker-before-block-child.htmlnew file mode 100644index 00000000000..17706c69674--- /dev/null+++ b/Tests/LibWeb/Layout/input/list-item-inside-marker-before-block-child.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<style>+ li {+ list-style-position: inside;+ }+</style>+<details><summary><li>hello</li></summary></details>+<ul>+ <li><div>block first</div></li>+ <li>inline first<div>then a block</div></li>+ <li><div>block first</div>then inline</li>+</ul>