mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +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) {
|
pub fn set_selectedness(&self, selected: bool) {
|
||||||
self.selectedness.set(selected);
|
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) {
|
fn collect_text(element: &Element, value: &mut DOMString) {
|
||||||
|
@ -139,13 +150,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
fn SetSelected(&self, selected: bool) {
|
fn SetSelected(&self, selected: bool) {
|
||||||
self.dirtiness.set(true);
|
self.dirtiness.set(true);
|
||||||
self.selectedness.set(selected);
|
self.selectedness.set(selected);
|
||||||
if let Some(select) = self.upcast::<Node>().ancestors()
|
self.pick_if_selected_and_reset();
|
||||||
.filter_map(Root::downcast::<HTMLSelectElement>).next() {
|
|
||||||
if selected {
|
|
||||||
select.pick_option(self);
|
|
||||||
}
|
|
||||||
select.ask_for_reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,14 +203,7 @@ impl VirtualMethods for HTMLOptionElement {
|
||||||
|
|
||||||
self.upcast::<Element>().check_parent_disabled_state_for_option();
|
self.upcast::<Element>().check_parent_disabled_state_for_option();
|
||||||
|
|
||||||
if let Some(select) = self.upcast::<Node>().ancestors()
|
self.pick_if_selected_and_reset();
|
||||||
.filter_map(Root::downcast::<HTMLSelectElement>)
|
|
||||||
.next() {
|
|
||||||
if self.Selected() {
|
|
||||||
select.pick_option(self);
|
|
||||||
}
|
|
||||||
select.ask_for_reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unbind_from_tree(&self, tree_in_doc: bool) {
|
fn unbind_from_tree(&self, tree_in_doc: bool) {
|
||||||
|
|
|
@ -70,13 +70,12 @@ impl HTMLSelectElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match last_selected {
|
if let Some(last_selected) = last_selected {
|
||||||
Some(last_selected) => last_selected.set_selectedness(true),
|
last_selected.set_selectedness(true);
|
||||||
None => {
|
} else {
|
||||||
if self.display_size() == 1 {
|
if self.display_size() == 1 {
|
||||||
if let Some(first_enabled) = first_enabled {
|
if let Some(first_enabled) = first_enabled {
|
||||||
first_enabled.set_selectedness(true);
|
first_enabled.set_selectedness(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue