Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ask_for_reset for HTMLSelectElement. #7963

Merged
merged 11 commits into from Oct 28, 2015
Prev

Add fixes based on review.

- Use if let instead of match for Option

- Refactor common code into pick_if_selected_and_reset
  • Loading branch information
dagnir committed Oct 28, 2015
commit 4849033297815625939d2f7d8f68a14adfaa5477
@@ -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) {
@@ -70,13 +70,12 @@ impl HTMLSelectElement {
}
}

match last_selected {
Some(last_selected) => last_selected.set_selectedness(true),
None => {
if self.display_size() == 1 {
if let Some(first_enabled) = first_enabled {
first_enabled.set_selectedness(true);
}
if let Some(last_selected) = last_selected {
last_selected.set_selectedness(true);
} else {
if self.display_size() == 1 {
if let Some(first_enabled) = first_enabled {
first_enabled.set_selectedness(true);
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.