mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Document::create_collection's callback should return a boolean instead of a node. (#2027)
This commit is contained in:
parent
e3bf08ea53
commit
faea175505
1 changed files with 5 additions and 15 deletions
|
@ -563,31 +563,21 @@ impl Document {
|
|||
HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter)
|
||||
}
|
||||
|
||||
pub fn create_collection<T>(&self, callback: |elem: &JS<Node>| -> Option<JS<T>>) -> ~[JS<T>] {
|
||||
let mut nodes = ~[];
|
||||
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
|
||||
let mut nodes: ~[JS<Node>] = ~[];
|
||||
match self.GetDocumentElement() {
|
||||
None => {},
|
||||
Some(root) => {
|
||||
let root: JS<Node> = NodeCast::from(&root);
|
||||
for child in root.traverse_preorder() {
|
||||
match callback(&child) {
|
||||
Some(node) => nodes.push(node),
|
||||
None => (),
|
||||
if callback(&child) {
|
||||
nodes.push(child.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nodes
|
||||
}
|
||||
|
||||
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
|
||||
NodeList::new_simple_list(&self.window, self.create_collection(|node| {
|
||||
if !callback(node) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(node.clone())
|
||||
}))
|
||||
NodeList::new_simple_list(&self.window, nodes)
|
||||
}
|
||||
|
||||
pub fn content_changed(&self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue