mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Implement selectedIndex
property on <select>
.
This commit is contained in:
parent
f90b256472
commit
bec5bf49bd
5 changed files with 110 additions and 7 deletions
|
@ -299,6 +299,36 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
|||
opt.set_selectedness(false);
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-select-selectedindex
|
||||
fn SelectedIndex(&self) -> i32 {
|
||||
self.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLOptionElement>)
|
||||
.enumerate()
|
||||
.filter(|&(_, ref opt_elem)| opt_elem.Selected())
|
||||
.map(|(i, _)| i as i32)
|
||||
.next()
|
||||
.unwrap_or(-1)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-select-selectedindex
|
||||
fn SetSelectedIndex(&self, index: i32) {
|
||||
let mut opt_iter = self.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLOptionElement>);
|
||||
for opt in opt_iter.by_ref().take(index as usize) {
|
||||
opt.set_selectedness(false);
|
||||
}
|
||||
if let Some(opt) = opt_iter.next() {
|
||||
opt.set_selectedness(true);
|
||||
opt.set_dirtiness(true);
|
||||
// Reset remaining <option> elements
|
||||
for opt in opt_iter {
|
||||
opt.set_selectedness(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLSelectElement {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue