diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2018-02-12 14:58:15 -0800 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2018-02-16 16:01:41 -0800 |
commit | b416bb3aa7e3da3a33dc0c115f1f7619914f382f (patch) | |
tree | 2bc5fffa324289d0a76bb130cad731da89489763 /components | |
parent | d423e54d58d6cced950896eed1957ee2989f4eee (diff) | |
download | servo-b416bb3aa7e3da3a33dc0c115f1f7619914f382f.tar.gz servo-b416bb3aa7e3da3a33dc0c115f1f7619914f382f.zip |
Add get_column_styles for getting column structure and styles for a table
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/flow.rs | 6 | ||||
-rw-r--r-- | components/layout/fragment.rs | 10 | ||||
-rw-r--r-- | components/layout/table.rs | 35 | ||||
-rw-r--r-- | components/layout/table_colgroup.rs | 13 |
4 files changed, 57 insertions, 7 deletions
diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 3f2b64827af..30877defa43 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -171,6 +171,12 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { panic!("called as_mut_table_colgroup() on a non-tablecolgroup flow") } + /// If this is a table colgroup flow, returns the underlying object. Fails + /// otherwise. + fn as_table_colgroup(&self) -> &TableColGroupFlow { + panic!("called as_table_colgroup() on a non-tablecolgroup flow") + } + /// If this is a table rowgroup flow, returns the underlying object, borrowed mutably. Fails /// otherwise. fn as_mut_table_rowgroup(&mut self) -> &mut TableRowGroupFlow { diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index e03de77a6cd..dc09280315a 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1408,6 +1408,16 @@ impl Fragment { } } + /// If this is a Column fragment, get the col span + /// + /// Panics for non-column fragments + pub fn column_span(&self) -> u32 { + match self.specific { + SpecificFragmentInfo::TableColumn(col_fragment) => max(col_fragment.span, 1), + _ => panic!("non-table-column fragment inside table column?!"), + } + } + /// Returns true if this element can be split. This is true for text fragments, unless /// `white-space: pre` or `white-space: nowrap` is set. pub fn can_split(&self) -> bool { diff --git a/components/layout/table.rs b/components/layout/table.rs index 5068827c0d7..54e9b73d2fe 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -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 { diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index a341a611404..cd1260098f1 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -11,9 +11,8 @@ use context::LayoutContext; use display_list::{DisplayListBuildState, StackingContextCollectionState}; use euclid::Point2D; use flow::{BaseFlow, Flow, FlowClass, ForceNonfloatedFlag, OpaqueFlow}; -use fragment::{Fragment, FragmentBorderBoxIterator, Overflow, SpecificFragmentInfo}; +use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use layout_debug; -use std::cmp::max; use std::fmt; use style::logical_geometry::LogicalSize; use style::properties::ComputedValues; @@ -63,6 +62,10 @@ impl Flow for TableColGroupFlow { self } + fn as_table_colgroup(&self) -> &TableColGroupFlow { + self + } + fn bubble_inline_sizes(&mut self) { let _scope = layout_debug_scope!("table_colgroup::bubble_inline_sizes {:x}", self.base.debug_id()); @@ -70,11 +73,7 @@ impl Flow for TableColGroupFlow { for fragment in &self.cols { // Retrieve the specified value from the appropriate CSS property. let inline_size = fragment.style().content_inline_size(); - let span = match fragment.specific { - SpecificFragmentInfo::TableColumn(col_fragment) => max(col_fragment.span, 1), - _ => panic!("non-table-column fragment inside table column?!"), - }; - for _ in 0..span { + for _ in 0..fragment.column_span() { self.inline_sizes.push(inline_size) } } |