layout: Make sure anonymous table flows are statically positioned.

The failing `float-applies-to-*` CSS 2.1 tests never really should have
been passing in the first place; they depend on floats inside
fixed-layout tables working properly, which they don't.

Closes #6078.
Closes #6709.
Closes #6858.
This commit is contained in:
Patrick Walton 2015-08-04 14:38:08 -07:00
parent da06c2dda0
commit ed4172b2c6
21 changed files with 142 additions and 114 deletions

View file

@ -45,7 +45,6 @@ use layout_debug;
use layout_task::DISPLAY_PORT_SIZE_FACTOR;
use model::{IntrinsicISizes, MarginCollapseInfo};
use model::{MaybeAuto, CollapsibleMargins, specified, specified_or_none};
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect, Size2D};
use gfx::display_list::{ClippingRegion, DisplayList};
@ -572,13 +571,10 @@ impl Encodable for BlockFlowFlags {
}
impl BlockFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode,
fragment: Fragment,
float_kind: Option<FloatKind>)
-> BlockFlow {
let writing_mode = node.style().writing_mode;
pub fn from_fragment(fragment: Fragment, float_kind: Option<FloatKind>) -> BlockFlow {
let writing_mode = fragment.style().writing_mode;
BlockFlow {
base: BaseFlow::new(Some((*node).clone()), writing_mode, match float_kind {
base: BaseFlow::new(Some(fragment.style()), writing_mode, match float_kind {
Some(_) => ForceNonfloatedFlag::FloatIfNecessary,
None => ForceNonfloatedFlag::ForceNonfloated,
}),

View file

@ -363,27 +363,41 @@ impl<'a> FlowConstructor<'a> {
}
if child.is_table_cell() {
let fragment = Fragment::new(child_node, SpecificFragmentInfo::TableRow);
let mut new_child = FlowRef::new(box TableRowFlow::from_node_and_fragment(child_node,
fragment));
let mut style = child_node.style().clone();
properties::modify_style_for_anonymous_table_object(&mut style, display::T::table_row);
let fragment = Fragment::from_opaque_node_and_style(child_node.opaque(),
PseudoElementType::Normal,
style,
child_node.restyle_damage(),
SpecificFragmentInfo::TableRow);
let mut new_child = FlowRef::new(box TableRowFlow::from_fragment(fragment));
new_child.add_new_child(child.clone());
child.finish();
*child = new_child
}
if child.is_table_row() || child.is_table_rowgroup() {
let fragment = Fragment::new(child_node, SpecificFragmentInfo::Table);
let mut new_child = FlowRef::new(box TableFlow::from_node_and_fragment(child_node,
fragment));
let mut style = child_node.style().clone();
properties::modify_style_for_anonymous_table_object(&mut style, display::T::table);
let fragment = Fragment::from_opaque_node_and_style(child_node.opaque(),
PseudoElementType::Normal,
style,
child_node.restyle_damage(),
SpecificFragmentInfo::Table);
let mut new_child = FlowRef::new(box TableFlow::from_fragment(fragment));
new_child.add_new_child(child.clone());
child.finish();
*child = new_child
}
if child.is_table() {
let fragment = Fragment::new(child_node, SpecificFragmentInfo::TableWrapper);
let mut new_child =
FlowRef::new(box TableWrapperFlow::from_node_and_fragment(child_node,
fragment,
None));
let mut style = child_node.style().clone();
properties::modify_style_for_anonymous_table_object(&mut style, display::T::table);
let fragment =
Fragment::from_opaque_node_and_style(child_node.opaque(),
PseudoElementType::Normal,
style,
child_node.restyle_damage(),
SpecificFragmentInfo::TableWrapper);
let mut new_child = FlowRef::new(box TableWrapperFlow::from_fragment(fragment, None));
new_child.add_new_child(child.clone());
child.finish();
*child = new_child
@ -467,7 +481,8 @@ impl<'a> FlowConstructor<'a> {
let (ascent, descent) =
inline_flow.compute_minimum_ascent_and_descent(&mut self.layout_context.font_context(),
inline_flow.compute_minimum_ascent_and_descent(&mut self.layout_context
.font_context(),
&**node.style());
inline_flow.minimum_block_size_above_baseline = ascent;
inline_flow.minimum_depth_below_baseline = descent;
@ -482,15 +497,15 @@ impl<'a> FlowConstructor<'a> {
}
}
fn build_block_flow_using_construction_result_of_child(&mut self,
flow: &mut FlowRef,
consecutive_siblings: &mut Vec<FlowRef>,
node: &ThreadSafeLayoutNode,
kid: ThreadSafeLayoutNode,
inline_fragment_accumulator:
&mut InlineFragmentsAccumulator,
abs_descendants: &mut Descendants,
first_fragment: &mut bool) {
fn build_block_flow_using_construction_result_of_child(
&mut self,
flow: &mut FlowRef,
consecutive_siblings: &mut Vec<FlowRef>,
node: &ThreadSafeLayoutNode,
kid: ThreadSafeLayoutNode,
inline_fragment_accumulator: &mut InlineFragmentsAccumulator,
abs_descendants: &mut Descendants,
first_fragment: &mut bool) {
match kid.swap_out_construction_result() {
ConstructionResult::None => {}
ConstructionResult::Flow(mut kid_flow, kid_abs_descendants) => {
@ -731,9 +746,9 @@ impl<'a> FlowConstructor<'a> {
-> ConstructionResult {
let fragment = self.build_fragment_for_block(node);
let flow = if node.style().is_multicol() {
box MulticolFlow::from_node_and_fragment(node, fragment, float_kind) as Box<Flow>
box MulticolFlow::from_fragment(fragment, float_kind) as Box<Flow>
} else {
box BlockFlow::from_node_and_fragment(node, fragment, float_kind) as Box<Flow>
box BlockFlow::from_fragment(fragment, float_kind) as Box<Flow>
};
self.build_flow_for_block_like(FlowRef::new(flow), node)
}
@ -1039,12 +1054,12 @@ impl<'a> FlowConstructor<'a> {
fn build_flow_for_table_wrapper(&mut self, node: &ThreadSafeLayoutNode, float_value: float::T)
-> ConstructionResult {
let fragment = Fragment::new(node, SpecificFragmentInfo::TableWrapper);
let wrapper_flow = box TableWrapperFlow::from_node_and_fragment(
node, fragment, FloatKind::from_property(float_value));
let wrapper_flow =
box TableWrapperFlow::from_fragment(fragment, FloatKind::from_property(float_value));
let mut wrapper_flow = FlowRef::new(wrapper_flow as Box<Flow>);
let table_fragment = Fragment::new(node, SpecificFragmentInfo::Table);
let table_flow = box TableFlow::from_node_and_fragment(node, table_fragment);
let table_flow = box TableFlow::from_fragment(table_fragment);
let table_flow = FlowRef::new(table_flow as Box<Flow>);
// First populate the table flow with its children.
@ -1102,7 +1117,7 @@ impl<'a> FlowConstructor<'a> {
/// with possibly other `BlockFlow`s or `InlineFlow`s underneath it.
fn build_flow_for_table_caption(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let fragment = self.build_fragment_for_block(node);
let flow = box TableCaptionFlow::from_node_and_fragment(node, fragment) as Box<Flow>;
let flow = box TableCaptionFlow::from_fragment(fragment) as Box<Flow>;
self.build_flow_for_block_like(FlowRef::new(flow), node)
}
@ -1111,8 +1126,7 @@ impl<'a> FlowConstructor<'a> {
fn build_flow_for_table_rowgroup(&mut self, node: &ThreadSafeLayoutNode)
-> ConstructionResult {
let fragment = Fragment::new(node, SpecificFragmentInfo::TableRow);
let flow = box TableRowGroupFlow::from_node_and_fragment(node, fragment);
let flow = flow as Box<Flow>;
let flow = box TableRowGroupFlow::from_fragment(fragment) as Box<Flow>;
self.build_flow_for_block_like(FlowRef::new(flow), node)
}
@ -1120,7 +1134,7 @@ impl<'a> FlowConstructor<'a> {
/// possibly other `TableCellFlow`s underneath it.
fn build_flow_for_table_row(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult {
let fragment = Fragment::new(node, SpecificFragmentInfo::TableRow);
let flow = box TableRowFlow::from_node_and_fragment(node, fragment) as Box<Flow>;
let flow = box TableRowFlow::from_fragment(fragment) as Box<Flow>;
self.build_flow_for_block_like(FlowRef::new(flow), node)
}
@ -1191,19 +1205,15 @@ impl<'a> FlowConstructor<'a> {
let main_fragment = self.build_fragment_for_block(node);
let flow = match node.style().get_list().list_style_position {
list_style_position::T::outside => {
box ListItemFlow::from_node_fragments_and_flotation(node,
main_fragment,
marker_fragment,
flotation)
box ListItemFlow::from_fragments_and_flotation(main_fragment,
marker_fragment,
flotation)
}
list_style_position::T::inside => {
if let Some(marker_fragment) = marker_fragment {
initial_fragments.fragments.push_back(marker_fragment)
}
box ListItemFlow::from_node_fragments_and_flotation(node,
main_fragment,
None,
flotation)
box ListItemFlow::from_fragments_and_flotation(main_fragment, None, flotation)
}
};
@ -1250,7 +1260,7 @@ impl<'a> FlowConstructor<'a> {
let specific = SpecificFragmentInfo::TableColumn(TableColumnFragmentInfo::new(node));
col_fragments.push(Fragment::new(node, specific));
}
let flow = box TableColGroupFlow::from_node_and_fragments(node, fragment, col_fragments);
let flow = box TableColGroupFlow::from_fragments(fragment, col_fragments);
let mut flow = FlowRef::new(flow as Box<Flow>);
flow.finish();

View file

@ -44,7 +44,7 @@ use table_row::TableRowFlow;
use table_rowgroup::TableRowGroupFlow;
use table_wrapper::TableWrapperFlow;
use multicol::MulticolFlow;
use wrapper::ThreadSafeLayoutNode;
use wrapper::{PseudoElementType, ThreadSafeLayoutNode};
use euclid::{Point2D, Rect, Size2D};
use gfx::display_list::ClippingRegion;
@ -58,8 +58,8 @@ use std::raw;
use std::slice::IterMut;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use style::computed_values::{clear, empty_cells, float, position, text_align};
use style::properties::ComputedValues;
use style::computed_values::{clear, display, empty_cells, float, position, text_align};
use style::properties::{self, ComputedValues};
use style::values::computed::LengthOrPercentageOrAuto;
use util::geometry::{Au, ZERO_RECT};
use util::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
@ -968,19 +968,18 @@ pub enum ForceNonfloatedFlag {
impl BaseFlow {
#[inline]
pub fn new(node: Option<ThreadSafeLayoutNode>,
pub fn new(style: Option<&ComputedValues>,
writing_mode: WritingMode,
force_nonfloated: ForceNonfloatedFlag)
-> BaseFlow {
let mut flags = FlowFlags::empty();
match node {
Some(node) => {
let node_style = node.style();
match node_style.get_box().position {
match style {
Some(style) => {
match style.get_box().position {
position::T::absolute | position::T::fixed => {
flags.insert(IS_ABSOLUTELY_POSITIONED);
let logical_position = node_style.logical_position();
let logical_position = style.logical_position();
if logical_position.inline_start == LengthOrPercentageOrAuto::Auto &&
logical_position.inline_end == LengthOrPercentageOrAuto::Auto {
flags.insert(INLINE_POSITION_IS_STATIC);
@ -994,14 +993,14 @@ impl BaseFlow {
}
if force_nonfloated == ForceNonfloatedFlag::FloatIfNecessary {
match node_style.get_box().float {
match style.get_box().float {
float::T::none => {}
float::T::left => flags.insert(FLOATS_LEFT),
float::T::right => flags.insert(FLOATS_RIGHT),
}
}
match node_style.get_box().clear {
match style.get_box().clear {
clear::T::none => {}
clear::T::left => flags.insert(CLEARS_LEFT),
clear::T::right => flags.insert(CLEARS_RIGHT),
@ -1011,8 +1010,8 @@ impl BaseFlow {
}
}
if !node_style.get_counters().counter_reset.0.is_empty() ||
!node_style.get_counters().counter_increment.0.is_empty() {
if !style.get_counters().counter_reset.0.is_empty() ||
!style.get_counters().counter_increment.0.is_empty() {
flags.insert(AFFECTS_COUNTERS)
}
}
@ -1192,18 +1191,35 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) {
}
/// Generates missing child flow of this flow.
///
/// FIXME(pcwalton): This duplicates some logic in
/// `generate_anonymous_table_flows_if_necessary()`. We should remove this function eventually,
/// as it's harder to understand.
fn generate_missing_child_flow(self, node: &ThreadSafeLayoutNode) -> FlowRef {
let mut style = node.style().clone();
let flow = match self.class() {
FlowClass::Table | FlowClass::TableRowGroup => {
let fragment =
Fragment::new_anonymous_from_specific_info(node,
SpecificFragmentInfo::TableRow);
box TableRowFlow::from_node_and_fragment(node, fragment) as Box<Flow>
properties::modify_style_for_anonymous_table_object(
&mut style,
display::T::table_row);
let fragment = Fragment::from_opaque_node_and_style(
node.opaque(),
PseudoElementType::Normal,
style,
node.restyle_damage(),
SpecificFragmentInfo::TableRow);
box TableRowFlow::from_fragment(fragment) as Box<Flow>
},
FlowClass::TableRow => {
let fragment =
Fragment::new_anonymous_from_specific_info(node,
SpecificFragmentInfo::TableCell);
properties::modify_style_for_anonymous_table_object(
&mut style,
display::T::table_cell);
let fragment = Fragment::from_opaque_node_and_style(
node.opaque(),
PseudoElementType::Normal,
style,
node.restyle_damage(),
SpecificFragmentInfo::TableCell);
let hide = node.style().get_inheritedtable().empty_cells == empty_cells::T::hide;
box TableCellFlow::from_node_fragment_and_visibility_flag(node, fragment, !hide) as
Box<Flow>

View file

@ -17,7 +17,6 @@ use generated_content;
use incremental::RESOLVE_GENERATED_CONTENT;
use inline::InlineMetrics;
use text;
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use gfx::display_list::DisplayList;
@ -39,13 +38,12 @@ pub struct ListItemFlow {
}
impl ListItemFlow {
pub fn from_node_fragments_and_flotation(node: &ThreadSafeLayoutNode,
main_fragment: Fragment,
marker_fragment: Option<Fragment>,
flotation: Option<FloatKind>)
-> ListItemFlow {
pub fn from_fragments_and_flotation(main_fragment: Fragment,
marker_fragment: Option<Fragment>,
flotation: Option<FloatKind>)
-> ListItemFlow {
let mut this = ListItemFlow {
block_flow: BlockFlow::from_node_and_fragment(node, main_fragment, flotation),
block_flow: BlockFlow::from_fragment(main_fragment, flotation),
marker: marker_fragment,
};

View file

@ -11,7 +11,6 @@ use context::LayoutContext;
use floats::FloatKind;
use flow::{FlowClass, Flow, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator};
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use util::geometry::Au;
@ -25,12 +24,9 @@ pub struct MulticolFlow {
}
impl MulticolFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode,
fragment: Fragment,
float_kind: Option<FloatKind>)
-> MulticolFlow {
pub fn from_fragment(fragment: Fragment, float_kind: Option<FloatKind>) -> MulticolFlow {
MulticolFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment, float_kind)
block_flow: BlockFlow::from_fragment(fragment, float_kind)
}
}
}

View file

@ -19,7 +19,6 @@ use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto};
use table_row::{self, CellIntrinsicInlineSize, CollapsedBorder, CollapsedBorderProvenance};
use table_row::{TableRowFlow};
use table_wrapper::TableLayout;
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use gfx::display_list::DisplayList;
@ -61,10 +60,8 @@ pub struct TableFlow {
}
impl TableFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode,
fragment: Fragment)
-> TableFlow {
let mut block_flow = BlockFlow::from_node_and_fragment(node, fragment, None);
pub fn from_fragment(fragment: Fragment) -> TableFlow {
let mut block_flow = BlockFlow::from_fragment(fragment, None);
let table_layout =
if block_flow.fragment().style().get_table().table_layout == table_layout::T::fixed {
TableLayout::Fixed

View file

@ -10,7 +10,6 @@ use block::BlockFlow;
use context::LayoutContext;
use flow::{FlowClass, Flow, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator};
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use util::geometry::Au;
@ -25,10 +24,9 @@ pub struct TableCaptionFlow {
}
impl TableCaptionFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode, fragment: Fragment)
-> TableCaptionFlow {
pub fn from_fragment(fragment: Fragment) -> TableCaptionFlow {
TableCaptionFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment, None)
block_flow: BlockFlow::from_fragment(fragment, None)
}
}
}

View file

@ -51,7 +51,7 @@ impl TableCellFlow {
visible: bool)
-> TableCellFlow {
TableCellFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment, None),
block_flow: BlockFlow::from_fragment(fragment, None),
collapsed_borders: CollapsedBordersForCell::new(),
column_span: node.get_unsigned_integer_attribute(UnsignedIntegerAttribute::ColSpan)
.unwrap_or(1),

View file

@ -10,7 +10,6 @@ use context::LayoutContext;
use flow::{BaseFlow, FlowClass, Flow, ForceNonfloatedFlag, OpaqueFlow};
use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
use layout_debug;
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use util::geometry::{Au, ZERO_RECT};
@ -39,13 +38,12 @@ pub struct TableColGroupFlow {
}
impl TableColGroupFlow {
pub fn from_node_and_fragments(node: &ThreadSafeLayoutNode,
fragment: Fragment,
fragments: Vec<Fragment>)
-> TableColGroupFlow {
let writing_mode = node.style().writing_mode;
pub fn from_fragments(fragment: Fragment, fragments: Vec<Fragment>) -> TableColGroupFlow {
let writing_mode = fragment.style().writing_mode;
TableColGroupFlow {
base: BaseFlow::new(Some((*node).clone()), writing_mode, ForceNonfloatedFlag::ForceNonfloated),
base: BaseFlow::new(Some(fragment.style()),
writing_mode,
ForceNonfloatedFlag::ForceNonfloated),
fragment: Some(fragment),
cols: fragments,
inline_sizes: vec!(),

View file

@ -16,7 +16,6 @@ use layout_debug;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt};
use table_cell::{CollapsedBordersForCell, TableCellFlow};
use model::MaybeAuto;
use wrapper::ThreadSafeLayoutNode;
use cssparser::{Color, RGBA};
use euclid::{Point2D, Rect};
@ -80,11 +79,10 @@ pub struct CellIntrinsicInlineSize {
impl TableRowFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode, fragment: Fragment)
-> TableRowFlow {
pub fn from_fragment(fragment: Fragment) -> TableRowFlow {
let writing_mode = fragment.style().writing_mode;
TableRowFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment, None),
block_flow: BlockFlow::from_fragment(fragment, None),
cell_intrinsic_inline_sizes: Vec::new(),
column_computed_inline_sizes: Vec::new(),
spacing: border_spacing::T {

View file

@ -14,7 +14,6 @@ use layout_debug;
use style::computed_values::{border_collapse, border_spacing};
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow};
use table_row::{self, CollapsedBordersForRow};
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use rustc_serialize::{Encoder, Encodable};
@ -63,11 +62,10 @@ impl Encodable for TableRowGroupFlow {
}
impl TableRowGroupFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode, fragment: Fragment)
-> TableRowGroupFlow {
pub fn from_fragment(fragment: Fragment) -> TableRowGroupFlow {
let writing_mode = fragment.style().writing_mode;
TableRowGroupFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment, None),
block_flow: BlockFlow::from_fragment(fragment, None),
column_intrinsic_inline_sizes: Vec::new(),
column_computed_inline_sizes: Vec::new(),
spacing: border_spacing::T {

View file

@ -23,7 +23,6 @@ use fragment::{Fragment, FragmentBorderBoxIterator};
use model::MaybeAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize};
use table_row;
use wrapper::ThreadSafeLayoutNode;
use euclid::{Point2D, Rect};
use util::geometry::Au;
@ -56,11 +55,8 @@ pub struct TableWrapperFlow {
}
impl TableWrapperFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode,
fragment: Fragment,
float_kind: Option<FloatKind>)
-> TableWrapperFlow {
let mut block_flow = BlockFlow::from_node_and_fragment(node, fragment, float_kind);
pub fn from_fragment(fragment: Fragment, float_kind: Option<FloatKind>) -> TableWrapperFlow {
let mut block_flow = BlockFlow::from_fragment(fragment, float_kind);
let table_layout = if block_flow.fragment().style().get_table().table_layout ==
table_layout::T::fixed {
TableLayout::Fixed