Implement selectedIndex IDL attribute on HTMLOptionsCollection.

This commit is contained in:
Corey Farwell 2017-02-12 19:27:08 -05:00
parent a656782075
commit d4ad51bfde
5 changed files with 65 additions and 24 deletions

View file

@ -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};
@ -16,6 +17,7 @@ use dom::bindings::str::DOMString;
use dom::element::Element;
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
use dom::htmloptionelement::HTMLOptionElement;
use dom::htmlselectelement::HTMLSelectElement;
use dom::node::{document_from_node, Node};
use dom::window::Window;
@ -182,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)
}
}