From 3e36739e381c99f5f10faa9bd9d31c3a4623250d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 28 Feb 2016 18:21:08 +0100 Subject: script: Fix remaining bugs from Range.deleteContents --- components/script/dom/node.rs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'components/script/dom/node.rs') 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, } -impl Iterator for FollowingNodeIterator { - type Item = Root; - - // https://dom.spec.whatwg.org/#concept-tree-following - fn next(&mut self) -> Option> { +impl FollowingNodeIterator { + /// Skips iterating the children of the current node + pub fn next_skipping_children(&mut self) -> Option> { 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) -> Option> { if self.root == current { self.current = None; return None; @@ -1090,6 +1087,25 @@ impl Iterator for FollowingNodeIterator { } } +impl Iterator for FollowingNodeIterator { + type Item = Root; + + // https://dom.spec.whatwg.org/#concept-tree-following + fn next(&mut self) -> Option> { + 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: Root, -- cgit v1.2.3