Truly independent web browser
LibWeb: Make room in a table for the columns beside a percentage one
sideshowbarker800722eb15fd
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 65d38fe9ff2..8309d870c7e 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2635,6 +2635,35 @@ impl<'pass> TableFormattingContext<'pass> {};}}+ // AD-HOC: Whatever the percentage columns take of the table, the other columns have the rest for their+ // max-content sizes, so the table grows until they fit in it. Once the percentages reach 100%,+ // nothing is left for them, so the table fills its container. Other browsers do the same.+ let percentage_sum = self+ .columns+ .iter()+ .filter(|column| column.has_intrinsic_percentage)+ .map(|column| column.intrinsic_percentage)+ .sum::<f64>()+ .min(100.0);+ let non_percentage_max = self+ .columns+ .iter()+ .filter(|column| !column.has_intrinsic_percentage)+ .fold(CssPixels::default(), |sum, column| sum + column.max_size);+ if percentage_sum > 0.0 && non_percentage_max > CssPixels::default() {+ if percentage_sum < 100.0 {+ let needed = spacing+ + CssPixels::nearest_value_for(+ non_percentage_max.to_double() * 100.0 / (100.0 - percentage_sum),+ );+ value = match available_inline {+ AvailableSize::Definite(available) => value.max(needed).min(available),+ _ => value.max(needed),+ };+ } else if let AvailableSize::Definite(available) = available_inline {+ value = value.max(available);+ }+ }}value} else if table_style.width().is_max_content() {diff --git a/Tests/LibWeb/Layout/expected/table/percentage-cell-with-other-columns-fills-container.txt b/Tests/LibWeb/Layout/expected/table/percentage-cell-with-other-columns-fills-container.txtnew file mode 100644index 00000000000..30c381ddfe0--- /dev/null+++ b/Tests/LibWeb/Layout/expected/table/percentage-cell-with-other-columns-fills-container.txt@@ -0,0 +1,15 @@+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 32 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 16 0+0+8] children: not-inline+ TableWrapper <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline+ Box <div> at [8,8] table-box [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] [TFC] children: not-inline+ Box <(anonymous)> at [8,8] table-row [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [8,20.796875] table-cell [0+0+0 10 0+0+0] [0+0+12.796875 0 3.203125+0+0] [BFC] children: not-inline+ BlockContainer <span.icon> at [8,20.796875] floating [0+0+0 10 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline+ BlockContainer <span.text> at [18,8] table-cell [0+0+0 774 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 1, rect: [18,8 9.34375x16] baseline: 12.796875+ "a"+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x32] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/table/percentage-cell-with-other-columns-fills-container.html b/Tests/LibWeb/Layout/input/table/percentage-cell-with-other-columns-fills-container.htmlnew file mode 100644index 00000000000..b0dccfe6b15--- /dev/null+++ b/Tests/LibWeb/Layout/input/table/percentage-cell-with-other-columns-fills-container.html@@ -0,0 +1,14 @@+<!DOCTYPE html><style>+ div {+ background-color: lightgray;+ display: table;+ }+ .text {+ display: table-cell;+ width: 100%;+ }+ .icon {+ float: left;+ width: 10px;+ }+</style><div><span class="icon"></span><span class="text">a</span></div>