diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/node.rs | 34 | ||||
-rw-r--r-- | components/script/dom/range.rs | 28 |
2 files changed, 42 insertions, 20 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index c82fbb49e88..ec72b6eed2f 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1051,21 +1051,18 @@ pub struct FollowingNodeIterator { root: Root<Node>, } -impl Iterator for FollowingNodeIterator { - type Item = Root<Node>; - - // https://dom.spec.whatwg.org/#concept-tree-following - fn next(&mut self) -> Option<Root<Node>> { +impl FollowingNodeIterator { + /// Skips iterating the children of the current node + pub fn next_skipping_children(&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) + } + fn next_skipping_children_impl(&mut self, current: Root<Node>) -> Option<Root<Node>> { if self.root == current { self.current = 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 { current: Option<Root<Node>>, root: Root<Node>, diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 88fc9ad35bc..df3d0d35883 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -750,7 +750,7 @@ impl RangeMethods for Range { if let Some(text) = start_node.downcast::<CharacterData>() { return text.ReplaceData(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 ancestor = self.CommonAncestorContainer(); - for child in start_node.following_nodes(ancestor.r()) { - if self.contains(child.r()) && - !contained_children.contains(&JS::from_ref(child.GetParentNode().unwrap().r())) { + let mut iter = start_node.following_nodes(ancestor.r()); + + let mut next = iter.next(); + while let Some(child) = next { + if self.contains(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; } - panic!() + unreachable!() } compute_reference(start_node.r(), end_node.r()) @@ -786,9 +791,9 @@ impl RangeMethods for Range { // Step 7. if let Some(text) = start_node.downcast::<CharacterData>() { - try!(text.ReplaceData(start_offset, - start_node.len() - start_offset, - DOMString::from(""))); + text.ReplaceData(start_offset, + start_node.len() - start_offset, + DOMString::new()).unwrap(); } // Step 8. @@ -798,12 +803,13 @@ impl RangeMethods for Range { // Step 9. 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. - try!(self.SetStart(new_node.r(), new_offset)); - self.SetEnd(new_node.r(), new_offset) + self.SetStart(new_node.r(), new_offset).unwrap(); + self.SetEnd(new_node.r(), new_offset).unwrap(); + Ok(()) } // https://dom.spec.whatwg.org/#dom-range-surroundcontents |