mirror of
https://github.com/servo/servo.git
synced 2025-07-16 11:53:39 +01:00
layout: Add incremental box tree construction for inline atomics (#37866)
This changes extend the incremental box tree construction for inline atomic Testing: This should not change observable behavior and is thus covered by existing WPT tests. Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This commit is contained in:
parent
291b42f6e9
commit
75e5c1bced
2 changed files with 33 additions and 7 deletions
|
@ -290,7 +290,7 @@ impl<'dom, 'style> BlockContainerBuilder<'dom, 'style> {
|
||||||
|
|
||||||
if inline_table {
|
if inline_table {
|
||||||
self.ensure_inline_formatting_context_builder()
|
self.ensure_inline_formatting_context_builder()
|
||||||
.push_atomic(ifc);
|
.push_atomic(|| ArcRefCell::new(ifc), None);
|
||||||
} else {
|
} else {
|
||||||
let table_block = ArcRefCell::new(BlockLevelBox::Independent(ifc));
|
let table_block = ArcRefCell::new(BlockLevelBox::Independent(ifc));
|
||||||
|
|
||||||
|
@ -472,15 +472,20 @@ impl<'dom> BlockContainerBuilder<'dom, '_> {
|
||||||
// If this inline element is an atomic, handle it and return.
|
// If this inline element is an atomic, handle it and return.
|
||||||
let context = self.context;
|
let context = self.context;
|
||||||
let propagated_data = self.propagated_data;
|
let propagated_data = self.propagated_data;
|
||||||
let atomic = self.ensure_inline_formatting_context_builder().push_atomic(
|
|
||||||
IndependentFormattingContext::construct(
|
let construction_callback = || {
|
||||||
|
ArcRefCell::new(IndependentFormattingContext::construct(
|
||||||
context,
|
context,
|
||||||
info,
|
info,
|
||||||
display_inside,
|
display_inside,
|
||||||
contents,
|
contents,
|
||||||
propagated_data,
|
propagated_data,
|
||||||
),
|
))
|
||||||
);
|
};
|
||||||
|
let old_layout_box = box_slot.take_layout_box_if_undamaged(info.damage);
|
||||||
|
let atomic = self
|
||||||
|
.ensure_inline_formatting_context_builder()
|
||||||
|
.push_atomic(construction_callback, old_layout_box);
|
||||||
box_slot.set(LayoutBox::InlineLevel(vec![atomic]));
|
box_slot.set(LayoutBox::InlineLevel(vec![atomic]));
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,6 +18,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use crate::cell::ArcRefCell;
|
use crate::cell::ArcRefCell;
|
||||||
use crate::context::LayoutContext;
|
use crate::context::LayoutContext;
|
||||||
|
use crate::dom::LayoutBox;
|
||||||
use crate::dom_traversal::NodeAndStyleInfo;
|
use crate::dom_traversal::NodeAndStyleInfo;
|
||||||
use crate::flow::float::FloatBox;
|
use crate::flow::float::FloatBox;
|
||||||
use crate::formatting_contexts::IndependentFormattingContext;
|
use crate::formatting_contexts::IndependentFormattingContext;
|
||||||
|
@ -153,10 +154,30 @@ impl InlineFormattingContextBuilder {
|
||||||
|
|
||||||
pub(crate) fn push_atomic(
|
pub(crate) fn push_atomic(
|
||||||
&mut self,
|
&mut self,
|
||||||
independent_formatting_context: IndependentFormattingContext,
|
independent_formatting_context_creator: impl FnOnce()
|
||||||
|
-> ArcRefCell<IndependentFormattingContext>,
|
||||||
|
old_layout_box: Option<LayoutBox>,
|
||||||
) -> ArcRefCell<InlineItem> {
|
) -> ArcRefCell<InlineItem> {
|
||||||
|
// If there is an existing undamaged layout box that's compatible, use that.
|
||||||
|
let independent_formatting_context = old_layout_box
|
||||||
|
.and_then(|layout_box| {
|
||||||
|
let LayoutBox::InlineLevel(inline_level_boxes) = layout_box else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
|
// If there's an existing box, it should be a compatible atomic inline and should
|
||||||
|
// not have been subject to inline-block splitting.
|
||||||
|
assert_eq!(inline_level_boxes.len(), 1);
|
||||||
|
let first_box = inline_level_boxes.into_iter().next()?;
|
||||||
|
match &*first_box.borrow() {
|
||||||
|
InlineItem::Atomic(atomic, ..) => Some(atomic.clone()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or_else(independent_formatting_context_creator);
|
||||||
|
|
||||||
let inline_level_box = ArcRefCell::new(InlineItem::Atomic(
|
let inline_level_box = ArcRefCell::new(InlineItem::Atomic(
|
||||||
ArcRefCell::new(independent_formatting_context),
|
independent_formatting_context,
|
||||||
self.current_text_offset,
|
self.current_text_offset,
|
||||||
Level::ltr(), /* This will be assigned later if necessary. */
|
Level::ltr(), /* This will be assigned later if necessary. */
|
||||||
));
|
));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue