mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Basic support for Document::contentType
Spec: http://dom.spec.whatwg.org/#dom-document-contenttype This is a subtask for #1428, #1510 and #1526.
This commit is contained in:
parent
539cf58f73
commit
1067da7df8
7 changed files with 49 additions and 14 deletions
|
@ -88,7 +88,8 @@ pub struct Document {
|
|||
window: @mut Window,
|
||||
doctype: DocumentType,
|
||||
idmap: HashMap<DOMString, AbstractNode>,
|
||||
implementation: Option<@mut DOMImplementation>
|
||||
implementation: Option<@mut DOMImplementation>,
|
||||
content_type: DOMString
|
||||
}
|
||||
|
||||
impl Document {
|
||||
|
@ -109,7 +110,7 @@ impl Document {
|
|||
abstract
|
||||
}
|
||||
|
||||
pub fn new_inherited(window: @mut Window, doctype: DocumentType) -> Document {
|
||||
pub fn new_inherited(window: @mut Window, doctype: DocumentType, content_type: Option<DOMString>) -> Document {
|
||||
let node_type = match doctype {
|
||||
HTML => HTMLDocumentTypeId,
|
||||
SVG | XML => PlainDocumentTypeId
|
||||
|
@ -120,19 +121,28 @@ impl Document {
|
|||
window: window,
|
||||
doctype: doctype,
|
||||
idmap: HashMap::new(),
|
||||
implementation: None
|
||||
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",
|
||||
// http://dom.spec.whatwg.org/#concept-document-content-type
|
||||
SVG | XML => ~"application/xml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(window: @mut Window, doctype: DocumentType) -> AbstractDocument {
|
||||
let document = Document::new_inherited(window, doctype);
|
||||
pub fn new(window: @mut Window, doctype: DocumentType, content_type: Option<DOMString>) -> AbstractDocument {
|
||||
let document = Document::new_inherited(window, doctype, content_type);
|
||||
Document::reflect_document(@mut document, window, DocumentBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl Document {
|
||||
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
|
||||
Ok(Document::new(owner, XML))
|
||||
Ok(Document::new(owner, XML, None))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,6 +174,11 @@ impl Document {
|
|||
self.implementation.unwrap()
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-document-content_type
|
||||
pub fn ContentType(&self) -> DOMString {
|
||||
self.content_type.clone()
|
||||
}
|
||||
|
||||
pub fn GetDoctype(&self) -> Option<AbstractNode> {
|
||||
self.node.children().find(|child| child.is_doctype())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue