Skip to content

Commit

Permalink
implemented iterator for child elements
Browse files Browse the repository at this point in the history
  • Loading branch information
khodzha committed Jan 3, 2014
1 parent be8ed32 commit 8bb1724
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/components/script/dom/document.rs
Expand Up @@ -162,9 +162,7 @@ impl Reflectable for Document {

impl Document {
pub fn GetDocumentElement(&self) -> Option<AbstractNode> {
do self.node.children().find |c| {
c.is_element()
}
self.node.child_elements().next()
}

fn get_cx(&self) -> *JSContext {
Expand Down
23 changes: 19 additions & 4 deletions src/components/script/dom/node.rs
Expand Up @@ -25,6 +25,7 @@ use std::cast::transmute;
use std::cast;
use std::unstable::raw::Box;
use std::util;
use std::iter::Filter;

//
// The basic Node structure
Expand Down Expand Up @@ -486,6 +487,10 @@ impl<'self> AbstractNode {
self.node().children()
}

pub fn child_elements(&self) -> Filter<AbstractNode, AbstractNodeChildrenIterator> {
self.node().child_elements()
}

pub fn is_in_doc(&self) -> bool {
self.node().flags.is_in_doc()
}
Expand Down Expand Up @@ -749,6 +754,10 @@ impl Node {
}
}

pub fn child_elements(&self) -> Filter<AbstractNode, AbstractNodeChildrenIterator> {
self.children().filter(|node| node.is_element())
}

pub fn reflect_node<N: Reflectable>
(node: @mut N,
document: AbstractDocument,
Expand Down Expand Up @@ -1041,11 +1050,13 @@ impl Node {
if node.children().any(|c| c.is_text()) {
return Err(HierarchyRequest);
}
match node.children().count(|c| c.is_element()) {
match node.child_elements().len() {
0 => (),
// Step 6.1.2
1 => {
if parent.children().any(|c| c.is_element()) {
// FIXME: change to empty() when https://github.com/mozilla/rust/issues/11218
// will be fixed
if parent.child_elements().len() > 0 {
return Err(HierarchyRequest);
}
if inclusively_followed_by_doctype(child) {
Expand All @@ -1058,7 +1069,9 @@ impl Node {
},
// Step 6.2
ElementNodeTypeId(_) => {
if parent.children().any(|c| c.is_element()) {
// FIXME: change to empty() when https://github.com/mozilla/rust/issues/11218
// will be fixed
if parent.child_elements().len() > 0 {
return Err(HierarchyRequest);
}
if inclusively_followed_by_doctype(child) {
Expand All @@ -1079,7 +1092,9 @@ impl Node {
}
},
None => {
if parent.children().any(|c| c.is_element()) {
// FIXME: change to empty() when https://github.com/mozilla/rust/issues/11218
// will be fixed
if parent.child_elements().len() > 0 {
return Err(HierarchyRequest);
}
},
Expand Down

5 comments on commit 8bb1724

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at khodzha@8bb1724

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging khodzha/servo/child_elements = 8bb1724 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

khodzha/servo/child_elements = 8bb1724 merged ok, testing candidate = 8cdfbf3

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 8cdfbf3

Please sign in to comment.