mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make traverse_preorder follow shadow roots (#34503)
* script: Ensure shadow-inclusve preorder traversals follow hosted shadow roots. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Handle unregistering element id/name values inside of a shadow root. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Merge shadow root tree iteration logic. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
ad48ab7ec3
commit
4242ff9626
15 changed files with 20733 additions and 123 deletions
|
@ -492,7 +492,7 @@ impl Element {
|
|||
self.ScrollWidth(can_gc) > self.ClientWidth(can_gc)
|
||||
}
|
||||
|
||||
fn shadow_root(&self) -> Option<DomRoot<ShadowRoot>> {
|
||||
pub(crate) fn shadow_root(&self) -> Option<DomRoot<ShadowRoot>> {
|
||||
self.rare_data()
|
||||
.as_ref()?
|
||||
.shadow_root
|
||||
|
@ -3632,19 +3632,21 @@ impl VirtualMethods for Element {
|
|||
|
||||
let doc = document_from_node(self);
|
||||
|
||||
if let Some(ref shadow_root) = self.shadow_root() {
|
||||
shadow_root.unbind_from_tree(context);
|
||||
}
|
||||
|
||||
let fullscreen = doc.GetFullscreenElement();
|
||||
if fullscreen.as_deref() == Some(self) {
|
||||
doc.exit_fullscreen(CanGc::note());
|
||||
}
|
||||
if let Some(ref value) = *self.id_attribute.borrow() {
|
||||
doc.unregister_element_id(self, value.clone());
|
||||
if let Some(ref shadow_root) = self.upcast::<Node>().containing_shadow_root() {
|
||||
shadow_root.unregister_element_id(self, value.clone());
|
||||
} else {
|
||||
doc.unregister_element_id(self, value.clone());
|
||||
}
|
||||
}
|
||||
if let Some(ref value) = self.name_attribute() {
|
||||
doc.unregister_element_name(self, value.clone());
|
||||
if self.upcast::<Node>().containing_shadow_root().is_none() {
|
||||
doc.unregister_element_name(self, value.clone());
|
||||
}
|
||||
}
|
||||
// This is used for layout optimization.
|
||||
doc.decrement_dom_count();
|
||||
|
|
|
@ -1744,9 +1744,14 @@ impl Iterator for TreeIterator {
|
|||
fn next(&mut self) -> Option<DomRoot<Node>> {
|
||||
let current = self.current.take()?;
|
||||
|
||||
if !self.shadow_including {
|
||||
if let Some(element) = current.downcast::<Element>() {
|
||||
if element.is_shadow_host() {
|
||||
// Handle a potential shadow root on the element
|
||||
if let Some(element) = current.downcast::<Element>() {
|
||||
if let Some(shadow_root) = element.shadow_root() {
|
||||
if self.shadow_including {
|
||||
self.current = Some(DomRoot::from_ref(shadow_root.upcast::<Node>()));
|
||||
self.depth += 1;
|
||||
return Some(current);
|
||||
} else {
|
||||
return self.next_skipping_children_impl(current);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,13 +315,6 @@ impl VirtualMethods for ShadowRoot {
|
|||
let document = document_from_node(self);
|
||||
document.unregister_shadow_root(self);
|
||||
}
|
||||
|
||||
let shadow_root = self.upcast::<Node>();
|
||||
shadow_root.set_flag(NodeFlags::IS_CONNECTED, false);
|
||||
for node in shadow_root.children() {
|
||||
node.set_flag(NodeFlags::IS_CONNECTED, false);
|
||||
node.unbind_from_tree(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue