Remove DocumentTypeId.

This commit is contained in:
Ms2ger 2014-02-22 21:03:39 +01:00
parent 5ede84fa46
commit 870ccd95d2
8 changed files with 46 additions and 44 deletions

View file

@ -644,7 +644,7 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
CommentNodeTypeId | CommentNodeTypeId |
DoctypeNodeTypeId | DoctypeNodeTypeId |
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
DocumentNodeTypeId(_) | DocumentNodeTypeId |
ProcessingInstructionNodeTypeId => (display::none, float::none, position::static_), ProcessingInstructionNodeTypeId => (display::none, float::none, position::static_),
}; };
@ -717,7 +717,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
CommentNodeTypeId | CommentNodeTypeId |
DoctypeNodeTypeId | DoctypeNodeTypeId |
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
DocumentNodeTypeId(_) | DocumentNodeTypeId |
ElementNodeTypeId(HTMLImageElementTypeId) => true, ElementNodeTypeId(HTMLImageElementTypeId) => true,
ElementNodeTypeId(HTMLObjectElementTypeId) => self.has_object_data(), ElementNodeTypeId(HTMLObjectElementTypeId) => self.has_object_data(),
ElementNodeTypeId(_) => false, ElementNodeTypeId(_) => false,

View file

@ -45,9 +45,9 @@ use std::hashmap::HashMap;
use extra::serialize::{Encoder, Encodable}; use extra::serialize::{Encoder, Encodable};
#[deriving(Eq,Encodable)] #[deriving(Eq,Encodable)]
pub enum DocumentTypeId { pub enum IsHTMLDocument {
PlainDocumentTypeId, HTMLDocument,
HTMLDocumentTypeId NonHTMLDocument,
} }
#[deriving(Encodable)] #[deriving(Encodable)]
@ -59,6 +59,7 @@ pub struct Document {
implementation: Option<JS<DOMImplementation>>, implementation: Option<JS<DOMImplementation>>,
content_type: DOMString, content_type: DOMString,
encoding_name: DOMString, encoding_name: DOMString,
is_html_document: bool,
extra: Untraceable, extra: Untraceable,
} }
@ -75,7 +76,7 @@ impl<S: Encoder> Encodable<S> for Untraceable {
impl DocumentDerived for EventTarget { impl DocumentDerived for EventTarget {
fn is_document(&self) -> bool { fn is_document(&self) -> bool {
match self.type_id { match self.type_id {
NodeTargetTypeId(DocumentNodeTypeId(_)) => true, NodeTargetTypeId(DocumentNodeTypeId) => true,
_ => false _ => false
} }
} }
@ -97,20 +98,23 @@ impl Document {
raw_doc raw_doc
} }
pub fn new_inherited(window: JS<Window>, url: Option<Url>, doctype: DocumentTypeId, content_type: Option<DOMString>) -> Document { pub fn new_inherited(window: JS<Window>,
url: Option<Url>,
is_html_document: IsHTMLDocument,
content_type: Option<DOMString>) -> Document {
Document { Document {
node: Node::new_without_doc(DocumentNodeTypeId(doctype)), node: Node::new_without_doc(DocumentNodeTypeId),
reflector_: Reflector::new(), reflector_: Reflector::new(),
window: window, window: window,
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 is_html_document {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
HTMLDocumentTypeId => ~"text/html", HTMLDocument => ~"text/html",
// http://dom.spec.whatwg.org/#concept-document-content-type // http://dom.spec.whatwg.org/#concept-document-content-type
PlainDocumentTypeId => ~"application/xml" NonHTMLDocument => ~"application/xml"
} }
}, },
extra: Untraceable { extra: Untraceable {
@ -123,10 +127,11 @@ impl Document {
}, },
// http://dom.spec.whatwg.org/#concept-document-encoding // http://dom.spec.whatwg.org/#concept-document-encoding
encoding_name: ~"utf-8", encoding_name: ~"utf-8",
is_html_document: is_html_document == HTMLDocument,
} }
} }
pub fn new(window: &JS<Window>, url: Option<Url>, doctype: DocumentTypeId, content_type: Option<DOMString>) -> JS<Document> { pub fn new(window: &JS<Window>, url: Option<Url>, doctype: IsHTMLDocument, 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)
} }
@ -135,7 +140,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, PlainDocumentTypeId, None)) Ok(Document::new(owner, None, NonHTMLDocument, None))
} }
} }

View file

