Add binding for Document (getElementsByName)

This commit is contained in:
Youngsoo Son 2013-07-25 13:51:36 +09:00
parent fe91f6e238
commit f8f9d203f5
2 changed files with 52 additions and 0 deletions

View file

@ -12,6 +12,8 @@ use script_task::global_script_context;
use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot};
use servo_util::tree::{TreeNodeRef, TreeUtils};
use std::str::eq_slice;
pub struct Document {
root: AbstractNode<ScriptView>,
wrapper: WrapperCache,
@ -52,6 +54,22 @@ impl Document {
Some(HTMLCollection::new(elements))
}
pub fn getElementsByName(&self, name: DOMString) -> Option<@mut HTMLCollection> {
let mut elements = ~[];
let name = name.to_str();
let _ = for self.root.traverse_preorder |child| {
if child.is_element() {
do child.with_imm_element |elem| {
match elem.get_attr("name") {
Some(val) => if eq_slice(val, name) { elements.push(child) },
None() => ()
}
}
}
};
Some(HTMLCollection::new(elements))
}
pub fn content_changed(&self) {
for self.window.iter().advance |window| {
window.content_changed()