mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #15520 - frewsxcv:html-options-collection-selected-index, r=nox
Implement `selectedIndex` IDL attribute on `HTMLOptionsCollection`. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15520) <!-- Reviewable:end -->
This commit is contained in:
commit
5f813233c9
5 changed files with 64 additions and 24 deletions
|
@ -6,6 +6,7 @@ use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
|||
use dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLOptionsCollectionBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLOptionsCollectionBinding::HTMLOptionsCollectionMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods;
|
||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods;
|
||||
use dom::bindings::codegen::UnionTypes::{HTMLOptionElementOrHTMLOptGroupElement, HTMLElementOrLong};
|
||||
use dom::bindings::error::{Error, ErrorResult};
|
||||
|
@ -183,4 +184,22 @@ impl HTMLOptionsCollectionMethods for HTMLOptionsCollection {
|
|||
element.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-htmloptionscollection-selectedindex
|
||||
fn SelectedIndex(&self) -> i32 {
|
||||
self.upcast()
|
||||
.root_node()
|
||||
.downcast::<HTMLSelectElement>()
|
||||
.expect("HTMLOptionsCollection not rooted on a HTMLSelectElement")
|
||||
.SelectedIndex()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-htmloptionscollection-selectedindex
|
||||
fn SetSelectedIndex(&self, index: i32) {
|
||||
self.upcast()
|
||||
.root_node()
|
||||
.downcast::<HTMLSelectElement>()
|
||||
.expect("HTMLOptionsCollection not rooted on a HTMLSelectElement")
|
||||
.SetSelectedIndex(index)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ interface HTMLOptionsCollection : HTMLCollection {
|
|||
void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
|
||||
//[CEReactions]
|
||||
void remove(long index);
|
||||
//attribute long selectedIndex;
|
||||
attribute long selectedIndex;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue