aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2013-10-17 09:49:20 -0700
committerbors-servo <release+servo@mozilla.com>2013-10-17 09:49:20 -0700
commitc14c2cc63fec15f1f6d9ff0156a0137fbef50ff1 (patch)
treea618504bc2096f5be1aa3223acebd4071a56321b
parent34f89b27b36220748a344b32b4ba0cb4e8efd5a4 (diff)
parentc08e4fe36b128208c4386539a137a3250a7e4434 (diff)
downloadservo-c14c2cc63fec15f1f6d9ff0156a0137fbef50ff1.tar.gz
servo-c14c2cc63fec15f1f6d9ff0156a0137fbef50ff1.zip
auto merge of #1066 : Ms2ger/servo/priv-owner-doc, r=jdm
When `Document` is a `Node`, we can only set its `owner_doc` after creating the `AbstractDocument`, and thus the `Document`, and thus the `Node`; i.e., when creating the `Node`, the `AbstractDocument` can't exist yet. That means that we'll need to turn `owner_doc` back into an `Option`. We don't want to expose that to everyone, though, so this adds encapsulation so we'll be able to just `unwrap` in the `owner_doc()` function rather than at all call sites.
-rw-r--r--src/components/script/dom/document.rs2
-rw-r--r--src/components/script/dom/element.rs6
-rw-r--r--src/components/script/dom/htmlimageelement.rs6
-rw-r--r--src/components/script/dom/node.rs36
4 files changed, 30 insertions, 20 deletions
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index ef8f7ec12ec..28ebe79fb49 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -90,7 +90,7 @@ impl AbstractDocument {
pub fn set_root(&self, root: AbstractNode<ScriptView>) {
assert!(root.traverse_preorder().all(|node| {
do node.with_base |node| {
- node.owner_doc == *self
+ node.owner_doc() == *self
}
}));
self.with_mut_base(|document| {
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index fb6cb9e8d2a..3c4f7e9d9b4 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -193,7 +193,7 @@ impl<'self> Element {
}
if abstract_self.is_in_doc() {
- do self.node.owner_doc.with_base |owner| {
+ do self.node.owner_doc().with_base |owner| {
owner.content_changed();
}
}
@@ -280,7 +280,7 @@ impl Element {
}
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
- let document = self.node.owner_doc;
+ let document = self.node.owner_doc();
let win = document.with_base(|doc| doc.window);
let node = abstract_self;
assert!(node.is_element());
@@ -307,7 +307,7 @@ impl Element {
}
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
- let document = self.node.owner_doc;
+ let document = self.node.owner_doc();
let win = document.with_base(|doc| doc.window);
let node = abstract_self;
assert!(node.is_element());
diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs
index 67ed8f3797d..d9d301b6dfe 100644
--- a/src/components/script/dom/htmlimageelement.rs
+++ b/src/components/script/dom/htmlimageelement.rs
@@ -43,7 +43,7 @@ impl HTMLImageElement {
pub fn AfterSetAttr(&mut self, name: &DOMString, _value: &DOMString) {
let name = null_str_as_empty(name);
if "src" == name {
- let doc = self.htmlelement.element.node.owner_doc;
+ let doc = self.htmlelement.element.node.owner_doc();
do doc.with_base |doc| {
let window = doc.window;
let url = window.page.url.map(|&(ref url, _)| url.clone());
@@ -100,7 +100,7 @@ impl HTMLImageElement {
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
let node = &self.htmlelement.element.node;
- let page = node.owner_doc.with_base(|doc| doc.window).page;
+ let page = node.owner_doc().with_base(|doc| doc.window).page;
let (port, chan) = stream();
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
ContentBoxResponse(rect) => {
@@ -121,7 +121,7 @@ impl HTMLImageElement {
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
let node = &self.htmlelement.element.node;
- let page = node.owner_doc.with_base(|doc| doc.window).page;
+ let page = node.owner_doc().with_base(|doc| doc.window).page;
let (port, chan) = stream();
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
ContentBoxResponse(rect) => {
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index 6d841922f97..292c54aa7d1 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -88,7 +88,7 @@ pub struct Node<View> {
prev_sibling: Option<AbstractNode<View>>,
/// The document that this node belongs to.
- owner_doc: AbstractDocument,
+ priv owner_doc: AbstractDocument,
/// The live list of children return by .childNodes.
child_list: Option<@mut NodeList>,
@@ -425,7 +425,7 @@ impl<'self, View> AbstractNode<View> {
// Issue #1030: should not walk the tree
pub fn is_in_doc(&self) -> bool {
do self.with_base |node| {
- do node.owner_doc.with_base |document| {
+ do node.owner_doc().with_base |document| {
match document.GetDocumentElement() {
None => false,
Some(root) => {
@@ -459,6 +459,16 @@ impl<View> Iterator<AbstractNode<View>> for AbstractNodeChildrenIterator<View> {
}
}
+impl<View> Node<View> {
+ pub fn owner_doc(&self) -> AbstractDocument {
+ self.owner_doc
+ }
+
+ pub fn set_owner_doc(&mut self, document: AbstractDocument) {
+ self.owner_doc = document;
+ }
+}
+
impl Node<ScriptView> {
pub unsafe fn as_abstract_node<N>(cx: *JSContext, node: @N) -> AbstractNode<ScriptView> {
// This surrenders memory management of the node!
@@ -470,13 +480,13 @@ impl Node<ScriptView> {
}
pub fn add_to_doc(&mut self, abstract_self: AbstractNode<ScriptView>, doc: AbstractDocument) {
- let old_doc = self.owner_doc;
- self.owner_doc = doc;
+ let old_doc = self.owner_doc();
+ self.set_owner_doc(doc);
let mut cur_node = self.first_child;
while cur_node.is_some() {
for node in cur_node.unwrap().traverse_preorder() {
do node.with_mut_base |node_base| {
- node_base.owner_doc = doc;
+ node_base.set_owner_doc(doc);
}
};
cur_node = cur_node.unwrap().next_sibling();
@@ -583,7 +593,7 @@ impl Node<ScriptView> {
CommentNodeTypeId |
TextNodeTypeId |
DoctypeNodeTypeId |
- DocumentFragmentNodeTypeId => Some(self.owner_doc),
+ DocumentFragmentNodeTypeId => Some(self.owner_doc()),
// DocumentNodeTypeId => None
}
}
@@ -672,7 +682,7 @@ impl Node<ScriptView> {
}
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
- let win = self.owner_doc.with_base(|doc| doc.window);
+ let win = self.owner_doc().with_base(|doc| doc.window);
(win.reflector().get_jsobject(), win.get_cx())
}
@@ -704,8 +714,8 @@ impl Node<ScriptView> {
let node = if is_empty {
None
} else {
- let text_node = do self.owner_doc.with_base |document| {
- document.CreateTextNode(self.owner_doc, value)
+ let text_node = do self.owner_doc().with_base |document| {
+ document.CreateTextNode(self.owner_doc(), value)
};
Some(text_node)
};
@@ -718,7 +728,7 @@ impl Node<ScriptView> {
characterdata.data = null_str_as_empty(value);
// Notify the document that the content of this node is different
- do self.owner_doc.with_base |doc| {
+ do self.owner_doc().with_base |doc| {
doc.content_changed();
}
}
@@ -733,7 +743,7 @@ impl Node<ScriptView> {
}
fn wait_until_safe_to_modify_dom(&self) {
- do self.owner_doc.with_base |doc| {
+ do self.owner_doc().with_base |doc| {
doc.wait_until_safe_to_modify_dom();
}
}
@@ -774,7 +784,7 @@ impl Node<ScriptView> {
node.parent_node().map(|parent| parent.remove_child(node));
abstract_self.add_child(node);
do node.with_mut_base |node| {
- node.add_to_doc(abstract_self, self.owner_doc);
+ node.add_to_doc(abstract_self, self.owner_doc());
}
Ok(node)
}
@@ -808,7 +818,7 @@ impl Node<ScriptView> {
abstract_self.remove_child(node);
// Signal the document that it needs to update its display.
- do self.owner_doc.with_base |document| {
+ do self.owner_doc().with_base |document| {
document.content_changed();
}
Ok(node)