Rename Root<T> to DomRoot<T>

In a later PR, DomRoot<T> will become a type alias of Root<Dom<T>>,
where Root<T> will be able to handle all the things that need to be
rooted that have a stable traceable address that doesn't move for the
whole lifetime of the root. Stay tuned.
This commit is contained in:
Anthony Ramine 2017-09-26 01:53:40 +02:00
parent 577370746e
commit f87c2a8d76
291 changed files with 1774 additions and 1770 deletions

View file

@ -23,7 +23,7 @@ use dom::bindings::inheritance::{Castable, CharacterDataTypeId, ElementTypeId};
use dom::bindings::inheritance::{EventTargetTypeId, HTMLElementTypeId, NodeTypeId};
use dom::bindings::inheritance::{SVGElementTypeId, SVGGraphicsElementTypeId};
use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::root::{Dom, LayoutDom, MutNullableDom, Root, RootedReference};
use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom, RootedReference};
use dom::bindings::str::{DOMString, USVString};
use dom::bindings::xmlname::namespace_from_domstring;
use dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
@ -327,10 +327,10 @@ impl Node {
UntrustedNodeAddress(self.reflector().get_jsobject().get() as *const c_void)
}
pub fn as_custom_element(&self) -> Option<Root<Element>> {
pub fn as_custom_element(&self) -> Option<DomRoot<Element>> {
self.downcast::<Element>()
.and_then(|element| if element.get_custom_element_definition().is_some() {
Some(Root::from_ref(element))
Some(DomRoot::from_ref(element))
} else {
None
})
@ -353,9 +353,9 @@ impl<'a> QuerySelectorIterator {
}
impl<'a> Iterator for QuerySelectorIterator {
type Item = Root<Node>;
type Item = DomRoot<Node>;
fn next(&mut self) -> Option<Root<Node>> {
fn next(&mut self) -> Option<DomRoot<Node>> {
let selectors = &self.selectors;
self.iterator.by_ref().filter_map(|node| {
@ -365,9 +365,9 @@ impl<'a> Iterator for QuerySelectorIterator {
// FIXME(bholley): Consider an nth-index cache here.
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
node.owner_doc().quirks_mode());
if let Some(element) = Root::downcast(node) {
if let Some(element) = DomRoot::downcast(node) {
if matches_selector_list(selectors, &element, &mut ctx) {
return Some(Root::upcast(element));
return Some(DomRoot::upcast(element));
}
}
None
@ -497,7 +497,7 @@ impl Node {
// its descendants version, and the document's version. Normally, this will just be
// the document's version, but we do have to deal with the case where the node has moved
// document, so may have a higher version count than its owning document.
let doc: Root<Node> = Root::upcast(self.owner_doc());
let doc: DomRoot<Node> = DomRoot::upcast(self.owner_doc());
let version = cmp::max(self.inclusive_descendants_version(), doc.inclusive_descendants_version()) + 1;
for ancestor in self.inclusive_ancestors() {
ancestor.inclusive_descendants_version.set(version);
@ -530,16 +530,16 @@ impl Node {
TreeIterator::new(self)
}
pub fn inclusively_following_siblings(&self) -> impl Iterator<Item=Root<Node>> {
pub fn inclusively_following_siblings(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: Some(Root::from_ref(self)),
current: Some(DomRoot::from_ref(self)),
next_node: |n| n.GetNextSibling(),
}
}
pub fn inclusively_preceding_siblings(&self) -> impl Iterator<Item=Root<Node>> {
pub fn inclusively_preceding_siblings(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: Some(Root::from_ref(self)),
current: Some(DomRoot::from_ref(self)),
next_node: |n| n.GetPreviousSibling(),
}
}
@ -552,14 +552,14 @@ impl Node {
parent.ancestors().any(|ancestor| &*ancestor == self)
}
pub fn following_siblings(&self) -> impl Iterator<Item=Root<Node>> {
pub fn following_siblings(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: self.GetNextSibling(),
next_node: |n| n.GetNextSibling(),
}
}
pub fn preceding_siblings(&self) -> impl Iterator<Item=Root<Node>> {
pub fn preceding_siblings(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: self.GetPreviousSibling(),
next_node: |n| n.GetPreviousSibling(),
@ -568,19 +568,19 @@ impl Node {
pub fn following_nodes(&self, root: &Node) -> FollowingNodeIterator {
FollowingNodeIterator {
current: Some(Root::from_ref(self)),
root: Root::from_ref(root),
current: Some(DomRoot::from_ref(self)),
root: DomRoot::from_ref(root),
}
}
pub fn preceding_nodes(&self, root: &Node) -> PrecedingNodeIterator {
PrecedingNodeIterator {
current: Some(Root::from_ref(self)),
root: Root::from_ref(root),
current: Some(DomRoot::from_ref(self)),
root: DomRoot::from_ref(root),
}
}
pub fn descending_last_children(&self) -> impl Iterator<Item=Root<Node>> {
pub fn descending_last_children(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: self.GetLastChild(),
next_node: |n| n.GetLastChild(),
@ -747,7 +747,7 @@ impl Node {
}
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
// Step 1.
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2.
@ -757,7 +757,7 @@ impl Node {
// FIXME(bholley): Consider an nth-index cache here.
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
self.owner_doc().quirks_mode());
Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| {
Ok(self.traverse_preorder().filter_map(DomRoot::downcast).find(|element| {
matches_selector_list(&selectors, element, &mut ctx)
}))
}
@ -786,27 +786,27 @@ impl Node {
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
#[allow(unsafe_code)]
pub fn query_selector_all(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
pub fn query_selector_all(&self, selectors: DOMString) -> Fallible<DomRoot<NodeList>> {
let window = window_from_node(self);
let iter = self.query_selector_iter(selectors)?;
Ok(NodeList::new_simple_list(&window, iter))
}
pub fn ancestors(&self) -> impl Iterator<Item=Root<Node>> {
pub fn ancestors(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: self.GetParentNode(),
next_node: |n| n.GetParentNode(),
}
}
pub fn inclusive_ancestors(&self) -> impl Iterator<Item=Root<Node>> {
pub fn inclusive_ancestors(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: Some(Root::from_ref(self)),
current: Some(DomRoot::from_ref(self)),
next_node: |n| n.GetParentNode(),
}
}
pub fn owner_doc(&self) -> Root<Document> {
pub fn owner_doc(&self) -> DomRoot<Document> {
self.owner_doc.get().unwrap()
}
@ -822,22 +822,22 @@ impl Node {
self.is_in_doc() && self.owner_doc().browsing_context().is_some()
}
pub fn children(&self) -> impl Iterator<Item=Root<Node>> {
pub fn children(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: self.GetFirstChild(),
next_node: |n| n.GetNextSibling(),
}
}
pub fn rev_children(&self) -> impl Iterator<Item=Root<Node>> {
pub fn rev_children(&self) -> impl Iterator<Item=DomRoot<Node>> {
SimpleNodeIterator {
current: self.GetLastChild(),
next_node: |n| n.GetPreviousSibling(),
}
}
pub fn child_elements(&self) -> impl Iterator<Item=Root<Element>> {
self.children().filter_map(Root::downcast as fn(_) -> _).peekable()
pub fn child_elements(&self) -> impl Iterator<Item=DomRoot<Element>> {
self.children().filter_map(DomRoot::downcast as fn(_) -> _).peekable()
}
pub fn remove_self(&self) {
@ -878,9 +878,9 @@ impl Node {
}
/// Used by `HTMLTableSectionElement::InsertRow` and `HTMLTableRowElement::InsertCell`
pub fn insert_cell_or_row<F, G, I>(&self, index: i32, get_items: F, new_child: G) -> Fallible<Root<HTMLElement>>
where F: Fn() -> Root<HTMLCollection>,
G: Fn() -> Root<I>,
pub fn insert_cell_or_row<F, G, I>(&self, index: i32, get_items: F, new_child: G) -> Fallible<DomRoot<HTMLElement>>
where F: Fn() -> DomRoot<HTMLCollection>,
G: Fn() -> DomRoot<I>,
I: DerivedFrom<Node> + DerivedFrom<HTMLElement> + DomObject,
{
if index < -1 {
@ -897,7 +897,7 @@ impl Node {
} else {
let items = get_items();
let node = match items.elements_iter()
.map(Root::upcast::<Node>)
.map(DomRoot::upcast::<Node>)
.map(Some)
.chain(iter::once(None))
.nth(index as usize) {
@ -908,12 +908,12 @@ impl Node {
}
}
Ok(Root::upcast::<HTMLElement>(tr))
Ok(DomRoot::upcast::<HTMLElement>(tr))
}
/// Used by `HTMLTableSectionElement::DeleteRow` and `HTMLTableRowElement::DeleteCell`
pub fn delete_cell_or_row<F, G>(&self, index: i32, get_items: F, is_delete_type: G) -> ErrorResult
where F: Fn() -> Root<HTMLCollection>,
where F: Fn() -> DomRoot<HTMLCollection>,
G: Fn(&Element) -> bool
{
let element = match index {
@ -921,7 +921,7 @@ impl Node {
-1 => {
let last_child = self.upcast::<Node>().GetLastChild();
match last_child.and_then(|node| node.inclusively_preceding_siblings()
.filter_map(Root::downcast::<Element>)
.filter_map(DomRoot::downcast::<Element>)
.filter(|elem| is_delete_type(elem))
.next()) {
Some(element) => element,
@ -950,7 +950,7 @@ impl Node {
}
}
pub fn get_cssom_stylesheet(&self) -> Option<Root<CSSStyleSheet>> {
pub fn get_cssom_stylesheet(&self) -> Option<DomRoot<CSSStyleSheet>> {
if let Some(node) = self.downcast::<HTMLStyleElement>() {
node.get_cssom_stylesheet()
} else if let Some(node) = self.downcast::<HTMLLinkElement>() {
@ -965,8 +965,8 @@ impl Node {
/// Iterate through `nodes` until we find a `Node` that is not in `not_in`
fn first_node_not_in<I>(mut nodes: I, not_in: &[NodeOrString]) -> Option<Root<Node>>
where I: Iterator<Item=Root<Node>>
fn first_node_not_in<I>(mut nodes: I, not_in: &[NodeOrString]) -> Option<DomRoot<Node>>
where I: Iterator<Item=DomRoot<Node>>
{
nodes.find(|node| {
not_in.iter().all(|n| {
@ -982,7 +982,7 @@ fn first_node_not_in<I>(mut nodes: I, not_in: &[NodeOrString]) -> Option<Root<No
/// returns it.
#[allow(unsafe_code)]
pub unsafe fn from_untrusted_node_address(_runtime: *mut JSRuntime, candidate: UntrustedNodeAddress)
-> Root<Node> {
-> DomRoot<Node> {
// https://github.com/servo/servo/issues/6383
let candidate: uintptr_t = mem::transmute(candidate.0);
// let object: *mut JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime,
@ -992,7 +992,7 @@ pub unsafe fn from_untrusted_node_address(_runtime: *mut JSRuntime, candidate: U
panic!("Attempted to create a `Dom<Node>` from an invalid pointer!")
}
let boxed_node = conversions::private_from_object(object) as *const Node;
Root::from_ref(&*boxed_node)
DomRoot::from_ref(&*boxed_node)
}
#[allow(unsafe_code)]
@ -1199,13 +1199,13 @@ impl LayoutNodeHelpers for LayoutDom<Node> {
//
pub struct FollowingNodeIterator {
current: Option<Root<Node>>,
root: Root<Node>,
current: Option<DomRoot<Node>>,
root: DomRoot<Node>,
}
impl FollowingNodeIterator {
/// Skips iterating the children of the current node
pub fn next_skipping_children(&mut self) -> Option<Root<Node>> {
pub fn next_skipping_children(&mut self) -> Option<DomRoot<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
@ -1214,7 +1214,7 @@ impl FollowingNodeIterator {
self.next_skipping_children_impl(current)
}
fn next_skipping_children_impl(&mut self, current: Root<Node>) -> Option<Root<Node>> {
fn next_skipping_children_impl(&mut self, current: DomRoot<Node>) -> Option<DomRoot<Node>> {
if self.root == current {
self.current = None;
return None;
@ -1240,10 +1240,10 @@ impl FollowingNodeIterator {
}
impl Iterator for FollowingNodeIterator {
type Item = Root<Node>;
type Item = DomRoot<Node>;
// https://dom.spec.whatwg.org/#concept-tree-following
fn next(&mut self) -> Option<Root<Node>> {
fn next(&mut self) -> Option<DomRoot<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
@ -1259,15 +1259,15 @@ impl Iterator for FollowingNodeIterator {
}
pub struct PrecedingNodeIterator {
current: Option<Root<Node>>,
root: Root<Node>,
current: Option<DomRoot<Node>>,
root: DomRoot<Node>,
}
impl Iterator for PrecedingNodeIterator {
type Item = Root<Node>;
type Item = DomRoot<Node>;
// https://dom.spec.whatwg.org/#concept-tree-preceding
fn next(&mut self) -> Option<Root<Node>> {
fn next(&mut self) -> Option<DomRoot<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
@ -1291,16 +1291,16 @@ impl Iterator for PrecedingNodeIterator {
}
struct SimpleNodeIterator<I>
where I: Fn(&Node) -> Option<Root<Node>>
where I: Fn(&Node) -> Option<DomRoot<Node>>
{
current: Option<Root<Node>>,
current: Option<DomRoot<Node>>,
next_node: I,
}
impl<I> Iterator for SimpleNodeIterator<I>
where I: Fn(&Node) -> Option<Root<Node>>
where I: Fn(&Node) -> Option<DomRoot<Node>>
{
type Item = Root<Node>;
type Item = DomRoot<Node>;
fn next(&mut self) -> Option<Self::Item> {
let current = self.current.take();
@ -1310,19 +1310,19 @@ impl<I> Iterator for SimpleNodeIterator<I>
}
pub struct TreeIterator {
current: Option<Root<Node>>,
current: Option<DomRoot<Node>>,
depth: usize,
}
impl TreeIterator {
fn new(root: &Node) -> TreeIterator {
TreeIterator {
current: Some(Root::from_ref(root)),
current: Some(DomRoot::from_ref(root)),
depth: 0,
}
}
pub fn next_skipping_children(&mut self) -> Option<Root<Node>> {
pub fn next_skipping_children(&mut self) -> Option<DomRoot<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
@ -1331,7 +1331,7 @@ impl TreeIterator {
self.next_skipping_children_impl(current)
}
fn next_skipping_children_impl(&mut self, current: Root<Node>) -> Option<Root<Node>> {
fn next_skipping_children_impl(&mut self, current: DomRoot<Node>) -> Option<DomRoot<Node>> {
for ancestor in current.inclusive_ancestors() {
if self.depth == 0 {
break;
@ -1349,10 +1349,10 @@ impl TreeIterator {
}
impl Iterator for TreeIterator {
type Item = Root<Node>;
type Item = DomRoot<Node>;
// https://dom.spec.whatwg.org/#concept-tree-order
fn next(&mut self) -> Option<Root<Node>> {
fn next(&mut self) -> Option<DomRoot<Node>> {
let current = match self.current.take() {
None => return None,
Some(current) => current,
@ -1380,8 +1380,8 @@ impl Node {
pub fn reflect_node<N>(
node: Box<N>,
document: &Document,
wrap_fn: unsafe extern "Rust" fn(*mut JSContext, &GlobalScope, Box<N>) -> Root<N>)
-> Root<N>
wrap_fn: unsafe extern "Rust" fn(*mut JSContext, &GlobalScope, Box<N>) -> DomRoot<N>)
-> DomRoot<N>
where N: DerivedFrom<Node> + DomObject
{
let window = document.window();
@ -1437,7 +1437,7 @@ impl Node {
for descendant in node.traverse_preorder().filter_map(|d| d.as_custom_element()) {
// Step 3.2.
ScriptThread::enqueue_callback_reaction(&*descendant,
CallbackReaction::Adopted(old_doc.clone(), Root::from_ref(document)), None);
CallbackReaction::Adopted(old_doc.clone(), DomRoot::from_ref(document)), None);
}
for descendant in node.traverse_preorder() {
// Step 3.3.
@ -1562,7 +1562,7 @@ impl Node {
// https://dom.spec.whatwg.org/#concept-node-pre-insert
pub fn pre_insert(node: &Node, parent: &Node, child: Option<&Node>)
-> Fallible<Root<Node>> {
-> Fallible<DomRoot<Node>> {
// Step 1.
Node::ensure_pre_insertion_validity(node, parent, child)?;
@ -1584,7 +1584,7 @@ impl Node {
Node::insert(node, parent, reference_child, SuppressObserver::Unsuppressed);
// Step 6.
Ok(Root::from_ref(node))
Ok(DomRoot::from_ref(node))
}
// https://dom.spec.whatwg.org/#concept-node-insert
@ -1648,7 +1648,7 @@ impl Node {
// Step 7.1.
parent.add_child(*kid, child);
// Step 7.7.
for descendant in kid.traverse_preorder().filter_map(Root::downcast::<Element>) {
for descendant in kid.traverse_preorder().filter_map(DomRoot::downcast::<Element>) {
// Step 7.7.2.
if descendant.is_connected() {
if descendant.get_custom_element_definition().is_some() {
@ -1719,7 +1719,7 @@ impl Node {
}
// https://dom.spec.whatwg.org/#concept-node-pre-remove
fn pre_remove(child: &Node, parent: &Node) -> Fallible<Root<Node>> {
fn pre_remove(child: &Node, parent: &Node) -> Fallible<DomRoot<Node>> {
// Step 1.
match child.GetParentNode() {
Some(ref node) if &**node != parent => return Err(Error::NotFound),
@ -1731,7 +1731,7 @@ impl Node {
Node::remove(child, parent, SuppressObserver::Unsuppressed);
// Step 3.
Ok(Root::from_ref(child))
Ok(DomRoot::from_ref(child))
}
// https://dom.spec.whatwg.org/#concept-node-remove
@ -1780,27 +1780,27 @@ impl Node {
// https://dom.spec.whatwg.org/#concept-node-clone
pub fn clone(node: &Node, maybe_doc: Option<&Document>,
clone_children: CloneChildrenFlag) -> Root<Node> {
clone_children: CloneChildrenFlag) -> DomRoot<Node> {
// Step 1.
let document = match maybe_doc {
Some(doc) => Root::from_ref(doc),
Some(doc) => DomRoot::from_ref(doc),
None => node.owner_doc()
};
// Step 2.
// XXXabinader: clone() for each node as trait?
let copy: Root<Node> = match node.type_id() {
let copy: DomRoot<Node> = match node.type_id() {
NodeTypeId::DocumentType => {
let doctype = node.downcast::<DocumentType>().unwrap();
let doctype = DocumentType::new(doctype.name().clone(),
Some(doctype.public_id().clone()),
Some(doctype.system_id().clone()),
&document);
Root::upcast::<Node>(doctype)
DomRoot::upcast::<Node>(doctype)
},
NodeTypeId::DocumentFragment => {
let doc_fragment = DocumentFragment::new(&document);
Root::upcast::<Node>(doc_fragment)
DomRoot::upcast::<Node>(doc_fragment)
},
NodeTypeId::CharacterData(_) => {
let cdata = node.downcast::<CharacterData>().unwrap();
@ -1823,7 +1823,7 @@ impl Node {
None, DocumentActivity::Inactive,
DocumentSource::NotFromParser, loader,
None, None);
Root::upcast::<Node>(document)
DomRoot::upcast::<Node>(document)
},
NodeTypeId::Element(..) => {
let element = node.downcast::<Element>().unwrap();
@ -1837,14 +1837,14 @@ impl Node {
&document,
ElementCreator::ScriptCreated,
CustomElementCreationMode::Asynchronous);
Root::upcast::<Node>(element)
DomRoot::upcast::<Node>(element)
},
};
// Step 3.
let document = match copy.downcast::<Document>() {
Some(doc) => Root::from_ref(doc),
None => Root::from_ref(&*document),
Some(doc) => DomRoot::from_ref(doc),
None => DomRoot::from_ref(&*document),
};
assert!(copy.owner_doc() == document);
@ -1892,7 +1892,7 @@ impl Node {
Node::collect_text_contents(self.children())
}
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString {
pub fn collect_text_contents<T: Iterator<Item=DomRoot<Node>>>(iterator: T) -> DOMString {
let mut content = String::new();
for node in iterator {
if let Some(ref text) = node.downcast::<Text>() {
@ -1976,7 +1976,7 @@ impl NodeMethods for Node {
}
// https://dom.spec.whatwg.org/#dom-node-ownerdocument
fn GetOwnerDocument(&self) -> Option<Root<Document>> {
fn GetOwnerDocument(&self) -> Option<DomRoot<Document>> {
match self.type_id() {
NodeTypeId::CharacterData(..) |
NodeTypeId::Element(..) |
@ -1987,18 +1987,18 @@ impl NodeMethods for Node {
}
// https://dom.spec.whatwg.org/#dom-node-getrootnode
fn GetRootNode(&self) -> Root<Node> {
fn GetRootNode(&self) -> DomRoot<Node> {
self.inclusive_ancestors().last().unwrap()
}
// https://dom.spec.whatwg.org/#dom-node-parentnode
fn GetParentNode(&self) -> Option<Root<Node>> {
fn GetParentNode(&self) -> Option<DomRoot<Node>> {
self.parent_node.get()
}
// https://dom.spec.whatwg.org/#dom-node-parentelement
fn GetParentElement(&self) -> Option<Root<Element>> {
self.GetParentNode().and_then(Root::downcast)
fn GetParentElement(&self) -> Option<DomRoot<Element>> {
self.GetParentNode().and_then(DomRoot::downcast)
}
// https://dom.spec.whatwg.org/#dom-node-haschildnodes
@ -2007,7 +2007,7 @@ impl NodeMethods for Node {
}
// https://dom.spec.whatwg.org/#dom-node-childnodes
fn ChildNodes(&self) -> Root<NodeList> {
fn ChildNodes(&self) -> DomRoot<NodeList> {
self.child_list.or_init(|| {
let doc = self.owner_doc();
let window = doc.window();
@ -2016,22 +2016,22 @@ impl NodeMethods for Node {
}
// https://dom.spec.whatwg.org/#dom-node-firstchild
fn GetFirstChild(&self) -> Option<Root<Node>> {
fn GetFirstChild(&self) -> Option<DomRoot<Node>> {
self.first_child.get()
}
// https://dom.spec.whatwg.org/#dom-node-lastchild
fn GetLastChild(&self) -> Option<Root<Node>> {
fn GetLastChild(&self) -> Option<DomRoot<Node>> {
self.last_child.get()
}
// https://dom.spec.whatwg.org/#dom-node-previoussibling
fn GetPreviousSibling(&self) -> Option<Root<Node>> {
fn GetPreviousSibling(&self) -> Option<DomRoot<Node>> {
self.prev_sibling.get()
}
// https://dom.spec.whatwg.org/#dom-node-nextsibling
fn GetNextSibling(&self) -> Option<Root<Node>> {
fn GetNextSibling(&self) -> Option<DomRoot<Node>> {
self.next_sibling.get()
}
@ -2076,7 +2076,7 @@ impl NodeMethods for Node {
let node = if value.is_empty() {
None
} else {
Some(Root::upcast(self.owner_doc().CreateTextNode(value)))
Some(DomRoot::upcast(self.owner_doc().CreateTextNode(value)))
};
// Step 3.
@ -2092,17 +2092,17 @@ impl NodeMethods for Node {
}
// https://dom.spec.whatwg.org/#dom-node-insertbefore
fn InsertBefore(&self, node: &Node, child: Option<&Node>) -> Fallible<Root<Node>> {
fn InsertBefore(&self, node: &Node, child: Option<&Node>) -> Fallible<DomRoot<Node>> {
Node::pre_insert(node, self, child)
}
// https://dom.spec.whatwg.org/#dom-node-appendchild
fn AppendChild(&self, node: &Node) -> Fallible<Root<Node>> {
fn AppendChild(&self, node: &Node) -> Fallible<DomRoot<Node>> {
Node::pre_insert(node, self, None)
}
// https://dom.spec.whatwg.org/#concept-node-replace
fn ReplaceChild(&self, node: &Node, child: &Node) -> Fallible<Root<Node>> {
fn ReplaceChild(&self, node: &Node, child: &Node) -> Fallible<DomRoot<Node>> {
// Step 1.
match self.type_id() {
NodeTypeId::Document(_) |
@ -2240,12 +2240,12 @@ impl NodeMethods for Node {
MutationObserver::queue_a_mutation_record(&self, mutation);
// Step 15.
Ok(Root::from_ref(child))
Ok(DomRoot::from_ref(child))
}
// https://dom.spec.whatwg.org/#dom-node-removechild
fn RemoveChild(&self, node: &Node)
-> Fallible<Root<Node>> {
-> Fallible<DomRoot<Node>> {
Node::pre_remove(node, self)
}
@ -2276,7 +2276,7 @@ impl NodeMethods for Node {
}
// https://dom.spec.whatwg.org/#dom-node-clonenode
fn CloneNode(&self, deep: bool) -> Root<Node> {
fn CloneNode(&self, deep: bool) -> DomRoot<Node> {
Node::clone(self, None, if deep {
CloneChildrenFlag::CloneChildren
} else {
@ -2499,13 +2499,13 @@ impl NodeMethods for Node {
}
}
pub fn document_from_node<T: DerivedFrom<Node> + DomObject>(derived: &T) -> Root<Document> {
pub fn document_from_node<T: DerivedFrom<Node> + DomObject>(derived: &T) -> DomRoot<Document> {
derived.upcast().owner_doc()
}
pub fn window_from_node<T: DerivedFrom<Node> + DomObject>(derived: &T) -> Root<Window> {
pub fn window_from_node<T: DerivedFrom<Node> + DomObject>(derived: &T) -> DomRoot<Window> {
let document = document_from_node(derived);
Root::from_ref(document.window())
DomRoot::from_ref(document.window())
}
impl VirtualMethods for Node {
@ -2626,7 +2626,7 @@ impl<'a> ChildrenMutation<'a> {
/// NOTE: This does not check whether the inserted/removed nodes were elements, so in some
/// cases it will return a false positive. This doesn't matter for correctness, because at
/// worst the returned element will be restyled unnecessarily.
pub fn modified_edge_element(&self) -> Option<Root<Node>> {
pub fn modified_edge_element(&self) -> Option<DomRoot<Node>> {
match *self {
// Add/remove at start of container: Return the first following element.
ChildrenMutation::Prepend { next, .. } |
@ -2807,7 +2807,7 @@ impl<T> VecPreOrderInsertionHelper<T> for Vec<Dom<T>>
let elem_node = elem.upcast::<Node>();
let mut head: usize = 0;
for node in tree_root.traverse_preorder() {
let head_node = Root::upcast::<Node>(Root::from_ref(&*self[head]));
let head_node = DomRoot::upcast::<Node>(DomRoot::from_ref(&*self[head]));
if head_node == node {
head += 1;
}