Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for Document::contentType #1525

Merged
merged 1 commit into from Jan 22, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Basic support for Document::contentType

  • Loading branch information
brunoabinader committed Jan 21, 2014
commit 1067da7df8b891b9df961ff6ab57ed2925bd2d03
@@ -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())
}
@@ -62,16 +62,13 @@ impl DOMImplementation {

// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> AbstractDocument {
// Step 1.
// Step 1-2.
let abstract_doc = HTMLDocument::new(self.owner);
assert!(abstract_doc.document().doctype == HTML);

let abstract_node = AbstractNode::from_document(abstract_doc);
assert!(abstract_node.type_id() == DocumentNodeTypeId(HTMLDocumentTypeId));

// Step 2.
// FIXME: https://github.com/mozilla/servo/pull/1519

{
// Step 3.
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::utils::{DOMString, Fallible, Reflector, Reflectable, reflect_dom_object};
use dom::bindings::utils::FailureUnknown;
use dom::document::{AbstractDocument, Document, XML};
use dom::document::{AbstractDocument, Document};
use dom::htmldocument::HTMLDocument;
use dom::window::Window;

@@ -41,7 +41,7 @@ impl DOMParser {
Ok(HTMLDocument::new(self.owner))
}
Text_xml => {
Ok(Document::new(self.owner, XML))
Document::Constructor(self.owner)
}
_ => {
Err(FailureUnknown)
@@ -20,7 +20,7 @@ pub struct HTMLDocument {
impl HTMLDocument {
pub fn new_inherited(window: @mut Window) -> 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 compatMode;
// readonly attribute DOMString characterSet;
// readonly attribute DOMString contentType;
readonly attribute DOMString contentType;

readonly attribute DocumentType? doctype;
readonly attribute Element? documentElement;
@@ -22,6 +22,7 @@ function _printer(opstr, op) {

var is = _printer("==", function (a,b) { return a == 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_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; });
@@ -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>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.