Truly independent web browser
LibWeb: Apply a table’s min-height and max-height to its grid
sideshowbarkerf1357255e305
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 9498de09fdf..4aa46d8fce3 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -3120,15 +3120,29 @@ impl<'pass> TableFormattingContext<'pass> {self.table_block_size = self.table_block_size.max(content_min);}let table_style = self.style(self.run.box_);- if !table_style.height().is_auto() {- // If the table has a `height` property other than auto, it is treated as a minimum block size for the- // table grid, and will eventually be distributed to the rows if their collective minimum block size is smaller.- let mut specified = table_style.height().to_px(self.table_constraints.block_basis());- if table_style.box_sizing() == box_sizing::BORDER_BOX {- let used = &self.table_box_cells;- let collapsed = used.uses_collapsing_borders_model();- specified -= used.border_box_top(collapsed) + used.border_box_bottom(collapsed);- }+ let block_basis = self.table_constraints.block_basis();+ let border_box_offsets = if table_style.box_sizing() == box_sizing::BORDER_BOX {+ let used = &self.table_box_cells;+ let collapsed = used.uses_collapsing_borders_model();+ used.border_box_top(collapsed) + used.border_box_bottom(collapsed)+ } else {+ CssPixels::default()+ };+ // If the table has a `height` property other than auto, it is treated as a minimum block size for the+ // table grid, and will eventually be distributed to the rows if their collective minimum block size is smaller.+ // The table's `max-height` lowers that size, and its `min-height` raises it, as for the block size of any box.+ let mut specified =+ (!table_style.height().is_auto()).then(|| table_style.height().to_px(block_basis) - border_box_offsets);+ if let Some(size) = specified.as_mut()+ && table_style.max_height().is_length()+ {+ *size = (*size).min(table_style.max_height().to_px(block_basis) - border_box_offsets);+ }+ if !crate::layout::sizing_context::is_plain_auto(table_style.min_height()) {+ let minimum = table_style.min_height().to_px(block_basis) - border_box_offsets;+ specified = Some(specified.map_or(minimum, |size| size.max(minimum)));+ }+ if let Some(specified) = specified {self.table_block_size = self.table_block_size.max(specified - row_spacing);}let table_percentage_basis = self.table_block_size + row_spacing;diff --git a/Tests/LibWeb/Text/expected/css/table-min-height-and-max-height.txt b/Tests/LibWeb/Text/expected/css/table-min-height-and-max-height.txtnew file mode 100644index 00000000000..b7d8c04f700--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/table-min-height-and-max-height.txt@@ -0,0 +1,5 @@+min-height: 100+max-height: 100+abspos-min-height: 100+centered: 200+content of the min-height table is vertically centered: truediff --git a/Tests/LibWeb/Text/input/css/table-min-height-and-max-height.html b/Tests/LibWeb/Text/input/css/table-min-height-and-max-height.htmlnew file mode 100644index 00000000000..d7c57d2a715--- /dev/null+++ b/Tests/LibWeb/Text/input/css/table-min-height-and-max-height.html@@ -0,0 +1,33 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ .table {+ display: table;+ width: 100px;+ }+ .cell {+ display: table-cell;+ vertical-align: middle;+ }+ .row {+ display: block;+ height: 16px;+ }+ .container {+ position: relative;+ height: 300px;+ }+</style>+<div class="table" id="min-height" style="min-height: 100px"><div class="cell"><span class="row"></span></div></div>+<div class="table" id="max-height" style="height: 200px; max-height: 100px"><div class="cell"><span class="row"></span></div></div>+<div class="container"><div class="table" id="abspos-min-height" style="position: absolute; min-height: 100px"><div class="cell"><span class="row"></span></div></div></div>+<div class="table" id="centered" style="min-height: 200px"><div class="cell"><span class="row" id="centered-content"></span></div></div>+<script>+ test(() => {+ for (const id of ["min-height", "max-height", "abspos-min-height", "centered"])+ println(`${id}: ${document.getElementById(id).getBoundingClientRect().height}`);+ const table = document.getElementById("centered").getBoundingClientRect();+ const content = document.getElementById("centered-content").getBoundingClientRect();+ println(`content of the min-height table is vertically centered: ${content.top - table.top === table.bottom - content.bottom}`);+ });+</script>