mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue