Skip to content

Commit 8a657a9

Browse files
committed
LibWeb: Follow explicit cell widths when calculating fixed table layouts
1 parent c701781 commit 8a657a9

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

Libraries/LibWeb/Layout/TableFormattingContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ void TableFormattingContext::compute_cell_measures()
179179
// The min-content and max-content width of cells is considered zero unless they are directly specified as a length-percentage,
180180
// in which case they are resolved based on the table width (if it is definite, otherwise use 0).
181181
auto width_is_specified_length_or_percentage = computed_values.width().is_length() || computed_values.width().is_percentage();
182+
if (use_fixed_mode_layout()) {
183+
min_content_width = max_content_width = width_is_specified_length_or_percentage ? computed_values.width().to_px(cell.box, containing_block_width) : 0;
184+
if (computed_values.box_sizing() == CSS::BoxSizing::BorderBox)
185+
min_content_width = max_content_width = max(CSSPixels(0), min_content_width - padding_left - padding_right - border_left - border_right);
186+
}
187+
182188
if (!use_fixed_mode_layout() || width_is_specified_length_or_percentage) {
183189
cell.outer_min_width = max(min_width, min_content_width) + cell_intrinsic_width_offsets;
184190
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
2+
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 26 0+0+0] [BFC] children: not-inline
3+
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 10 0+0+8] children: not-inline
4+
TableWrapper <(anonymous)> at [8,8] [0+0+0 50 0+0+734] [0+0+0 10 0+0+0] [BFC] children: not-inline
5+
Box <table> at [8,8] table-box [0+0+0 50 0+0+50] [0+0+0 10 0+0+0] [TFC] children: not-inline
6+
BlockContainer <(anonymous)> (not painted) children: inline
7+
TextNode <#text> (not painted)
8+
Box <tbody> at [8,8] table-row-group [0+0+0 50 0+0+0] [0+0+0 10 0+0+0] children: not-inline
9+
Box <tr> at [8,8] table-row [0+0+0 50 0+0+0] [0+0+0 10 0+0+0] children: not-inline
10+
BlockContainer <(anonymous)> (not painted) children: inline
11+
TextNode <#text> (not painted)
12+
BlockContainer <td> at [8,8] table-cell [0+0+0 50 0+0+0] [0+0+0 10 0+0+0] [BFC] children: not-inline
13+
BlockContainer <(anonymous)> at [8,8] [0+0+0 50 0+0+0] [0+0+0 0 0+0+0] children: inline
14+
TextNode <#text> (not painted)
15+
BlockContainer <div> at [8,8] [0+0+0 10 0+0+40] [0+0+0 10 0+0+0] children: not-inline
16+
BlockContainer <(anonymous)> at [8,18] [0+0+0 50 0+0+0] [0+0+0 0 0+0+0] children: inline
17+
TextNode <#text> (not painted)
18+
BlockContainer <(anonymous)> (not painted) children: inline
19+
TextNode <#text> (not painted)
20+
BlockContainer <(anonymous)> (not painted) children: inline
21+
TextNode <#text> (not painted)
22+
BlockContainer <(anonymous)> at [8,18] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
23+
TextNode <#text> (not painted)
24+
25+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
26+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x26]
27+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x10]
28+
PaintableWithLines (TableWrapper(anonymous)) [8,8 50x10]
29+
PaintableBox (Box<TABLE>) [8,8 50x10]
30+
PaintableBox (Box<TBODY>) [8,8 50x10]
31+
PaintableBox (Box<TR>) [8,8 50x10]
32+
PaintableWithLines (BlockContainer<TD>) [8,8 50x10]
33+
PaintableWithLines (BlockContainer(anonymous)) [8,8 50x0]
34+
PaintableWithLines (BlockContainer<DIV>) [8,8 10x10]
35+
PaintableWithLines (BlockContainer(anonymous)) [8,18 50x0]
36+
PaintableWithLines (BlockContainer(anonymous)) [8,18 784x0]
37+
38+
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
39+
SC for BlockContainer<HTML> [0,0 800x26] [children: 0] (z-index: auto)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<!-- This test ensures that in fixed table layouts, explicit cell widths take precedence over intrinsic content size.
3+
Previously, the table would incorrectly squash to 10px instead of honoring the 50px cell width. -->
4+
<style>
5+
table {
6+
table-layout: fixed;
7+
width: 0;
8+
border-collapse: collapse;
9+
}
10+
td {
11+
width: 50px;
12+
padding: 0;
13+
border: none;
14+
}
15+
div {
16+
width: 10px;
17+
height: 10px;
18+
background: red;
19+
}
20+
</style>
21+
<table>
22+
<tr>
23+
<td>
24+
<div></div>
25+
</td>
26+
</tr>
27+
</table>

0 commit comments

Comments
 (0)