@ -8,13 +8,13 @@ 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, HTMLDocumentTypeId}; use dom::document::{Document, HTMLDocument};
use dom::documenttype::DocumentType; use dom::documenttype::DocumentType;
use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement; use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement; use dom::htmltitleelement::HTMLTitleElement;
use dom::node::{Node, DocumentNodeTypeId, NodeHelpers, INode}; use dom::node::{Node, INode};
use dom::text::Text; use dom::text::Text;
use dom::window::Window; use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
@ -66,9 +66,8 @@ 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, HTMLDocumentTypeId, None); let doc = Document::new(&self.owner, None, HTMLDocument, None);
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));
{ {
// Step 3. // Step 3.

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, HTMLDocumentTypeId}; use dom::document::{Document, HTMLDocument};
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, HTMLDocumentTypeId, None)) Ok(Document::new(&self.owner, None, HTMLDocument, None))
} }
Text_xml => { Text_xml => {
Document::Constructor(&self.owner) Document::Constructor(&self.owner)

View file

@ -16,12 +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, HTMLDocumentTypeId}; use dom::document::Document;
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::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeHelpers, NodeIterator}; use dom::node::{ElementNodeTypeId, Node, NodeHelpers, NodeIterator};
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};
@ -152,10 +152,8 @@ impl Element {
} }
pub fn html_element_in_html_document(&self) -> bool { pub fn html_element_in_html_document(&self) -> bool {
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" self.node.owner_doc().get().is_html_document
owner.get().node.type_id == DocumentNodeTypeId(HTMLDocumentTypeId)
} }
pub fn get_attribute(&self, pub fn get_attribute(&self,

View file

@ -52,7 +52,7 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str {
DocumentFragmentNodeTypeId => { DocumentFragmentNodeTypeId => {
~"" ~""
} }
DocumentNodeTypeId(_) => { DocumentNodeTypeId => {
fail!("It shouldn't be possible to serialize a document node") fail!("It shouldn't be possible to serialize a document node")
} }
} }

View file

@ -12,7 +12,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::bindings::utils::{ErrorResult, Fallible, NotFound, HierarchyRequest};
use dom::bindings::utils; use dom::bindings::utils;
use dom::characterdata::CharacterData; use dom::characterdata::CharacterData;
use dom::document::{Document, DocumentTypeId}; use dom::document::Document;
use dom::documenttype::DocumentType; use dom::documenttype::DocumentType;
use dom::element::{Element, ElementTypeId, HTMLAnchorElementTypeId}; use dom::element::{Element, ElementTypeId, HTMLAnchorElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -101,7 +101,7 @@ impl NodeFlags {
pub fn new(type_id: NodeTypeId) -> NodeFlags { pub fn new(type_id: NodeTypeId) -> NodeFlags {
let mut flags = NodeFlags(0); let mut flags = NodeFlags(0);
match type_id { match type_id {
DocumentNodeTypeId(_) => { flags.set_is_in_doc(true); } DocumentNodeTypeId => { flags.set_is_in_doc(true); }
_ => {} _ => {}
} }
flags flags
@ -208,7 +208,7 @@ pub enum NodeTypeId {
DoctypeNodeTypeId, DoctypeNodeTypeId,
DocumentFragmentNodeTypeId, DocumentFragmentNodeTypeId,
CommentNodeTypeId, CommentNodeTypeId,
DocumentNodeTypeId(DocumentTypeId), DocumentNodeTypeId,
ElementNodeTypeId(ElementTypeId), ElementNodeTypeId(ElementTypeId),
TextNodeTypeId, TextNodeTypeId,
ProcessingInstructionNodeTypeId, ProcessingInstructionNodeTypeId,
@ -362,7 +362,7 @@ impl NodeHelpers for JS<Node> {
#[inline] #[inline]
fn is_document(&self) -> bool { fn is_document(&self) -> bool {
match self.type_id() { match self.type_id() {
DocumentNodeTypeId(..) => true, DocumentNodeTypeId => true,
_ => false _ => false
} }
} }
@ -804,7 +804,7 @@ impl Node {
TextNodeTypeId => 3, TextNodeTypeId => 3,
ProcessingInstructionNodeTypeId => 7, ProcessingInstructionNodeTypeId => 7,
CommentNodeTypeId => 8, CommentNodeTypeId => 8,
DocumentNodeTypeId(_) => 9, DocumentNodeTypeId => 9,
DoctypeNodeTypeId => 10, DoctypeNodeTypeId => 10,
DocumentFragmentNodeTypeId => 11, DocumentFragmentNodeTypeId => 11,
} }
@ -829,7 +829,7 @@ impl Node {
doctype.get().name.clone() doctype.get().name.clone()
}, },
DocumentFragmentNodeTypeId => ~"#document-fragment", DocumentFragmentNodeTypeId => ~"#document-fragment",
DocumentNodeTypeId(_) => ~"#document" DocumentNodeTypeId => ~"#document"
} }
} }
@ -847,7 +847,7 @@ impl Node {
ProcessingInstructionNodeTypeId | ProcessingInstructionNodeTypeId |
DoctypeNodeTypeId | DoctypeNodeTypeId |
DocumentFragmentNodeTypeId => Some(self.owner_doc()), DocumentFragmentNodeTypeId => Some(self.owner_doc()),
DocumentNodeTypeId(_) => None DocumentNodeTypeId => None
} }
} }
@ -931,7 +931,7 @@ impl Node {
Some(characterdata.get().Data()) Some(characterdata.get().Data())
} }
DoctypeNodeTypeId | DoctypeNodeTypeId |
DocumentNodeTypeId(_) => { DocumentNodeTypeId => {
None None
} }
} }
@ -975,7 +975,7 @@ impl Node {
-> Fallible<JS<Node>> { -> Fallible<JS<Node>> {
// Step 1. // Step 1.
match parent.type_id() { match parent.type_id() {
DocumentNodeTypeId(..) | DocumentNodeTypeId |
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => (), ElementNodeTypeId(..) => (),
_ => return Err(HierarchyRequest) _ => return Err(HierarchyRequest)
@ -1010,12 +1010,12 @@ impl Node {
ElementNodeTypeId(_) | ElementNodeTypeId(_) |
ProcessingInstructionNodeTypeId | ProcessingInstructionNodeTypeId |
CommentNodeTypeId => (), CommentNodeTypeId => (),
DocumentNodeTypeId(..) => return Err(HierarchyRequest) DocumentNodeTypeId => return Err(HierarchyRequest)
} }
// Step 6. // Step 6.
match parent.type_id() { match parent.type_id() {
DocumentNodeTypeId(_) => { DocumentNodeTypeId => {
match node.type_id() { match node.type_id() {
// Step 6.1 // Step 6.1
DocumentFragmentNodeTypeId => { DocumentFragmentNodeTypeId => {
@ -1084,7 +1084,7 @@ impl Node {
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId | ProcessingInstructionNodeTypeId |
CommentNodeTypeId => (), CommentNodeTypeId => (),
DocumentNodeTypeId(_) => unreachable!(), DocumentNodeTypeId => unreachable!(),
} }
}, },
_ => (), _ => (),
@ -1252,7 +1252,7 @@ impl Node {
document.get().content_changed(); document.get().content_changed();
} }
DoctypeNodeTypeId | DoctypeNodeTypeId |
DocumentNodeTypeId(_) => {} DocumentNodeTypeId => {}
} }
Ok(()) Ok(())
} }
@ -1279,7 +1279,7 @@ impl Node {
-> Fallible<JS<Node>> { -> Fallible<JS<Node>> {
// Step 1. // Step 1.
match parent.type_id() { match parent.type_id() {
DocumentNodeTypeId(..) | DocumentNodeTypeId |
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => (), ElementNodeTypeId(..) => (),
_ => return Err(HierarchyRequest) _ => return Err(HierarchyRequest)
@ -1305,12 +1305,12 @@ impl Node {
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId | ProcessingInstructionNodeTypeId |
CommentNodeTypeId => (), CommentNodeTypeId => (),
DocumentNodeTypeId(..) => return Err(HierarchyRequest) DocumentNodeTypeId => return Err(HierarchyRequest)
} }
// Step 6. // Step 6.
match parent.type_id() { match parent.type_id() {
DocumentNodeTypeId(..) => { DocumentNodeTypeId => {
match node.type_id() { match node.type_id() {
// Step 6.1 // Step 6.1
DocumentFragmentNodeTypeId => { DocumentFragmentNodeTypeId => {
@ -1358,7 +1358,7 @@ impl Node {
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId | ProcessingInstructionNodeTypeId |
CommentNodeTypeId => (), CommentNodeTypeId => (),
DocumentNodeTypeId(..) => unreachable!() DocumentNodeTypeId => unreachable!()
} }
}, },
_ => () _ => ()

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, HTMLDocumentTypeId}; use dom::document::{Document, HTMLDocument};
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()), HTMLDocumentTypeId, None); let mut document = Document::new(&window, Some(url.clone()), HTMLDocument, 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(),