Introduce ShadowIncluding enum for tree traversals

This commit is contained in:
Fernando Jiménez Moreno 2019-02-21 13:19:01 +01:00
parent 2674a3e717
commit 3ccd622c9b
14 changed files with 58 additions and 50 deletions

View file

@ -15,7 +15,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::document::AnimationFrameCallback; use crate::dom::document::AnimationFrameCallback;
use crate::dom::element::Element; use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::node::{window_from_node, Node}; use crate::dom::node::{window_from_node, Node, ShadowIncluding};
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_thread::Documents; use crate::script_thread::Documents;
use devtools_traits::TimelineMarkerType; use devtools_traits::TimelineMarkerType;
@ -103,7 +103,7 @@ fn find_node_by_unique_id(
documents.find_document(pipeline).and_then(|document| { documents.find_document(pipeline).and_then(|document| {
document document
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.find(|candidate| candidate.unique_id() == node_id) .find(|candidate| candidate.unique_id() == node_id)
}) })
} }

View file

@ -26,7 +26,7 @@ use crate::dom::domexception::{DOMErrorName, DOMException};
use crate::dom::element::{CustomElementState, Element}; use crate::dom::element::{CustomElementState, Element};
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::node::{document_from_node, window_from_node, Node}; use crate::dom::node::{document_from_node, window_from_node, Node, ShadowIncluding};
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::microtask::Microtask; use crate::microtask::Microtask;
@ -364,7 +364,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
// Steps 14-15 // Steps 14-15
for candidate in document for candidate in document
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ true) .traverse_preorder(ShadowIncluding::Yes)
.filter_map(DomRoot::downcast::<Element>) .filter_map(DomRoot::downcast::<Element>)
{ {
let is = candidate.get_is(); let is = candidate.get_is();

View file

@ -76,7 +76,7 @@ use crate::dom::messageevent::MessageEvent;
use crate::dom::mouseevent::MouseEvent; use crate::dom::mouseevent::MouseEvent;
use crate::dom::node::VecPreOrderInsertionHelper; use crate::dom::node::VecPreOrderInsertionHelper;
use crate::dom::node::{self, document_from_node, window_from_node, CloneChildrenFlag}; use crate::dom::node::{self, document_from_node, window_from_node, CloneChildrenFlag};
use crate::dom::node::{LayoutNodeHelpers, Node, NodeDamage, NodeFlags}; use crate::dom::node::{LayoutNodeHelpers, Node, NodeDamage, NodeFlags, ShadowIncluding};
use crate::dom::nodeiterator::NodeIterator; use crate::dom::nodeiterator::NodeIterator;
use crate::dom::nodelist::NodeList; use crate::dom::nodelist::NodeList;
use crate::dom::pagetransitionevent::PageTransitionEvent; use crate::dom::pagetransitionevent::PageTransitionEvent;
@ -596,7 +596,7 @@ impl Document {
pub fn refresh_base_element(&self) { pub fn refresh_base_element(&self) {
let base = self let base = self
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<HTMLBaseElement>) .filter_map(DomRoot::downcast::<HTMLBaseElement>)
.find(|element| { .find(|element| {
element element
@ -834,7 +834,7 @@ impl Document {
}; };
let doc_node = self.upcast::<Node>(); let doc_node = self.upcast::<Node>();
doc_node doc_node
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast) .filter_map(DomRoot::downcast)
.find(|node| check_anchor(&node)) .find(|node| check_anchor(&node))
.map(DomRoot::upcast) .map(DomRoot::upcast)
@ -943,7 +943,7 @@ impl Document {
pub fn dirty_all_nodes(&self) { pub fn dirty_all_nodes(&self) {
let root = self.upcast::<Node>(); let root = self.upcast::<Node>();
for node in root.traverse_preorder(/* shadow including */ true) { for node in root.traverse_preorder(ShadowIncluding::Yes) {
node.dirty(NodeDamage::OtherNodeDamage) node.dirty(NodeDamage::OtherNodeDamage)
} }
} }
@ -2238,7 +2238,7 @@ impl Document {
/// Iterate over all iframes in the document. /// Iterate over all iframes in the document.
pub fn iter_iframes(&self) -> impl Iterator<Item = DomRoot<HTMLIFrameElement>> { pub fn iter_iframes(&self) -> impl Iterator<Item = DomRoot<HTMLIFrameElement>> {
self.upcast::<Node>() self.upcast::<Node>()
.traverse_preorder(/* shadow including */ true) .traverse_preorder(ShadowIncluding::Yes)
.filter_map(DomRoot::downcast::<HTMLIFrameElement>) .filter_map(DomRoot::downcast::<HTMLIFrameElement>)
} }
@ -2827,7 +2827,7 @@ impl Document {
let maybe_node = doc.deref().map(Castable::upcast::<Node>); let maybe_node = doc.deref().map(Castable::upcast::<Node>);
let iter = maybe_node let iter = maybe_node
.iter() .iter()
.flat_map(|node| node.traverse_preorder(/* shadow including */ false)) .flat_map(|node| node.traverse_preorder(ShadowIncluding::No))
.filter(|node| callback(&node)); .filter(|node| callback(&node));
NodeList::new_simple_list(&self.window, iter) NodeList::new_simple_list(&self.window, iter)
} }
@ -3726,7 +3726,7 @@ impl DocumentMethods for Document {
} else { } else {
// Step 2. // Step 2.
root.upcast::<Node>() root.upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.find(|node| node.is::<HTMLTitleElement>()) .find(|node| node.is::<HTMLTitleElement>())
} }
}); });
@ -3773,7 +3773,7 @@ impl DocumentMethods for Document {
} else if root.namespace() == &ns!(html) { } else if root.namespace() == &ns!(html) {
let elem = root let elem = root
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.find(|node| node.is::<HTMLTitleElement>()); .find(|node| node.is::<HTMLTitleElement>());
match elem { match elem {
Some(elem) => elem, Some(elem) => elem,
@ -4140,7 +4140,7 @@ impl DocumentMethods for Document {
{ {
// Step 1. // Step 1.
let mut elements = root let mut elements = root
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter(|node| filter_by_name(&name, &node)) .filter(|node| filter_by_name(&name, &node))
.peekable(); .peekable();
if let Some(first) = elements.next() { if let Some(first) = elements.next() {
@ -4268,7 +4268,7 @@ impl DocumentMethods for Document {
// Step 8 // Step 8
for node in self for node in self
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ true) .traverse_preorder(ShadowIncluding::Yes)
{ {
node.upcast::<EventTarget>().remove_all_listeners(); node.upcast::<EventTarget>().remove_all_listeners();
} }

View file

@ -13,7 +13,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document; use crate::dom::document::Document;
use crate::dom::element::Element; use crate::dom::element::Element;
use crate::dom::htmlcollection::HTMLCollection; use crate::dom::htmlcollection::HTMLCollection;
use crate::dom::node::{window_from_node, Node}; use crate::dom::node::{window_from_node, Node, ShadowIncluding};
use crate::dom::nodelist::NodeList; use crate::dom::nodelist::NodeList;
use crate::dom::window::Window; use crate::dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -59,7 +59,7 @@ impl DocumentFragmentMethods for DocumentFragment {
fn GetElementById(&self, id: DOMString) -> Option<DomRoot<Element>> { fn GetElementById(&self, id: DOMString) -> Option<DomRoot<Element>> {
let node = self.upcast::<Node>(); let node = self.upcast::<Node>();
let id = Atom::from(id); let id = Atom::from(id);
node.traverse_preorder(/* shadow including */ false) node.traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<Element>) .filter_map(DomRoot::downcast::<Element>)
.find( .find(
|descendant| match descendant.get_attribute(&ns!(), &local_name!("id")) { |descendant| match descendant.get_attribute(&ns!(), &local_name!("id")) {

View file

@ -28,7 +28,7 @@ use crate::dom::htmlhtmlelement::HTMLHtmlElement;
use crate::dom::htmlinputelement::{HTMLInputElement, InputType}; use crate::dom::htmlinputelement::{HTMLInputElement, InputType};
use crate::dom::htmllabelelement::HTMLLabelElement; use crate::dom::htmllabelelement::HTMLLabelElement;
use crate::dom::node::{document_from_node, window_from_node}; use crate::dom::node::{document_from_node, window_from_node};
use crate::dom::node::{Node, NodeFlags}; use crate::dom::node::{Node, NodeFlags, ShadowIncluding};
use crate::dom::nodelist::NodeList; use crate::dom::nodelist::NodeList;
use crate::dom::text::Text; use crate::dom::text::Text;
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
@ -707,7 +707,7 @@ impl HTMLElement {
let root_element = element.root_element(); let root_element = element.root_element();
let root_node = root_element.upcast::<Node>(); let root_node = root_element.upcast::<Node>();
let children = root_node let children = root_node
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<Element>) .filter_map(DomRoot::downcast::<Element>)
.filter(|elem| elem.is::<HTMLLabelElement>()) .filter(|elem| elem.is::<HTMLLabelElement>())
.filter(|elem| elem.get_string_attribute(&local_name!("for")) == id) .filter(|elem| elem.get_string_attribute(&local_name!("for")) == id)

View file

@ -13,7 +13,7 @@ use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlformelement::{FormControl, HTMLFormElement}; use crate::dom::htmlformelement::{FormControl, HTMLFormElement};
use crate::dom::htmllegendelement::HTMLLegendElement; use crate::dom::htmllegendelement::HTMLLegendElement;
use crate::dom::node::{window_from_node, Node}; use crate::dom::node::{window_from_node, Node, ShadowIncluding};
use crate::dom::validitystate::ValidityState; use crate::dom::validitystate::ValidityState;
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -128,7 +128,7 @@ impl VirtualMethods for HTMLFieldSetElement {
}); });
let fields = children.flat_map(|child| { let fields = children.flat_map(|child| {
child child
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter(|descendant| match descendant.type_id() { .filter(|descendant| match descendant.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement( NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLButtonElement, HTMLElementTypeId::HTMLButtonElement,

View file

@ -41,7 +41,8 @@ use crate::dom::htmloutputelement::HTMLOutputElement;
use crate::dom::htmlselectelement::HTMLSelectElement; use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::htmltextareaelement::HTMLTextAreaElement; use crate::dom::htmltextareaelement::HTMLTextAreaElement;
use crate::dom::node::{document_from_node, window_from_node}; use crate::dom::node::{document_from_node, window_from_node};
use crate::dom::node::{Node, NodeFlags, UnbindContext, VecPreOrderInsertionHelper}; use crate::dom::node::{Node, NodeFlags, ShadowIncluding};
use crate::dom::node::{UnbindContext, VecPreOrderInsertionHelper};
use crate::dom::validitystate::ValidationFlags; use crate::dom::validitystate::ValidationFlags;
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use crate::dom::window::Window; use crate::dom::window::Window;
@ -582,7 +583,7 @@ impl HTMLFormElement {
// form, refactor this when html5ever's form owner PR lands // form, refactor this when html5ever's form owner PR lands
// Step 1-3 // Step 1-3
let invalid_controls = node let invalid_controls = node
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(|field| { .filter_map(|field| {
if let Some(el) = field.downcast::<Element>() { if let Some(el) = field.downcast::<Element>() {
if el.disabled_state() { if el.disabled_state() {

View file

@ -10,7 +10,7 @@ use crate::dom::document::{determine_policy_for_token, Document};
use crate::dom::element::Element; use crate::dom::element::Element;
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlmetaelement::HTMLMetaElement; use crate::dom::htmlmetaelement::HTMLMetaElement;
use crate::dom::node::{document_from_node, Node}; use crate::dom::node::{document_from_node, Node, ShadowIncluding};
use crate::dom::userscripts::load_script; use crate::dom::userscripts::load_script;
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -55,7 +55,7 @@ impl HTMLHeadElement {
let node = self.upcast::<Node>(); let node = self.upcast::<Node>();
let candidates = node let candidates = node
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<Element>) .filter_map(DomRoot::downcast::<Element>)
.filter(|elem| elem.is::<HTMLMetaElement>()) .filter(|elem| elem.is::<HTMLMetaElement>())
.filter(|elem| elem.get_string_attribute(&local_name!("name")) == "referrer") .filter(|elem| elem.get_string_attribute(&local_name!("name")) == "referrer")

View file

@ -32,7 +32,8 @@ use crate::dom::htmlmapelement::HTMLMapElement;
use crate::dom::htmlpictureelement::HTMLPictureElement; use crate::dom::htmlpictureelement::HTMLPictureElement;
use crate::dom::htmlsourceelement::HTMLSourceElement; use crate::dom::htmlsourceelement::HTMLSourceElement;
use crate::dom::mouseevent::MouseEvent; use crate::dom::mouseevent::MouseEvent;
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, UnbindContext}; use crate::dom::node::UnbindContext;
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, ShadowIncluding};
use crate::dom::performanceresourcetiming::InitiatorType; use crate::dom::performanceresourcetiming::InitiatorType;
use crate::dom::progressevent::ProgressEvent; use crate::dom::progressevent::ProgressEvent;
use crate::dom::values::UNSIGNED_LONG_MAX; use crate::dom::values::UNSIGNED_LONG_MAX;
@ -1259,7 +1260,7 @@ impl HTMLImageElement {
let useMapElements = document_from_node(self) let useMapElements = document_from_node(self)
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<HTMLMapElement>) .filter_map(DomRoot::downcast::<HTMLMapElement>)
.find(|n| { .find(|n| {
n.upcast::<Element>() n.upcast::<Element>()

View file

@ -15,7 +15,7 @@ use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlformelement::{FormControl, FormControlElementHelpers, HTMLFormElement}; use crate::dom::htmlformelement::{FormControl, FormControlElementHelpers, HTMLFormElement};
use crate::dom::node::{document_from_node, Node}; use crate::dom::node::{document_from_node, Node, ShadowIncluding};
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix}; use html5ever::{LocalName, Prefix};
@ -162,7 +162,7 @@ impl VirtualMethods for HTMLLabelElement {
impl HTMLLabelElement { impl HTMLLabelElement {
pub fn first_labelable_descendant(&self) -> Option<DomRoot<HTMLElement>> { pub fn first_labelable_descendant(&self) -> Option<DomRoot<HTMLElement>> {
self.upcast::<Node>() self.upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<HTMLElement>) .filter_map(DomRoot::downcast::<HTMLElement>)
.filter(|elem| elem.is_labelable_element()) .filter(|elem| elem.is_labelable_element())
.next() .next()

View file

@ -8,7 +8,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::document::Document; use crate::dom::document::Document;
use crate::dom::htmlareaelement::HTMLAreaElement; use crate::dom::htmlareaelement::HTMLAreaElement;
use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlelement::HTMLElement;
use crate::dom::node::Node; use crate::dom::node::{Node, ShadowIncluding};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix}; use html5ever::{LocalName, Prefix};
@ -43,7 +43,7 @@ impl HTMLMapElement {
pub fn get_area_elements(&self) -> Vec<DomRoot<HTMLAreaElement>> { pub fn get_area_elements(&self) -> Vec<DomRoot<HTMLAreaElement>> {
self.upcast::<Node>() self.upcast::<Node>()
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<HTMLAreaElement>) .filter_map(DomRoot::downcast::<HTMLAreaElement>)
.collect() .collect()
} }

View file

@ -293,7 +293,7 @@ impl Node {
let parent_in_shadow_tree = self.is_in_shadow_tree(); let parent_in_shadow_tree = self.is_in_shadow_tree();
let parent_is_connected = self.is_connected(); let parent_is_connected = self.is_connected();
for node in new_child.traverse_preorder(/* shadow including */ false) { for node in new_child.traverse_preorder(ShadowIncluding::No) {
if parent_in_shadow_tree { if parent_in_shadow_tree {
if let Some(shadow_root) = self.downcast::<ShadowRoot>() { if let Some(shadow_root) = self.downcast::<ShadowRoot>() {
node.set_owner_shadow_root(&*shadow_root); node.set_owner_shadow_root(&*shadow_root);
@ -351,7 +351,7 @@ impl Node {
child.composed_parent_node.set(None); child.composed_parent_node.set(None);
self.children_count.set(self.children_count.get() - 1); self.children_count.set(self.children_count.get() - 1);
for node in child.traverse_preorder(/* shadow including */ true) { for node in child.traverse_preorder(ShadowIncluding::Yes) {
// Out-of-document elements never have the descendants flag set. // Out-of-document elements never have the descendants flag set.
node.set_flag( node.set_flag(
NodeFlags::IS_IN_DOC | NodeFlags::IS_IN_DOC |
@ -362,7 +362,7 @@ impl Node {
false, false,
); );
} }
for node in child.traverse_preorder(/* shadow including */ true) { for node in child.traverse_preorder(ShadowIncluding::Yes) {
// This needs to be in its own loop, because unbind_from_tree may // This needs to be in its own loop, because unbind_from_tree may
// rely on the state of IS_IN_DOC of the context node's descendants, // rely on the state of IS_IN_DOC of the context node's descendants,
// e.g. when removing a <form>. // e.g. when removing a <form>.
@ -625,7 +625,7 @@ impl Node {
} }
/// Iterates over this node and all its descendants, in preorder. /// Iterates over this node and all its descendants, in preorder.
pub fn traverse_preorder(&self, shadow_including: bool) -> TreeIterator { pub fn traverse_preorder(&self, shadow_including: ShadowIncluding) -> TreeIterator {
TreeIterator::new(self, shadow_including) TreeIterator::new(self, shadow_including)
} }
@ -873,7 +873,7 @@ impl Node {
self.owner_doc().quirks_mode(), self.owner_doc().quirks_mode(),
); );
Ok(self Ok(self
.traverse_preorder(/* shadow including */ false) .traverse_preorder(ShadowIncluding::No)
.filter_map(DomRoot::downcast) .filter_map(DomRoot::downcast)
.find(|element| matches_selector_list(&selectors, element, &mut ctx))) .find(|element| matches_selector_list(&selectors, element, &mut ctx)))
}, },
@ -891,7 +891,7 @@ impl Node {
Err(_) => Err(Error::Syntax), Err(_) => Err(Error::Syntax),
// Step 3. // Step 3.
Ok(selectors) => { Ok(selectors) => {
let mut descendants = self.traverse_preorder(/* shadow including */ false); let mut descendants = self.traverse_preorder(ShadowIncluding::No);
// Skip the root of the tree. // Skip the root of the tree.
assert!(&*descendants.next().unwrap() == self); assert!(&*descendants.next().unwrap() == self);
Ok(QuerySelectorIterator::new(descendants, selectors)) Ok(QuerySelectorIterator::new(descendants, selectors))
@ -1510,6 +1510,13 @@ where
} }
} }
/// Whether a tree traversal should pass shadow tree boundaries.
#[derive(PartialEq)]
pub enum ShadowIncluding {
No,
Yes,
}
pub struct TreeIterator { pub struct TreeIterator {
current: Option<DomRoot<Node>>, current: Option<DomRoot<Node>>,
depth: usize, depth: usize,
@ -1517,11 +1524,11 @@ pub struct TreeIterator {
} }
impl TreeIterator { impl TreeIterator {
fn new(root: &Node, shadow_including: bool) -> TreeIterator { fn new(root: &Node, shadow_including: ShadowIncluding) -> TreeIterator {
TreeIterator { TreeIterator {
current: Some(DomRoot::from_ref(root)), current: Some(DomRoot::from_ref(root)),
depth: 0, depth: 0,
shadow_including, shadow_including: shadow_including == ShadowIncluding::Yes,
} }
} }
@ -1655,11 +1662,11 @@ impl Node {
// Step 3. // Step 3.
if &*old_doc != document { if &*old_doc != document {
// Step 3.1. // Step 3.1.
for descendant in node.traverse_preorder(/* shadow including */ true) { for descendant in node.traverse_preorder(ShadowIncluding::Yes) {
descendant.set_owner_doc(document); descendant.set_owner_doc(document);
} }
for descendant in node for descendant in node
.traverse_preorder(/* shadow including */ true) .traverse_preorder(ShadowIncluding::Yes)
.filter_map(|d| d.as_custom_element()) .filter_map(|d| d.as_custom_element())
{ {
// Step 3.2. // Step 3.2.
@ -1669,7 +1676,7 @@ impl Node {
None, None,
); );
} }
for descendant in node.traverse_preorder(/* shadow including */ true) { for descendant in node.traverse_preorder(ShadowIncluding::Yes) {
// Step 3.3. // Step 3.3.
vtable_for(&descendant).adopting_steps(&old_doc); vtable_for(&descendant).adopting_steps(&old_doc);
} }
@ -1890,7 +1897,7 @@ impl Node {
parent.add_child(*kid, child); parent.add_child(*kid, child);
// Step 7.7. // Step 7.7.
for descendant in kid for descendant in kid
.traverse_preorder(/* shadow including */ true) .traverse_preorder(ShadowIncluding::Yes)
.filter_map(DomRoot::downcast::<Element>) .filter_map(DomRoot::downcast::<Element>)
{ {
// Step 7.7.2. // Step 7.7.2.
@ -2335,9 +2342,8 @@ impl NodeMethods for Node {
fn GetTextContent(&self) -> Option<DOMString> { fn GetTextContent(&self) -> Option<DOMString> {
match self.type_id() { match self.type_id() {
NodeTypeId::DocumentFragment(_) | NodeTypeId::Element(..) => { NodeTypeId::DocumentFragment(_) | NodeTypeId::Element(..) => {
let content = Node::collect_text_contents( let content =
self.traverse_preorder(/* shadow including */ false), Node::collect_text_contents(self.traverse_preorder(ShadowIncluding::No));
);
Some(content) Some(content)
}, },
NodeTypeId::CharacterData(..) => { NodeTypeId::CharacterData(..) => {
@ -3190,7 +3196,7 @@ where
let elem_node = elem.upcast::<Node>(); let elem_node = elem.upcast::<Node>();
let mut head: usize = 0; let mut head: usize = 0;
for node in tree_root.traverse_preorder(/* shadow including */ false) { for node in tree_root.traverse_preorder(ShadowIncluding::No) {
let head_node = DomRoot::upcast::<Node>(DomRoot::from_ref(&*self[head])); let head_node = DomRoot::upcast::<Node>(DomRoot::from_ref(&*self[head]));
if head_node == node { if head_node == node {
head += 1; head += 1;

View file

@ -24,7 +24,7 @@ use crate::dom::document::Document;
use crate::dom::documentfragment::DocumentFragment; use crate::dom::documentfragment::DocumentFragment;
use crate::dom::element::Element; use crate::dom::element::Element;
use crate::dom::htmlscriptelement::HTMLScriptElement; use crate::dom::htmlscriptelement::HTMLScriptElement;
use crate::dom::node::{Node, UnbindContext}; use crate::dom::node::{Node, ShadowIncluding, UnbindContext};
use crate::dom::text::Text; use crate::dom::text::Text;
use crate::dom::window::Window; use crate::dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -978,7 +978,7 @@ impl RangeMethods for Range {
// Step 4. // Step 4.
for node in fragment_node for node in fragment_node
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow incluing */ false) .traverse_preorder(ShadowIncluding::No)
{ {
if let Some(script) = node.downcast::<HTMLScriptElement>() { if let Some(script) = node.downcast::<HTMLScriptElement>() {
script.set_already_started(false); script.set_already_started(false);

View file

@ -22,7 +22,7 @@ use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmliframeelement::HTMLIFrameElement; use crate::dom::htmliframeelement::HTMLIFrameElement;
use crate::dom::htmlinputelement::HTMLInputElement; use crate::dom::htmlinputelement::HTMLInputElement;
use crate::dom::htmloptionelement::HTMLOptionElement; use crate::dom::htmloptionelement::HTMLOptionElement;
use crate::dom::node::{window_from_node, Node}; use crate::dom::node::{window_from_node, Node, ShadowIncluding};
use crate::script_thread::Documents; use crate::script_thread::Documents;
use cookie::Cookie; use cookie::Cookie;
use euclid::{Point2D, Rect, Size2D}; use euclid::{Point2D, Rect, Size2D};
@ -50,7 +50,7 @@ fn find_node_by_unique_id(
documents.find_document(pipeline).and_then(|document| { documents.find_document(pipeline).and_then(|document| {
document document
.upcast::<Node>() .upcast::<Node>()
.traverse_preorder(/* shadow including */ true) .traverse_preorder(ShadowIncluding::Yes)
.find(|candidate| candidate.unique_id() == node_id) .find(|candidate| candidate.unique_id() == node_id)
}) })
} }