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

View file

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

View file

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