mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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:
parent
92e008307f
commit
4849033297
2 changed files with 19 additions and 22 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue