Truly independent web browser
LibWeb: Keep stashed inline items for every later run of the container
Aliaksandr Kalenik557dcf252e11
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex e3cced7e77f..f390f23af6d 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -989,6 +989,9 @@ fn record_entered_inline_box<'context>(used}+/// The inline items a block container generated, kept for the later runs of the container in the same pass. Their+/// glyphs are shared, so that each run that reads them copies no glyphs.+#[derive(Clone)]pub(crate) struct StashedInlineItems {items: Vec<Item>,entered_box_model_nodes: Vec<Node>,@@ -1117,7 +1120,7 @@ impl InlineLevelIterator {atomic_sizing: AtomicInlineSizing,) -> Option<Self> {let callbacks = context.callbacks;- match callbacks.scratch().take_inline_item_stash(context.containing_block) {+ match callbacks.scratch().inline_item_stash(context.containing_block) {Some(stash) => Some(Self::from_stash(context, stash)),None => InlineLevelIteratorGenerator::generate(context, atomic_sizing),}@@ -1155,10 +1158,16 @@ impl InlineLevelIterator {if !self.is_independent_of_available_space(context) {return;}+ let mut items = self.items.into_vec();+ for glyphs in items.iter_mut().filter_map(|item| item.glyphs.as_mut()) {+ if let libgfx_rust::text_layout::GlyphBuffer::Owned(owned) = &mut glyphs.glyphs {+ glyphs.glyphs = libgfx_rust::text_layout::GlyphBuffer::Shared(std::mem::take(owned).into());+ }+ }context.callbacks.scratch().store_inline_item_stash(context.containing_block,StashedInlineItems {- items: self.items.into_vec(),+ items,entered_box_model_nodes: self.entered_box_model_nodes,},);diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex cb86e2125b5..aa5ca55cdee 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -19,7 +19,7 @@ pub(crate) struct LayoutScratch {run_record_stack: RunRecordStack,/// The intrinsic sizes passes measured, kept for the passes after them.pub(crate) intrinsic_size_caches: super::layout_node_arena::IntrinsicSizeCaches,- /// The inline items a block container generated, kept for its next run in the same pass. The+ /// The inline items a block container generated, kept for its later runs in the same pass. The/// items borrow fonts for the current pass, so the stashes are cleared when the pass ends.inline_item_stashes: RefCell<HashMap<NodeSlotId, super::inline_level_iterator::StashedInlineItems>>,measurement_memo: RefCell<MeasurementMemo>,@@ -188,11 +188,11 @@ impl LayoutScratch {self.inline_item_stashes.borrow_mut().insert(block_container, stash);}- pub(crate) fn take_inline_item_stash(+ pub(crate) fn inline_item_stash(&self,block_container: NodeSlotId,) -> Option<super::inline_level_iterator::StashedInlineItems> {- self.inline_item_stashes.borrow_mut().remove(&block_container)+ self.inline_item_stashes.borrow().get(&block_container).cloned()}/// Notes what the innermost run in progress found out for the host, or the pass outside any run.