Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Implement basic column spans and the legacy `bgcolor` and `border` attributes. #4278

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

style: Implement basic column spans.

This patch provides some of the groundwork for column spans greater than
1. It implements the column-span CSS property (prefixed so as not to be
exposed to content) as well as the corresponding colspan attribute;
although the former is not well-specified outside of CSS multi-column
layout, INTRINSIC refers to it. Although width is distributed to
spanning columns, they do not yet contribute minimum and preferred
widths; this will be implemented in a follow-up.

Additionally, this patch cleans up some miscellaneous formatting issues
and improves the handling of table rowgroups.
  • Loading branch information
pcwalton committed Dec 8, 2014
commit 47075b5a89f0376f5f49a31e268c366c9b7a1105
@@ -11,11 +11,12 @@ use block::{ISizeConstraintInput, ISizeConstraintSolution};
use construct::FlowConstructor;
use context::LayoutContext;
use floats::FloatKind;
use flow::{Flow, FlowClass, IMPACTED_BY_LEFT_FLOATS, IMPACTED_BY_RIGHT_FLOATS, ImmutableFlowUtils};
use flow::{TableFlowClass};
use flow::{mod, Flow, FlowClass, IMPACTED_BY_LEFT_FLOATS, IMPACTED_BY_RIGHT_FLOATS};
use flow::{ImmutableFlowUtils, TableFlowClass};
use fragment::{Fragment, FragmentBoundsIterator};
use layout_debug;
use model::{IntrinsicISizes, IntrinsicISizesContribution};
use table_row::CellIntrinsicInlineSize;
use table_wrapper::{TableLayout, FixedLayout, AutoLayout};
use wrapper::ThreadSafeLayoutNode;

@@ -97,24 +98,52 @@ impl TableFlow {
/// Update the corresponding value of `self_inline_sizes` if a value of `kid_inline_sizes` has
/// a larger value than one of `self_inline_sizes`. Returns the minimum and preferred inline
/// sizes.
pub fn update_column_inline_sizes(parent_inline_sizes: &mut Vec<ColumnInlineSize>,
child_inline_sizes: &Vec<ColumnInlineSize>)
-> IntrinsicISizes {
fn update_automatic_column_inline_sizes(parent_inline_sizes: &mut Vec<ColumnInlineSize>,
child_cell_inline_sizes: &[CellIntrinsicInlineSize])
-> IntrinsicISizes {
let mut total_inline_sizes = IntrinsicISizes::new();
for (parent_sizes, child_sizes) in parent_inline_sizes.iter_mut()
.zip(child_inline_sizes.iter()) {
*parent_sizes = ColumnInlineSize {
minimum_length: max(parent_sizes.minimum_length, child_sizes.minimum_length),
percentage: parent_sizes.greatest_percentage(child_sizes),
preferred: max(parent_sizes.preferred, child_sizes.preferred),
constrained: parent_sizes.constrained || child_sizes.constrained
};

total_inline_sizes.minimum_inline_size = total_inline_sizes.minimum_inline_size +
parent_sizes.minimum_length;
total_inline_sizes.preferred_inline_size = total_inline_sizes.preferred_inline_size +
parent_sizes.preferred;
let mut column_index = 0;
for child_cell_inline_size in child_cell_inline_sizes.iter() {
for _ in range(0, child_cell_inline_size.column_span) {
if column_index < parent_inline_sizes.len() {
// We already have some intrinsic size information for this column. Merge it in
// according to the rules specified in INTRINSIC § 4.
let parent_sizes = &mut parent_inline_sizes[column_index];
if child_cell_inline_size.column_span > 1 {
// TODO(pcwalton): Perform the recursive algorithm specified in INTRINSIC §
// 4. For now we make this column contribute no width.
} else {
let column_size = &child_cell_inline_size.column_size;
*parent_sizes = ColumnInlineSize {
minimum_length: max(parent_sizes.minimum_length,
column_size.minimum_length),
percentage: parent_sizes.greatest_percentage(column_size),
preferred: max(parent_sizes.preferred, column_size.preferred),
constrained: parent_sizes.constrained || column_size.constrained,
}
}
} else {
// We discovered a new column. Initialize its data.
debug_assert!(column_index == parent_inline_sizes.len());
if child_cell_inline_size.column_span > 1 {
// TODO(pcwalton): Perform the recursive algorithm specified in INTRINSIC §
// 4. For now we make this column contribute no width.
parent_inline_sizes.push(ColumnInlineSize::new())
} else {
parent_inline_sizes.push(child_cell_inline_size.column_size)
}
}

total_inline_sizes.minimum_inline_size = total_inline_sizes.minimum_inline_size +
parent_inline_sizes[column_index].minimum_length;
total_inline_sizes.preferred_inline_size =
total_inline_sizes.preferred_inline_size +
parent_inline_sizes[column_index].preferred;

column_index += 1
}
}

total_inline_sizes
}

@@ -128,6 +157,39 @@ impl TableFlow {
fn assign_block_size_table_base<'a>(&mut self, layout_context: &'a LayoutContext<'a>) {
self.block_flow.assign_block_size_block_base(layout_context, MarginsMayNotCollapse);
}

/// Updates the minimum and preferred inline-size calculation for a single row. This is
/// factored out into a separate function because we process children of rowgroups too.
fn update_column_inline_sizes_for_row(child: &mut Flow,
column_inline_sizes: &mut Vec<ColumnInlineSize>,
computation: &mut IntrinsicISizesContribution,
did_first_row: &mut bool,
table_layout: TableLayout) {
// Read column inline-sizes from the table-row, and assign inline-size=0 for the columns
// not defined in the column group.
//
// FIXME: Need to read inline-sizes from either table-header-group OR the first table-row.
debug_assert!(child.is_table_row());
let row = child.as_table_row();
match table_layout {
FixedLayout => {
// Fixed table layout only looks at the first row.
//
// FIXME(pcwalton): This is really inefficient. We should stop after the first row!
if !*did_first_row {
*did_first_row = true;
for cell_inline_size in row.cell_intrinsic_inline_sizes.iter() {
column_inline_sizes.push(cell_inline_size.column_size);
}
}
}
AutoLayout => {
computation.union_block(&TableFlow::update_automatic_column_inline_sizes(
column_inline_sizes,
row.cell_intrinsic_inline_sizes.as_slice()))
}
}
}
}

impl Flow for TableFlow {
@@ -178,49 +240,20 @@ impl Flow for TableFlow {
constrained: false,
})
}
} else if kid.is_table_rowgroup() || kid.is_table_row() {
// Read column inline-sizes from the table-row-group/table-row, and assign
// inline-size=0 for the columns not defined in the column group.
// FIXME: Need to read inline-sizes from either table-header-group OR the first
// table-row.
match self.table_layout {
FixedLayout => {
// Fixed table layout only looks at the first row.
if !did_first_row {
did_first_row = true;
for child_column_inline_size in kid.column_inline_sizes().iter() {
self.column_inline_sizes.push(*child_column_inline_size);
}
}
}
AutoLayout => {
let child_column_inline_sizes = kid.column_inline_sizes();
let mut child_intrinsic_sizes =
TableFlow::update_column_inline_sizes(&mut self.column_inline_sizes,
child_column_inline_sizes);

// Add new columns if processing this row caused us to discover them.
let child_column_count = child_column_inline_sizes.len();
let parent_column_count = self.column_inline_sizes.len();
debug!("table until the previous row has {} column(s) and this row has {} \
column(s)",
parent_column_count,
child_column_count);
self.column_inline_sizes.reserve(child_column_count);
for i in range(parent_column_count, child_column_count) {
let inline_size_for_new_column = (*child_column_inline_sizes)[i];
child_intrinsic_sizes.minimum_inline_size =
child_intrinsic_sizes.minimum_inline_size +
inline_size_for_new_column.minimum_length;
child_intrinsic_sizes.preferred_inline_size =
child_intrinsic_sizes.preferred_inline_size +
inline_size_for_new_column.preferred;
self.column_inline_sizes.push(inline_size_for_new_column);
}

computation.union_block(&child_intrinsic_sizes)
}
} else if kid.is_table_rowgroup() {
for grandkid in flow::mut_base(kid).child_iter() {
TableFlow::update_column_inline_sizes_for_row(grandkid,
&mut self.column_inline_sizes,
&mut computation,
&mut did_first_row,
self.table_layout)
}
} else if kid.is_table_row() {
TableFlow::update_column_inline_sizes_for_row(kid,
&mut self.column_inline_sizes,
&mut computation,
&mut did_first_row,
self.table_layout)
}
}

@@ -389,6 +422,16 @@ pub struct ColumnInlineSize {
}

