LibWeb: Count the width of inline-blocks in InlineNodes only once

An BlockContainer inside an InlineNode is called from the
`for each in inclusive_subtree_of_type`  but is also a fragment
 of that InlineNode. Don't count the the Node twice.
This commit is contained in:
Lorenz A 2025-10-14 06:18:09 +02:00 committed by Jelle Raaijmakers
parent 93fde59892
commit ffcd3a4bb2
Notes: github-actions[bot] 2025-10-28 04:46:57 +00:00
6 changed files with 66 additions and 6 deletions

View file

@ -383,6 +383,8 @@ void LayoutState::commit(Box& root)
paintable_with_lines->for_each_in_inclusive_subtree_of_type<Painting::PaintableWithLines>([&](auto& paintable) {
if (paintable.line_index() != line_index)
return TraversalDecision::Continue;
if (is<BlockContainer>(paintable.layout_node()))
return TraversalDecision::Continue;
auto used_values = used_values_per_layout_node.get(paintable.layout_node_with_style_and_box_metrics());
if (&paintable != paintable_with_lines && used_values.has_value())

View file

@ -1,6 +1,6 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
InlineNode <body> at [0,13] [8+0+0 36.84375 0+0+8] [8+0+0 0 0+0+8]
InlineNode <body> at [8,13] [8+0+0 0 0+0+8] [8+0+0 0 0+0+8]
frag 0 from BlockContainer start: 0, length: 0, rect: [8,13 0x0] baseline: 0
BlockContainer <main> at [8,13] inline-block [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline
BlockContainer <div> at [8,0] positioned [0+0+0 36.84375 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
@ -10,7 +10,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x18]
PaintableWithLines (InlineNode<BODY>) [0,13 36.84375x0]
PaintableWithLines (InlineNode<BODY>) [8,13 0x0]
PaintableWithLines (BlockContainer<MAIN>) [8,13 0x0]
PaintableWithLines (BlockContainer<DIV>) [8,0 36.84375x18]
TextPaintable (TextNode<#text>)

View file

@ -0,0 +1,38 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 34 0+0+0] [BFC] children: not-inline
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 18 0+0+8] children: inline
TextNode <#text> (not painted)
InlineNode <span> at [8,8] [0+0+0 193.453125 0+0+0] [0+0+0 18 0+0+0]
frag 0 from BlockContainer start: 0, length: 0, rect: [8,8 185.453125x18] baseline: 13.796875
frag 1 from TextNode start: 0, length: 1, rect: [193.453125,8 8x18] baseline: 13.796875
" "
TextNode <#text> (not painted)
BlockContainer <div> at [8,8] inline-block [0+0+0 185.453125 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 13, rect: [8,8 185.453125x18] baseline: 13.796875
"AAAAAAAAAAAAA"
TextNode <#text> (not painted)
TextNode <#text> (not painted)
TextNode <#text> (not painted)
InlineNode <span> at [201.453125,8] [0+0+0 46.71875 0+0+0] [0+0+0 18 0+0+0]
frag 0 from BlockContainer start: 0, length: 0, rect: [201.453125,8 46.71875x18] baseline: 13.796875
TextNode <#text> (not painted)
BlockContainer <div> at [201.453125,8] inline-block [0+0+0 46.71875 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 5, rect: [201.453125,8 46.71875x18] baseline: 13.796875
"BBBBB"
TextNode <#text> (not painted)
TextNode <#text> (not painted)
TextNode <#text> (not painted)
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x34]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x18]
PaintableWithLines (InlineNode<SPAN>) [8,8 193.453125x18]
PaintableWithLines (BlockContainer<DIV>) [8,8 185.453125x18]
TextPaintable (TextNode<#text>)
TextPaintable (TextNode<#text>)
PaintableWithLines (InlineNode<SPAN>) [201.453125,8 46.71875x18]
PaintableWithLines (BlockContainer<DIV>) [201.453125,8 46.71875x18]
TextPaintable (TextNode<#text>)
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
SC for BlockContainer<HTML> [0,0 800x34] [children: 0] (z-index: auto)

View file

@ -1,6 +1,6 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
InlineNode <body> at [0,0] [8+0+0 23.59375 0+0+8] [8+0+0 18 0+0+8]
InlineNode <body> at [8,0] [8+0+0 11.796875 0+0+8] [8+0+0 18 0+0+8]
frag 0 from BlockContainer start: 0, length: 0, rect: [8,0 11.796875x18] baseline: 13.796875
BlockContainer <div> at [8,0] positioned inline-block [0+0+0 11.796875 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 1, rect: [8,0 11.796875x18] baseline: 13.796875
@ -9,7 +9,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x18]
PaintableWithLines (InlineNode<BODY>) [0,0 23.59375x18]
PaintableWithLines (InlineNode<BODY>) [8,0 11.796875x18]
PaintableWithLines (BlockContainer<DIV>) [8,0 11.796875x18]
TextPaintable (TextNode<#text>)

View file

@ -1,6 +1,6 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
InlineNode <body> at [0,0] [8+0+0 73.6875 0+0+8] [8+0+0 18 0+0+8]
InlineNode <body> at [8,0] [8+0+0 36.84375 0+0+8] [8+0+0 18 0+0+8]
frag 0 from BlockContainer start: 0, length: 0, rect: [8,0 36.84375x18] baseline: 13.796875
BlockContainer <main> at [8,0] inline-block [0+0+0 36.84375 0+0+0] [0+0+0 18 0+0+0] [BFC] children: not-inline
BlockContainer <div> at [8,0] [0+0+0 36.84375 0+0+0] [0+0+0 18 0+0+0] children: inline
@ -11,7 +11,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x18]
PaintableWithLines (InlineNode<BODY>) [0,0 73.6875x18]
PaintableWithLines (InlineNode<BODY>) [8,0 36.84375x18]
PaintableWithLines (BlockContainer<MAIN>) [8,0 36.84375x18]
PaintableWithLines (BlockContainer<DIV>) [8,0 36.84375x18]
TextPaintable (TextNode<#text>)

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<style>
body>span {
background-color: red;
}
div {
display: inline-block
}
</style>
<body>
<span style="background-color: red;">
<div>AAAAAAAAAAAAA</div>
</span>
<span style="background-color: green;">
<div>BBBBB</div>
</span>
</body>