Inform the devtools about shadow roots on a node (#35294)

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-02-05 14:16:36 +01:00 committed by GitHub
parent 2bd96633d4
commit 09bfaf51b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 108 additions and 35 deletions

View file

@ -162,23 +162,24 @@ pub(crate) fn handle_get_children(
})
.collect();
let children: Vec<_> = parent
.children()
.enumerate()
.filter_map(|(i, child)| {
// Filter whitespace only text nodes that are not inline level
// https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/examine_and_edit_html/index.html#whitespace-only-text-nodes
let prev_inline = i > 0 && inline[i - 1];
let next_inline = i < inline.len() - 1 && inline[i + 1];
let mut children = vec![];
if let Some(shadow_root) = parent.downcast::<Element>().and_then(Element::shadow_root) {
children.push(shadow_root.upcast::<Node>().summarize());
}
let children_iter = parent.children().enumerate().filter_map(|(i, child)| {
// Filter whitespace only text nodes that are not inline level
// https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/how_to/examine_and_edit_html/index.html#whitespace-only-text-nodes
let prev_inline = i > 0 && inline[i - 1];
let next_inline = i < inline.len() - 1 && inline[i + 1];
let info = child.summarize();
if !is_whitespace(&info) {
return Some(info);
}
let info = child.summarize();
if !is_whitespace(&info) {
return Some(info);
}
(prev_inline && next_inline).then_some(info)
})
.collect();
(prev_inline && next_inline).then_some(info)
});
children.extend(children_iter);
reply.send(Some(children)).unwrap();
},