diff options
author | Anthony Ramine <nox@nox.paris> | 2020-06-11 14:10:26 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-06-15 18:09:15 +0200 |
commit | d0a1066d2d4fee2ac307bb4ec11ac843a76a26f7 (patch) | |
tree | a1bde847bbfc4816247430cd5d87005bc9c329d8 | |
parent | b53959d23d54e3a30a4c9d01ab2eb5b605d2579c (diff) | |
download | servo-d0a1066d2d4fee2ac307bb4ec11ac843a76a26f7.tar.gz servo-d0a1066d2d4fee2ac307bb4ec11ac843a76a26f7.zip |
Remove PositioningContext::create_and_layout_positioned
It has only one call site.
-rw-r--r-- | components/layout_2020/positioned.rs | 197 |
1 files changed, 86 insertions, 111 deletions
diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index ca46f65cc2f..2a6fb99764f 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -218,27 +218,6 @@ impl PositioningContext { 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 // to the given `BoxFragment`. pub fn layout_collected_children( @@ -467,100 +446,96 @@ impl HoistedAbsolutelyPositionedBox { block_end: block_axis.margin_end, }; - PositioningContext::create_and_layout_positioned( - layout_context, - style, - for_nearest_containing_block_for_all_descendants, - |positioning_context| { - let size; - let fragments; - match absolutely_positioned_box.context.contents.as_replaced() { - Ok(replaced) => { - // https://drafts.csswg.org/css2/visudet.html#abs-replaced-width - // https://drafts.csswg.org/css2/visudet.html#abs-replaced-height - let style = &absolutely_positioned_box.context.style; - size = replaced_used_size.unwrap(); - fragments = replaced.make_fragments(style, size.clone()); - }, - Err(non_replaced) => { - // https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-width - // https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-height - let inline_size = inline_axis.size.auto_is(|| { - 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 - 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, - positioning_context, - &containing_block_for_children, - dummy_tree_rank, - ); - - size = Vec2 { - inline: inline_size, - block: block_axis - .size - .auto_is(|| independent_layout.content_block_size), + let mut positioning_context = PositioningContext::new_for_style(style).unwrap(); + let mut new_fragment = { + let size; + let fragments; + match absolutely_positioned_box.context.contents.as_replaced() { + Ok(replaced) => { + // https://drafts.csswg.org/css2/visudet.html#abs-replaced-width + // https://drafts.csswg.org/css2/visudet.html#abs-replaced-height + let style = &absolutely_positioned_box.context.style; + size = replaced_used_size.unwrap(); + fragments = replaced.make_fragments(style, size.clone()); + }, + Err(non_replaced) => { + // https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-width + // https://drafts.csswg.org/css2/visudet.html#abs-non-replaced-height + let inline_size = inline_axis.size.auto_is(|| { + let anchor = match inline_axis.anchor { + Anchor::Start(start) => start, + Anchor::End(end) => end, }; - fragments = independent_layout.fragments - }, - }; + 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 + 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, + ); + + size = Vec2 { + inline: inline_size, + block: block_axis + .size + .auto_is(|| independent_layout.content_block_size), + }; + fragments = independent_layout.fragments + }, + }; - let pb = &pbm.padding + &pbm.border; - let inline_start = match inline_axis.anchor { - Anchor::Start(start) => start + pb.inline_start + margin.inline_start, - Anchor::End(end) => { - cbis - end - pb.inline_end - margin.inline_end - size.inline - }, - }; - 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 pb = &pbm.padding + &pbm.border; + let inline_start = match inline_axis.anchor { + Anchor::Start(start) => start + pb.inline_start + margin.inline_start, + Anchor::End(end) => cbis - end - pb.inline_end - margin.inline_end - size.inline, + }; + 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 { - start_corner: Vec2 { - inline: inline_start, - block: block_start, - }, - size, - }; + let content_rect = Rect { + start_corner: Vec2 { + inline: inline_start, + block: block_start, + }, + size, + }; - BoxFragment::new( - absolutely_positioned_box.context.tag, - style.clone(), - fragments, - content_rect, - pbm.padding, - 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 } } |