mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Replace the closure in layout_in_flow_non_replaced_block_level
with an enum
This commit is contained in:
parent
6fce97c65c
commit
c0962aa3fc
1 changed files with 38 additions and 45 deletions
|
@ -7,7 +7,7 @@
|
||||||
use crate::context::LayoutContext;
|
use crate::context::LayoutContext;
|
||||||
use crate::flow::float::{FloatBox, FloatContext};
|
use crate::flow::float::{FloatBox, FloatContext};
|
||||||
use crate::flow::inline::InlineFormattingContext;
|
use crate::flow::inline::InlineFormattingContext;
|
||||||
use crate::formatting_contexts::{IndependentFormattingContext, IndependentLayout};
|
use crate::formatting_contexts::{IndependentFormattingContext, IndependentLayout, NonReplacedIFC};
|
||||||
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment};
|
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment};
|
||||||
use crate::fragments::{CollapsedBlockMargins, CollapsedMargin};
|
use crate::fragments::{CollapsedBlockMargins, CollapsedMargin};
|
||||||
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
||||||
|
@ -274,19 +274,9 @@ impl BlockLevelBox {
|
||||||
positioning_context,
|
positioning_context,
|
||||||
containing_block,
|
containing_block,
|
||||||
style,
|
style,
|
||||||
BlockLevelKind::SameFormattingContextBlock,
|
BlockLevelKind::SameFormattingContextBlock(contents),
|
||||||
|positioning_context,
|
|
||||||
containing_block,
|
|
||||||
collapsible_with_parent_start_margin| {
|
|
||||||
contents.layout(
|
|
||||||
layout_context,
|
|
||||||
positioning_context,
|
|
||||||
containing_block,
|
|
||||||
tree_rank,
|
tree_rank,
|
||||||
float_context,
|
float_context
|
||||||
collapsible_with_parent_start_margin,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
BlockLevelBox::Independent(contents) => match contents.as_replaced() {
|
BlockLevelBox::Independent(contents) => match contents.as_replaced() {
|
||||||
|
@ -300,20 +290,9 @@ impl BlockLevelBox {
|
||||||
positioning_context,
|
positioning_context,
|
||||||
containing_block,
|
containing_block,
|
||||||
&contents.style,
|
&contents.style,
|
||||||
BlockLevelKind::EstablishesAnIndependentFormattingContext,
|
BlockLevelKind::EstablishesAnIndependentFormattingContext(non_replaced),
|
||||||
|positioning_context, containing_block, _| {
|
|
||||||
let independent_layout = non_replaced.layout(
|
|
||||||
layout_context,
|
|
||||||
positioning_context,
|
|
||||||
containing_block,
|
|
||||||
tree_rank,
|
tree_rank,
|
||||||
);
|
float_context
|
||||||
FlowLayout {
|
|
||||||
fragments: independent_layout.fragments,
|
|
||||||
content_block_size: independent_layout.content_block_size,
|
|
||||||
collapsible_margins_in_children: CollapsedBlockMargins::zero(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(box_) => {
|
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(box_) => {
|
||||||
|
@ -332,10 +311,9 @@ impl BlockLevelBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
enum BlockLevelKind<'a> {
|
||||||
enum BlockLevelKind {
|
SameFormattingContextBlock(&'a BlockContainer),
|
||||||
SameFormattingContextBlock,
|
EstablishesAnIndependentFormattingContext(NonReplacedIFC<'a>),
|
||||||
EstablishesAnIndependentFormattingContext,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css2/visudet.html#blockwidth
|
/// https://drafts.csswg.org/css2/visudet.html#blockwidth
|
||||||
|
@ -345,12 +323,9 @@ fn layout_in_flow_non_replaced_block_level<'a>(
|
||||||
positioning_context: &mut PositioningContext<'a>,
|
positioning_context: &mut PositioningContext<'a>,
|
||||||
containing_block: &ContainingBlock,
|
containing_block: &ContainingBlock,
|
||||||
style: &Arc<ComputedValues>,
|
style: &Arc<ComputedValues>,
|
||||||
block_level_kind: BlockLevelKind,
|
block_level_kind: BlockLevelKind<'a>,
|
||||||
layout_contents: impl FnOnce(
|
tree_rank: usize,
|
||||||
&mut PositioningContext<'a>,
|
float_context: Option<&mut FloatContext>,
|
||||||
&ContainingBlock,
|
|
||||||
CollapsibleWithParentStartMargin,
|
|
||||||
) -> FlowLayout,
|
|
||||||
) -> BoxFragment {
|
) -> BoxFragment {
|
||||||
let cbis = containing_block.inline_size;
|
let cbis = containing_block.inline_size;
|
||||||
let padding = style.padding().percentages_relative_to(cbis);
|
let padding = style.padding().percentages_relative_to(cbis);
|
||||||
|
@ -424,20 +399,38 @@ fn layout_in_flow_non_replaced_block_level<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let this_start_margin_can_collapse_with_children = CollapsibleWithParentStartMargin(
|
let this_start_margin_can_collapse_with_children = CollapsibleWithParentStartMargin(
|
||||||
block_level_kind == BlockLevelKind::SameFormattingContextBlock &&
|
matches!(block_level_kind, BlockLevelKind::SameFormattingContextBlock(_)) &&
|
||||||
pb.block_start == Length::zero(),
|
pb.block_start == Length::zero(),
|
||||||
);
|
);
|
||||||
let this_end_margin_can_collapse_with_children = block_size == LengthOrAuto::Auto &&
|
let this_end_margin_can_collapse_with_children = block_size == LengthOrAuto::Auto &&
|
||||||
min_box_size.block == Length::zero() &&
|
min_box_size.block == Length::zero() &&
|
||||||
pb.block_end == Length::zero() &&
|
pb.block_end == Length::zero() &&
|
||||||
block_level_kind == BlockLevelKind::SameFormattingContextBlock;
|
matches!(block_level_kind, BlockLevelKind::SameFormattingContextBlock(_));
|
||||||
|
|
||||||
positioning_context.for_maybe_position_relative(layout_context, style, |positioning_context| {
|
positioning_context.for_maybe_position_relative(layout_context, style, |positioning_context| {
|
||||||
let mut flow_layout = layout_contents(
|
let mut flow_layout = match block_level_kind {
|
||||||
|
BlockLevelKind::SameFormattingContextBlock(contents) => contents.layout(
|
||||||
|
layout_context,
|
||||||
positioning_context,
|
positioning_context,
|
||||||
&containing_block_for_children,
|
&containing_block_for_children,
|
||||||
|
tree_rank,
|
||||||
|
float_context,
|
||||||
this_start_margin_can_collapse_with_children,
|
this_start_margin_can_collapse_with_children,
|
||||||
|
),
|
||||||
|
BlockLevelKind::EstablishesAnIndependentFormattingContext(non_replaced) => {
|
||||||
|
let independent_layout = non_replaced.layout(
|
||||||
|
layout_context,
|
||||||
|
positioning_context,
|
||||||
|
&containing_block_for_children,
|
||||||
|
tree_rank,
|
||||||
);
|
);
|
||||||
|
FlowLayout {
|
||||||
|
fragments: independent_layout.fragments,
|
||||||
|
content_block_size: independent_layout.content_block_size,
|
||||||
|
collapsible_margins_in_children: CollapsedBlockMargins::zero(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
let mut block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin);
|
let mut block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin);
|
||||||
if this_start_margin_can_collapse_with_children.0 {
|
if this_start_margin_can_collapse_with_children.0 {
|
||||||
block_margins_collapsed_with_children
|
block_margins_collapsed_with_children
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue