Remove document::DocumentType (fixes #1730).

This commit is contained in:
Ms2ger 2014-02-22 14:31:30 +01:00
parent e2617a6396
commit 5ede84fa46
5 changed files with 53 additions and 83 deletions

View file

@ -13,7 +13,7 @@ use dom::bindings::utils::{ErrorResult, Fallible, NotSupported, InvalidCharacter
use dom::bindings::utils::{xml_name_type, InvalidXMLName}; use dom::bindings::utils::{xml_name_type, InvalidXMLName};
use dom::comment::Comment; use dom::comment::Comment;
use dom::documentfragment::DocumentFragment; use dom::documentfragment::DocumentFragment;
use dom::documenttype; use dom::documenttype::DocumentType;
use dom::domimplementation::DOMImplementation; use dom::domimplementation::DOMImplementation;
use dom::element::{Element}; use dom::element::{Element};
use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId}; use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId};
@ -50,19 +50,11 @@ pub enum DocumentTypeId {
HTMLDocumentTypeId HTMLDocumentTypeId
} }
#[deriving(Eq,Encodable)]
pub enum DocumentType {
HTML,
SVG,
XML
}
#[deriving(Encodable)] #[deriving(Encodable)]
pub struct Document { pub struct Document {
node: Node, node: Node,
reflector_: Reflector, reflector_: Reflector,
window: JS<Window>, window: JS<Window>,
doctype: DocumentType,
idmap: HashMap<DOMString, JS<Element>>, idmap: HashMap<DOMString, JS<Element>>,
implementation: Option<JS<DOMImplementation>>, implementation: Option<JS<DOMImplementation>>,
content_type: DOMString, content_type: DOMString,
@ -105,25 +97,20 @@ impl Document {
raw_doc raw_doc
} }
pub fn new_inherited(window: JS<Window>, url: Option<Url>, doctype: DocumentType, content_type: Option<DOMString>) -> Document { pub fn new_inherited(window: JS<Window>, url: Option<Url>, doctype: DocumentTypeId, content_type: Option<DOMString>) -> Document {
let node_type = match doctype {
HTML => HTMLDocumentTypeId,
SVG | XML => PlainDocumentTypeId
};
Document { Document {
node: Node::new_without_doc(DocumentNodeTypeId(node_type)), node: Node::new_without_doc(DocumentNodeTypeId(doctype)),
reflector_: Reflector::new(), reflector_: Reflector::new(),
window: window, window: window,
doctype: doctype,
idmap: HashMap::new(), idmap: HashMap::new(),
implementation: None, implementation: None,
content_type: match content_type { content_type: match content_type {
Some(string) => string.clone(), Some(string) => string.clone(),
None => match doctype { None => match doctype {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
HTML => ~"text/html", HTMLDocumentTypeId => ~"text/html",
// http://dom.spec.whatwg.org/#concept-document-content-type // http://dom.spec.whatwg.org/#concept-document-content-type
SVG | XML => ~"application/xml" PlainDocumentTypeId => ~"application/xml"
} }
}, },
extra: Untraceable { 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); let document = Document::new_inherited(window.clone(), url, doctype, content_type);
Document::reflect_document(~document, window, DocumentBinding::Wrap) Document::reflect_document(~document, window, DocumentBinding::Wrap)
} }
@ -148,7 +135,7 @@ impl Document {
impl Document { impl Document {
// http://dom.spec.whatwg.org/#dom-document // http://dom.spec.whatwg.org/#dom-document
pub fn Constructor(owner: &JS<Window>) -> Fallible<JS<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 // 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()) self.node.children().find(|child| child.is_doctype())
.map(|node| DocumentTypeCast::to(&node)) .map(|node| DocumentTypeCast::to(&node))
} }
@ -290,11 +277,6 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#document.title // http://www.whatwg.org/specs/web-apps/current-work/#document.title
pub fn Title(&self, _: &JS<Document>) -> DOMString { pub fn Title(&self, _: &JS<Document>) -> DOMString {
let mut title = ~""; let mut title = ~"";
match self.doctype {
SVG => {
fail!("no SVG document yet")
},
_ => {
self.GetDocumentElement().map(|root| { self.GetDocumentElement().map(|root| {
let root: JS<Node> = NodeCast::from(&root); let root: JS<Node> = NodeCast::from(&root);
root.traverse_preorder() root.traverse_preorder()
@ -306,8 +288,6 @@ impl Document {
} }
}); });
}); });
}
}
let v: ~[&str] = title.words().collect(); let v: ~[&str] = title.words().collect();
title = v.connect(" "); title = v.connect(" ");
title = title.trim().to_owned(); title = title.trim().to_owned();
@ -316,11 +296,6 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#document.title // http://www.whatwg.org/specs/web-apps/current-work/#document.title
pub fn SetTitle(&self, abstract_self: &JS<Document>, title: DOMString) -> ErrorResult { pub fn SetTitle(&self, abstract_self: &JS<Document>, title: DOMString) -> ErrorResult {
match self.doctype {
SVG => {
fail!("no SVG document yet")
},
_ => {
self.GetDocumentElement().map(|root| { self.GetDocumentElement().map(|root| {
let root: JS<Node> = NodeCast::from(&root); let root: JS<Node> = NodeCast::from(&root);
let mut head_node = root.traverse_preorder().find(|child| { let mut head_node = root.traverse_preorder().find(|child| {
@ -349,8 +324,6 @@ impl Document {
} }
}); });
}); });
}
}
Ok(()) Ok(())
} }

View file

@ -8,7 +8,7 @@ use dom::bindings::js::JS;
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::utils::{Fallible, InvalidCharacter, NamespaceError}; use dom::bindings::utils::{Fallible, InvalidCharacter, NamespaceError};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; 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::documenttype::DocumentType;
use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement; use dom::htmlheadelement::HTMLHeadElement;
@ -66,9 +66,7 @@ impl DOMImplementation {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> JS<Document> { pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> JS<Document> {
// Step 1-2. // Step 1-2.
let doc = Document::new(&self.owner, None, HTML, None); let doc = Document::new(&self.owner, None, HTMLDocumentTypeId, None);
assert!(doc.get().doctype == HTML);
let mut doc_node: JS<Node> = NodeCast::from(&doc); let mut doc_node: JS<Node> = NodeCast::from(&doc);
assert!(doc_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId)); assert!(doc_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId));

View file

@ -8,7 +8,7 @@ use dom::bindings::js::JS;
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::utils::Fallible; use dom::bindings::utils::Fallible;
use dom::bindings::utils::FailureUnknown; use dom::bindings::utils::FailureUnknown;
use dom::document::{Document, HTML}; use dom::document::{Document, HTMLDocumentTypeId};
use dom::window::Window; use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
@ -41,7 +41,7 @@ impl DOMParser {
-> Fallible<JS<Document>> { -> Fallible<JS<Document>> {
match ty { match ty {
Text_html => { Text_html => {
Ok(Document::new(&self.owner, None, HTML, None)) Ok(Document::new(&self.owner, None, HTMLDocumentTypeId, None))
} }
Text_xml => { Text_xml => {
Document::Constructor(&self.owner) Document::Constructor(&self.owner)

View file

@ -16,13 +16,12 @@ use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
use dom::htmlcollection::HTMLCollection; use dom::htmlcollection::HTMLCollection;
use dom::clientrect::ClientRect; use dom::clientrect::ClientRect;
use dom::clientrectlist::ClientRectList; use dom::clientrectlist::ClientRectList;
use dom::document::Document; use dom::document::{Document, HTMLDocumentTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlimageelement::HTMLImageElement; use dom::htmlimageelement::HTMLImageElement;
use dom::htmliframeelement::HTMLIFrameElement; use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmlobjectelement::HTMLObjectElement; use dom::htmlobjectelement::HTMLObjectElement;
use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator}; use dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeHelpers, NodeIterator};
use dom::document;
use dom::htmlserializer::serialize; use dom::htmlserializer::serialize;
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery}; use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse, ContentChangedDocumentDamage}; use layout_interface::{ContentBoxesResponse, ContentChangedDocumentDamage};
@ -156,7 +155,7 @@ impl Element {
let owner = self.node.owner_doc(); let owner = self.node.owner_doc();
self.namespace == namespace::HTML && self.namespace == namespace::HTML &&
// FIXME: check that this matches what the spec calls "is in an HTML document" // 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, pub fn get_attribute(&self,

View file

@ -9,7 +9,7 @@ use dom::bindings::codegen::RegisterBindings;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast};
use dom::bindings::js::JS; use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, GlobalStaticData, with_gc_enabled}; 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::element::Element;
use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent};
use dom::event::Event; use dom::event::Event;
@ -717,7 +717,7 @@ impl ScriptTask {
// Parse HTML. // Parse HTML.
// //
// Note: We can parse the next document in parallel with any previous documents. // 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, let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr,
&mut document, &mut document,
url.clone(), url.clone(),