Hide servo internal shadow roots from the inspector by default (#35958)

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-03-13 14:08:24 +01:00 committed by GitHub
parent 4a9967725f
commit e627ac5cfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 4 deletions

View file

@ -542,6 +542,7 @@ impl Element {
mode,
slot_assignment_mode,
clonable,
is_ua_widget,
can_gc,
);

View file

@ -35,6 +35,7 @@ use selectors::matching::{
};
use selectors::parser::SelectorList;
use servo_arc::Arc;
use servo_config::pref;
use servo_url::ServoUrl;
use smallvec::SmallVec;
use style::context::QuirksMode;
@ -1209,9 +1210,12 @@ impl Node {
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 is_shadow_host = self.downcast::<Element>().is_some_and(|potential_host| {
let Some(root) = potential_host.shadow_root() else {
return false;
};
!root.is_user_agent_widget() || pref!(inspector_show_servo_internal_shadow_roots)
});
let num_children = if is_shadow_host {
// Shadow roots count as children

View file

@ -77,6 +77,8 @@ pub(crate) struct ShadowRoot {
available_to_element_internals: Cell<bool>,
slots: DomRefCell<HashMap<DOMString, Vec<Dom<HTMLSlotElement>>>>,
is_user_agent_widget: bool,
}
impl ShadowRoot {
@ -87,6 +89,7 @@ impl ShadowRoot {
mode: ShadowRootMode,
slot_assignment_mode: SlotAssignmentMode,
clonable: bool,
is_user_agent_widget: IsUserAgentWidget,
) -> ShadowRoot {
let document_fragment = DocumentFragment::new_inherited(document);
let node = document_fragment.upcast::<Node>();
@ -109,6 +112,7 @@ impl ShadowRoot {
clonable,
available_to_element_internals: Cell::new(false),
slots: Default::default(),
is_user_agent_widget: is_user_agent_widget == IsUserAgentWidget::Yes,
}
}
@ -118,6 +122,7 @@ impl ShadowRoot {
mode: ShadowRootMode,
slot_assignment_mode: SlotAssignmentMode,
clonable: bool,
is_user_agent_widget: IsUserAgentWidget,
can_gc: CanGc,
) -> DomRoot<ShadowRoot> {
reflect_dom_object(
@ -127,6 +132,7 @@ impl ShadowRoot {
mode,
slot_assignment_mode,
clonable,
is_user_agent_widget,
)),
document.window(),
can_gc,
@ -266,6 +272,10 @@ impl ShadowRoot {
pub(crate) fn is_available_to_element_internals(&self) -> bool {
self.available_to_element_internals.get()
}
pub(crate) fn is_user_agent_widget(&self) -> bool {
self.is_user_agent_widget
}
}
impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {