mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Rewrite replace_all.
This commit is contained in:
parent
6a0201a5a6
commit
9bcf5468e4
1 changed files with 43 additions and 14 deletions
|
@ -889,18 +889,45 @@ 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,
|
pub fn replace_all(node: Option<AbstractNode<ScriptView>>,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
parent: AbstractNode<ScriptView>) {
|
||||||
node: Option<AbstractNode<ScriptView>>) {
|
// Step 1.
|
||||||
//FIXME: We should batch document notifications that occur here
|
|
||||||
for child in abstract_self.children() {
|
|
||||||
self.RemoveChild(abstract_self, child);
|
|
||||||
}
|
|
||||||
match node {
|
match node {
|
||||||
None => {},
|
Some(node) => Node::adopt(node, parent.node().owner_doc()),
|
||||||
Some(node) => {
|
None => (),
|
||||||
self.AppendChild(abstract_self, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
|
let removedNodes: ~[AbstractNode<ScriptView>] = parent.children().collect();
|
||||||
|
|
||||||
|
// Step 3.
|
||||||
|
let addedNodes = match node {
|
||||||
|
None => ~[],
|
||||||
|
Some(node) => match node.type_id() {
|
||||||
|
DocumentFragmentNodeTypeId => node.children().collect(),
|
||||||
|
_ => ~[node],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 4.
|
||||||
|
for child in parent.children() {
|
||||||
|
Node::remove(child, parent, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 5.
|
||||||
|
match node {
|
||||||
|
Some(node) => Node::insert(node, parent, None, true),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 6: mutation records.
|
||||||
|
|
||||||
|
// Step 7.
|
||||||
|
for removedNode in removedNodes.iter() {
|
||||||
|
removedNode.node_removed();
|
||||||
|
}
|
||||||
|
for addedNode in addedNodes.iter() {
|
||||||
|
addedNode.node_inserted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,20 +966,22 @@ impl Node<ScriptView> {
|
||||||
pub fn SetTextContent(&mut self,
|
pub fn SetTextContent(&mut self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
value: &Option<DOMString>) -> ErrorResult {
|
value: &Option<DOMString>) -> ErrorResult {
|
||||||
|
self.wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
let value = null_str_as_empty(value);
|
let value = null_str_as_empty(value);
|
||||||
match self.type_id {
|
match self.type_id {
|
||||||
DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => {
|
DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => {
|
||||||
|
// Step 1-2.
|
||||||
let node = if value.len() == 0 {
|
let node = if value.len() == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let document = self.owner_doc();
|
let document = self.owner_doc();
|
||||||
Some(document.document().CreateTextNode(document, &value))
|
Some(document.document().CreateTextNode(document, &value))
|
||||||
};
|
};
|
||||||
self.replace_all(abstract_self, node);
|
// Step 3.
|
||||||
|
Node::replace_all(node, abstract_self);
|
||||||
}
|
}
|
||||||
CommentNodeTypeId | TextNodeTypeId => {
|
CommentNodeTypeId | TextNodeTypeId => {
|
||||||
self.wait_until_safe_to_modify_dom();
|
|
||||||
|
|
||||||
do abstract_self.with_mut_characterdata() |characterdata| {
|
do abstract_self.with_mut_characterdata() |characterdata| {
|
||||||
characterdata.data = value.clone();
|
characterdata.data = value.clone();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue