mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
Remove document::DocumentType (fixes #1730).
This commit is contained in:
parent
e2617a6396
commit
5ede84fa46
5 changed files with 53 additions and 83 deletions
|
@ -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,11 +277,6 @@ 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()
|
||||
|
@ -306,8 +288,6 @@ impl Document {
|
|||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
let v: ~[&str] = title.words().collect();
|
||||
title = v.connect(" ");
|
||||
title = title.trim().to_owned();
|
||||
|
@ -316,11 +296,6 @@ 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| {
|
||||
|
@ -349,8 +324,6 @@ impl Document {
|
|||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue