Skip to content

Commit c845e2c

Browse files
committed
LibWeb: Don't join anonymous pseudo wrappers for block node insertion
This can happen if pseudo elements are absolutely positioned, they need the nearest non-inline parent to determine their position.
1 parent ac829cf commit c845e2c

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

Libraries/LibWeb/Layout/TreeBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
113113
if (!has_inline_or_in_flow_block_children(*new_parent))
114114
return *new_parent;
115115

116-
// If the block is out-of-flow,
117-
if (layout_node.is_out_of_flow()) {
116+
// If the block is out-of-flow and is not a pseudo element,
117+
if (layout_node.is_out_of_flow() && !layout_node.is_generated_for_pseudo_element()) {
118118
// And the parent's last child is an anonymous block, join that anonymous block.
119119
if (!new_parent->display().is_flex_inside()
120120
&& !new_parent->display().is_grid_inside()

Tests/LibWeb/Layout/expected/block-and-inline/button-with-after-pseudo.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
44
frag 0 from BlockContainer start: 0, length: 0, rect: [13,10 414.703125x57] baseline: 45.484375
55
BlockContainer <button.button_button___eDCW> at [13,10] positioned inline-block [0+1+4 414.703125 4+1+0] [0+1+1 57 1+1+0] [BFC] children: not-inline
66
BlockContainer <(anonymous)> at [13,10] flex-container(column) [0+0+0 414.703125 0+0+0] [0+0+0 57 0+0+0] [FFC] children: not-inline
7-
BlockContainer <(anonymous)> at [13,10] flex-item [0+0+0 414.703125 0+0+0] [0+0+0 57 0+0+0] [BFC] children: inline
8-
frag 0 from TextNode start: 0, length: 14, rect: [13,10 414.703125x57] baseline: 43.484375
9-
"See more games"
10-
TextNode <#text> (not painted)
7+
BlockContainer <(anonymous)> at [13,10] flex-item [0+0+0 414.703125 0+0+0] [0+0+0 57 0+0+0] [BFC] children: not-inline
8+
BlockContainer <(anonymous)> at [13,10] [0+0+0 414.703125 0+0+0] [0+0+0 57 0+0+0] children: inline
9+
frag 0 from TextNode start: 0, length: 14, rect: [13,10 414.703125x57] baseline: 43.484375
10+
"See more games"
11+
TextNode <#text> (not painted)
1112
BlockContainer <(anonymous)> at [9,9] positioned [0+0+0 422.703125 0+0+0] [0+0+0 59 0+0+0] [BFC] children: inline
1213
TextNode <#text> (not painted)
1314

@@ -17,7 +18,8 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
1718
PaintableWithLines (BlockContainer<BUTTON>.button_button___eDCW) [8,8 424.703125x61]
1819
PaintableWithLines (BlockContainer(anonymous)) [13,10 414.703125x57]
1920
PaintableWithLines (BlockContainer(anonymous)) [13,10 414.703125x57]
20-
TextPaintable (TextNode<#text>)
21+
PaintableWithLines (BlockContainer(anonymous)) [13,10 414.703125x57]
22+
TextPaintable (TextNode<#text>)
2123
PaintableWithLines (BlockContainer(anonymous)) [9,9 422.703125x59]
2224

2325
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
2+
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 70 0+0+0] [BFC] children: not-inline
3+
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 54 0+0+8] children: not-inline
4+
BlockContainer <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 18 0+0+0] children: inline
5+
InlineNode <span> at [8,8] [0+0+0 54.796875 0+0+0] [0+0+0 18 0+0+0]
6+
frag 0 from TextNode start: 0, length: 6, rect: [8,8 54.796875x18] baseline: 13.796875
7+
"foobar"
8+
TextNode <#text> (not painted)
9+
BlockContainer <(anonymous)> at [8,26] positioned [0+0+0 50 0+0+0] [0+0+0 50 0+0+0] [BFC] children: inline
10+
frag 0 from TextNode start: 0, length: 3, rect: [8,26 27.203125x18] baseline: 13.796875
11+
"baz"
12+
TextNode <#text> (not painted)
13+
BlockContainer <(anonymous)> at [8,26] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
14+
TextNode <#text> (not painted)
15+
BlockContainer <div> at [8,26] [0+0+0 784 0+0+0] [0+0+0 18 0+0+0] children: inline
16+
frag 0 from TextNode start: 0, length: 11, rect: [8,26 97.640625x18] baseline: 13.796875
17+
"lorem ipsum"
18+
TextNode <#text> (not painted)
19+
BlockContainer <(anonymous)> at [8,44] [0+0+0 784 0+0+0] [0+0+0 18 0+0+0] children: inline
20+
TextNode <#text> (not painted)
21+
InlineNode <span> at [8,44] [0+0+0 54.796875 0+0+0] [0+0+0 18 0+0+0]
22+
frag 0 from TextNode start: 0, length: 6, rect: [8,44 54.796875x18] baseline: 13.796875
23+
"foobar"
24+
TextNode <#text> (not painted)
25+
BlockContainer <(anonymous)> at [8,62] positioned [0+0+0 50 0+0+0] [0+0+0 50 0+0+0] [BFC] children: inline
26+
frag 0 from TextNode start: 0, length: 3, rect: [8,62 27.203125x18] baseline: 13.796875
27+
"baz"
28+
TextNode <#text> (not painted)
29+
BlockContainer <(anonymous)> at [8,62] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
30+
TextNode <#text> (not painted)
31+
32+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
33+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x70]
34+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x54]
35+
PaintableWithLines (BlockContainer(anonymous)) [8,8 784x18]
36+
PaintableWithLines (InlineNode<SPAN>) [8,8 54.796875x18]
37+
TextPaintable (TextNode<#text>)
38+
PaintableWithLines (BlockContainer(anonymous)) [8,26 50x50]
39+
TextPaintable (TextNode<#text>)
40+
PaintableWithLines (BlockContainer(anonymous)) [8,26 784x0]
41+
PaintableWithLines (BlockContainer<DIV>) [8,26 784x18]
42+
TextPaintable (TextNode<#text>)
43+
PaintableWithLines (BlockContainer(anonymous)) [8,44 784x18]
44+
PaintableWithLines (InlineNode<SPAN>) [8,44 54.796875x18]
45+
TextPaintable (TextNode<#text>)
46+
PaintableWithLines (BlockContainer(anonymous)) [8,62 50x50]
47+
TextPaintable (TextNode<#text>)
48+
PaintableWithLines (BlockContainer(anonymous)) [8,62 784x0]
49+
50+
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
51+
SC for BlockContainer<HTML> [0,0 800x70] [children: 0] (z-index: auto)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<style>
3+
span::after {
4+
background: green;
5+
content: "baz";
6+
display: block;
7+
height: 50px;
8+
position: absolute;
9+
width: 50px;
10+
}
11+
</style>
12+
<span>foobar</span>
13+
<div>lorem ipsum</div>
14+
<span>foobar</span>

0 commit comments

Comments
 (0)