Pass the AbstractNode into the Node.textContent setter.

This commit is contained in:
Josh Matthews 2013-09-16 23:29:05 -04:00
parent bea1c4f01e
commit 37787d55d0
3 changed files with 38 additions and 31 deletions

View file

@ -293,7 +293,7 @@ DOMInterfaces = {
'nativeType': 'AbstractNode<ScriptView>', 'nativeType': 'AbstractNode<ScriptView>',
'concreteType': 'Node<ScriptView>', 'concreteType': 'Node<ScriptView>',
'pointerType': '', 'pointerType': '',
'needsAbstract': ['appendChild', 'removeChild'] 'needsAbstract': ['appendChild', 'removeChild', 'textContent']
}, },
'NodeList': [ 'NodeList': [

View file

@ -331,7 +331,7 @@ impl Document {
for title_child in child.children() { for title_child in child.children() {
child.remove_child(title_child); child.remove_child(title_child);
} }
child.add_child(self.createText(title.to_str())); child.add_child(self.CreateTextNode(title));
break; break;
} }
if !has_title { if !has_title {
@ -341,7 +341,7 @@ impl Document {
let new_title = unsafe { let new_title = unsafe {
Node::as_abstract_node(cx, new_title) Node::as_abstract_node(cx, new_title)
}; };
new_title.add_child(self.createText(title.to_str())); new_title.add_child(self.CreateTextNode(title));
node.add_child(new_title); node.add_child(new_title);
} }
break; break;
@ -438,13 +438,6 @@ impl Document {
elem.get_attr("name").is_some() && eq_slice(elem.get_attr("name").unwrap(), name.to_str())) elem.get_attr("name").is_some() && eq_slice(elem.get_attr("name").unwrap(), name.to_str()))
} }
pub fn createText(&self, data: ~str) -> AbstractNode<ScriptView> {
let (_scope, cx) = self.get_scope_and_cx();
unsafe {
Node::as_abstract_node(cx, @Text::new(data))
}
}
pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection { pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection {
let mut elements = ~[]; let mut elements = ~[];
let _ = for child in self.root.traverse_preorder() { let _ = for child in self.root.traverse_preorder() {

View file

@ -562,11 +562,11 @@ impl Node<ScriptView> {
pub fn SetNodeValue(&mut self, _val: &DOMString, _rv: &mut ErrorResult) { pub fn SetNodeValue(&mut self, _val: &DOMString, _rv: &mut ErrorResult) {
} }
pub fn GetTextContent(&self) -> DOMString { pub fn GetTextContent(&self, abstract_self: AbstractNode<ScriptView>) -> DOMString {
match self.type_id { match self.type_id {
ElementNodeTypeId(*) => { ElementNodeTypeId(*) => {
let mut content = ~""; let mut content = ~"";
for node in self.abstract.unwrap().traverse_preorder() { for node in abstract_self.traverse_preorder() {
if node.is_text() { if node.is_text() {
do node.with_imm_text() |text| { do node.with_imm_text() |text| {
let s = text.parent.Data(); let s = text.parent.Data();
@ -577,7 +577,7 @@ impl Node<ScriptView> {
str(content) str(content)
} }
CommentNodeTypeId | TextNodeTypeId => { CommentNodeTypeId | TextNodeTypeId => {
do self.abstract.unwrap().with_imm_characterdata() |characterdata| { do abstract_self.with_imm_characterdata() |characterdata| {
characterdata.Data() characterdata.Data()
} }
} }
@ -588,38 +588,52 @@ impl Node<ScriptView> {
} }
// http://dom.spec.whatwg.org/#concept-node-replace-all // http://dom.spec.whatwg.org/#concept-node-replace-all
pub fn replace_all(&mut self, node: Option<AbstractNode<ScriptView>>) { pub fn replace_all(&mut self,
let this = self.abstract.unwrap(); abstract_self: AbstractNode<ScriptView>,
for child in this.children() { node: Option<AbstractNode<ScriptView>>) {
this.remove_child(child); //FIXME: We should batch document notifications that occur here
let mut rv = Ok(());
for child in abstract_self.children() {
self.RemoveChild(abstract_self, child, &mut rv);
} }
match node { match node {
None => {}, None => {},
Some(node) => this.add_child(node) Some(node) => {
self.AppendChild(abstract_self, node, &mut rv);
}
} }
} }
pub fn SetTextContent(&mut self, value: &DOMString, _rv: &mut ErrorResult) { pub fn SetTextContent(&mut self,
let text_content = match value { abstract_self: AbstractNode<ScriptView>,
&str(ref s) => s.as_slice(), value: &DOMString,
&null_string => &"" _rv: &mut ErrorResult) {
let is_empty = match value {
&str(~"") | &null_string => true,
_ => false
}; };
match self.type_id { match self.type_id {
ElementNodeTypeId(*) => { ElementNodeTypeId(*) => {
let node = match text_content { let node = if is_empty {
"" => None, None
s => { } else {
let text_node = do self.owner_doc.unwrap().with_base |document| { let text_node = do self.owner_doc.unwrap().with_base |document| {
document.createText(s.to_str()) document.CreateTextNode(value)
}; };
Some(text_node) Some(text_node)
}
}; };
self.replace_all(node); self.replace_all(abstract_self, node);
} }
CommentNodeTypeId | TextNodeTypeId => { CommentNodeTypeId | TextNodeTypeId => {
do self.abstract.unwrap().with_mut_characterdata() |characterdata| { do abstract_self.with_mut_characterdata() |characterdata| {
characterdata.data = text_content.to_str(); characterdata.data = value.to_str();
// Notify the document that the content of this node is different
for doc in self.owner_doc.iter() {
do doc.with_base |doc| {
doc.content_changed();
}
}
} }
} }
DoctypeNodeTypeId => {} DoctypeNodeTypeId => {}