Skip to content

Truly independent web browser

LibWeb: Ignore a percentage min-width on a table cell

sideshowbarker01f791e1bd58
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 06f30f0db8d..3b17d051a9e 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -1937,7 +1937,15 @@ impl<'pass> TableFormattingContext<'pass> {
let inline_offsets = cell_box.border_box_left(collapsed) + cell_box.border_box_right(collapsed);
let width = style.width();
let max_width = style.max_width();
- let mut min_inline = style.min_width().to_px(inline_basis);
+ // https://www.w3.org/TR/css-tables-3/#percentage-contribution
+ // "Please note that 'min-width' is not included in this computation. As a result, a percentage 'min-width'
+ // is ignored."
+ let min_width = style.min_width();
+ let mut min_inline = if min_width.is_length() {
+ min_width.to_px(inline_basis)
+ } else {
+ CssPixels::default()
+ };
let mut inline_size = if width.is_length() {
width.to_px(inline_basis)
} else {
diff --git a/Tests/LibWeb/Text/expected/table/percentage-min-width-of-a-cell-is-ignored.txt b/Tests/LibWeb/Text/expected/table/percentage-min-width-of-a-cell-is-ignored.txt
new file mode 100644
index 00000000000..6017c4d4fc4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/table/percentage-min-width-of-a-cell-is-ignored.txt
@@ -0,0 +1,9 @@
+one-cell: cells 40, table 40
+with-max-width: cells 40, table 40
+three-cells: cells 30 40 50, table 120
+collapsed-borders: cells 30 40 50, table 120
+full-width: cells 150 200 250, table 600
+half-percent: cells 30 40 50, table 120
+column: cells 30 40 50, table 120
+length-min-width: cells 30 100 50, table 180
+percentage-width: cells 30 80 50, table 160
diff --git a/Tests/LibWeb/Text/input/table/percentage-min-width-of-a-cell-is-ignored.html b/Tests/LibWeb/Text/input/table/percentage-min-width-of-a-cell-is-ignored.html
new file mode 100644
index 00000000000..e90d3cf406a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/table/percentage-min-width-of-a-cell-is-ignored.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+@font-face { font-family: Ahem; src: url("../../../Ref/data/fonts/Ahem.ttf"); }
+body { margin: 0; font: 10px/10px Ahem; }
+.box { width: 600px; }
+table { table-layout: auto; border-spacing: 0; margin-bottom: 10px; }
+td { padding: 0; }
+.collapse { border-collapse: collapse; }
+</style>
+<!-- A percentage min-width on a table cell or column is ignored, while a length one still counts. -->
+<div class="box">
+<table id="one-cell"><tr><td style="min-width: 100%">XXXX</td></tr></table>
+<table id="with-max-width"><tr><td style="min-width: 100%; max-width: 125px">XXXX</td></tr></table>
+<table id="three-cells"><tr><td>XXX</td><td style="min-width: 100%">XXXX</td><td>XXXXX</td></tr></table>
+<table id="collapsed-borders" class="collapse"><tr><td>XXX</td><td style="min-width: 100%">XXXX</td><td>XXXXX</td></tr></table>
+<table id="full-width" style="width: 100%"><tr><td>XXX</td><td style="min-width: 100%">XXXX</td><td>XXXXX</td></tr></table>
+<table id="half-percent"><tr><td>XXX</td><td style="min-width: 50%">XXXX</td><td>XXXXX</td></tr></table>
+<table id="column"><col><col style="min-width: 100%"><col><tr><td>XXX</td><td>XXXX</td><td>XXXXX</td></tr></table>
+<table id="length-min-width"><tr><td>XXX</td><td style="min-width: 100px">XXXX</td><td>XXXXX</td></tr></table>
+<table id="percentage-width"><tr><td>XXX</td><td style="width: 50%">XXXX</td><td>XXXXX</td></tr></table>
+</div>
+<script>
+asyncTest(done => document.fonts.ready.then(() => {
+ for (const t of document.querySelectorAll("table"))
+ println(`${t.id}: cells ${[...t.querySelectorAll("td")].map(c => c.getBoundingClientRect().width).join(" ")}, table ${t.getBoundingClientRect().width}`);
+ done();
+}));
+</script>