Move Node::SetTextContent to a better place.

This commit is contained in:
Ms2ger 2014-03-05 18:53:20 +01:00
parent 22a6485708
commit daf9cf8b9d

View file

@ -956,6 +956,41 @@ impl Node {
}
}
// http://dom.spec.whatwg.org/#dom-node-textcontent
pub fn SetTextContent(&mut self, abstract_self: &mut JS<Node>, value: Option<DOMString>)
-> ErrorResult {
let value = null_str_as_empty(&value);
match self.type_id {
DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => {
// Step 1-2.
let node = if value.len() == 0 {
None
} else {
let document = self.owner_doc();
Some(NodeCast::from(&document.get().CreateTextNode(&document, value)))
};
// Step 3.
Node::replace_all(node, abstract_self);
}
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
self.wait_until_safe_to_modify_dom();
let mut characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
characterdata.get_mut().data = value.clone();
// Notify the document that the content of this node is different
let document = self.owner_doc();
document.get().content_changed();
}
DoctypeNodeTypeId |
DocumentNodeTypeId => {}
}
Ok(())
}
// http://dom.spec.whatwg.org/#concept-node-adopt
fn adopt(node: &mut JS<Node>, document: &JS<Document>) {
// Step 1.
@ -1227,41 +1262,6 @@ impl Node {
}
}
// http://dom.spec.whatwg.org/#dom-node-textcontent
pub fn SetTextContent(&mut self, abstract_self: &mut JS<Node>, value: Option<DOMString>)
-> ErrorResult {
let value = null_str_as_empty(&value);
match self.type_id {
DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => {
// Step 1-2.
let node = if value.len() == 0 {
None
} else {
let document = self.owner_doc();
Some(NodeCast::from(&document.get().CreateTextNode(&document, value)))
};
// Step 3.
Node::replace_all(node, abstract_self);
}
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
self.wait_until_safe_to_modify_dom();
let mut characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
characterdata.get_mut().data = value.clone();
// Notify the document that the content of this node is different
let document = self.owner_doc();
document.get().content_changed();
}
DoctypeNodeTypeId |
DocumentNodeTypeId => {}
}
Ok(())
}
// http://dom.spec.whatwg.org/#dom-node-insertbefore
pub fn InsertBefore(&self, abstract_self: &mut JS<Node>, node: &mut JS<Node>, child: Option<JS<Node>>)
-> Fallible<JS<Node>> {