From 070bb7ff58c42119566df5085529eb9241f2311f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 6 Sep 2016 22:04:26 -0700 Subject: [PATCH 1/3] Account for percentages in fixed table layout Fixes #13166 --- components/layout/table.rs | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/components/layout/table.rs b/components/layout/table.rs index a67312d1bc3..442454f47fe 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -335,13 +335,17 @@ impl Flow for TableFlow { let containing_block_inline_size = self.block_flow.base.block_container_inline_size; let mut num_unspecified_inline_sizes = 0; + let mut num_percentage_inline_sizes = 0; let mut total_column_inline_size = Au(0); + let mut total_column_percentage_size = 0.0; for column_inline_size in &self.column_intrinsic_inline_sizes { - if column_inline_size.constrained { - total_column_inline_size = total_column_inline_size + - column_inline_size.minimum_length + if column_inline_size.percentage != 0.0 { + total_column_percentage_size += column_inline_size.percentage; + num_percentage_inline_sizes += 1; + } else if column_inline_size.constrained { + total_column_inline_size += column_inline_size.minimum_length; } else { - num_unspecified_inline_sizes += 1 + num_unspecified_inline_sizes += 1; } } @@ -364,20 +368,12 @@ impl Flow for TableFlow { TableLayout::Fixed => { // In fixed table layout, we distribute extra space among the unspecified columns // if there are any, or among all the columns if all are specified. + // See: https://drafts.csswg.org/css-tables-3/#distributing-width-to-columns (infobox) self.column_computed_inline_sizes.clear(); - if num_unspecified_inline_sizes == 0 { - let ratio = content_inline_size.to_f32_px() / - total_column_inline_size.to_f32_px(); - for column_inline_size in &self.column_intrinsic_inline_sizes { - self.column_computed_inline_sizes.push(ColumnComputedInlineSize { - size: column_inline_size.minimum_length.scale_by(ratio), - }); - } - } else if num_unspecified_inline_sizes != 0 { + if num_unspecified_inline_sizes != 0 { let extra_column_inline_size = content_inline_size - total_column_inline_size; for column_inline_size in &self.column_intrinsic_inline_sizes { - if !column_inline_size.constrained && - column_inline_size.percentage == 0.0 { + if !column_inline_size.constrained { self.column_computed_inline_sizes.push(ColumnComputedInlineSize { size: extra_column_inline_size / num_unspecified_inline_sizes, }); @@ -387,6 +383,23 @@ impl Flow for TableFlow { }); } } + } else if num_percentage_inline_sizes != 0 { + let extra_column_inline_size = content_inline_size - total_column_inline_size; + let ratio = content_inline_size.to_f32_px() / + total_column_percentage_size; + for column_inline_size in &self.column_intrinsic_inline_sizes { + self.column_computed_inline_sizes.push(ColumnComputedInlineSize { + size: extra_column_inline_size.scale_by(ratio * column_inline_size.percentage), + }); + } + } else { + let ratio = content_inline_size.to_f32_px() / + total_column_inline_size.to_f32_px(); + for column_inline_size in &self.column_intrinsic_inline_sizes { + self.column_computed_inline_sizes.push(ColumnComputedInlineSize { + size: column_inline_size.minimum_length.scale_by(ratio), + }); + } } } _ => { From 516adfa6c9c54a96efdaf571d15428d951007d9c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 6 Sep 2016 22:39:19 -0700 Subject: [PATCH 2/3] Add reftest for #13166 --- tests/wpt/mozilla/meta/MANIFEST.json | 24 +++++++++++++++++++ .../wpt/mozilla/tests/css/fixed_percent.html | 16 +++++++++++++ .../mozilla/tests/css/fixed_percent_ref.html | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 tests/wpt/mozilla/tests/css/fixed_percent.html create mode 100644 tests/wpt/mozilla/tests/css/fixed_percent_ref.html diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index bbc79260a5f..6120163ff4e 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -1500,6 +1500,18 @@ "url": "/_mozilla/css/first_of_type_pseudo_a.html" } ], + "css/fixed_percent.html": [ + { + "path": "css/fixed_percent.html", + "references": [ + [ + "/_mozilla/css/fixed_percent_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/fixed_percent.html" + } + ], "css/fixed_width_overrides_child_intrinsic_width_a.html": [ { "path": "css/fixed_width_overrides_child_intrinsic_width_a.html", @@ -10894,6 +10906,18 @@ "url": "/_mozilla/css/first_of_type_pseudo_a.html" } ], + "css/fixed_percent.html": [ + { + "path": "css/fixed_percent.html", + "references": [ + [ + "/_mozilla/css/fixed_percent_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/fixed_percent.html" + } + ], "css/fixed_width_overrides_child_intrinsic_width_a.html": [ { "path": "css/fixed_width_overrides_child_intrinsic_width_a.html", diff --git a/tests/wpt/mozilla/tests/css/fixed_percent.html b/tests/wpt/mozilla/tests/css/fixed_percent.html new file mode 100644 index 00000000000..ccc89607150 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/fixed_percent.html @@ -0,0 +1,16 @@ + + +Table with fixed layout gives according to percentages + + + +
Test text
diff --git a/tests/wpt/mozilla/tests/css/fixed_percent_ref.html b/tests/wpt/mozilla/tests/css/fixed_percent_ref.html new file mode 100644 index 00000000000..5963b38c184 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/fixed_percent_ref.html @@ -0,0 +1,4 @@ + +Table with fixed layout gives according to percentages +Test text + From 102ea5a7aea0328d623dc17255005904d1ef7e6d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 8 Sep 2016 09:16:13 -0700 Subject: [PATCH 3/3] Change test expectation: floats-149 = PASS --- tests/wpt/metadata-css/css21_dev/html4/floats-149.htm.ini | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 tests/wpt/metadata-css/css21_dev/html4/floats-149.htm.ini diff --git a/tests/wpt/metadata-css/css21_dev/html4/floats-149.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/floats-149.htm.ini deleted file mode 100644 index 28383a7707b..00000000000 --- a/tests/wpt/metadata-css/css21_dev/html4/floats-149.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[floats-149.htm] - type: reftest - expected: FAIL