mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Remove PositioningContext::create_and_layout_positioned
It has only one call site.
This commit is contained in:
parent
b53959d23d
commit
d0a1066d2d
1 changed files with 85 additions and 110 deletions
|
@ -218,27 +218,6 @@ impl PositioningContext {
|
||||||
new_fragment
|
new_fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given `fragment_layout_fn`, a closure which lays out a fragment in a provided
|
|
||||||
/// `PositioningContext`, create a positioning context for a positioned fragment and lay out
|
|
||||||
/// the fragment and all its children. Returns the resulting `BoxFragment`.
|
|
||||||
fn create_and_layout_positioned(
|
|
||||||
layout_context: &LayoutContext,
|
|
||||||
style: &ComputedValues,
|
|
||||||
for_nearest_containing_block_for_all_descendants: &mut Vec<HoistedAbsolutelyPositionedBox>,
|
|
||||||
fragment_layout_fn: impl FnOnce(&mut Self) -> BoxFragment,
|
|
||||||
) -> BoxFragment {
|
|
||||||
let mut new_context = match Self::new_for_style(style) {
|
|
||||||
Some(new_context) => new_context,
|
|
||||||
None => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut new_fragment = fragment_layout_fn(&mut new_context);
|
|
||||||
new_context.layout_collected_children(layout_context, &mut new_fragment);
|
|
||||||
for_nearest_containing_block_for_all_descendants
|
|
||||||
.extend(new_context.for_nearest_containing_block_for_all_descendants);
|
|
||||||
new_fragment
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lay out the hoisted boxes collected into this `PositioningContext` and add them
|
// Lay out the hoisted boxes collected into this `PositioningContext` and add them
|
||||||
// to the given `BoxFragment`.
|
// to the given `BoxFragment`.
|
||||||
pub fn layout_collected_children(
|
pub fn layout_collected_children(
|
||||||
|
@ -467,100 +446,96 @@ impl HoistedAbsolutelyPositionedBox {
|
||||||
block_end: block_axis.margin_end,
|
block_end: block_axis.margin_end,
|
||||||
};
|
};
|
||||||
|
|
||||||
PositioningContext::create_and_layout_positioned(
|
let mut positioning_context = PositioningContext::new_for_style(style).unwrap();
|
||||||
layout_context,
|
let mut new_fragment = {
|
||||||
style,
|
let size;
|
||||||
for_nearest_containing_block_for_all_descendants,
|
let fragments;
|
||||||
|positioning_context| {
|
match absolutely_positioned_box.context.contents.as_replaced() {
|
||||||
let size;
|
Ok(replaced) => {
|
||||||
let fragments;
|
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
|
||||||
match absolutely_positioned_box.context.contents.as_replaced() {
|
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-height
|
||||||
Ok(replaced) => {
|
let style = &absolutely_positioned_box.context.style;
|
||||||
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
|
size = replaced_used_size.unwrap();
|
||||||
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-height
|
fragments = replaced.make_fragments(style, size.clone());
|
||||||
let style = &absolutely_positioned_box.context.style;
|
},
|
||||||
size = replaced_used_size.unwrap();
|
Err(non_replaced) => {
|
||||||
fragments = replaced.make_fragments(style, size.clone());
|
// https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-width
|
||||||
},
|
// https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-height
|
||||||
Err(non_replaced) => {
|
let inline_size = inline_axis.size.auto_is(|| {
|
||||||
// https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-width
|
let anchor = match inline_axis.anchor {
|
||||||
// https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-height
|
Anchor::Start(start) => start,
|
||||||
let inline_size = inline_axis.size.auto_is(|| {
|
Anchor::End(end) => end,
|
||||||
let anchor = match inline_axis.anchor {
|
|
||||||
Anchor::Start(start) => start,
|
|
||||||
Anchor::End(end) => end,
|
|
||||||
};
|
|
||||||
let available_size = cbis -
|
|
||||||
anchor -
|
|
||||||
pbm.padding_border_sums.inline -
|
|
||||||
margin.inline_sum();
|
|
||||||
absolutely_positioned_box
|
|
||||||
.context
|
|
||||||
.content_sizes
|
|
||||||
.shrink_to_fit(available_size)
|
|
||||||
});
|
|
||||||
|
|
||||||
let containing_block_for_children = ContainingBlock {
|
|
||||||
inline_size,
|
|
||||||
block_size: block_axis.size,
|
|
||||||
style,
|
|
||||||
};
|
};
|
||||||
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
|
let available_size =
|
||||||
assert_eq!(
|
cbis - anchor - pbm.padding_border_sums.inline - margin.inline_sum();
|
||||||
containing_block.style.writing_mode,
|
absolutely_positioned_box
|
||||||
containing_block_for_children.style.writing_mode,
|
.context
|
||||||
"Mixed writing modes are not supported yet"
|
.content_sizes
|
||||||
);
|
.shrink_to_fit(available_size)
|
||||||
let dummy_tree_rank = 0;
|
});
|
||||||
let independent_layout = non_replaced.layout(
|
|
||||||
layout_context,
|
|
||||||
positioning_context,
|
|
||||||
&containing_block_for_children,
|
|
||||||
dummy_tree_rank,
|
|
||||||
);
|
|
||||||
|
|
||||||
size = Vec2 {
|
let containing_block_for_children = ContainingBlock {
|
||||||
inline: inline_size,
|
inline_size,
|
||||||
block: block_axis
|
block_size: block_axis.size,
|
||||||
.size
|
style,
|
||||||
.auto_is(|| independent_layout.content_block_size),
|
};
|
||||||
};
|
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
|
||||||
fragments = independent_layout.fragments
|
assert_eq!(
|
||||||
},
|
containing_block.style.writing_mode,
|
||||||
};
|
containing_block_for_children.style.writing_mode,
|
||||||
|
"Mixed writing modes are not supported yet"
|
||||||
|
);
|
||||||
|
let dummy_tree_rank = 0;
|
||||||
|
let independent_layout = non_replaced.layout(
|
||||||
|
layout_context,
|
||||||
|
&mut positioning_context,
|
||||||
|
&containing_block_for_children,
|
||||||
|
dummy_tree_rank,
|
||||||
|
);
|
||||||
|
|
||||||
let pb = &pbm.padding + &pbm.border;
|
size = Vec2 {
|
||||||
let inline_start = match inline_axis.anchor {
|
inline: inline_size,
|
||||||
Anchor::Start(start) => start + pb.inline_start + margin.inline_start,
|
block: block_axis
|
||||||
Anchor::End(end) => {
|
.size
|
||||||
cbis - end - pb.inline_end - margin.inline_end - size.inline
|
.auto_is(|| independent_layout.content_block_size),
|
||||||
},
|
};
|
||||||
};
|
fragments = independent_layout.fragments
|
||||||
let block_start = match block_axis.anchor {
|
},
|
||||||
Anchor::Start(start) => start + pb.block_start + margin.block_start,
|
};
|
||||||
Anchor::End(end) => cbbs - end - pb.block_end - margin.block_end - size.block,
|
|
||||||
};
|
|
||||||
|
|
||||||
let content_rect = Rect {
|
let pb = &pbm.padding + &pbm.border;
|
||||||
start_corner: Vec2 {
|
let inline_start = match inline_axis.anchor {
|
||||||
inline: inline_start,
|
Anchor::Start(start) => start + pb.inline_start + margin.inline_start,
|
||||||
block: block_start,
|
Anchor::End(end) => cbis - end - pb.inline_end - margin.inline_end - size.inline,
|
||||||
},
|
};
|
||||||
size,
|
let block_start = match block_axis.anchor {
|
||||||
};
|
Anchor::Start(start) => start + pb.block_start + margin.block_start,
|
||||||
|
Anchor::End(end) => cbbs - end - pb.block_end - margin.block_end - size.block,
|
||||||
|
};
|
||||||
|
|
||||||
BoxFragment::new(
|
let content_rect = Rect {
|
||||||
absolutely_positioned_box.context.tag,
|
start_corner: Vec2 {
|
||||||
style.clone(),
|
inline: inline_start,
|
||||||
fragments,
|
block: block_start,
|
||||||
content_rect,
|
},
|
||||||
pbm.padding,
|
size,
|
||||||
pbm.border,
|
};
|
||||||
margin,
|
|
||||||
CollapsedBlockMargins::zero(),
|
BoxFragment::new(
|
||||||
)
|
absolutely_positioned_box.context.tag,
|
||||||
},
|
style.clone(),
|
||||||
)
|
fragments,
|
||||||
|
content_rect,
|
||||||
|
pbm.padding,
|
||||||
|
pbm.border,
|
||||||
|
margin,
|
||||||
|
CollapsedBlockMargins::zero(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
positioning_context.layout_collected_children(layout_context, &mut new_fragment);
|
||||||
|
for_nearest_containing_block_for_all_descendants
|
||||||
|
.extend(positioning_context.for_nearest_containing_block_for_all_descendants);
|
||||||
|
new_fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue