Skip to content

Commit

Permalink
Assign table row block sizes in the parent table or rowgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 27, 2018
1 parent 2c2f8be commit 2a0e1cd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
15 changes: 11 additions & 4 deletions components/layout/table.rs
Expand Up @@ -496,10 +496,10 @@ impl Flow for TableFlow {
});
}

fn assign_block_size(&mut self, _: &LayoutContext) {
fn assign_block_size(&mut self, lc: &LayoutContext) {
debug!("assign_block_size: assigning block_size for table");
let vertical_spacing = self.spacing().vertical();
self.block_flow.assign_block_size_for_table_like_flow(vertical_spacing)
self.block_flow.assign_block_size_for_table_like_flow(vertical_spacing, lc)
}

fn compute_stacking_relative_position(&mut self, layout_context: &LayoutContext) {
Expand Down Expand Up @@ -771,15 +771,22 @@ fn perform_border_collapse_for_row(child_table_row: &mut TableRowFlow,
/// rowgroups.
pub trait TableLikeFlow {
/// Lays out the rows of a table.
fn assign_block_size_for_table_like_flow(&mut self, block_direction_spacing: Au);
fn assign_block_size_for_table_like_flow(&mut self, block_direction_spacing: Au,
layout_context: &LayoutContext);
}

impl TableLikeFlow for BlockFlow {
fn assign_block_size_for_table_like_flow(&mut self, block_direction_spacing: Au) {
fn assign_block_size_for_table_like_flow(&mut self, block_direction_spacing: Au,
layout_context: &LayoutContext) {
debug_assert!(self.fragment.style.get_inheritedtable().border_collapse ==
border_collapse::T::Separate || block_direction_spacing == Au(0));

if self.base.restyle_damage.contains(ServoRestyleDamage::REFLOW) {
for kid in self.base.child_iter_mut() {
if kid.is_table_row() {
kid.as_mut_table_row().assign_block_size_table_row_base(layout_context)
}
}
// 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;
Expand Down
11 changes: 11 additions & 0 deletions components/layout/table_cell.rs
Expand Up @@ -148,6 +148,17 @@ impl TableCellFlow {
}
}
}

// Total block size of child
//
// Call after block size calculation
pub fn total_block_size(&mut self) -> Au {
// TODO: Percentage block-size
let specified = MaybeAuto::from_style(self.fragment().style()
.content_block_size(),
Au(0)).specified_or_zero();
specified + self.fragment().border_padding.block_start_end()
}
}

impl Flow for TableCellFlow {
Expand Down
88 changes: 42 additions & 46 deletions components/layout/table_row.rs
Expand Up @@ -114,7 +114,7 @@ impl TableRowFlow {
/// inline(always) because this is only ever called by in-order or non-in-order top-level
/// methods
#[inline(always)]
fn assign_block_size_table_row_base(&mut self, layout_context: &LayoutContext) {
pub fn assign_block_size_table_row_base(&mut self, layout_context: &LayoutContext) {
if self.block_flow.base.restyle_damage.contains(ServoRestyleDamage::REFLOW) {
// Per CSS 2.1 § 17.5.3, find max_y = max(computed `block-size`, minimum block-size of
// all cells).
Expand All @@ -132,15 +132,8 @@ impl TableRowFlow {
}

{
let child_fragment = kid.as_mut_table_cell().fragment();
// TODO: Percentage block-size
let child_specified_block_size =
MaybeAuto::from_style(child_fragment.style().content_block_size(),
Au(0)).specified_or_zero();
max_block_size =
max(max_block_size,
child_specified_block_size +
child_fragment.border_padding.block_start_end());
max(max_block_size, kid.as_mut_table_cell().total_block_size());
}
let child_node = kid.mut_base();
child_node.position.start.b = Au(0);
Expand All @@ -158,45 +151,49 @@ impl TableRowFlow {
MaybeAuto::Specified(value) => max(value, block_size),
};

// Assign the block-size of own fragment
let mut position = self.block_flow.fragment.border_box;
position.size.block = block_size;
self.block_flow.fragment.border_box = position;
self.block_flow.base.position.size.block = block_size;
self.assign_block_size_to_self_and_children(block_size);
}

// Assign the block-size of kid fragments, which is the same value as own block-size.
for kid in self.block_flow.base.child_iter_mut() {
let child_table_cell = kid.as_mut_table_cell();
{
let kid_fragment = child_table_cell.mut_fragment();
let mut position = kid_fragment.border_box;
position.size.block = block_size;
kid_fragment.border_box = position;
}
self.block_flow.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW);
}

// 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,
};
pub fn assign_block_size_to_self_and_children(&mut self, block_size: Au) {
// Assign the block-size of kid fragments, which is the same value as own block-size.
for kid in self.block_flow.base.child_iter_mut() {
let child_table_cell = kid.as_mut_table_cell();
{
let kid_fragment = child_table_cell.mut_fragment();
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,
};
}

self.block_flow.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW);
// Assign the block-size of own fragment
let mut position = self.block_flow.fragment.border_box;
position.size.block = block_size;
self.block_flow.fragment.border_box = position;
self.block_flow.base.position.size.block = block_size;
}

pub fn populate_collapsed_border_spacing<'a, I>(
Expand Down Expand Up @@ -449,9 +446,8 @@ impl Flow for TableRowFlow {
})
}

fn assign_block_size(&mut self, layout_context: &LayoutContext) {
debug!("assign_block_size: assigning block_size for table_row");
self.assign_block_size_table_row_base(layout_context);
fn assign_block_size(&mut self, _: &LayoutContext) {
// the surrounding table or rowgroup does this
}

fn compute_stacking_relative_position(&mut self, layout_context: &LayoutContext) {
Expand Down
4 changes: 2 additions & 2 deletions components/layout/table_rowgroup.rs
Expand Up @@ -159,9 +159,9 @@ impl Flow for TableRowGroupFlow {
});
}

fn assign_block_size(&mut self, _: &LayoutContext) {
fn assign_block_size(&mut self, lc: &LayoutContext) {
debug!("assign_block_size: assigning block_size for table_rowgroup");
self.block_flow.assign_block_size_for_table_like_flow(self.spacing.vertical());
self.block_flow.assign_block_size_for_table_like_flow(self.spacing.vertical(), lc);
}

fn compute_stacking_relative_position(&mut self, layout_context: &LayoutContext) {
Expand Down

0 comments on commit 2a0e1cd

Please sign in to comment.