Include non-shadowdom children of shadow hosts in style calculation (#34298)

* Include non-shadowdom children of shadow hosts in style calculation

This was previously causing crashes because the layout nodes
of those children would never be assigned style data by stylo.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2024-11-20 20:28:35 +01:00 committed by GitHub
parent 2889e934f5
commit f3ad078358
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
77 changed files with 284 additions and 96 deletions

View file

@ -140,20 +140,41 @@ impl<'dom> ServoLayoutElement<'dom> {
}
}
pub struct DomChildrenIncludingShadowDom<N> {
children: DomChildren<N>,
children_in_shadow_root: Option<DomChildren<N>>,
}
impl<N> Iterator for DomChildrenIncludingShadowDom<N>
where
N: TNode,
{
type Item = N;
fn next(&mut self) -> Option<Self::Item> {
self.children
.next()
.or_else(|| self.children_in_shadow_root.as_mut()?.next())
}
}
impl<'dom> style::dom::TElement for ServoLayoutElement<'dom> {
type ConcreteNode = ServoLayoutNode<'dom>;
type TraversalChildrenIterator = DomChildren<Self::ConcreteNode>;
type TraversalChildrenIterator = DomChildrenIncludingShadowDom<Self::ConcreteNode>;
fn as_node(&self) -> ServoLayoutNode<'dom> {
ServoLayoutNode::from_layout_js(self.element.upcast())
}
fn traversal_children(&self) -> LayoutIterator<Self::TraversalChildrenIterator> {
LayoutIterator(if let Some(shadow) = self.shadow_root() {
shadow.as_node().dom_children()
} else {
self.as_node().dom_children()
})
let children = DomChildrenIncludingShadowDom {
children: self.as_node().dom_children(),
children_in_shadow_root: self
.shadow_root()
.map(|shadow| shadow.as_node().dom_children()),
};
LayoutIterator(children)
}
fn is_html_element(&self) -> bool {