aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-09-08 23:17:06 -0500
committerGitHub <noreply@github.com>2016-09-08 23:17:06 -0500
commit2d13178d2930da8668e77de078eeb65438eb502e (patch)
tree877f37073a6696d46372a59da5a74e84e7c62ec7
parent3117787fd2a8b7748cfde1e9b8c5be3c00f2c599 (diff)
parent102ea5a7aea0328d623dc17255005904d1ef7e6d (diff)
downloadservo-2d13178d2930da8668e77de078eeb65438eb502e.tar.gz
servo-2d13178d2930da8668e77de078eeb65438eb502e.zip
Auto merge of #13192 - notriddle:master, r=pcwalton
Account for percentages in fixed table layout Don't just use the minimum length all the time. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13166 (github issue number if applicable). - [X] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13192) <!-- Reviewable:end -->
-rw-r--r--components/layout/table.rs43
-rw-r--r--tests/wpt/metadata-css/css21_dev/html4/floats-149.htm.ini3
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json24
-rw-r--r--tests/wpt/mozilla/tests/css/fixed_percent.html16
-rw-r--r--tests/wpt/mozilla/tests/css/fixed_percent_ref.html4
5 files changed, 72 insertions, 18 deletions
diff --git a/components/layout/table.rs b/components/layout/table.rs
index 7db800c5042..ebd2bb65e8a 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),
+ });
+ }
}
}
_ => {
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
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 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Table with fixed layout gives according to percentages</title>
+<link rel="match" href="fixed_percent_ref.html">
+<link rel="spec" href="https://drafts.csswg.org/css-tables-3/#distributing-width-to-columns">
+<style>
+#c {
+ display: table;
+ width: 100%;
+ table-layout: fixed;
+}
+#d {
+ width: 100%;
+}
+</style>
+<div id=c><div id=d>Test text</div></div>
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 @@
+<!DOCTYPE html>
+<title>Table with fixed layout gives according to percentages</title>
+Test text
+