LibWeb: Use caption content width for inline layout in table captions

Previously, `run_caption_layout()` passed the table's border-box width
as the available space to the caption's formatting context. The BFC then
used this width directly for inline line breaking, causing text to
overflow the caption's content box by the size of the caption's own
border and padding.
This commit is contained in:
Tim Ledbetter
2026-04-05 20:05:47 +01:00
committed by Sam Atkins
parent 6f3833e857
commit d8825c89af
Notes: github-actions[bot] 2026-04-22 14:36:15 +00:00
5 changed files with 83 additions and 22 deletions

View File

@@ -11,12 +11,12 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [50,120] [0+0+0 102 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
BlockContainer <figcaption> at [50,16] [0+2+0 102 0+2+0] [0+2+0 50 0+2+0] [BFC] children: not-inline
BlockContainer <(anonymous)> at [50,16] [0+0+0 106 0+0+0] [0+0+0 18 0+0+0] children: inline
BlockContainer <(anonymous)> at [50,16] [0+0+0 102 0+0+0] [0+0+0 18 0+0+0] children: inline
frag 0 from TextNode start: 9, length: 12, rect: [50,16 100.609375x18] baseline: 13.796875
"Caption text"
TextNode <#text> (not painted)
BlockContainer <div.caption-content> at [51,35] [0+1+0 104 0+1+0] [0+1+0 30 0+1+0] children: not-inline
BlockContainer <(anonymous)> at [50,66] [0+0+0 106 0+0+0] [0+0+0 0 0+0+0] children: inline
BlockContainer <div.caption-content> at [51,35] [0+1+0 100 0+1+0] [0+1+0 30 0+1+0] children: not-inline
BlockContainer <(anonymous)> at [50,66] [0+0+0 102 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text> (not painted)
@@ -34,10 +34,10 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<DIV>.table-content) [50,68 102x52]
PaintableWithLines (BlockContainer(anonymous)) [50,120 102x0]
PaintableWithLines (BlockContainer<FIGCAPTION>) [48,14 106x54]
PaintableWithLines (BlockContainer(anonymous)) [50,16 106x18]
PaintableWithLines (BlockContainer(anonymous)) [50,16 102x18]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer<DIV>.caption-content) [50,34 106x32]
PaintableWithLines (BlockContainer(anonymous)) [50,66 106x0]
PaintableWithLines (BlockContainer<DIV>.caption-content) [50,34 102x32]
PaintableWithLines (BlockContainer(anonymous)) [50,66 102x0]
PaintableWithLines (BlockContainer(anonymous)) [8,192 784x0]
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)

View File

@@ -0,0 +1,42 @@
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 77 0+0+0] [BFC] children: not-inline
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 61 0+0+8] children: not-inline
TableWrapper <(anonymous)> at [8,8] [0+0+0 208 0+0+576] [0+0+0 61 0+0+0] [BFC] children: not-inline
Box <table> at [9,29] table-box [0+1+0 206 0+1+0] [0+1+0 17 0+1+22] [TFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text> (not painted)
TextNode <#text> (not painted)
BlockContainer <caption> at [15,8] [0+1+6 194 6+1+0] [0+1+0 20 0+1+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 10, rect: [62,8 100x10] baseline: 8
"AAAAAAAAAA"
frag 1 from TextNode start: 11, length: 14, rect: [42,18 140x10] baseline: 8
"BBBBBBBBB CCCC"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text> (not painted)
Box <tbody> at [11,31] table-row-group [0+0+0 202 0+0+0] [0+0+0 13 0+0+0] children: not-inline
Box <tr> at [11,31] table-row [0+0+0 202 0+0+0] [0+0+0 13 0+0+0] children: not-inline
BlockContainer <td> at [12,32] table-cell [0+0+1 200 1+0+0] [0+0+1 11 1+0+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 1, rect: [12,31 10x10] baseline: 8
"x"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text> (not painted)
BlockContainer <(anonymous)> at [8,69] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x77]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x61]
PaintableWithLines (TableWrapper(anonymous)) [8,8 208x61]
PaintableBox (Box<TABLE>) [8,28 208x19]
PaintableWithLines (BlockContainer<CAPTION>) [8,7 208x22]
TextPaintable (TextNode<#text>)
PaintableBox (Box<TBODY>) [11,31 202x13]
PaintableBox (Box<TR>) [11,31 202x13]
PaintableWithLines (BlockContainer<TD>) [11,31 202x13]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer(anonymous)) [8,69 784x0]
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
SC for BlockContainer<HTML> [0,0 800x77] [children: 0] (z-index: auto)

View File

@@ -6,7 +6,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text> (not painted)
BlockContainer <caption> at [18,8] [0+0+10 60.46875 10+0+0] [0+0+10 18 10+0+0] [BFC] children: inline
frag 0 from TextNode start: 5, length: 7, rect: [28,8 60.46875x18] baseline: 13.796875
frag 0 from TextNode start: 5, length: 7, rect: [18,8 60.46875x18] baseline: 13.796875
"Caption"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) children: inline

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<style>
@font-face {
font-family: 'Ahem';
src: url('../../../Ref/data/fonts/Ahem.ttf');
}
table {
border: 1px solid black;
font: 10px/1 Ahem;
}
caption {
padding: 0 6px;
border: 1px solid gray;
}
</style>
<table>
<!-- The text should not overflow the table border -->
<caption>AAAAAAAAAA BBBBBBBBB CCCC</caption>
<tr><td style="width: 200px">x</td></tr>
</table>