diff options
author | lpy <pylaurent1314@gmail.com> | 2014-03-01 14:24:41 +0800 |
---|---|---|
committer | lpy <pylaurent1314@gmail.com> | 2014-03-01 21:57:37 +0800 |
commit | 77938bf6f669d8491b41ffa991149be5f986c911 (patch) | |
tree | 8ad28f14a3c50e58a5b7f7755e82ca6ccb4d5729 /src/components/script/dom/node.rs | |
parent | ea29e3a001fb70b5e94af7a676345b4046771315 (diff) | |
download | servo-77938bf6f669d8491b41ffa991149be5f986c911.tar.gz servo-77938bf6f669d8491b41ffa991149be5f986c911.zip |
Implement document_from_node and window_from_node helpers.(fixes #1761)
Diffstat (limited to 'src/components/script/dom/node.rs')
-rw-r--r-- | src/components/script/dom/node.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 50b70cf14e8..ef3b4a03ffa 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -19,6 +19,7 @@ use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::nodelist::{NodeList}; use dom::text::Text; use dom::processinginstruction::ProcessingInstruction; +use dom::window::Window; use layout_interface::{LayoutChan, ReapLayoutDataMsg, UntrustedNodeAddress}; use layout_interface::TrustedNodeAddress; use servo_util::str::{DOMString, null_str_as_empty}; @@ -396,7 +397,7 @@ impl NodeHelpers for JS<Node> { // http://dom.spec.whatwg.org/#node-is-inserted fn node_inserted(&self) { assert!(self.parent_node().is_some()); - let document = self.get().owner_doc(); + let document = document_from_node(self); for node in self.traverse_preorder() { if node.is_element() { @@ -411,7 +412,7 @@ impl NodeHelpers for JS<Node> { // http://dom.spec.whatwg.org/#node-is-removed fn node_removed(&self) { assert!(self.parent_node().is_none()); - let document = self.get().owner_doc(); + let document = document_from_node(self); for node in self.traverse_preorder() { if node.is_element() { @@ -964,7 +965,7 @@ impl Node { } // Step 2. - if node.get().owner_doc() != *document { + if document_from_node(node) != *document { for mut descendant in node.traverse_preorder() { descendant.get_mut().set_owner_doc(document); } @@ -1101,7 +1102,7 @@ impl Node { }; // Step 9. - Node::adopt(node, &parent.get().owner_doc()); + Node::adopt(node, &document_from_node(parent)); // Step 10. Node::insert(node, parent, referenceChild, Unsuppressed); @@ -1156,7 +1157,7 @@ impl Node { pub fn replace_all(mut node: Option<JS<Node>>, parent: &mut JS<Node>) { // Step 1. match node { - Some(ref mut node) => Node::adopt(node, &parent.get().owner_doc()), + Some(ref mut node) => Node::adopt(node, &document_from_node(parent)), None => (), } @@ -1381,7 +1382,7 @@ impl Node { }; // Step 9. - Node::adopt(node, &parent.get().owner_doc()); + Node::adopt(node, &document_from_node(parent)); { // Step 10. @@ -1627,3 +1628,12 @@ impl Reflectable for Node { } } +pub fn document_from_node<T: NodeBase>(derived: &JS<T>) -> JS<Document> { + let node: JS<Node> = NodeCast::from(derived); + node.get().owner_doc().clone() +} + +pub fn window_from_node<T: NodeBase>(derived: &JS<T>) -> JS<Window> { + let document: JS<Document> = document_from_node(derived); + document.get().window.clone() +} |