Truly independent web browser
LibWeb: Cap a table cell’s min-content width at its max-width
sideshowbarkerc37e49f93d84
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 2620bd7348b..e8fe2f5e14f 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1884,7 +1884,11 @@ impl<'pass> TableFormattingContext<'pass> {(content_sizes.min, content_sizes.max)};// The outer min-content inline size of a table cell is its minimum inline size adjusted by the cell intrinsic offsets.- self.cells[cell_index].outer_min_inline_size = min_inline.max(min_content_inline) + inline_offsets;+ // AD-HOC: The spec's max(min-width, min-content width) lets the min-content width override a definite max-width,+ // so a cell whose content can't wrap widens its column past its max-width, where pages expect the cell+ // to cut that content off. So cap the min-content width at the max-width; min-width still wins over both.+ let capped_min_content_inline = min_content_inline.min(max_inline);+ self.cells[cell_index].outer_min_inline_size = min_inline.max(capped_min_content_inline) + inline_offsets;self.cells[cell_index].max_content_inline_size = (!fixed).then_some(max_content_inline);if include_rows {@@ -1961,7 +1965,8 @@ impl<'pass> TableFormattingContext<'pass> {} else {// The outer max-content width of a table-cell in a non-constrained column is// max(min-width, width, min-content width, min(max-width, max-content width)) adjusted by the cell intrinsic offsets.- min_inline.max(inline_size.max(min_content_inline.max(max_inline.min(max_content_inline))))+ // AD-HOC: With the min-content width capped at a definite max-width, as for the outer min-content width.+ min_inline.max(inline_size.max(capped_min_content_inline.max(max_inline.min(max_content_inline))))+ inline_offsets};}diff --git a/Tests/LibWeb/Text/expected/css/table-cell-max-width-caps-min-content.txt b/Tests/LibWeb/Text/expected/css/table-cell-max-width-caps-min-content.txtnew file mode 100644index 00000000000..bab1f7c01fe--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/table-cell-max-width-caps-min-content.txt@@ -0,0 +1,3 @@+capped: table keeps its width: true+uncapped: table keeps its width: false+min-width-wins: first cell is 150px wide: true, table is wider than 100px: truediff --git a/Tests/LibWeb/Text/input/css/table-cell-max-width-caps-min-content.html b/Tests/LibWeb/Text/input/css/table-cell-max-width-caps-min-content.htmlnew file mode 100644index 00000000000..fe2c70bb137--- /dev/null+++ b/Tests/LibWeb/Text/input/css/table-cell-max-width-caps-min-content.html@@ -0,0 +1,48 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ table {+ width: 300px;+ border-collapse: collapse;+ font: 16px/1 serif;+ }+ td {+ padding: 0;+ }+ .row {+ display: flex;+ overflow: hidden;+ }+ .summary {+ flex: 1;+ overflow: hidden;+ white-space: nowrap;+ text-overflow: ellipsis;+ }+</style>+<table id="capped"><tr>+ <td style="max-width: 100px"><div class="row"><span class="summary">A commit message far too long to fit in its table cell, on one line</span></div></td>+ <td>age</td>+</tr></table>+<table id="uncapped"><tr>+ <td><div class="row"><span class="summary">A commit message far too long to fit in its table cell, on one line</span></div></td>+ <td>age</td>+</tr></table>+<table id="min-width-wins" style="width: 100px"><tr>+ <td style="max-width: 100px; min-width: 150px"><div class="row"><span class="summary">A commit message far too long to fit in its table cell, on one line</span></div></td>+ <td>age</td>+</tr></table>+<script>+ test(() => {+ // A cell's max-width caps the width its unbreakable content asks for, so the table keeps its width.+ for (const id of ["capped", "uncapped"]) {+ const table = document.getElementById(id);+ println(`${id}: table keeps its width: ${table.getBoundingClientRect().width === 300}`);+ }++ // A min-width still wins over the max-width, and widens the table past its width.+ const table = document.getElementById("min-width-wins");+ const cell = table.querySelector("td");+ println(`min-width-wins: first cell is 150px wide: ${cell.getBoundingClientRect().width === 150}, table is wider than 100px: ${table.getBoundingClientRect().width > 100}`);+ });+</script>