Move call to for_maybe_position_relative out of layout_in_flow_non_replaced_block_level

This commit is contained in:
Simon Sapin 2019-12-13 12:41:58 +01:00
parent 672d971d58
commit 04b701b9e0

View file

@ -269,31 +269,43 @@ impl BlockLevelBox {
) -> Fragment { ) -> Fragment {
match self { match self {
BlockLevelBox::SameFormattingContextBlock { style, contents } => { BlockLevelBox::SameFormattingContextBlock { style, contents } => {
Fragment::Box(layout_in_flow_non_replaced_block_level( Fragment::Box(positioning_context.for_maybe_position_relative(
layout_context, layout_context,
positioning_context,
containing_block,
style, style,
BlockLevelKind::SameFormattingContextBlock(contents), |positioning_context| {
tree_rank, layout_in_flow_non_replaced_block_level(
float_context, layout_context,
positioning_context,
containing_block,
style,
BlockLevelKind::SameFormattingContextBlock(contents),
tree_rank,
float_context,
)
},
)) ))
}, },
BlockLevelBox::Independent(contents) => match contents.as_replaced() { BlockLevelBox::Independent(contents) => {
Ok(replaced) => Fragment::Box(layout_in_flow_replaced_block_level( Fragment::Box(positioning_context.for_maybe_position_relative(
containing_block,
&contents.style,
replaced,
)),
Err(non_replaced) => Fragment::Box(layout_in_flow_non_replaced_block_level(
layout_context, layout_context,
positioning_context,
containing_block,
&contents.style, &contents.style,
BlockLevelKind::EstablishesAnIndependentFormattingContext(non_replaced), |positioning_context| match contents.as_replaced() {
tree_rank, Ok(replaced) => layout_in_flow_replaced_block_level(
float_context, containing_block,
)), &contents.style,
replaced,
),
Err(non_replaced) => layout_in_flow_non_replaced_block_level(
layout_context,
positioning_context,
containing_block,
&contents.style,
BlockLevelKind::EstablishesAnIndependentFormattingContext(non_replaced),
tree_rank,
float_context,
),
},
))
}, },
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(box_) => { BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(box_) => {
positioning_context.push(box_.layout(Vec2::zero(), tree_rank)); positioning_context.push(box_.layout(Vec2::zero(), tree_rank));
@ -302,6 +314,7 @@ impl BlockLevelBox {
)) ))
}, },
BlockLevelBox::OutOfFlowFloatBox(_box_) => { BlockLevelBox::OutOfFlowFloatBox(_box_) => {
// FIXME: call for_maybe_position_relative here
// TODO // TODO
Fragment::Anonymous(AnonymousFragment::no_op( Fragment::Anonymous(AnonymousFragment::no_op(
containing_block.style.writing_mode, containing_block.style.writing_mode,
@ -400,89 +413,86 @@ fn layout_in_flow_non_replaced_block_level<'a>(
let mut block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin); let mut block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin);
positioning_context.for_maybe_position_relative(layout_context, style, |positioning_context| { let fragments;
let fragments; let mut content_block_size;
let mut content_block_size; match block_level_kind {
match block_level_kind { BlockLevelKind::SameFormattingContextBlock(contents) => {
BlockLevelKind::SameFormattingContextBlock(contents) => { let this_start_margin_can_collapse_with_children = pb.block_start == Length::zero();
let this_start_margin_can_collapse_with_children = pb.block_start == Length::zero(); let this_end_margin_can_collapse_with_children = pb.block_end == Length::zero() &&
let this_end_margin_can_collapse_with_children = pb.block_end == Length::zero() && block_size == LengthOrAuto::Auto &&
block_size == LengthOrAuto::Auto && min_box_size.block == Length::zero();
min_box_size.block == Length::zero();
let flow_layout = contents.layout( let flow_layout = contents.layout(
layout_context, layout_context,
positioning_context, positioning_context,
&containing_block_for_children, &containing_block_for_children,
tree_rank, tree_rank,
float_context, float_context,
CollapsibleWithParentStartMargin(this_start_margin_can_collapse_with_children), CollapsibleWithParentStartMargin(this_start_margin_can_collapse_with_children),
); );
fragments = flow_layout.fragments; fragments = flow_layout.fragments;
content_block_size = flow_layout.content_block_size; content_block_size = flow_layout.content_block_size;
let mut collapsible_margins_in_children = let mut collapsible_margins_in_children = flow_layout.collapsible_margins_in_children;
flow_layout.collapsible_margins_in_children;
if this_start_margin_can_collapse_with_children { if this_start_margin_can_collapse_with_children {
block_margins_collapsed_with_children
.start
.adjoin_assign(&collapsible_margins_in_children.start);
if collapsible_margins_in_children.collapsed_through {
block_margins_collapsed_with_children block_margins_collapsed_with_children
.start .start
.adjoin_assign(&collapsible_margins_in_children.start); .adjoin_assign(&std::mem::replace(
if collapsible_margins_in_children.collapsed_through { &mut collapsible_margins_in_children.end,
block_margins_collapsed_with_children.start.adjoin_assign( CollapsedMargin::zero(),
&std::mem::replace( ));
&mut collapsible_margins_in_children.end,
CollapsedMargin::zero(),
),
);
}
} }
if this_end_margin_can_collapse_with_children { }
block_margins_collapsed_with_children if this_end_margin_can_collapse_with_children {
.end block_margins_collapsed_with_children
.adjoin_assign(&collapsible_margins_in_children.end); .end
} else { .adjoin_assign(&collapsible_margins_in_children.end);
content_block_size += collapsible_margins_in_children.end.solve(); } else {
} content_block_size += collapsible_margins_in_children.end.solve();
block_margins_collapsed_with_children.collapsed_through = }
this_start_margin_can_collapse_with_children && block_margins_collapsed_with_children.collapsed_through =
this_end_margin_can_collapse_with_children && this_start_margin_can_collapse_with_children &&
collapsible_margins_in_children.collapsed_through; this_end_margin_can_collapse_with_children &&
}, collapsible_margins_in_children.collapsed_through;
BlockLevelKind::EstablishesAnIndependentFormattingContext(non_replaced) => { },
let independent_layout = non_replaced.layout( BlockLevelKind::EstablishesAnIndependentFormattingContext(non_replaced) => {
layout_context, let independent_layout = non_replaced.layout(
positioning_context, layout_context,
&containing_block_for_children, positioning_context,
tree_rank, &containing_block_for_children,
); tree_rank,
fragments = independent_layout.fragments; );
content_block_size = independent_layout.content_block_size; fragments = independent_layout.fragments;
}, content_block_size = independent_layout.content_block_size;
}; },
let relative_adjustement = relative_adjustement(style, inline_size, block_size); };
let block_size = block_size.auto_is(|| { let relative_adjustement = relative_adjustement(style, inline_size, block_size);
content_block_size.clamp_between_extremums(min_box_size.block, max_box_size.block) let block_size = block_size.auto_is(|| {
}); content_block_size.clamp_between_extremums(min_box_size.block, max_box_size.block)
let content_rect = Rect { });
start_corner: Vec2 { let content_rect = Rect {
block: pb.block_start + relative_adjustement.block, start_corner: Vec2 {
inline: pb.inline_start + relative_adjustement.inline + margin.inline_start, block: pb.block_start + relative_adjustement.block,
}, inline: pb.inline_start + relative_adjustement.inline + margin.inline_start,
size: Vec2 { },
block: block_size, size: Vec2 {
inline: inline_size, block: block_size,
}, inline: inline_size,
}; },
BoxFragment { };
style: style.clone(), BoxFragment {
children: fragments, style: style.clone(),
content_rect, children: fragments,
padding, content_rect,
border, padding,
margin, border,
block_margins_collapsed_with_children, margin,
} block_margins_collapsed_with_children,
}) }
} }
/// https://drafts.csswg.org/css2/visudet.html#block-replaced-width /// https://drafts.csswg.org/css2/visudet.html#block-replaced-width