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 -->
This commit is contained in:
bors-servo 2016-09-08 23:17:06 -05:00 committed by GitHub
commit 2d13178d29
5 changed files with 72 additions and 18 deletions

View file

@ -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),
});
}
}
}
_ => {

View file

@ -1,3 +0,0 @@
[floats-149.htm]
type: reftest
expected: FAIL

View file

@ -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",

View file

@ -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>

View file

@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>Table with fixed layout gives according to percentages</title>
Test text