зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #13818 - Implement `selectedIndex` property on `<select>` (from frewsxcv:selected-index); r=KiChjang
Source-Repo: https://github.com/servo/servo Source-Revision: 94ab5905f8757098faa915423f42225fd5328559
This commit is contained in:
Родитель
ef5ad37fc9
Коммит
9a353e3cb2
|
@ -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 {
|
||||
|
|
|
@ -25,7 +25,7 @@ interface HTMLSelectElement : HTMLElement {
|
|||
//setter void (unsigned long index, HTMLOptionElement? option);
|
||||
|
||||
//readonly attribute HTMLCollection selectedOptions;
|
||||
// attribute long selectedIndex;
|
||||
attribute long selectedIndex;
|
||||
attribute DOMString value;
|
||||
|
||||
//readonly attribute boolean willValidate;
|
||||
|
|
Загрузка…
Ссылка в новой задаче