mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Merge Node::shadow_including_inclusive_ancestors into inclusive_ancestors
This commit is contained in:
parent
0ca4792dc6
commit
8eba587547
9 changed files with 95 additions and 59 deletions
|
@ -934,7 +934,7 @@ impl Document {
|
|||
|
||||
let el = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
node.inclusive_ancestors()
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
});
|
||||
|
@ -1118,7 +1118,7 @@ impl Document {
|
|||
|
||||
let maybe_new_target = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
node.inclusive_ancestors()
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
});
|
||||
|
@ -1154,7 +1154,7 @@ impl Document {
|
|||
if !old_target_is_ancestor_of_new_target {
|
||||
for element in old_target
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
{
|
||||
element.set_hover_state(false);
|
||||
|
@ -1172,7 +1172,7 @@ impl Document {
|
|||
if let Some(ref new_target) = maybe_new_target {
|
||||
for element in new_target
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
{
|
||||
if element.hover_state() {
|
||||
|
@ -1214,7 +1214,7 @@ impl Document {
|
|||
|
||||
let el = node_address.and_then(|address| {
|
||||
let node = unsafe { node::from_untrusted_node_address(js_runtime, address) };
|
||||
node.inclusive_ancestors()
|
||||
node.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Element>)
|
||||
.next()
|
||||
});
|
||||
|
|
|
@ -73,7 +73,7 @@ use crate::dom::mutationobserver::{Mutation, MutationObserver};
|
|||
use crate::dom::namednodemap::NamedNodeMap;
|
||||
use crate::dom::node::{document_from_node, window_from_node};
|
||||
use crate::dom::node::{BindContext, NodeDamage, NodeFlags, UnbindContext};
|
||||
use crate::dom::node::{ChildrenMutation, LayoutNodeHelpers, Node};
|
||||
use crate::dom::node::{ChildrenMutation, LayoutNodeHelpers, Node, ShadowIncluding};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::raredata::ElementRareData;
|
||||
|
@ -1111,7 +1111,7 @@ impl Element {
|
|||
|
||||
let inclusive_ancestor_elements = self
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<Self>);
|
||||
|
||||
// Steps 3-4.
|
||||
|
@ -1227,7 +1227,7 @@ impl Element {
|
|||
.unwrap()
|
||||
} else {
|
||||
self.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast)
|
||||
.last()
|
||||
.expect("We know inclusive_ancestors will return `self` which is an element")
|
||||
|
@ -1236,7 +1236,10 @@ impl Element {
|
|||
|
||||
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix
|
||||
pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> {
|
||||
for node in self.upcast::<Node>().inclusive_ancestors() {
|
||||
for node in self
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
{
|
||||
let element = node.downcast::<Element>()?;
|
||||
// Step 1.
|
||||
if *element.namespace() == namespace {
|
||||
|
@ -3235,7 +3238,7 @@ impl Element {
|
|||
// https://html.spec.whatwg.org/multipage/#language
|
||||
pub fn get_lang(&self) -> String {
|
||||
self.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(|node| {
|
||||
node.downcast::<Element>().and_then(|el| {
|
||||
el.get_attribute(&ns!(xml), &local_name!("lang"))
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::dom::htmlformelement::HTMLFormElement;
|
|||
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
|
||||
use crate::dom::htmlscriptelement::HTMLScriptElement;
|
||||
use crate::dom::htmlselectelement::HTMLSelectElement;
|
||||
use crate::dom::node::{BindContext, Node, UnbindContext};
|
||||
use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
|
||||
use crate::dom::text::Text;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -251,7 +251,7 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
|
||||
if let Some(select) = context
|
||||
.parent
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<HTMLSelectElement>)
|
||||
.next()
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
|||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::mutationrecord::MutationRecord;
|
||||
use crate::dom::node::Node;
|
||||
use crate::dom::node::{Node, ShadowIncluding};
|
||||
use crate::dom::window::Window;
|
||||
use crate::microtask::Microtask;
|
||||
use crate::script_thread::ScriptThread;
|
||||
|
@ -131,7 +131,7 @@ impl MutationObserver {
|
|||
let mut interested_observers: Vec<(DomRoot<MutationObserver>, Option<DOMString>)> = vec![];
|
||||
|
||||
// Step 2 & 3
|
||||
for node in target.inclusive_ancestors() {
|
||||
for node in target.inclusive_ancestors(ShadowIncluding::No) {
|
||||
for registered in &*node.registered_mutation_observers() {
|
||||
if &*node != target && !registered.options.subtree {
|
||||
continue;
|
||||
|
|
|
@ -559,7 +559,7 @@ impl Node {
|
|||
pub fn note_dirty_descendants(&self) {
|
||||
debug_assert!(self.is_in_doc());
|
||||
|
||||
for ancestor in self.shadow_including_inclusive_ancestors() {
|
||||
for ancestor in self.inclusive_ancestors(ShadowIncluding::Yes) {
|
||||
if ancestor.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS) {
|
||||
return;
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ impl Node {
|
|||
self.inclusive_descendants_version(),
|
||||
doc.inclusive_descendants_version(),
|
||||
) + 1;
|
||||
for ancestor in self.inclusive_ancestors() {
|
||||
for ancestor in self.inclusive_ancestors(ShadowIncluding::No) {
|
||||
ancestor.inclusive_descendants_version.set(version);
|
||||
}
|
||||
doc.inclusive_descendants_version.set(version);
|
||||
|
@ -638,7 +638,7 @@ impl Node {
|
|||
}
|
||||
|
||||
fn is_shadow_including_inclusive_ancestor_of(&self, node: &Node) -> bool {
|
||||
node.shadow_including_inclusive_ancestors()
|
||||
node.inclusive_ancestors(ShadowIncluding::Yes)
|
||||
.any(|ancestor| &*ancestor == self)
|
||||
}
|
||||
|
||||
|
@ -900,25 +900,22 @@ impl Node {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn inclusive_ancestors(&self) -> Box<Iterator<Item = DomRoot<Node>>> {
|
||||
Box::new(SimpleNodeIterator {
|
||||
current: Some(DomRoot::from_ref(self)),
|
||||
next_node: |n| n.GetParentNode(),
|
||||
})
|
||||
}
|
||||
|
||||
/// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor
|
||||
pub fn shadow_including_inclusive_ancestors(&self) -> Box<Iterator<Item = DomRoot<Node>>> {
|
||||
Box::new(SimpleNodeIterator {
|
||||
pub fn inclusive_ancestors(
|
||||
&self,
|
||||
shadow_including: ShadowIncluding,
|
||||
) -> impl Iterator<Item = DomRoot<Node>> {
|
||||
SimpleNodeIterator {
|
||||
current: Some(DomRoot::from_ref(self)),
|
||||
next_node: |n| {
|
||||
next_node: move |n| {
|
||||
if shadow_including == ShadowIncluding::Yes {
|
||||
if let Some(shadow_root) = n.downcast::<ShadowRoot>() {
|
||||
Some(DomRoot::from_ref(shadow_root.Host().upcast::<Node>()))
|
||||
} else {
|
||||
n.GetParentNode()
|
||||
return Some(DomRoot::from_ref(shadow_root.Host().upcast::<Node>()));
|
||||
}
|
||||
}
|
||||
n.GetParentNode()
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn owner_doc(&self) -> DomRoot<Document> {
|
||||
|
@ -1436,7 +1433,7 @@ impl FollowingNodeIterator {
|
|||
return current.GetNextSibling();
|
||||
}
|
||||
|
||||
for ancestor in current.inclusive_ancestors() {
|
||||
for ancestor in current.inclusive_ancestors(ShadowIncluding::No) {
|
||||
if self.root == ancestor {
|
||||
break;
|
||||
}
|
||||
|
@ -1545,11 +1542,11 @@ impl TreeIterator {
|
|||
}
|
||||
|
||||
fn next_skipping_children_impl(&mut self, current: DomRoot<Node>) -> Option<DomRoot<Node>> {
|
||||
let iter = if self.shadow_including {
|
||||
current.shadow_including_inclusive_ancestors()
|
||||
let iter = current.inclusive_ancestors(if self.shadow_including {
|
||||
ShadowIncluding::Yes
|
||||
} else {
|
||||
current.inclusive_ancestors()
|
||||
};
|
||||
ShadowIncluding::No
|
||||
});
|
||||
|
||||
for ancestor in iter {
|
||||
if self.depth == 0 {
|
||||
|
@ -2282,7 +2279,9 @@ impl NodeMethods for Node {
|
|||
return shadow_root.Host().upcast::<Node>().GetRootNode(options);
|
||||
}
|
||||
}
|
||||
self.inclusive_ancestors().last().unwrap()
|
||||
self.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-parentnode
|
||||
|
@ -2687,8 +2686,12 @@ impl NodeMethods for Node {
|
|||
|
||||
// FIXME(emilio): This will eventually need to handle attribute nodes.
|
||||
|
||||
let mut self_and_ancestors = self.inclusive_ancestors().collect::<SmallVec<[_; 20]>>();
|
||||
let mut other_and_ancestors = other.inclusive_ancestors().collect::<SmallVec<[_; 20]>>();
|
||||
let mut self_and_ancestors = self
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.collect::<SmallVec<[_; 20]>>();
|
||||
let mut other_and_ancestors = other
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.collect::<SmallVec<[_; 20]>>();
|
||||
|
||||
if self_and_ancestors.last() != other_and_ancestors.last() {
|
||||
let random = as_uintptr(self_and_ancestors.last().unwrap()) <
|
||||
|
|
|
@ -102,10 +102,10 @@ impl Range {
|
|||
// https://dom.spec.whatwg.org/#partially-contained
|
||||
fn partially_contains(&self, node: &Node) -> bool {
|
||||
self.StartContainer()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.any(|n| &*n == node) !=
|
||||
self.EndContainer()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.any(|n| &*n == node)
|
||||
}
|
||||
|
||||
|
@ -193,8 +193,14 @@ impl Range {
|
|||
// https://dom.spec.whatwg.org/#dom-range-comparepointnode-offset
|
||||
fn compare_point(&self, node: &Node, offset: u32) -> Fallible<Ordering> {
|
||||
let start_node = self.StartContainer();
|
||||
let start_node_root = start_node.inclusive_ancestors().last().unwrap();
|
||||
let node_root = node.inclusive_ancestors().last().unwrap();
|
||||
let start_node_root = start_node
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
let node_root = node
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
if start_node_root != node_root {
|
||||
// Step 1.
|
||||
return Err(Error::WrongDocument);
|
||||
|
@ -253,7 +259,10 @@ impl RangeMethods for Range {
|
|||
fn CommonAncestorContainer(&self) -> DomRoot<Node> {
|
||||
let end_container = self.EndContainer();
|
||||
// Step 1.
|
||||
for container in self.StartContainer().inclusive_ancestors() {
|
||||
for container in self
|
||||
.StartContainer()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
{
|
||||
// Step 2.
|
||||
if container.is_inclusive_ancestor_of(&end_container) {
|
||||
// Step 3.
|
||||
|
@ -368,8 +377,16 @@ impl RangeMethods for Range {
|
|||
// Step 1.
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
let this_root = self.StartContainer().inclusive_ancestors().last().unwrap();
|
||||
let other_root = other.StartContainer().inclusive_ancestors().last().unwrap();
|
||||
let this_root = self
|
||||
.StartContainer()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
let other_root = other
|
||||
.StartContainer()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
if this_root != other_root {
|
||||
// Step 2.
|
||||
return Err(Error::WrongDocument);
|
||||
|
@ -429,8 +446,15 @@ impl RangeMethods for Range {
|
|||
// https://dom.spec.whatwg.org/#dom-range-intersectsnode
|
||||
fn IntersectsNode(&self, node: &Node) -> bool {
|
||||
let start_node = self.StartContainer();
|
||||
let start_node_root = self.StartContainer().inclusive_ancestors().last().unwrap();
|
||||
let node_root = node.inclusive_ancestors().last().unwrap();
|
||||
let start_node_root = self
|
||||
.StartContainer()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
let node_root = node
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
if start_node_root != node_root {
|
||||
// Step 1.
|
||||
return false;
|
||||
|
@ -868,9 +892,9 @@ impl RangeMethods for Range {
|
|||
let end = self.EndContainer();
|
||||
|
||||
if start
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.any(|n| !n.is_inclusive_ancestor_of(&end) && !n.is::<Text>()) ||
|
||||
end.inclusive_ancestors()
|
||||
end.inclusive_ancestors(ShadowIncluding::No)
|
||||
.any(|n| !n.is_inclusive_ancestor_of(&start) && !n.is::<Text>())
|
||||
{
|
||||
return Err(Error::InvalidState);
|
||||
|
@ -1051,7 +1075,7 @@ fn bp_position(a_node: &Node, a_offset: u32, b_node: &Node, b_offset: u32) -> Op
|
|||
}
|
||||
} else if position & NodeConstants::DOCUMENT_POSITION_CONTAINS != 0 {
|
||||
// Step 3-1, 3-2.
|
||||
let mut b_ancestors = b_node.inclusive_ancestors();
|
||||
let mut b_ancestors = b_node.inclusive_ancestors(ShadowIncluding::No);
|
||||
let child = b_ancestors
|
||||
.find(|child| &*child.GetParentNode().unwrap() == a_node)
|
||||
.unwrap();
|
||||
|
|
|
@ -27,7 +27,7 @@ use crate::dom::htmlformelement::{FormControlElementHelpers, HTMLFormElement};
|
|||
use crate::dom::htmlimageelement::HTMLImageElement;
|
||||
use crate::dom::htmlscriptelement::{HTMLScriptElement, ScriptResult};
|
||||
use crate::dom::htmltemplateelement::HTMLTemplateElement;
|
||||
use crate::dom::node::Node;
|
||||
use crate::dom::node::{Node, ShadowIncluding};
|
||||
use crate::dom::performanceentry::PerformanceEntry;
|
||||
use crate::dom::performancenavigationtiming::PerformanceNavigationTiming;
|
||||
use crate::dom::processinginstruction::ProcessingInstruction;
|
||||
|
@ -194,7 +194,7 @@ impl ServoParser {
|
|||
|
||||
// Step 11.
|
||||
let form = context_node
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.find(|element| element.is::<HTMLFormElement>());
|
||||
|
||||
let fragment_context = FragmentContext {
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::dom::document::Document;
|
|||
use crate::dom::documentfragment::DocumentFragment;
|
||||
use crate::dom::documentorshadowroot::{DocumentOrShadowRoot, StyleSheetInDocument};
|
||||
use crate::dom::element::Element;
|
||||
use crate::dom::node::{Node, NodeDamage, NodeFlags};
|
||||
use crate::dom::node::{Node, NodeDamage, NodeFlags, ShadowIncluding};
|
||||
use crate::dom::stylesheetlist::{StyleSheetList, StyleSheetListOwner};
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -140,7 +140,11 @@ impl ShadowRoot {
|
|||
|
||||
/// Associate an element present in this shadow tree with the provided id.
|
||||
pub fn register_named_element(&self, element: &Element, id: Atom) {
|
||||
let root = self.upcast::<Node>().inclusive_ancestors().last().unwrap();
|
||||
let root = self
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.last()
|
||||
.unwrap();
|
||||
self.document_or_shadow_root.register_named_element(
|
||||
self.document_fragment.id_map(),
|
||||
element,
|
||||
|
|
|
@ -51,7 +51,9 @@ use crate::dom::globalscope::GlobalScope;
|
|||
use crate::dom::htmlanchorelement::HTMLAnchorElement;
|
||||
use crate::dom::htmliframeelement::{HTMLIFrameElement, NavigationType};
|
||||
use crate::dom::mutationobserver::MutationObserver;
|
||||
use crate::dom::node::{from_untrusted_node_address, window_from_node, Node, NodeDamage};
|
||||
use crate::dom::node::{
|
||||
from_untrusted_node_address, window_from_node, Node, NodeDamage, ShadowIncluding,
|
||||
};
|
||||
use crate::dom::performanceentry::PerformanceEntry;
|
||||
use crate::dom::performancepainttiming::PerformancePaintTiming;
|
||||
use crate::dom::serviceworker::TrustedServiceWorkerAddress;
|
||||
|
@ -3097,7 +3099,7 @@ impl ScriptThread {
|
|||
if let Some(target) = self.topmost_mouse_over_target.get() {
|
||||
if let Some(anchor) = target
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<HTMLAnchorElement>)
|
||||
.next()
|
||||
{
|
||||
|
@ -3121,7 +3123,7 @@ impl ScriptThread {
|
|||
if let Some(target) = prev_mouse_over_target {
|
||||
if let Some(_) = target
|
||||
.upcast::<Node>()
|
||||
.inclusive_ancestors()
|
||||
.inclusive_ancestors(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast::<HTMLAnchorElement>)
|
||||
.next()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue