mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
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:
parent
2bd96633d4
commit
09bfaf51b0
5 changed files with 108 additions and 35 deletions
|
@ -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();
|
||||
},
|
||||
|
|
|
@ -46,6 +46,7 @@ use uuid::Uuid;
|
|||
use xml5ever::serialize as xml_serialize;
|
||||
|
||||
use super::globalscope::GlobalScope;
|
||||
use crate::conversions::Convert;
|
||||
use crate::document_loader::DocumentLoader;
|
||||
use crate::dom::attr::Attr;
|
||||
use crate::dom::bindings::cell::{DomRefCell, Ref, RefMut};
|
||||
|
@ -60,7 +61,9 @@ use crate::dom::bindings::codegen::Bindings::NodeBinding::{
|
|||
use crate::dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRoot_Binding::ShadowRootMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::SlotAssignmentMode;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::{
|
||||
ShadowRootMode, SlotAssignmentMode,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use crate::dom::bindings::codegen::InheritTypes::DocumentFragmentTypeId;
|
||||
use crate::dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
|
@ -1180,8 +1183,28 @@ impl Node {
|
|||
pub(crate) fn summarize(&self) -> NodeInfo {
|
||||
let USVString(base_uri) = self.BaseURI();
|
||||
let node_type = self.NodeType();
|
||||
|
||||
let maybe_shadow_root = self.downcast::<ShadowRoot>();
|
||||
let shadow_root_mode = maybe_shadow_root
|
||||
.map(ShadowRoot::Mode)
|
||||
.map(ShadowRootMode::convert);
|
||||
let host = maybe_shadow_root
|
||||
.map(ShadowRoot::Host)
|
||||
.map(|host| host.upcast::<Node>().unique_id());
|
||||
let is_shadow_host = self
|
||||
.downcast::<Element>()
|
||||
.is_some_and(Element::is_shadow_host);
|
||||
|
||||
let num_children = if is_shadow_host {
|
||||
// Shadow roots count as children
|
||||
self.ChildNodes().Length() as usize + 1
|
||||
} else {
|
||||
self.ChildNodes().Length() as usize
|
||||
};
|
||||
|
||||
NodeInfo {
|
||||
unique_id: self.unique_id(),
|
||||
host,
|
||||
base_uri,
|
||||
parent: self
|
||||
.GetParentNode()
|
||||
|
@ -1190,8 +1213,10 @@ impl Node {
|
|||
is_top_level_document: node_type == NodeConstants::DOCUMENT_NODE,
|
||||
node_name: String::from(self.NodeName()),
|
||||
node_value: self.GetNodeValue().map(|v| v.into()),
|
||||
num_children: self.ChildNodes().Length() as usize,
|
||||
num_children,
|
||||
attrs: self.downcast().map(Element::summarize).unwrap_or(vec![]),
|
||||
is_shadow_host,
|
||||
shadow_root_mode,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use style::shared_lock::SharedRwLockReadGuard;
|
|||
use style::stylesheets::Stylesheet;
|
||||
use style::stylist::{CascadeData, Stylist};
|
||||
|
||||
use crate::conversions::Convert;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRoot_Binding::ShadowRootMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::{
|
||||
|
@ -421,3 +422,12 @@ impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Convert<devtools_traits::ShadowRootMode> for ShadowRootMode {
|
||||
fn convert(self) -> devtools_traits::ShadowRootMode {
|
||||
match self {
|
||||
ShadowRootMode::Open => devtools_traits::ShadowRootMode::Open,
|
||||
ShadowRootMode::Closed => devtools_traits::ShadowRootMode::Closed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue