servo: Merge #12593 - Fix table vertical alignment (middle, bottom) (from adamncasey:table-row-cell-height); r=pcwalton
authorAdam Casey <adamncasey@gmail.com>
Tue, 26 Jul 2016 20:17:02 -0500
changeset 368399 77c49fc5ce18f89f7d6e6a1eff1b78510fb1efd2
parent 368398 a2e8e9dfd4356353e60a4f29106c62465b2de7b4
child 368400 b43b28b4a31ad1a05b6680e3fb26b46d88f1fcf6
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
servo: Merge #12593 - Fix table vertical alignment (middle, bottom) (from adamncasey:table-row-cell-height); r=pcwalton Fix table vertical alignment (middle, bottom) <!-- Please describe your changes on the following line: --> Fixes table cell vertical alignment (middle, bottom, not yet baseline) when the row contains cells of differing heights. Moved the work done earlier by @notriddle into a separate public function on TableCellFlow. This function is then called by TableRowFlow once the cell's block size has been calculator. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12531 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: b374582e232c0d564e8f71126f81d85ea46e0f9b
servo/components/layout/table_cell.rs
servo/components/layout/table_row.rs
--- a/servo/components/layout/table_cell.rs
+++ b/servo/components/layout/table_cell.rs
@@ -75,16 +75,20 @@ impl TableCellFlow {
         let remaining = self.block_flow.assign_block_size_block_base(
             layout_context,
             None,
             MarginsMayCollapseFlag::MarginsMayNotCollapse);
         debug_assert!(remaining.is_none());
         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| {
             let kid_base = flow::base(kid);
             flow::base(kid).position.start.b
                 - kid_base.collapsible_margins.block_start_margin_for_noncollapsible_context()
         });
         if let Some(mut first_start) = first_start {
@@ -101,16 +105,19 @@ impl TableCellFlow {
                 if end > last_end {
                     last_end = end;
                 }
             }
             let kids_size = last_end - first_start;
             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,
                 _ => Au(0),
             };
             if offset != Au(0) {
                 for kid in flow::mut_base(self).children.iter_mut() {
                     flow::mut_base(kid).position.start.b = flow::mut_base(kid).position.start.b + offset;
--- a/servo/components/layout/table_row.rs
+++ b/servo/components/layout/table_row.rs
@@ -157,16 +157,19 @@ impl TableRowFlow {
                 let mut position = kid_fragment.border_box;
                 position.size.block = block_size;
                 kid_fragment.border_box = position;
             }
 
             // 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 =
                 EarlyAbsolutePositionInfo {
                     relative_containing_block_size: self.block_flow.fragment.content_box().size,
                     relative_containing_block_mode: self.block_flow.fragment.style().writing_mode,
                 };
         }