mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement DOMImplementation::createDocument
Spec: http://dom.spec.whatwg.org/#dom-domimplementation-createdocument Closes #1509.
This commit is contained in:
parent
bb8a037cb2
commit
41898f0a76
2 changed files with 39 additions and 3 deletions
|
@ -8,7 +8,7 @@ use dom::bindings::js::JS;
|
|||
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
|
||||
use dom::bindings::error::{Fallible, InvalidCharacter, NamespaceError};
|
||||
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
|
||||
use dom::document::{Document, HTMLDocument};
|
||||
use dom::document::{Document, HTMLDocument, NonHTMLDocument};
|
||||
use dom::documenttype::DocumentType;
|
||||
use dom::htmlbodyelement::HTMLBodyElement;
|
||||
use dom::htmlheadelement::HTMLHeadElement;
|
||||
|
@ -63,6 +63,42 @@ impl DOMImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-domimplementation-createdocument
|
||||
pub fn CreateDocument(&self, namespace: Option<DOMString>, qname: DOMString,
|
||||
maybe_doctype: Option<JS<DocumentType>>) -> Fallible<JS<Document>> {
|
||||
// Step 1.
|
||||
let doc = Document::new(&self.owner, None, NonHTMLDocument, None);
|
||||
let mut doc_node: JS<Node> = NodeCast::from(&doc);
|
||||
|
||||
// Step 2-3.
|
||||
let maybe_elem = if qname.is_empty() {
|
||||
None
|
||||
} else {
|
||||
match doc.get().CreateElementNS(&doc, namespace, qname) {
|
||||
Err(error) => return Err(error),
|
||||
Ok(elem) => Some(elem)
|
||||
}
|
||||
};
|
||||
|
||||
// Step 4.
|
||||
match maybe_doctype {
|
||||
None => (),
|
||||
Some(ref doctype) => assert!(doc_node.AppendChild(&mut NodeCast::from(doctype)).is_ok())
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
match maybe_elem {
|
||||
None => (),
|
||||
Some(ref elem) => assert!(doc_node.AppendChild(&mut NodeCast::from(elem)).is_ok())
|
||||
}
|
||||
|
||||
// Step 6.
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1522
|
||||
|
||||
// Step 7.
|
||||
Ok(doc)
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
||||
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> JS<Document> {
|
||||
// Step 1-2.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue