mirror of
https://github.com/servo/servo.git
synced 2025-06-29 11:33:39 +01:00
parent
6cf0eb1115
commit
c768097adc
1 changed files with 17 additions and 0 deletions
|
@ -2,10 +2,12 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::InheritTypes::{ElementCast};
|
||||||
use dom::bindings::codegen::HTMLCollectionBinding;
|
use dom::bindings::codegen::HTMLCollectionBinding;
|
||||||
use dom::bindings::js::JS;
|
use dom::bindings::js::JS;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
|
use dom::node::{Node, NodeHelpers};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
|
@ -31,6 +33,21 @@ impl HTMLCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HTMLCollection {
|
||||||
|
pub fn create(window: &JS<Window>, root: &JS<Node>, predicate: |elem: &JS<Element>| -> bool) -> JS<HTMLCollection> {
|
||||||
|
let mut elements = ~[];
|
||||||
|
for child in root.traverse_preorder() {
|
||||||
|
if child.is_element() {
|
||||||
|
let elem: JS<Element> = ElementCast::to(&child);
|
||||||
|
if predicate(&elem) {
|
||||||
|
elements.push(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HTMLCollection::new(window, elements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HTMLCollection {
|
impl HTMLCollection {
|
||||||
// http://dom.spec.whatwg.org/#dom-htmlcollection-length
|
// http://dom.spec.whatwg.org/#dom-htmlcollection-length
|
||||||
pub fn Length(&self) -> u32 {
|
pub fn Length(&self) -> u32 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue