mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Move Node::SetTextContent to a better place.
This commit is contained in:
parent
22a6485708
commit
daf9cf8b9d
1 changed files with 35 additions and 35 deletions
|
@ -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>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue