mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Add binding for Document (getElementsByName)
This commit is contained in:
parent
fe91f6e238
commit
f8f9d203f5
2 changed files with 52 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue