mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Add get_column_styles for getting column structure and styles for a table
This commit is contained in:
parent
d423e54d58
commit
b416bb3aa7
4 changed files with 57 additions and 7 deletions
|
@ -203,6 +203,34 @@ impl TableFlow {
|
|||
}
|
||||
self.spacing().horizontal() * (num_columns as i32 + 1)
|
||||
}
|
||||
|
||||
fn column_styles(&self) -> Vec<ColumnStyle> {
|
||||
let mut styles = vec![];
|
||||
for group in self.block_flow.base.child_iter()
|
||||
.filter(|kid| kid.is_table_colgroup()) {
|
||||
// XXXManishearth these as_foo methods should return options
|
||||
// so that we can filter_map
|
||||
let group = group.as_table_colgroup();
|
||||
let colgroup_style = group.fragment.as_ref().map(|f| f.style());
|
||||
|
||||
// The colgroup's span attribute is only relevant when
|
||||
// it has no children
|
||||
// https://html.spec.whatwg.org/multipage/#forming-a-table
|
||||
if group.cols.is_empty() {
|
||||
let span = group.fragment.as_ref().map(|f| f.column_span()).unwrap_or(1);
|
||||
styles.push(ColumnStyle { span, colgroup_style, col_style: None });
|
||||
} else {
|
||||
for col in &group.cols {
|
||||
styles.push(ColumnStyle {
|
||||
span: col.column_span(),
|
||||
colgroup_style,
|
||||
col_style: Some(col.style()),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
styles
|
||||
}
|
||||
}
|
||||
|
||||
impl Flow for TableFlow {
|
||||
|
@ -529,6 +557,13 @@ impl Flow for TableFlow {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
struct ColumnStyle<'a> {
|
||||
span: u32,
|
||||
colgroup_style: Option<&'a ComputedValues>,
|
||||
col_style: Option<&'a ComputedValues>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for TableFlow {
|
||||
/// Outputs a debugging string describing this table flow.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue