mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add is_connected flag to node and use it to replace most uses of is_in_doc
This commit is contained in:
parent
640fc04743
commit
441357b74e
29 changed files with 111 additions and 96 deletions
|
@ -185,8 +185,8 @@ pub trait TNode: Sized + Copy + Clone + Debug + NodeInfo + PartialEq {
|
|||
DomChildren(self.first_child())
|
||||
}
|
||||
|
||||
/// Returns whether the node is attached to a document.
|
||||
fn is_in_document(&self) -> bool;
|
||||
/// Returns whether the node is connected.
|
||||
fn is_connected(&self) -> bool;
|
||||
|
||||
/// Iterate over the DOM children of a node, in preorder.
|
||||
fn dom_descendants(&self) -> DomDescendants<Self> {
|
||||
|
|
|
@ -231,7 +231,7 @@ where
|
|||
// Optimize for when the root is a document or a shadow root and the element
|
||||
// is connected to that root.
|
||||
if root.as_document().is_some() {
|
||||
debug_assert!(element.as_node().is_in_document(), "Not connected?");
|
||||
debug_assert!(element.as_node().is_connected(), "Not connected?");
|
||||
debug_assert_eq!(
|
||||
root,
|
||||
root.owner_doc().as_node(),
|
||||
|
@ -275,18 +275,18 @@ where
|
|||
return Err(());
|
||||
}
|
||||
|
||||
if root.is_in_document() {
|
||||
if root.is_connected() {
|
||||
if let Some(shadow) = root.as_shadow_root() {
|
||||
return shadow.elements_with_id(id);
|
||||
}
|
||||
|
||||
if let Some(shadow) = root.as_element().and_then(|e| e.containing_shadow()) {
|
||||
return shadow.elements_with_id(id);
|
||||
}
|
||||
|
||||
return root.owner_doc().elements_with_id(id);
|
||||
}
|
||||
|
||||
if let Some(shadow) = root.as_shadow_root() {
|
||||
return shadow.elements_with_id(id);
|
||||
}
|
||||
|
||||
if let Some(shadow) = root.as_element().and_then(|e| e.containing_shadow()) {
|
||||
return shadow.elements_with_id(id);
|
||||
}
|
||||
|
||||
Err(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue