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)
|
HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_collection<T>(&self, callback: |elem: &JS<Node>| -> Option<JS<T>>) -> ~[JS<T>] {
|
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
|
||||||
let mut nodes = ~[];
|
let mut nodes: ~[JS<Node>] = ~[];
|
||||||
match self.GetDocumentElement() {
|
match self.GetDocumentElement() {
|
||||||
None => {},
|
None => {},
|
||||||
Some(root) => {
|
Some(root) => {
|
||||||
let root: JS<Node> = NodeCast::from(&root);
|
let root: JS<Node> = NodeCast::from(&root);
|
||||||
for child in root.traverse_preorder() {
|
for child in root.traverse_preorder() {
|
||||||
match callback(&child) {
|
if callback(&child) {
|
||||||
Some(node) => nodes.push(node),
|
nodes.push(child.clone());
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodes
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
|
NodeList::new_simple_list(&self.window, nodes)
|
||||||
NodeList::new_simple_list(&self.window, self.create_collection(|node| {
|
|
||||||
if !callback(node) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(node.clone())
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn content_changed(&self) {
|
pub fn content_changed(&self) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue