From cad5d8b670bffba22dcc324fe295178b68c59bae Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 27 Apr 2015 13:36:10 -0700 Subject: [PATCH] Ignore border-spacing for tables with zero cells --- components/layout/table.rs | 20 +++++++++++++------ components/layout/table_wrapper.rs | 3 +-- tests/ref/basic.list | 1 + tests/ref/border_spacing_empty_table.html | 19 ++++++++++++++++++ tests/ref/border_spacing_empty_table_ref.html | 15 ++++++++++++++ 5 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 tests/ref/border_spacing_empty_table.html create mode 100644 tests/ref/border_spacing_empty_table_ref.html diff --git a/components/layout/table.rs b/components/layout/table.rs index 25d17d04b8f..80edfa2742e 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -202,6 +202,14 @@ impl TableFlow { } } } + + pub fn total_horizontal_spacing(&self) -> Au { + let num_columns = self.column_intrinsic_inline_sizes.len(); + if num_columns == 0 { + return Au(0); + } + self.spacing().horizontal * (num_columns as i32 + 1) + } } impl Flow for TableFlow { @@ -396,9 +404,8 @@ impl Flow for TableFlow { } } - let spacing = self.spacing().horizontal * - (self.column_intrinsic_inline_sizes.len() as i32 + 1); - computation.surrounding_size = computation.surrounding_size + spacing; + computation.surrounding_size = computation.surrounding_size + + self.total_horizontal_spacing(); self.block_flow.base.intrinsic_inline_sizes = computation.finish() } @@ -435,8 +442,7 @@ impl Flow for TableFlow { let inline_end_content_edge = self.block_flow.fragment.border_padding.inline_end; let padding_and_borders = self.block_flow.fragment.border_padding.inline_start_end(); let spacing_per_cell = self.spacing(); - let spacing = spacing_per_cell.horizontal * - (self.column_intrinsic_inline_sizes.len() as i32 + 1); + let spacing = self.total_horizontal_spacing(); let content_inline_size = self.block_flow.fragment.border_box.size.inline - padding_and_borders - spacing; @@ -785,6 +791,7 @@ impl TableLikeFlow for BlockFlow { // Our current border-box position. let block_start_border_padding = self.fragment.border_padding.block_start; let mut current_block_offset = block_start_border_padding; + let mut has_rows = false; // At this point, `current_block_offset` is at the content edge of our box. Now iterate // over children. @@ -795,6 +802,7 @@ impl TableLikeFlow for BlockFlow { // Account for spacing or collapsed borders. if kid.is_table_row() { + has_rows = true; let child_table_row = kid.as_table_row(); current_block_offset = current_block_offset + match self.fragment.style.get_inheritedtable().border_collapse { @@ -843,7 +851,7 @@ impl TableLikeFlow for BlockFlow { // Take border, padding, and spacing into account. let block_end_offset = self.fragment.border_padding.block_end + - block_direction_spacing; + if has_rows { block_direction_spacing } else { Au(0) }; current_block_offset = current_block_offset + block_end_offset; // Now that `current_block_offset` is at the block-end of the border box, compute the diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 5e321382e97..a336ca55cfb 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -95,8 +95,7 @@ impl TableWrapperFlow { for kid in self.block_flow.base.child_iter() { if kid.is_table() { let kid_table = kid.as_table(); - let spacing_per_cell = kid_table.spacing().horizontal; - spacing = spacing_per_cell * (self.column_intrinsic_inline_sizes.len() as i32 + 1); + spacing = kid_table.total_horizontal_spacing(); table_border_padding = kid_table.block_flow.fragment.border_padding.inline_start_end(); break diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 635d79798de..a74da9f7fe0 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -86,6 +86,7 @@ flaky_cpu == append_style_a.html append_style_b.html == border_radius_overlapping_a.html border_radius_overlapping_ref.html == border_spacing_a.html border_spacing_ref.html == border_spacing_auto_layout_a.html border_spacing_ref.html +== border_spacing_empty_table.html border_spacing_empty_table_ref.html == border_spacing_fixed_layout_a.html border_spacing_ref.html == border_style_none_a.html border_style_none_b.html == borders_a.html borders_b.html diff --git a/tests/ref/border_spacing_empty_table.html b/tests/ref/border_spacing_empty_table.html new file mode 100644 index 00000000000..d1ee2cc66c3 --- /dev/null +++ b/tests/ref/border_spacing_empty_table.html @@ -0,0 +1,19 @@ + + + + + + + +
+ + + diff --git a/tests/ref/border_spacing_empty_table_ref.html b/tests/ref/border_spacing_empty_table_ref.html new file mode 100644 index 00000000000..727795d8e38 --- /dev/null +++ b/tests/ref/border_spacing_empty_table_ref.html @@ -0,0 +1,15 @@ + + + + + + + + + + +