Implemented Document.importNode

Spec:
http://dom.spec.whatwg.org/#dom-document-importnode
This commit is contained in:
Bruno de Oliveira Abinader 2014-03-17 00:55:57 -04:00
parent f34a64049a
commit 8a457a2caa
4 changed files with 24 additions and 3 deletions

View file

@ -40,6 +40,7 @@ DOMInterfaces = {
'getElementsByTagName',
'getElementsByTagNameNS',
'images',
'importNode',
'links',
'plugins',
'scripts',

View file

@ -28,6 +28,7 @@ use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::mouseevent::MouseEvent;
use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, INode};
use dom::node::{CloneChildren, DoNotCloneChildren};
use dom::text::Text;
use dom::processinginstruction::ProcessingInstruction;
use dom::uievent::UIEvent;
@ -294,6 +295,22 @@ impl Document {
Ok(ProcessingInstruction::new(target, data, abstract_self))
}
// http://dom.spec.whatwg.org/#dom-document-importnode
pub fn ImportNode(&self, abstract_self: &JS<Document>, node: &JS<Node>, deep: bool) -> Fallible<JS<Node>> {
// Step 1.
if node.is_document() {
return Err(NotSupported);
}
// Step 2.
let clone_children = match deep {
true => CloneChildren,
false => DoNotCloneChildren
};
Ok(Node::clone(node, Some(abstract_self), clone_children))
}
// http://dom.spec.whatwg.org/#dom-document-createevent
pub fn CreateEvent(&self, interface: DOMString) -> Fallible<JS<Event>> {
match interface.as_slice() {

View file

@ -728,7 +728,7 @@ fn gather_abstract_nodes(cur: &JS<Node>, refs: &mut ~[JS<Node>], postorder: bool
}
/// Specifies whether children must be recursively cloned or not.
enum CloneChildrenFlag {
pub enum CloneChildrenFlag {
CloneChildren,
DoNotCloneChildren
}
@ -1287,8 +1287,8 @@ impl Node {
}
// http://dom.spec.whatwg.org/#concept-node-clone
fn clone(node: &JS<Node>, maybe_doc: Option<&JS<Document>>, clone_children: CloneChildrenFlag)
-> JS<Node> {
pub fn clone(node: &JS<Node>, maybe_doc: Option<&JS<Document>>,
clone_children: CloneChildrenFlag) -> JS<Node> {
fn clone_recursively(node: &JS<Node>, copy: &mut JS<Node>, doc: &JS<Document>) {
for ref child in node.get().children() {
let mut cloned = Node::clone(child, Some(doc), DoNotCloneChildren);

View file

@ -36,6 +36,9 @@ interface Document : Node {
[Creator, Throws]
ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
[Throws]
Node importNode(Node node, optional boolean deep = false);
[Creator, Throws]
Event createEvent(DOMString interface_);
};