impl ColumnInlineSize {
/// Returns a `ColumnInlineSize` instance initialized to zero.
fn new() -> ColumnInlineSize {
ColumnInlineSize {
preferred: Au(0),
minimum_length: Au(0),
percentage: 0.0,
constrained: false,
}
}

/// Returns the true minimum size of this column, given the containing block's inline size.
/// Beware that this is generally only correct for fixed table layout. (Compare CSS 2.1 §
/// 17.5.2.1 with the algorithm in INTRINSIC § 4.)
@@ -30,16 +30,31 @@ use sync::Arc;
pub struct TableRowFlow {
pub block_flow: BlockFlow,

/// Information about the inline-sizes of each column.
/// Information about the intrinsic inline-sizes of each cell.
pub cell_intrinsic_inline_sizes: Vec<CellIntrinsicInlineSize>,

/// Computed inline-size for each column.
///
/// FIXME(pcwalton): This should be a separate type that only contains computed inline sizes.
pub column_inline_sizes: Vec<ColumnInlineSize>,
}

/// Information about the column inline size and span for each cell.
#[deriving(Encodable)]
pub struct CellIntrinsicInlineSize {
/// Inline sizes that this cell contributes to the column.
pub column_size: ColumnInlineSize,
/// The column span of this cell.
pub column_span: u32,
}

impl TableRowFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode,
fragment: Fragment)
-> TableRowFlow {
TableRowFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment),
cell_intrinsic_inline_sizes: Vec::new(),
column_inline_sizes: Vec::new()
}
}
@@ -49,6 +64,7 @@ impl TableRowFlow {
-> TableRowFlow {
TableRowFlow {
block_flow: BlockFlow::from_node(constructor, node),
cell_intrinsic_inline_sizes: Vec::new(),
column_inline_sizes: Vec::new()
}
}
@@ -172,10 +188,13 @@ impl Flow for TableRowFlow {

// Collect the specified column inline-size of the cell. This is used in both fixed and
// automatic table layout calculation.
let child_specified_inline_size = kid.as_table_cell()
.fragment()
.style()
.content_inline_size();
let child_specified_inline_size;
let child_column_span;
{
let child_style = kid.as_table_cell().fragment().style();
child_specified_inline_size = child_style.content_inline_size();
child_column_span = child_style.get_table()._servo_column_span
}

// Collect minimum and preferred inline-sizes of the cell for automatic table layout
// calculation.
@@ -199,16 +218,17 @@ impl Flow for TableRowFlow {
};
min_inline_size = min_inline_size + child_column_inline_size.minimum_length;
pref_inline_size = pref_inline_size + child_column_inline_size.preferred;
self.column_inline_sizes.push(child_column_inline_size);
self.cell_intrinsic_inline_sizes.push(CellIntrinsicInlineSize {
column_size: child_column_inline_size,
column_span: child_column_span,
});
}
self.block_flow.base.intrinsic_inline_sizes.minimum_inline_size = min_inline_size;
self.block_flow.base.intrinsic_inline_sizes.preferred_inline_size = max(min_inline_size,
pref_inline_size);
}

/// Recursively (top-down) determines the actual inline-size of child contexts and fragments.
/// When called on this context, the context has had its inline-size set by the parent context.
fn assign_inline_sizes(&mut self, ctx: &LayoutContext) {
fn assign_inline_sizes(&mut self, layout_context: &LayoutContext) {
let _scope = layout_debug_scope!("table_row::assign_inline_sizes {:x}",
self.block_flow.base.debug_id());
debug!("assign_inline_sizes({}): assigning inline_size for flow", "table_row");
@@ -221,13 +241,43 @@ impl Flow for TableRowFlow {

let inline_size_computer = InternalTable;
inline_size_computer.compute_used_inline_size(&mut self.block_flow,
ctx,
layout_context,
containing_block_inline_size);

self.block_flow
.propagate_assigned_inline_size_to_children(inline_start_content_edge,
containing_block_inline_size,
Some(self.column_inline_sizes.as_slice()));
// Spread out the completed inline sizes among columns with spans > 1.
let mut computed_inline_size_for_cells = Vec::new();
let mut column_inline_size_iterator = self.column_inline_sizes.iter();
for cell_intrinsic_inline_size in self.cell_intrinsic_inline_sizes.iter() {
//(intrinsic_inline_size_for_column, computed_inline_size_for_column) in
// Start with the computed inline size for the first column in the span.
let mut column_inline_size = match column_inline_size_iterator.next() {
Some(column_inline_size) => *column_inline_size,
None => {
// This could happen if there are too few cells in this row. Don't crash.
break
}
};

// Add in computed inline sizes for any extra columns in the span.
for _ in range(1, cell_intrinsic_inline_size.column_span) {
let extra_column_inline_size = match column_inline_size_iterator.next() {
Some(column_inline_size) => column_inline_size,
None => break,
};
column_inline_size.minimum_length = column_inline_size.minimum_length +
extra_column_inline_size.minimum_length;
column_inline_size.preferred = column_inline_size.preferred +
extra_column_inline_size.preferred;
}

computed_inline_size_for_cells.push(column_inline_size)
}

// Push those inline sizes down to the cells.
self.block_flow.propagate_assigned_inline_size_to_children(
inline_start_content_edge,
containing_block_inline_size,
Some(computed_inline_size_for_cells.as_slice()));
}

fn assign_block_size<'a>(&mut self, ctx: &'a LayoutContext<'a>) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.