From b6b2606c96a2e801bece36cb07d0a0f7a8686f93 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 13 Oct 2013 14:08:37 +0200 Subject: [PATCH] Make Document::root private, in preparation for removing it as part of making Document a Node. --- src/components/script/dom/document.rs | 14 +++++++------- src/components/script/dom/htmldocument.rs | 15 ++++----------- src/components/script/dom/node.rs | 2 +- src/components/script/script_task.rs | 8 +++++--- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index a8c417b986b..f9e99fdbaaf 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -104,7 +104,7 @@ pub enum DocumentType { } pub struct Document { - root: Option>, + priv root: Option>, reflector_: Reflector, window: Option<@mut Window>, doctype: DocumentType, @@ -322,7 +322,7 @@ impl Document { fail!("no SVG document yet") }, _ => { - match self.root { + match self.GetDocumentElement() { None => {}, Some(root) => { for node in root.traverse_preorder() { @@ -338,7 +338,7 @@ impl Document { } } break; - }; + } } } } @@ -356,7 +356,7 @@ impl Document { }, _ => { let (_scope, cx) = self.get_scope_and_cx(); - match self.root { + match self.GetDocumentElement() { None => {}, Some(root) => { for node in root.traverse_preorder() { @@ -386,7 +386,7 @@ impl Document { node.add_child(new_title); } break; - }; + } } } } @@ -484,7 +484,7 @@ impl Document { pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection { let mut elements = ~[]; - match self.root { + match self.GetDocumentElement() { None => {}, Some(root) => { for child in root.traverse_preorder() { @@ -495,7 +495,7 @@ impl Document { } } } - }; + } } } let (scope, cx) = self.get_scope_and_cx(); diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 5d9641d81a0..fafcf26cfe5 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -62,18 +62,11 @@ impl HTMLDocument { } pub fn GetHead(&self) -> Option> { - match self.parent.root { + match self.parent.GetDocumentElement() { None => None, - Some(root) => { - let mut headNode: Option> = None; - let _ = for child in root.traverse_preorder() { - if child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) { - headNode = Some(child); - break; - } - }; - headNode - } + Some(root) => root.traverse_preorder().find(|child| { + child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) + }) } } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 46ddc57ec36..79ca5bc20d6 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -417,7 +417,7 @@ impl<'self, View> AbstractNode { pub fn is_in_doc(&self) -> bool { do self.with_base |node| { do node.owner_doc.with_base |document| { - match document.root { + match document.GetDocumentElement() { None => false, Some(root) => { let mut node = *self; diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index c29a2d3c599..ca3a04910bc 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -217,7 +217,9 @@ impl<'self> Iterator<@mut Page> for PageTreeIterator<'self> { impl Page { /// Adds the given damage. fn damage(&mut self, level: DocumentDamageLevel) { - let root = do self.frame.get_ref().document.with_base |doc| { doc.root }; + let root = do self.frame.get_ref().document.with_base |doc| { + doc.GetDocumentElement() + }; match root { None => {}, Some(root) => { @@ -279,7 +281,7 @@ impl Page { None => fail!(~"Tried to relayout with no root frame!"), Some(ref frame) => { do frame.document.with_base |doc| { - doc.root + doc.GetDocumentElement() } } }; @@ -829,7 +831,7 @@ impl ScriptTask { debug!("ClickEvent: clicked at %?", point); let root = do page.frame.expect("root frame is None").document.with_base |doc| { - doc.root + doc.GetDocumentElement() }; if root.is_none() { return;