diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-03-05 18:53:20 +0100 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-03-05 18:53:20 +0100 |
commit | daf9cf8b9df34aee0a882cc462507746e86b8144 (patch) | |
tree | 8c4f238417076d843c7f6d9a74ee9dd16b97a203 /src/components/script/dom/node.rs | |
parent | 22a6485708658cc306cc2fbf25d8f59dd4684fec (diff) | |
download | servo-daf9cf8b9df34aee0a882cc462507746e86b8144.tar.gz servo-daf9cf8b9df34aee0a882cc462507746e86b8144.zip |
Move Node::SetTextContent to a better place.
Diffstat (limited to 'src/components/script/dom/node.rs')
-rw-r--r-- | src/components/script/dom/node.rs | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 56b3b853b48..98c61716b75 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -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>> { |