Owned ServoArc<ComputedValues> in TraversalHandler

This commit is contained in:
Simon Sapin 2020-06-03 13:55:11 +02:00
parent 29005e1626
commit fff5cd5142
3 changed files with 19 additions and 29 deletions

View file

@ -64,14 +64,14 @@ where
&mut self, &mut self,
node: Node, node: Node,
text: Cow<'dom, str>, text: Cow<'dom, str>,
parent_style: &ServoArc<ComputedValues>, parent_style: ServoArc<ComputedValues>,
); );
/// Or pseudo-element /// Or pseudo-element
fn handle_element( fn handle_element(
&mut self, &mut self,
node: Node, node: Node,
style: &ServoArc<ComputedValues>, style: ServoArc<ComputedValues>,
display: DisplayGeneratingBox, display: DisplayGeneratingBox,
contents: Contents, contents: Contents,
box_slot: BoxSlot<'dom>, box_slot: BoxSlot<'dom>,
@ -89,7 +89,7 @@ fn traverse_children_of<'dom, Node>(
for child in iter_child_nodes(parent_element) { for child in iter_child_nodes(parent_element) {
if let Some(contents) = child.as_text() { if let Some(contents) = child.as_text() {
handler.handle_text(child, contents, &child.style(context)); handler.handle_text(child, contents, child.style(context));
} else if child.is_element() { } else if child.is_element() {
traverse_element(child, context, handler); traverse_element(child, context, handler);
} }
@ -122,7 +122,7 @@ fn traverse_element<'dom, Node>(
Display::GeneratingBox(display) => { Display::GeneratingBox(display) => {
let contents = replaced.map_or(Contents::OfElement, Contents::Replaced); let contents = replaced.map_or(Contents::OfElement, Contents::Replaced);
let box_slot = element.element_box_slot(); let box_slot = element.element_box_slot();
handler.handle_element(element, &style, display, contents, box_slot); handler.handle_element(element, style, display, contents, box_slot);
}, },
} }
} }
@ -148,7 +148,7 @@ fn traverse_pseudo_element<'dom, Node>(
let items = generate_pseudo_element_content(&style, element, context); let items = generate_pseudo_element_content(&style, element, context);
let box_slot = element.pseudo_element_box_slot(which); let box_slot = element.pseudo_element_box_slot(which);
let contents = Contents::OfPseudoElement(items); let contents = Contents::OfPseudoElement(items);
handler.handle_element(element, &style, display, contents, box_slot); handler.handle_element(element, style, display, contents, box_slot);
}, },
} }
} else { } else {
@ -169,7 +169,7 @@ fn traverse_pseudo_element_contents<'dom, Node>(
for item in items { for item in items {
match item { match item {
PseudoElementContentItem::Text(text) => { PseudoElementContentItem::Text(text) => {
handler.handle_text(node, text.into(), pseudo_element_style) handler.handle_text(node, text.into(), pseudo_element_style.clone())
}, },
PseudoElementContentItem::Replaced(contents) => { PseudoElementContentItem::Replaced(contents) => {
let item_style = anonymous_style.get_or_insert_with(|| { let item_style = anonymous_style.get_or_insert_with(|| {
@ -193,7 +193,7 @@ fn traverse_pseudo_element_contents<'dom, Node>(
); );
handler.handle_element( handler.handle_element(
node, node,
item_style, item_style.clone(),
display_inline, display_inline,
Contents::Replaced(contents), Contents::Replaced(contents),
// We dont keep pointers to boxes generated by contents of pseudo-elements // We dont keep pointers to boxes generated by contents of pseudo-elements

View file

@ -80,11 +80,11 @@ where
&mut self, &mut self,
node: Node, node: Node,
text: Cow<'dom, str>, text: Cow<'dom, str>,
parent_style: &Arc<ComputedValues>, parent_style: Arc<ComputedValues>,
) { ) {
self.contiguous_text_runs.push(TextRun { self.contiguous_text_runs.push(TextRun {
tag: node.as_opaque(), tag: node.as_opaque(),
parent_style: parent_style.clone(), parent_style,
text: text.into(), text: text.into(),
}) })
} }
@ -93,7 +93,7 @@ where
fn handle_element( fn handle_element(
&mut self, &mut self,
node: Node, node: Node,
style: &Arc<ComputedValues>, style: Arc<ComputedValues>,
display: DisplayGeneratingBox, display: DisplayGeneratingBox,
contents: Contents, contents: Contents,
box_slot: BoxSlot<'dom>, box_slot: BoxSlot<'dom>,

View file

@ -273,7 +273,7 @@ where
fn handle_element( fn handle_element(
&mut self, &mut self,
node: Node, node: Node,
style: &Arc<ComputedValues>, style: Arc<ComputedValues>,
display: DisplayGeneratingBox, display: DisplayGeneratingBox,
contents: Contents, contents: Contents,
box_slot: BoxSlot<'dom>, box_slot: BoxSlot<'dom>,
@ -289,22 +289,12 @@ where
// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo // https://drafts.csswg.org/css2/visuren.html#dis-pos-flo
if box_style.position.is_absolutely_positioned() { if box_style.position.is_absolutely_positioned() {
self.handle_absolutely_positioned_element( self.handle_absolutely_positioned_element(
node, node, style, inside, contents, box_slot,
style.clone(),
inside,
contents,
box_slot,
) )
} else if box_style.float.is_floating() { } else if box_style.float.is_floating() {
self.handle_float_element(node, style.clone(), inside, contents, box_slot) self.handle_float_element(node, style, inside, contents, box_slot)
} else { } else {
self.handle_block_level_element( self.handle_block_level_element(node, style, inside, contents, box_slot)
node,
style.clone(),
inside,
contents,
box_slot,
)
} }
}, },
}, },
@ -315,7 +305,7 @@ where
&mut self, &mut self,
node: Node, node: Node,
input: Cow<'dom, str>, input: Cow<'dom, str>,
parent_style: &Arc<ComputedValues>, parent_style: Arc<ComputedValues>,
) { ) {
let (leading_whitespace, mut input) = self.handle_leading_whitespace(&input); let (leading_whitespace, mut input) = self.handle_leading_whitespace(&input);
if leading_whitespace || !input.is_empty() { if leading_whitespace || !input.is_empty() {
@ -365,7 +355,6 @@ where
} }
if let Some(text) = new_text_run_contents { if let Some(text) = new_text_run_contents {
let parent_style = parent_style.clone();
inlines.push(ArcRefCell::new(InlineLevelBox::TextRun(TextRun { inlines.push(ArcRefCell::new(InlineLevelBox::TextRun(TextRun {
tag: node.as_opaque(), tag: node.as_opaque(),
parent_style, parent_style,
@ -442,7 +431,7 @@ where
fn handle_inline_level_element( fn handle_inline_level_element(
&mut self, &mut self,
node: Node, node: Node,
style: &Arc<ComputedValues>, style: Arc<ComputedValues>,
display_inside: DisplayInside, display_inside: DisplayInside,
contents: Contents, contents: Contents,
) -> ArcRefCell<InlineLevelBox> { ) -> ArcRefCell<InlineLevelBox> {
@ -473,14 +462,15 @@ where
inline_box.last_fragment = true; inline_box.last_fragment = true;
ArcRefCell::new(InlineLevelBox::InlineBox(inline_box)) ArcRefCell::new(InlineLevelBox::InlineBox(inline_box))
} else { } else {
let content_sizes = ContentSizesRequest::inline_if(!style.inline_size_is_length());
ArcRefCell::new(InlineLevelBox::Atomic( ArcRefCell::new(InlineLevelBox::Atomic(
IndependentFormattingContext::construct( IndependentFormattingContext::construct(
self.context, self.context,
node, node,
style.clone(), style,
display_inside, display_inside,
contents, contents,
ContentSizesRequest::inline_if(!style.inline_size_is_length()), content_sizes,
// Text decorations are not propagated to atomic inline-level descendants. // Text decorations are not propagated to atomic inline-level descendants.
TextDecorationLine::NONE, TextDecorationLine::NONE,
), ),