mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix Node::ReplaceChild
This commit is contained in:
parent
8bab1cd7a4
commit
b63ca94c7f
1 changed files with 29 additions and 38 deletions
|
@ -283,6 +283,7 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
new_child.parent_node.set(Some(self));
|
new_child.parent_node.set(Some(self));
|
||||||
|
self.children_count.set(self.children_count.get() + 1);
|
||||||
|
|
||||||
let parent_in_doc = self.is_in_doc();
|
let parent_in_doc = self.is_in_doc();
|
||||||
for node in new_child.traverse_preorder() {
|
for node in new_child.traverse_preorder() {
|
||||||
|
@ -320,6 +321,7 @@ impl Node {
|
||||||
child.prev_sibling.set(None);
|
child.prev_sibling.set(None);
|
||||||
child.next_sibling.set(None);
|
child.next_sibling.set(None);
|
||||||
child.parent_node.set(None);
|
child.parent_node.set(None);
|
||||||
|
self.children_count.set(self.children_count.get() - 1);
|
||||||
|
|
||||||
let parent_in_doc = self.is_in_doc();
|
let parent_in_doc = self.is_in_doc();
|
||||||
for node in child.traverse_preorder() {
|
for node in child.traverse_preorder() {
|
||||||
|
@ -1576,7 +1578,7 @@ impl Node {
|
||||||
if let SuppressObserver::Unsuppressed = suppress_observers {
|
if let SuppressObserver::Unsuppressed = suppress_observers {
|
||||||
vtable_for(&parent).children_changed(
|
vtable_for(&parent).children_changed(
|
||||||
&ChildrenMutation::replace(old_previous_sibling.r(),
|
&ChildrenMutation::replace(old_previous_sibling.r(),
|
||||||
&node, &[],
|
&Some(&node), &[],
|
||||||
old_next_sibling.r()));
|
old_next_sibling.r()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2032,11 +2034,6 @@ impl NodeMethods for Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok if not caught by previous error checks.
|
|
||||||
if node == child {
|
|
||||||
return Ok(Root::from_ref(child));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 7-8.
|
// Step 7-8.
|
||||||
let child_next_sibling = child.GetNextSibling();
|
let child_next_sibling = child.GetNextSibling();
|
||||||
let node_next_sibling = node.GetNextSibling();
|
let node_next_sibling = node.GetNextSibling();
|
||||||
|
@ -2047,14 +2044,19 @@ impl NodeMethods for Node {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 9.
|
// Step 9.
|
||||||
|
let previous_sibling = child.GetPreviousSibling();
|
||||||
|
|
||||||
|
// Step 10.
|
||||||
let document = document_from_node(self);
|
let document = document_from_node(self);
|
||||||
Node::adopt(node, document.r());
|
Node::adopt(node, document.r());
|
||||||
|
|
||||||
// Step 10.
|
let removed_child = if node != child {
|
||||||
let previous_sibling = child.GetPreviousSibling();
|
// Step 11.
|
||||||
|
Node::remove(child, self, SuppressObserver::Suppressed);
|
||||||
// Step 11.
|
Some(child)
|
||||||
Node::remove(child, self, SuppressObserver::Suppressed);
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
// Step 12.
|
// Step 12.
|
||||||
let mut nodes = RootedVec::new();
|
let mut nodes = RootedVec::new();
|
||||||
|
@ -2071,7 +2073,7 @@ impl NodeMethods for Node {
|
||||||
// Step 14.
|
// Step 14.
|
||||||
vtable_for(&self).children_changed(
|
vtable_for(&self).children_changed(
|
||||||
&ChildrenMutation::replace(previous_sibling.r(),
|
&ChildrenMutation::replace(previous_sibling.r(),
|
||||||
&child, nodes,
|
&removed_child, nodes,
|
||||||
reference_child));
|
reference_child));
|
||||||
|
|
||||||
// Step 15.
|
// Step 15.
|
||||||
|
@ -2342,21 +2344,6 @@ impl VirtualMethods for Node {
|
||||||
if let Some(ref s) = self.super_type() {
|
if let Some(ref s) = self.super_type() {
|
||||||
s.children_changed(mutation);
|
s.children_changed(mutation);
|
||||||
}
|
}
|
||||||
match *mutation {
|
|
||||||
ChildrenMutation::Append { added, .. } |
|
|
||||||
ChildrenMutation::Insert { added, .. } |
|
|
||||||
ChildrenMutation::Prepend { added, .. } => {
|
|
||||||
self.children_count.set(
|
|
||||||
self.children_count.get() + added.len() as u32);
|
|
||||||
},
|
|
||||||
ChildrenMutation::Replace { added, .. } => {
|
|
||||||
self.children_count.set(
|
|
||||||
self.children_count.get() - 1u32 + added.len() as u32);
|
|
||||||
},
|
|
||||||
ChildrenMutation::ReplaceAll { added, .. } => {
|
|
||||||
self.children_count.set(added.len() as u32);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if let Some(list) = self.child_list.get() {
|
if let Some(list) = self.child_list.get() {
|
||||||
list.as_children_list().children_changed(mutation);
|
list.as_children_list().children_changed(mutation);
|
||||||
}
|
}
|
||||||
|
@ -2405,22 +2392,26 @@ impl<'a> ChildrenMutation<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace(prev: Option<&'a Node>,
|
fn replace(prev: Option<&'a Node>,
|
||||||
removed: &'a &'a Node,
|
removed: &'a Option<&'a Node>,
|
||||||
added: &'a [&'a Node],
|
added: &'a [&'a Node],
|
||||||
next: Option<&'a Node>)
|
next: Option<&'a Node>)
|
||||||
-> ChildrenMutation<'a> {
|
-> ChildrenMutation<'a> {
|
||||||
if let (None, None) = (prev, next) {
|
if let Some(ref removed) = *removed {
|
||||||
ChildrenMutation::ReplaceAll {
|
if let (None, None) = (prev, next) {
|
||||||
removed: ref_slice(removed),
|
ChildrenMutation::ReplaceAll {
|
||||||
added: added,
|
removed: ref_slice(removed),
|
||||||
|
added: added,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ChildrenMutation::Replace {
|
||||||
|
prev: prev,
|
||||||
|
removed: *removed,
|
||||||
|
added: added,
|
||||||
|
next: next,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ChildrenMutation::Replace {
|
ChildrenMutation::insert(prev, added, next)
|
||||||
prev: prev,
|
|
||||||
removed: *removed,
|
|
||||||
added: added,
|
|
||||||
next: next,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue