From b2b3ea992c2f045a49d7264df18f5f85b2c913fb Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 26 Nov 2019 11:22:23 +0100 Subject: Make IndependentFormattingContext a struct that owns styles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and has a private enum for its contents. Privacy forces the rest of the code to go through methods rather than matching on the enum, reducing accidental layout-mode-specific behavior. --- components/layout_2020/flow/construct.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'components/layout_2020/flow/construct.rs') diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index f3afabf15fc..52724eb121f 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -7,9 +7,10 @@ use crate::element_data::LayoutBox; use crate::flow::float::FloatBox; use crate::flow::inline::{InlineBox, InlineFormattingContext, InlineLevelBox, TextRun}; use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox}; +use crate::formatting_contexts::IndependentFormattingContext; use crate::positioned::AbsolutelyPositionedBox; use crate::style_ext::{DisplayGeneratingBox, DisplayInside, DisplayOutside}; -use crate::{take, IndependentFormattingContext}; +use crate::take; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon_croissant::ParallelIteratorExt; use servo_arc::Arc; @@ -450,11 +451,10 @@ where AbsolutelyPositionedBox { contents: IndependentFormattingContext::construct( unimplemented!(), - &style, + style, display_inside, contents, ), - style, }, )); self.current_inline_level_boxes().push(box_.clone()); @@ -482,11 +482,10 @@ where let box_ = Arc::new(InlineLevelBox::OutOfFlowFloatBox(FloatBox { contents: IndependentFormattingContext::construct( self.context, - &style, + style, display_inside, contents, ), - style, })); self.current_inline_level_boxes().push(box_.clone()); box_slot.set(LayoutBox::InlineLevel(box_)) @@ -562,12 +561,12 @@ where } => { let contents = IndependentFormattingContext::construct( context, - &style, + style, display_inside, contents, ); ( - Arc::new(BlockLevelBox::Independent { style, contents }), + Arc::new(BlockLevelBox::Independent(contents)), ContainsFloats::No, ) }, @@ -580,11 +579,10 @@ where AbsolutelyPositionedBox { contents: IndependentFormattingContext::construct( context, - &style, + style, display_inside, contents, ), - style: style, }, )); (block_level_box, ContainsFloats::No) @@ -596,14 +594,12 @@ where } => { let contents = IndependentFormattingContext::construct( context, - &style, + style, display_inside, contents, ); - let block_level_box = Arc::new(BlockLevelBox::OutOfFlowFloatBox(FloatBox { - contents, - style, - })); + let block_level_box = + Arc::new(BlockLevelBox::OutOfFlowFloatBox(FloatBox { contents })); (block_level_box, ContainsFloats::Yes) }, } -- cgit v1.2.3 From 80eec48d373f89415e95e01ab9aaf6d07ac01c3e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 26 Nov 2019 11:24:53 +0100 Subject: Use std::mem::take instead of defining it --- components/layout_2020/flow/construct.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'components/layout_2020/flow/construct.rs') diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index 52724eb121f..57d7bf9dd31 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -10,7 +10,6 @@ use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox}; use crate::formatting_contexts::IndependentFormattingContext; use crate::positioned::AbsolutelyPositionedBox; use crate::style_ext::{DisplayGeneratingBox, DisplayInside, DisplayOutside}; -use crate::take; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon_croissant::ParallelIteratorExt; use servo_arc::Arc; @@ -381,7 +380,7 @@ where // The fragmented boxes before the block level element // are obviously not the last fragment. last_fragment: false, - children: take(&mut ongoing.children), + children: std::mem::take(&mut ongoing.children), }; ongoing.first_fragment = false; fragmented @@ -516,7 +515,7 @@ where let box_ = IntermediateBlockLevelBox::SameFormattingContextBlock { style: anonymous_style.clone(), - contents: IntermediateBlockContainer::InlineFormattingContext(take( + contents: IntermediateBlockContainer::InlineFormattingContext(std::mem::take( &mut self.ongoing_inline_formatting_context, )), }; -- cgit v1.2.3