Add fixes based on review.

- Use if let instead of match for Option

- Refactor common code into pick_if_selected_and_reset
This commit is contained in:
Dongie Agnir 2015-10-27 15:20:35 -10:00
parent 92e008307f
commit 4849033297
2 changed files with 19 additions and 22 deletions

View file

@ -56,6 +56,17 @@ impl HTMLOptionElement {
pub fn set_selectedness(&self, selected: bool) {
self.selectedness.set(selected);
}
fn pick_if_selected_and_reset(&self) {
if let Some(select) = self.upcast::<Node>().ancestors()
.filter_map(Root::downcast::<HTMLSelectElement>)
.next() {
if self.Selected() {
select.pick_option(self);
}
select.ask_for_reset();
}
}
}
fn collect_text(element: &Element, value: &mut DOMString) {
@ -139,13 +150,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
fn SetSelected(&self, selected: bool) {
self.dirtiness.set(true);
self.selectedness.set(selected);
if let Some(select) = self.upcast::<Node>().ancestors()
.filter_map(Root::downcast::<HTMLSelectElement>).next() {
if selected {
select.pick_option(self);
}
select.ask_for_reset();
}
self.pick_if_selected_and_reset();
}
}
@ -198,14 +203,7 @@ impl VirtualMethods for HTMLOptionElement {
self.upcast::<Element>().check_parent_disabled_state_for_option();
if let Some(select) = self.upcast::<Node>().ancestors()
.filter_map(Root::downcast::<HTMLSelectElement>)
.next() {
if self.Selected() {
select.pick_option(self);
}
select.ask_for_reset();
}
self.pick_if_selected_and_reset();
}
fn unbind_from_tree(&self, tree_in_doc: bool) {