diff --git a/components/layout_2020/dom.rs b/components/layout_2020/dom.rs index 1b561969121..570226c88bd 100644 --- a/components/layout_2020/dom.rs +++ b/components/layout_2020/dom.rs @@ -22,7 +22,6 @@ use crate::cell::ArcRefCell; use crate::context::LayoutContext; use crate::dom_traversal::WhichPseudoElement; use crate::flexbox::FlexLevelBox; -use crate::flow::inline::inline_box::InlineBox; use crate::flow::inline::InlineItem; use crate::flow::BlockLevelBox; use crate::geom::PhysicalSize; @@ -41,8 +40,6 @@ pub struct InnerDOMLayoutData { pub(super) enum LayoutBox { DisplayContents, BlockLevel(ArcRefCell), - #[allow(dead_code)] - InlineBox(ArcRefCell), InlineLevel(ArcRefCell), FlexLevel(ArcRefCell), TaffyItemBox(ArcRefCell), diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index 43f0c0a3b8a..6a7545305a9 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -448,7 +448,8 @@ where // Otherwise, this is just a normal inline box. Whatever happened before, all we need to do // before recurring is to remember this ongoing inline level box. - self.inline_formatting_context_builder + let inline_item = self + .inline_formatting_context_builder .start_inline_box(InlineBox::new(info)); if is_list_item { @@ -467,9 +468,8 @@ where self.finish_anonymous_table_if_needed(); - box_slot.set(LayoutBox::InlineBox( - self.inline_formatting_context_builder.end_inline_box(), - )); + self.inline_formatting_context_builder.end_inline_box(); + box_slot.set(LayoutBox::InlineLevel(inline_item)); } fn handle_block_level_element( diff --git a/components/layout_2020/flow/inline/construct.rs b/components/layout_2020/flow/inline/construct.rs index 901f8a91c54..58a5ae87887 100644 --- a/components/layout_2020/flow/inline/construct.rs +++ b/components/layout_2020/flow/inline/construct.rs @@ -6,6 +6,7 @@ use std::borrow::Cow; use std::char::{ToLowercase, ToUppercase}; use icu_segmenter::WordSegmenter; +use servo_arc::Arc; use style::computed_values::white_space_collapse::T as WhiteSpaceCollapse; use style::values::computed::TextDecorationLine; use style::values::specified::text::TextTransformCase; @@ -124,7 +125,7 @@ impl InlineFormattingContextBuilder { independent_formatting_context: IndependentFormattingContext, ) -> ArcRefCell { let inline_level_box = ArcRefCell::new(InlineItem::Atomic( - independent_formatting_context, + Arc::new(independent_formatting_context), self.current_text_offset, Level::ltr(), /* This will be assigned later if necessary. */ )); @@ -155,19 +156,20 @@ impl InlineFormattingContextBuilder { } pub(crate) fn push_float_box(&mut self, float_box: FloatBox) -> ArcRefCell { - let inline_level_box = ArcRefCell::new(InlineItem::OutOfFlowFloatBox(float_box)); + let inline_level_box = ArcRefCell::new(InlineItem::OutOfFlowFloatBox(Arc::new(float_box))); self.inline_items.push(inline_level_box.clone()); self.contains_floats = true; inline_level_box } - pub(crate) fn start_inline_box(&mut self, inline_box: InlineBox) { + pub(crate) fn start_inline_box(&mut self, inline_box: InlineBox) -> ArcRefCell { self.push_control_character_string(inline_box.style.bidi_control_chars().0); - let identifier = self.inline_boxes.start_inline_box(inline_box); - self.inline_items - .push(ArcRefCell::new(InlineItem::StartInlineBox(identifier))); + let (identifier, inline_box) = self.inline_boxes.start_inline_box(inline_box); + let inline_level_box = ArcRefCell::new(InlineItem::StartInlineBox(inline_box)); + self.inline_items.push(inline_level_box.clone()); self.inline_box_stack.push(identifier); + inline_level_box } pub(crate) fn end_inline_box(&mut self) -> ArcRefCell { @@ -256,16 +258,14 @@ impl InlineFormattingContextBuilder { if let Some(inline_item) = self.inline_items.last() { if let InlineItem::TextRun(text_run) = &mut *inline_item.borrow_mut() { - text_run.text_range.end = new_range.end; + text_run.borrow_mut().text_range.end = new_range.end; return; } } self.inline_items - .push(ArcRefCell::new(InlineItem::TextRun(TextRun::new( - info.into(), - info.style.clone(), - new_range, + .push(ArcRefCell::new(InlineItem::TextRun(ArcRefCell::new( + TextRun::new(info.into(), info.style.clone(), new_range), )))); } diff --git a/components/layout_2020/flow/inline/inline_box.rs b/components/layout_2020/flow/inline/inline_box.rs index 13e33381fe1..57a86cd31e2 100644 --- a/components/layout_2020/flow/inline/inline_box.rs +++ b/components/layout_2020/flow/inline/inline_box.rs @@ -82,7 +82,10 @@ impl InlineBoxes { .push(InlineBoxTreePathToken::End(identifier)); } - pub(super) fn start_inline_box(&mut self, mut inline_box: InlineBox) -> InlineBoxIdentifier { + pub(super) fn start_inline_box( + &mut self, + mut inline_box: InlineBox, + ) -> (InlineBoxIdentifier, ArcRefCell) { assert!(self.inline_boxes.len() <= u32::MAX as usize); assert!(self.inline_box_tree.len() <= u32::MAX as usize); @@ -94,11 +97,13 @@ impl InlineBoxes { index_in_inline_boxes, }; inline_box.identifier = identifier; + let inline_box = ArcRefCell::new(inline_box); - self.inline_boxes.push(ArcRefCell::new(inline_box)); + self.inline_boxes.push(inline_box.clone()); self.inline_box_tree .push(InlineBoxTreePathToken::Start(identifier)); - identifier + + (identifier, inline_box) } pub(super) fn get_path( diff --git a/components/layout_2020/flow/inline/mod.rs b/components/layout_2020/flow/inline/mod.rs index 0f819cfd104..6fde268818e 100644 --- a/components/layout_2020/flow/inline/mod.rs +++ b/components/layout_2020/flow/inline/mod.rs @@ -180,16 +180,16 @@ pub(crate) struct FontKeyAndMetrics { #[derive(Debug, Serialize)] pub(crate) enum InlineItem { - StartInlineBox(InlineBoxIdentifier), + StartInlineBox(ArcRefCell), EndInlineBox, - TextRun(TextRun), + TextRun(ArcRefCell), OutOfFlowAbsolutelyPositionedBox( ArcRefCell, usize, /* offset_in_text */ ), - OutOfFlowFloatBox(FloatBox), + OutOfFlowFloatBox(Arc), Atomic( - IndependentFormattingContext, + Arc, usize, /* offset_in_text */ Level, /* bidi_level */ ), @@ -1536,7 +1536,7 @@ impl InlineFormattingContext { for item in builder.inline_items.iter() { match &mut *item.borrow_mut() { InlineItem::TextRun(ref mut text_run) => { - text_run.segment_and_shape( + text_run.borrow_mut().segment_and_shape( &text_content, &layout_context.font_context, &mut new_linebreaker, @@ -1544,8 +1544,7 @@ impl InlineFormattingContext { &bidi_info, ); }, - InlineItem::StartInlineBox(identifier) => { - let inline_box = builder.inline_boxes.get(identifier); + InlineItem::StartInlineBox(inline_box) => { let inline_box = &mut *inline_box.borrow_mut(); if let Some(font) = get_font_for_first_font_for_style( &inline_box.style, @@ -1676,11 +1675,11 @@ impl InlineFormattingContext { } match item { - InlineItem::StartInlineBox(identifier) => { - layout.start_inline_box(&self.inline_boxes.get(identifier).borrow()); + InlineItem::StartInlineBox(inline_box) => { + layout.start_inline_box(&inline_box.borrow()); }, InlineItem::EndInlineBox => layout.finish_inline_box(), - InlineItem::TextRun(run) => run.layout_into_line_items(&mut layout), + InlineItem::TextRun(run) => run.borrow().layout_into_line_items(&mut layout), InlineItem::Atomic(atomic_formatting_context, offset_in_text, bidi_level) => { atomic_formatting_context.layout_into_line_items( &mut layout, @@ -2237,12 +2236,11 @@ impl<'layout_data> ContentSizesComputation<'layout_data> { inline_formatting_context: &InlineFormattingContext, ) { match inline_item { - InlineItem::StartInlineBox(identifier) => { + InlineItem::StartInlineBox(inline_box) => { // For margins and paddings, a cyclic percentage is resolved against zero // for determining intrinsic size contributions. // https://drafts.csswg.org/css-sizing-3/#min-percentage-contribution - let inline_box = inline_formatting_context.inline_boxes.get(identifier); - let inline_box = (*inline_box).borrow(); + let inline_box = inline_box.borrow(); let zero = Au::zero(); let writing_mode = self.constraint_space.writing_mode; let padding = inline_box @@ -2271,6 +2269,7 @@ impl<'layout_data> ContentSizesComputation<'layout_data> { self.add_inline_size(length); }, InlineItem::TextRun(text_run) => { + let text_run = &*text_run.borrow(); for segment in text_run.shaped_text.iter() { let style_text = text_run.parent_style.get_inherited_text(); let can_wrap = style_text.text_wrap_mode == TextWrapMode::Wrap; diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index f9828e2308a..6f48ebd9e9d 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -185,7 +185,6 @@ impl BoxTree { }, _ => return None, }, - LayoutBox::InlineBox(_) => return None, LayoutBox::InlineLevel(inline_level_box) => match &*inline_level_box.borrow() { InlineItem::OutOfFlowAbsolutelyPositionedBox(_, text_offset_index) if box_style.position.is_absolutely_positioned() =>