From b1debc40be99a544d03b69c0ec9947b942767aea Mon Sep 17 00:00:00 2001 From: Adam Casey Date: Sat, 23 Jul 2016 01:07:16 +0100 Subject: [PATCH] Fix table vertical alignment (middle, bottom, not yet baseline) with differing height cells Includes reftest for this behaviour Patch fixes margin-collapse-clear-002,3,8,9 --- components/layout/table_cell.rs | 7 ++++ components/layout/table_row.rs | 3 ++ .../html4/margin-collapse-clear-002.htm.ini | 3 -- .../html4/margin-collapse-clear-003.htm.ini | 3 -- .../html4/margin-collapse-clear-008.htm.ini | 3 -- .../html4/margin-collapse-clear-009.htm.ini | 3 -- tests/wpt/mozilla/meta/MANIFEST.json | 24 +++++++++++++ .../mozilla/table_valign_uneven_height.html | 34 +++++++++++++++++++ .../table_valign_uneven_height_ref.html | 34 +++++++++++++++++++ 9 files changed, 102 insertions(+), 12 deletions(-) delete mode 100644 tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-002.htm.ini delete mode 100644 tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-003.htm.ini delete mode 100644 tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-008.htm.ini delete mode 100644 tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-009.htm.ini create mode 100644 tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height.html create mode 100644 tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height_ref.html diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index a71b78b8ace4..18ff88e109ab 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -80,6 +80,10 @@ impl TableCellFlow { if !flow::base(self).restyle_damage.contains(REFLOW) { return; } + } + + /// Position this cell's children according to vertical-align. + pub fn valign_children(&mut self) { // Note to the reader: this code has been tested with negative margins. // We end up with a "end" that's before the "start," but the math still works out. let first_start = flow::base(self).children.front().map(|kid| { @@ -106,6 +110,9 @@ impl TableCellFlow { let self_size = flow::base(self).position.size.block - self.block_flow.fragment.border_padding.block_start_end(); let kids_self_gap = self_size - kids_size; + + // This offset should also account for vertical_align::T::baseline. + // Need max cell ascent from the first row of this cell. let offset = match self.block_flow.fragment.style().get_box().vertical_align { vertical_align::T::middle => kids_self_gap / 2, vertical_align::T::bottom => kids_self_gap, diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 8fd0255f2612..cb2f8f76c7c1 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -162,6 +162,9 @@ impl TableRowFlow { // Assign the child's block size. child_table_cell.block_flow.base.position.size.block = block_size; + // Now we know the cell height, vertical align the cell's children. + child_table_cell.valign_children(); + // Write in the size of the relative containing block for children. (This information // is also needed to handle RTL.) child_table_cell.block_flow.base.early_absolute_position_info = diff --git a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-002.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-002.htm.ini deleted file mode 100644 index ea6943c1c806..000000000000 --- a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-002.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[margin-collapse-clear-002.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-003.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-003.htm.ini deleted file mode 100644 index ef6e83de26ca..000000000000 --- a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-003.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[margin-collapse-clear-003.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-008.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-008.htm.ini deleted file mode 100644 index 4a1f3812c59c..000000000000 --- a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-008.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[margin-collapse-clear-008.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-009.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-009.htm.ini deleted file mode 100644 index 62b047475e65..000000000000 --- a/tests/wpt/metadata-css/css21_dev/html4/margin-collapse-clear-009.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[margin-collapse-clear-009.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 3fedff120e59..db8aa5be87db 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6022,6 +6022,18 @@ "url": "/_mozilla/mozilla/table_valign_middle.html" } ], + "mozilla/table_valign_uneven_height.html": [ + { + "path": "mozilla/table_valign_uneven_height.html", + "references": [ + [ + "/_mozilla/mozilla/table_valign_uneven_height_ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/table_valign_uneven_height.html" + } + ], "mozilla/webgl/clearcolor.html": [ { "path": "mozilla/webgl/clearcolor.html", @@ -15110,6 +15122,18 @@ "url": "/_mozilla/mozilla/table_valign_middle.html" } ], + "mozilla/table_valign_uneven_height.html": [ + { + "path": "mozilla/table_valign_uneven_height.html", + "references": [ + [ + "/_mozilla/mozilla/table_valign_uneven_height_ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/table_valign_uneven_height.html" + } + ], "mozilla/webgl/clearcolor.html": [ { "path": "mozilla/webgl/clearcolor.html", diff --git a/tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height.html b/tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height.html new file mode 100644 index 000000000000..6668070831a8 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height.html @@ -0,0 +1,34 @@ + + +Vertical Alignment for row with uneven height cells + + + + + + + + +
diff --git a/tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height_ref.html b/tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height_ref.html new file mode 100644 index 000000000000..321132b7e7e2 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/table_valign_uneven_height_ref.html @@ -0,0 +1,34 @@ + + +Reference: Vertical Alignment for row with uneven height cells + + + + + + + +