mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +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,
|
window: @mut Window,
|
||||||
doctype: DocumentType,
|
doctype: DocumentType,
|
||||||
idmap: HashMap<DOMString, AbstractNode>,
|
idmap: HashMap<DOMString, AbstractNode>,
|
||||||
implementation: Option<@mut DOMImplementation>
|
implementation: Option<@mut DOMImplementation>,
|
||||||
|
content_type: DOMString
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Document {
|
impl Document {
|
||||||
|
@ -109,7 +110,7 @@ impl Document {
|
||||||
abstract
|
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 {
|
let node_type = match doctype {
|
||||||
HTML => HTMLDocumentTypeId,
|
HTML => HTMLDocumentTypeId,
|
||||||
SVG | XML => PlainDocumentTypeId
|
SVG | XML => PlainDocumentTypeId
|
||||||
|
@ -120,19 +121,28 @@ impl Document {
|
||||||
window: window,
|
window: window,
|
||||||
doctype: doctype,
|
doctype: doctype,
|
||||||
idmap: HashMap::new(),
|
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 {
|
pub fn new(window: @mut Window, doctype: DocumentType, content_type: Option<DOMString>) -> AbstractDocument {
|
||||||
let document = Document::new_inherited(window, doctype);
|
let document = Document::new_inherited(window, doctype, content_type);
|
||||||
Document::reflect_document(@mut document, window, DocumentBinding::Wrap)
|
Document::reflect_document(@mut document, window, DocumentBinding::Wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Document {
|
impl Document {
|
||||||
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
|
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()
|
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> {
|
pub fn GetDoctype(&self) -> Option<AbstractNode> {
|
||||||
self.node.children().find(|child| child.is_doctype())
|
self.node.children().find(|child| child.is_doctype())
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,16 +62,13 @@ 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>) -> AbstractDocument {
|
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> AbstractDocument {
|
||||||
// Step 1.
|
// Step 1-2.
|
||||||
let abstract_doc = HTMLDocument::new(self.owner);
|
let abstract_doc = HTMLDocument::new(self.owner);
|
||||||
assert!(abstract_doc.document().doctype == HTML);
|
assert!(abstract_doc.document().doctype == HTML);
|
||||||
|
|
||||||
let abstract_node = AbstractNode::from_document(abstract_doc);
|
let abstract_node = AbstractNode::from_document(abstract_doc);
|
||||||
assert!(abstract_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId));
|
assert!(abstract_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId));
|
||||||
|
|
||||||
// Step 2.
|
|
||||||
// FIXME: https://github.com/mozilla/servo/pull/1519
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let doc_type = DocumentType::new(~"html", None, None, abstract_doc);
|
let doc_type = DocumentType::new(~"html", None, None, abstract_doc);
|
||||||
|
|
|
@ -6,7 +6,7 @@ use dom::bindings::codegen::DOMParserBinding;
|
||||||
use dom::bindings::codegen::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml};
|
use dom::bindings::codegen::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml};
|
||||||
use dom::bindings::utils::{DOMString, Fallible, Reflector, Reflectable, reflect_dom_object};
|
use dom::bindings::utils::{DOMString, Fallible, Reflector, Reflectable, reflect_dom_object};
|
||||||
use dom::bindings::utils::FailureUnknown;
|
use dom::bindings::utils::FailureUnknown;
|
||||||
use dom::document::{AbstractDocument, Document, XML};
|
use dom::document::{AbstractDocument, Document};
|
||||||
use dom::htmldocument::HTMLDocument;
|
use dom::htmldocument::HTMLDocument;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ impl DOMParser {
|
||||||
Ok(HTMLDocument::new(self.owner))
|
Ok(HTMLDocument::new(self.owner))
|
||||||
}
|
}
|
||||||
Text_xml => {
|
Text_xml => {
|
||||||
Ok(Document::new(self.owner, XML))
|
Document::Constructor(self.owner)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Err(FailureUnknown)
|
Err(FailureUnknown)
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct HTMLDocument {
|
||||||
impl HTMLDocument {
|
impl HTMLDocument {
|
||||||
pub fn new_inherited(window: @mut Window) -> HTMLDocument {
|
pub fn new_inherited(window: @mut Window) -> HTMLDocument {
|
||||||
HTMLDocument {
|
HTMLDocument {
|
||||||
parent: Document::new_inherited(window, HTML)
|
parent: Document::new_inherited(window, HTML, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ interface Document : Node {
|
||||||
// readonly attribute DOMString documentURI;
|
// readonly attribute DOMString documentURI;
|
||||||
// readonly attribute DOMString compatMode;
|
// readonly attribute DOMString compatMode;
|
||||||
// readonly attribute DOMString characterSet;
|
// readonly attribute DOMString characterSet;
|
||||||
// readonly attribute DOMString contentType;
|
readonly attribute DOMString contentType;
|
||||||
|
|
||||||
readonly attribute DocumentType? doctype;
|
readonly attribute DocumentType? doctype;
|
||||||
readonly attribute Element? documentElement;
|
readonly attribute Element? documentElement;
|
||||||
|
|
|
@ -22,6 +22,7 @@ function _printer(opstr, op) {
|
||||||
|
|
||||||
var is = _printer("==", function (a,b) { return a == b; });
|
var is = _printer("==", function (a,b) { return a == b; });
|
||||||
var is_a = _printer("is a", function (a,b) { return a instanceof b; });
|
var is_a = _printer("is a", function (a,b) { return a instanceof b; });
|
||||||
|
var is_not_a = _printer("is not a", function (a,b) { return !(a instanceof b); });
|
||||||
var is_in = _printer("is in", function (a,b) { return a in b; });
|
var is_in = _printer("is in", function (a,b) { return a in b; });
|
||||||
var is_not_in = _printer("is not in", function (a,b) { return !(a in b); });
|
var is_not_in = _printer("is not in", function (a,b) { return !(a in b); });
|
||||||
var as_str_is = _printer("as string is", function (a,b) { return String(a) == b; });
|
var as_str_is = _printer("as string is", function (a,b) { return String(a) == b; });
|
||||||
|
|
22
src/test/html/content/test_document_contenttype.html
Normal file
22
src/test/html/content/test_document_contenttype.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="harness.js"></script>
|
||||||
|
<script>
|
||||||
|
// test1: HTML document
|
||||||
|
{
|
||||||
|
is_a(document, HTMLDocument, "test1-0, HTML document");
|
||||||
|
is(document.contentType, "text/html", "test1-1, HTML document");
|
||||||
|
}
|
||||||
|
|
||||||
|
// test2: XML document
|
||||||
|
{
|
||||||
|
var doc = new Document;
|
||||||
|
is_not_a(doc, HTMLDocument, "test2-0, XML document");
|
||||||
|
is(doc.contentType, "application/xml", "test2-1, XML document");
|
||||||
|
}
|
||||||
|
|
||||||
|
finish();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue