Skip to content

Truly independent web browser

LibWeb: Size an inline table’s box to fit its wrapper

sideshowbarkerec38ff5cd8ac
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index e6a51d58154..013f1985092 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -1855,7 +1855,11 @@ impl<'pass> BlockFormattingContext<'pass> {
+ padding_right
+ *margin_right;
- if !facts.is_inline() {
+ // NB: The table box of an inline-level table keeps its inline-level display, but its wrapper holds it as a
+ // block-level box, so it takes the wrapper's inline size as one would.
+ let sized_as_block_level = !facts.is_inline()
+ || (facts.is_table_box() && matches!(available_space.inline_size, AvailableSize::Definite(_)));
+ if sized_as_block_level {
// 10.3.3 Block-level, non-replaced elements in normal flow
// If 'width' is not 'auto' and 'border-left-width' + 'padding-left' + 'width' + 'padding-right' +
// 'border-right-width' (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larger than the
diff --git a/Tests/LibWeb/Layout/expected/table/inline-table-respects-ancestor-max-width.txt b/Tests/LibWeb/Layout/expected/table/inline-table-respects-ancestor-max-width.txt
new file mode 100644
index 00000000000..434f84b8033
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/table/inline-table-respects-ancestor-max-width.txt
@@ -0,0 +1,22 @@
+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 80 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 64 0+0+8] children: not-inline
+ BlockContainer <div#wrapper> at [8,8] [0+0+0 140 0+0+644] [0+0+0 64 0+0+0] children: inline
+ InlineNode <a> at [8,8] [0+0+0 140 0+0+0] [0+0+0 64 0+0+0]
+ frag 0 from TableWrapper start: 0, length: 0, rect: [8,8 140x64] baseline: 12.796875
+ TableWrapper <(anonymous)> at [8,8] inline-block [0+0+0 140 0+0+0] [0+0+0 64 0+0+0] [BFC] children: not-inline
+ Box <(anonymous)> at [8,8] inline-table table-box [0+0+0 140 0+0+0] [0+0+0 64 0+0+0] [TFC] children: not-inline
+ Box <(anonymous)> at [8,8] table-row [0+0+0 140 0+0+0] [0+0+0 64 0+0+0] children: not-inline
+ BlockContainer <span#long-cell> at [8,8] table-cell [0+0+0 140 0+0+0] [0+0+0 64 0+0+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 14, rect: [8,8 120x16] baseline: 12.796875
+ "A nested table"
+ frag 1 from TextNode start: 15, length: 17, rect: [8,24 128.59375x16] baseline: 12.796875
+ "cell that's wider"
+ frag 2 from TextNode start: 33, length: 8, rect: [8,40 67.984375x16] baseline: 12.796875
+ "than the"
+ frag 3 from TextNode start: 42, length: 8, rect: [8,56 70.125x16] baseline: 12.796875
+ "wrapper."
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x80] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/table/inline-table-respects-ancestor-max-width.html b/Tests/LibWeb/Layout/input/table/inline-table-respects-ancestor-max-width.html
new file mode 100644
index 00000000000..08e65853ad1
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/table/inline-table-respects-ancestor-max-width.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html><style>
+ #wrapper {
+ max-width: 140px;
+ }
+ #long-cell {
+ display: table-cell;
+ }
+</style><div id="wrapper"><a><span id="long-cell">A nested table cell that's wider than the wrapper.</span></a></div>
diff --git a/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt b/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
index a84e6c78785..5275dff8a72 100644
--- a/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
+++ b/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
@@ -36,7 +36,7 @@ aspect ratio: 130x40, 80x60, 130x40, 120x60
percentage aspect ratio: 100x50, 50x50, 100x50, 120x100
inline flex: 210x20, 100x60, 210x20, 120x60
inline grid: 210x20, 100x60, 210x20, 120x60
-inline table: 210x20, 100x40, 210x20, 120x40
+inline table: 210x20, 100x60, 210x20, 120x60
containment: 35x25, 35x25, 35x25, 35x25
scroll container: 160x20, 50x60, 160x20, 120x40
hanging indent: 160x20, 63x60, 160x20, 120x40