From daf9cf8b9df34aee0a882cc462507746e86b8144 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 5 Mar 2014 18:53:20 +0100 Subject: Move Node::SetTextContent to a better place. --- src/components/script/dom/node.rs | 70 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/components/script/dom/node.rs') 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, value: Option) + -> 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 = 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, document: &JS) { // 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, value: Option) - -> 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 = 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: &mut JS, child: Option>) -> Fallible> { -- cgit v1.2.3