aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/script/dom/document.rs117
-rw-r--r--src/components/script/dom/domimplementation.rs6
-rw-r--r--src/components/script/dom/domparser.rs4
-rw-r--r--src/components/script/dom/element.rs7
-rw-r--r--src/components/script/script_task.rs4
5 files changed, 54 insertions, 84 deletions
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index 5dbd8b1194b..055a4dcad6d 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -13,7 +13,7 @@ use dom::bindings::utils::{ErrorResult, Fallible, NotSupported, InvalidCharacter
use dom::bindings::utils::{xml_name_type, InvalidXMLName};
use dom::comment::Comment;
use dom::documentfragment::DocumentFragment;
-use dom::documenttype;
+use dom::documenttype::DocumentType;
use dom::domimplementation::DOMImplementation;
use dom::element::{Element};
use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId};
@@ -50,19 +50,11 @@ pub enum DocumentTypeId {
HTMLDocumentTypeId
}
-#[deriving(Eq,Encodable)]
-pub enum DocumentType {
- HTML,
- SVG,
- XML
-}
-
#[deriving(Encodable)]
pub struct Document {
node: Node,
reflector_: Reflector,
window: JS<Window>,
- doctype: DocumentType,
idmap: HashMap<DOMString, JS<Element>>,
implementation: Option<JS<DOMImplementation>>,
content_type: DOMString,
@@ -105,25 +97,20 @@ impl Document {
raw_doc
}
- pub fn new_inherited(window: JS<Window>, url: Option<Url>, doctype: DocumentType, content_type: Option<DOMString>) -> Document {
- let node_type = match doctype {
- HTML => HTMLDocumentTypeId,
- SVG | XML => PlainDocumentTypeId
- };
+ pub fn new_inherited(window: JS<Window>, url: Option<Url>, doctype: DocumentTypeId, content_type: Option<DOMString>) -> Document {
Document {
- node: Node::new_without_doc(DocumentNodeTypeId(node_type)),
+ node: Node::new_without_doc(DocumentNodeTypeId(doctype)),
reflector_: Reflector::new(),
window: window,
- doctype: doctype,
idmap: HashMap::new(),
implementation: None,
content_type: match content_type {
Some(string) => string.clone(),
None => match doctype {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
- HTML => ~"text/html",
+ HTMLDocumentTypeId => ~"text/html",
// http://dom.spec.whatwg.org/#concept-document-content-type
- SVG | XML => ~"application/xml"
+ PlainDocumentTypeId => ~"application/xml"
}
},
extra: Untraceable {
@@ -139,7 +126,7 @@ impl Document {
}
}
- pub fn new(window: &JS<Window>, url: Option<Url>, doctype: DocumentType, content_type: Option<DOMString>) -> JS<Document> {
+ pub fn new(window: &JS<Window>, url: Option<Url>, doctype: DocumentTypeId, content_type: Option<DOMString>) -> JS<Document> {
let document = Document::new_inherited(window.clone(), url, doctype, content_type);
Document::reflect_document(~document, window, DocumentBinding::Wrap)
}
@@ -148,7 +135,7 @@ impl Document {
impl Document {
// http://dom.spec.whatwg.org/#dom-document
pub fn Constructor(owner: &JS<Window>) -> Fallible<JS<Document>> {
- Ok(Document::new(owner, None, XML, None))
+ Ok(Document::new(owner, None, PlainDocumentTypeId, None))
}
}
@@ -208,7 +195,7 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document-doctype
- pub fn GetDoctype(&self) -> Option<JS<documenttype::DocumentType>> {
+ pub fn GetDoctype(&self) -> Option<JS<DocumentType>> {
self.node.children().find(|child| child.is_doctype())
.map(|node| DocumentTypeCast::to(&node))
}
@@ -290,24 +277,17 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
pub fn Title(&self, _: &JS<Document>) -> DOMString {
let mut title = ~"";
- match self.doctype {
- SVG => {
- fail!("no SVG document yet")
- },
- _ => {
- self.GetDocumentElement().map(|root| {
- let root: JS<Node> = NodeCast::from(&root);
- root.traverse_preorder()
- .find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId))
- .map(|title_elem| {
- for child in title_elem.children() {
- let text: JS<Text> = TextCast::to(&child);
- title.push_str(text.get().characterdata.data.as_slice());
- }
- });
+ self.GetDocumentElement().map(|root| {
+ let root: JS<Node> = NodeCast::from(&root);
+ root.traverse_preorder()
+ .find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId))
+ .map(|title_elem| {
+ for child in title_elem.children() {
+ let text: JS<Text> = TextCast::to(&child);
+ title.push_str(text.get().characterdata.data.as_slice());
+ }
});
- }
- }
+ });
let v: ~[&str] = title.words().collect();
title = v.connect(" ");
title = title.trim().to_owned();
@@ -316,41 +296,34 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
pub fn SetTitle(&self, abstract_self: &JS<Document>, title: DOMString) -> ErrorResult {
- match self.doctype {
- SVG => {
- fail!("no SVG document yet")
- },
- _ => {
- self.GetDocumentElement().map(|root| {
- let root: JS<Node> = NodeCast::from(&root);
- let mut head_node = root.traverse_preorder().find(|child| {
- child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
- });
- head_node.as_mut().map(|head| {
-
- let mut title_node = head.children().find(|child| {
- child.get().type_id == ElementNodeTypeId(HTMLTitleElementTypeId)
- });
-
- title_node.as_mut().map(|title_node| {
- for mut title_child in title_node.children() {
- title_node.RemoveChild(&mut title_child);
- }
- let new_text = self.CreateTextNode(abstract_self, title.clone());
- title_node.AppendChild(&mut NodeCast::from(&new_text));
- });
-
- if title_node.is_none() {
- let mut new_title: JS<Node> =
- NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self));
- let new_text = self.CreateTextNode(abstract_self, title.clone());
- new_title.AppendChild(&mut NodeCast::from(&new_text));
- head.AppendChild(&mut new_title);
- }
- });
+ self.GetDocumentElement().map(|root| {
+ let root: JS<Node> = NodeCast::from(&root);
+ let mut head_node = root.traverse_preorder().find(|child| {
+ child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
+ });
+ head_node.as_mut().map(|head| {
+
+ let mut title_node = head.children().find(|child| {
+ child.get().type_id == ElementNodeTypeId(HTMLTitleElementTypeId)
});
- }
- }
+
+ title_node.as_mut().map(|title_node| {
+ for mut title_child in title_node.children() {
+ title_node.RemoveChild(&mut title_child);
+ }
+ let new_text = self.CreateTextNode(abstract_self, title.clone());
+ title_node.AppendChild(&mut NodeCast::from(&new_text));
+ });
+
+ if title_node.is_none() {
+ let mut new_title: JS<Node> =
+ NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self));
+ let new_text = self.CreateTextNode(abstract_self, title.clone());
+ new_title.AppendChild(&mut NodeCast::from(&new_text));
+ head.AppendChild(&mut new_title);
+ }
+ });
+ });
Ok(())
}
diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs
index 329bcc74263..ee9af6206c9 100644
--- a/src/components/script/dom/domimplementation.rs
+++ b/src/components/script/dom/domimplementation.rs
@@ -8,7 +8,7 @@ use dom::bindings::js::JS;
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::utils::{Fallible, InvalidCharacter, NamespaceError};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
-use dom::document::{Document, HTML, HTMLDocumentTypeId};
+use dom::document::{Document, HTMLDocumentTypeId};
use dom::documenttype::DocumentType;
use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement;
@@ -66,9 +66,7 @@ impl DOMImplementation {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> JS<Document> {
// Step 1-2.
- let doc = Document::new(&self.owner, None, HTML, None);
- assert!(doc.get().doctype == HTML);
-
+ let doc = Document::new(&self.owner, None, HTMLDocumentTypeId, None);
let mut doc_node: JS<Node> = NodeCast::from(&doc);
assert!(doc_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId));
diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs
index 031cd8b3b4a..f95a8e853e5 100644
--- a/src/components/script/dom/domparser.rs
+++ b/src/components/script/dom/domparser.rs
@@ -8,7 +8,7 @@ use dom::bindings::js::JS;
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::utils::Fallible;
use dom::bindings::utils::FailureUnknown;
-use dom::document::{Document, HTML};
+use dom::document::{Document, HTMLDocumentTypeId};
use dom::window::Window;
use servo_util::str::DOMString;
@@ -41,7 +41,7 @@ impl DOMParser {
-> Fallible<JS<Document>> {
match ty {
Text_html => {
- Ok(Document::new(&self.owner, None, HTML, None))
+ Ok(Document::new(&self.owner, None, HTMLDocumentTypeId, None))
}
Text_xml => {
Document::Constructor(&self.owner)
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index f9b7c67d372..44a4a401e74 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -16,13 +16,12 @@ use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
use dom::htmlcollection::HTMLCollection;
use dom::clientrect::ClientRect;
use dom::clientrectlist::ClientRectList;
-use dom::document::Document;
+use dom::document::{Document, HTMLDocumentTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlimageelement::HTMLImageElement;
use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmlobjectelement::HTMLObjectElement;
-use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator};
-use dom::document;
+use dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeHelpers, NodeIterator};
use dom::htmlserializer::serialize;
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse, ContentChangedDocumentDamage};
@@ -156,7 +155,7 @@ impl Element {
let owner = self.node.owner_doc();
self.namespace == namespace::HTML &&
// FIXME: check that this matches what the spec calls "is in an HTML document"
- owner.get().doctype == document::HTML
+ owner.get().node.type_id == DocumentNodeTypeId(HTMLDocumentTypeId)
}
pub fn get_attribute(&self,
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index 0f17d4afce0..971fa215da8 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -9,7 +9,7 @@ use dom::bindings::codegen::RegisterBindings;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast};
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, GlobalStaticData, with_gc_enabled};
-use dom::document::{Document, HTML};
+use dom::document::{Document, HTMLDocumentTypeId};
use dom::element::Element;
use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent};
use dom::event::Event;
@@ -717,7 +717,7 @@ impl ScriptTask {
// Parse HTML.
//
// Note: We can parse the next document in parallel with any previous documents.
- let mut document = Document::new(&window, Some(url.clone()), HTML, None);
+ let mut document = Document::new(&window, Some(url.clone()), HTMLDocumentTypeId, None);
let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr,
&mut document,
url.clone(),