mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Make Node.owner_doc private.
This commit is contained in:
parent
34f89b27b3
commit
c08e4fe36b
4 changed files with 30 additions and 20 deletions
|
@ -90,7 +90,7 @@ impl AbstractDocument {
|
||||||
pub fn set_root(&self, root: AbstractNode<ScriptView>) {
|
pub fn set_root(&self, root: AbstractNode<ScriptView>) {
|
||||||
assert!(root.traverse_preorder().all(|node| {
|
assert!(root.traverse_preorder().all(|node| {
|
||||||
do node.with_base |node| {
|
do node.with_base |node| {
|
||||||
node.owner_doc == *self
|
node.owner_doc() == *self
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
self.with_mut_base(|document| {
|
self.with_mut_base(|document| {
|
||||||
|
|
|
@ -193,7 +193,7 @@ impl<'self> Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
if abstract_self.is_in_doc() {
|
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();
|
owner.content_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
|
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 win = document.with_base(|doc| doc.window);
|
||||||
let node = abstract_self;
|
let node = abstract_self;
|
||||||
assert!(node.is_element());
|
assert!(node.is_element());
|
||||||
|
@ -307,7 +307,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
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 win = document.with_base(|doc| doc.window);
|
||||||
let node = abstract_self;
|
let node = abstract_self;
|
||||||
assert!(node.is_element());
|
assert!(node.is_element());
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl HTMLImageElement {
|
||||||
pub fn AfterSetAttr(&mut self, name: &DOMString, _value: &DOMString) {
|
pub fn AfterSetAttr(&mut self, name: &DOMString, _value: &DOMString) {
|
||||||
let name = null_str_as_empty(name);
|
let name = null_str_as_empty(name);
|
||||||
if "src" == 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| {
|
do doc.with_base |doc| {
|
||||||
let window = doc.window;
|
let window = doc.window;
|
||||||
let url = window.page.url.map(|&(ref url, _)| url.clone());
|
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 {
|
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||||
let node = &self.htmlelement.element.node;
|
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();
|
let (port, chan) = stream();
|
||||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||||
ContentBoxResponse(rect) => {
|
ContentBoxResponse(rect) => {
|
||||||
|
@ -121,7 +121,7 @@ impl HTMLImageElement {
|
||||||
|
|
||||||
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||||
let node = &self.htmlelement.element.node;
|
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();
|
let (port, chan) = stream();
|
||||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||||
ContentBoxResponse(rect) => {
|
ContentBoxResponse(rect) => {
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub struct Node<View> {
|
||||||
prev_sibling: Option<AbstractNode<View>>,
|
prev_sibling: Option<AbstractNode<View>>,
|
||||||
|
|
||||||
/// The document that this node belongs to.
|
/// The document that this node belongs to.
|
||||||
owner_doc: AbstractDocument,
|
priv owner_doc: AbstractDocument,
|
||||||
|
|
||||||
/// The live list of children return by .childNodes.
|
/// The live list of children return by .childNodes.
|
||||||
child_list: Option<@mut NodeList>,
|
child_list: Option<@mut NodeList>,
|
||||||
|
@ -425,7 +425,7 @@ impl<'self, View> AbstractNode<View> {
|
||||||
// Issue #1030: should not walk the tree
|
// Issue #1030: should not walk the tree
|
||||||
pub fn is_in_doc(&self) -> bool {
|
pub fn is_in_doc(&self) -> bool {
|
||||||
do self.with_base |node| {
|
do self.with_base |node| {
|
||||||
do node.owner_doc.with_base |document| {
|
do node.owner_doc().with_base |document| {
|
||||||
match document.GetDocumentElement() {
|
match document.GetDocumentElement() {
|
||||||
None => false,
|
None => false,
|
||||||
Some(root) => {
|
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> {
|
impl Node<ScriptView> {
|
||||||
pub unsafe fn as_abstract_node<N>(cx: *JSContext, node: @N) -> AbstractNode<ScriptView> {
|
pub unsafe fn as_abstract_node<N>(cx: *JSContext, node: @N) -> AbstractNode<ScriptView> {
|
||||||
// This surrenders memory management of the node!
|
// 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) {
|
pub fn add_to_doc(&mut self, abstract_self: AbstractNode<ScriptView>, doc: AbstractDocument) {
|
||||||
let old_doc = self.owner_doc;
|
let old_doc = self.owner_doc();
|
||||||
self.owner_doc = doc;
|
self.set_owner_doc(doc);
|
||||||
let mut cur_node = self.first_child;
|
let mut cur_node = self.first_child;
|
||||||
while cur_node.is_some() {
|
while cur_node.is_some() {
|
||||||
for node in cur_node.unwrap().traverse_preorder() {
|
for node in cur_node.unwrap().traverse_preorder() {
|
||||||
do node.with_mut_base |node_base| {
|
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();
|
cur_node = cur_node.unwrap().next_sibling();
|
||||||
|
@ -583,7 +593,7 @@ impl Node<ScriptView> {
|
||||||
CommentNodeTypeId |
|
CommentNodeTypeId |
|
||||||
TextNodeTypeId |
|
TextNodeTypeId |
|
||||||
DoctypeNodeTypeId |
|
DoctypeNodeTypeId |
|
||||||
DocumentFragmentNodeTypeId => Some(self.owner_doc),
|
DocumentFragmentNodeTypeId => Some(self.owner_doc()),
|
||||||
// DocumentNodeTypeId => None
|
// DocumentNodeTypeId => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -672,7 +682,7 @@ impl Node<ScriptView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
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())
|
(win.reflector().get_jsobject(), win.get_cx())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,8 +714,8 @@ impl Node<ScriptView> {
|
||||||
let node = if is_empty {
|
let node = if is_empty {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let text_node = do self.owner_doc.with_base |document| {
|
let text_node = do self.owner_doc().with_base |document| {
|
||||||
document.CreateTextNode(self.owner_doc, value)
|
document.CreateTextNode(self.owner_doc(), value)
|
||||||
};
|
};
|
||||||
Some(text_node)
|
Some(text_node)
|
||||||
};
|
};
|
||||||
|
@ -718,7 +728,7 @@ impl Node<ScriptView> {
|
||||||
characterdata.data = null_str_as_empty(value);
|
characterdata.data = null_str_as_empty(value);
|
||||||
|
|
||||||
// Notify the document that the content of this node is different
|
// 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();
|
doc.content_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -733,7 +743,7 @@ impl Node<ScriptView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_until_safe_to_modify_dom(&self) {
|
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();
|
doc.wait_until_safe_to_modify_dom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -774,7 +784,7 @@ impl Node<ScriptView> {
|
||||||
node.parent_node().map(|parent| parent.remove_child(node));
|
node.parent_node().map(|parent| parent.remove_child(node));
|
||||||
abstract_self.add_child(node);
|
abstract_self.add_child(node);
|
||||||
do node.with_mut_base |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)
|
Ok(node)
|
||||||
}
|
}
|
||||||
|
@ -808,7 +818,7 @@ impl Node<ScriptView> {
|
||||||
|
|
||||||
abstract_self.remove_child(node);
|
abstract_self.remove_child(node);
|
||||||
// Signal the document that it needs to update its display.
|
// 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();
|
document.content_changed();
|
||||||
}
|
}
|
||||||
Ok(node)
|
Ok(node)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue