servo: Merge #13192 - Account for percentages in fixed table layout (from notriddle:master); r=pcwalton
authorMichael Howell <michael@notriddle.com>
Thu, 08 Sep 2016 23:17:06 -0500
changeset 368693 9db39658edadf80a4429eff968f2cd71bbc5efdc
parent 368692 89bfec936a22ef359e7b65a2deae11ff8f16d7c0
child 368694 baeebf74a83e6b234b831818182f23bd4900b24c
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 #13192 - Account for percentages in fixed table layout (from notriddle:master); r=pcwalton 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 Source-Repo: https://github.com/servo/servo Source-Revision: 2d13178d2930da8668e77de078eeb65438eb502e
servo/components/layout/table.rs
--- a/servo/components/layout/table.rs
+++ b/servo/components/layout/table.rs
@@ -330,23 +330,27 @@ impl Flow for TableFlow {
         let _scope = layout_debug_scope!("table::assign_inline_sizes {:x}",
                                             self.block_flow.base.debug_id());
         debug!("assign_inline_sizes({}): assigning inline_size for flow", "table");
 
         // The position was set to the containing block by the flow's parent.
         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;
             }
         }
 
         let inline_size_computer = InternalTable {
             border_collapse: self.block_flow.fragment.style.get_inheritedtable().border_collapse,
         };
         inline_size_computer.compute_used_inline_size(&mut self.block_flow,
                                                       shared_context,
@@ -359,39 +363,48 @@ impl Flow for TableFlow {
         let spacing = self.total_horizontal_spacing();
         let content_inline_size =
             self.block_flow.fragment.border_box.size.inline - padding_and_borders - spacing;
 
         match self.table_layout {
             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,
                             });
                         } else {
                             self.column_computed_inline_sizes.push(ColumnComputedInlineSize {
                                 size: column_inline_size.minimum_length,
                             });
                         }
                     }
+                } 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),
+                        });
+                    }
                 }
             }
             _ => {
                 // The table wrapper already computed the inline-sizes and propagated them down
                 // to us.
             }
         }