mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
script: Fix remaining bugs from Range.deleteContents
This commit is contained in:
parent
be6940db59
commit
3e36739e38
3 changed files with 42 additions and 43 deletions
|
@ -1051,21 +1051,18 @@ pub struct FollowingNodeIterator {
|
||||||
root: Root<Node>,
|
root: Root<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for FollowingNodeIterator {
|
impl FollowingNodeIterator {
|
||||||
type Item = Root<Node>;
|
/// Skips iterating the children of the current node
|
||||||
|
pub fn next_skipping_children(&mut self) -> Option<Root<Node>> {
|
||||||
// https://dom.spec.whatwg.org/#concept-tree-following
|
|
||||||
fn next(&mut self) -> Option<Root<Node>> {
|
|
||||||
let current = match self.current.take() {
|
let current = match self.current.take() {
|
||||||
None => return None,
|
None => return None,
|
||||||
Some(current) => current,
|
Some(current) => current,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(first_child) = current.GetFirstChild() {
|
self.next_skipping_children_impl(current)
|
||||||
self.current = Some(first_child);
|
|
||||||
return current.GetFirstChild()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next_skipping_children_impl(&mut self, current: Root<Node>) -> Option<Root<Node>> {
|
||||||
if self.root == current {
|
if self.root == current {
|
||||||
self.current = None;
|
self.current = None;
|
||||||
return None;
|
return None;
|
||||||
|
@ -1090,6 +1087,25 @@ impl Iterator for FollowingNodeIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Iterator for FollowingNodeIterator {
|
||||||
|
type Item = Root<Node>;
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#concept-tree-following
|
||||||
|
fn next(&mut self) -> Option<Root<Node>> {
|
||||||
|
let current = match self.current.take() {
|
||||||
|
None => return None,
|
||||||
|
Some(current) => current,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(first_child) = current.GetFirstChild() {
|
||||||
|
self.current = Some(first_child);
|
||||||
|
return current.GetFirstChild()
|
||||||
|
}
|
||||||
|
|
||||||
|
self.next_skipping_children_impl(current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PrecedingNodeIterator {
|
pub struct PrecedingNodeIterator {
|
||||||
current: Option<Root<Node>>,
|
current: Option<Root<Node>>,
|
||||||
root: Root<Node>,
|
root: Root<Node>,
|
||||||
|
|
|
@ -750,7 +750,7 @@ impl RangeMethods for Range {
|
||||||
if let Some(text) = start_node.downcast::<CharacterData>() {
|
if let Some(text) = start_node.downcast::<CharacterData>() {
|
||||||
return text.ReplaceData(start_offset,
|
return text.ReplaceData(start_offset,
|
||||||
end_offset - start_offset,
|
end_offset - start_offset,
|
||||||
DOMString::from(""));
|
DOMString::new());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,10 +758,15 @@ impl RangeMethods for Range {
|
||||||
let mut contained_children: RootedVec<JS<Node>> = RootedVec::new();
|
let mut contained_children: RootedVec<JS<Node>> = RootedVec::new();
|
||||||
let ancestor = self.CommonAncestorContainer();
|
let ancestor = self.CommonAncestorContainer();
|
||||||
|
|
||||||
for child in start_node.following_nodes(ancestor.r()) {
|
let mut iter = start_node.following_nodes(ancestor.r());
|
||||||
if self.contains(child.r()) &&
|
|
||||||
!contained_children.contains(&JS::from_ref(child.GetParentNode().unwrap().r())) {
|
let mut next = iter.next();
|
||||||
|
while let Some(child) = next {
|
||||||
|
if self.contains(child.r()) {
|
||||||
contained_children.push(JS::from_ref(child.r()));
|
contained_children.push(JS::from_ref(child.r()));
|
||||||
|
next = iter.next_skipping_children();
|
||||||
|
} else {
|
||||||
|
next = iter.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,7 +783,7 @@ impl RangeMethods for Range {
|
||||||
}
|
}
|
||||||
reference_node = parent;
|
reference_node = parent;
|
||||||
}
|
}
|
||||||
panic!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
compute_reference(start_node.r(), end_node.r())
|
compute_reference(start_node.r(), end_node.r())
|
||||||
|
@ -786,9 +791,9 @@ impl RangeMethods for Range {
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
if let Some(text) = start_node.downcast::<CharacterData>() {
|
if let Some(text) = start_node.downcast::<CharacterData>() {
|
||||||
try!(text.ReplaceData(start_offset,
|
text.ReplaceData(start_offset,
|
||||||
start_node.len() - start_offset,
|
start_node.len() - start_offset,
|
||||||
DOMString::from("")));
|
DOMString::new()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 8.
|
// Step 8.
|
||||||
|
@ -798,12 +803,13 @@ impl RangeMethods for Range {
|
||||||
|
|
||||||
// Step 9.
|
// Step 9.
|
||||||
if let Some(text) = end_node.downcast::<CharacterData>() {
|
if let Some(text) = end_node.downcast::<CharacterData>() {
|
||||||
try!(text.ReplaceData(0, end_offset, DOMString::from("")));
|
text.ReplaceData(0, end_offset, DOMString::new()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 10.
|
// Step 10.
|
||||||
try!(self.SetStart(new_node.r(), new_offset));
|
self.SetStart(new_node.r(), new_offset).unwrap();
|
||||||
self.SetEnd(new_node.r(), new_offset)
|
self.SetEnd(new_node.r(), new_offset).unwrap();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-range-surroundcontents
|
// https://dom.spec.whatwg.org/#dom-range-surroundcontents
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
[Range-deleteContents.html]
|
|
||||||
type: testharness
|
|
||||||
[Resulting DOM for range 24 [document, 0, document, 2\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Resulting DOM for range 10 [document.documentElement, 0, document.documentElement, 1\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Resulting DOM for range 11 [document.documentElement, 0, document.documentElement, 2\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Resulting DOM for range 12 [document.documentElement, 1, document.documentElement, 2\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Resulting DOM for range 15 [foreignDoc.documentElement, 0, foreignDoc.documentElement, 1\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Resulting DOM for range 27 [foreignDoc, 1, foreignComment, 2\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Resulting DOM for range 49 [document, 1, document, 2\]]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue