Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLSelectElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp |
| index 6451c393d720e84232f08ad098fe46c2d32925e0..23117bd6fcf856a6fd1ebfc997b1dbc365a2b050 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp |
| @@ -877,7 +877,7 @@ void HTMLSelectElement::resetToDefaultSelection(ResetReason reason) |
| ++optionIndex; |
| } |
| if (!lastSelectedOption && m_size <= 1 && firstEnabledOption && !firstEnabledOption->selected()) { |
| - selectOption(firstEnabledOption, firstEnabledOptionIndex, 0); |
| + selectOption(firstEnabledOption, firstEnabledOptionIndex, reason == ResetReasonSelectedOptionRemoved ? 0 : DeselectOtherOptions); |
|
tkent
2016/06/29 04:45:56
This is the main change.
|
| lastSelectedOption = firstEnabledOption; |
| didChange = true; |
| } |
| @@ -967,11 +967,11 @@ void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b |
| { |
| ASSERT(option->ownerSelectElement() == this); |
| if (optionIsSelected) |
| - selectOption(option); |
| + selectOption(option, multiple() ? 0 : DeselectOtherOptions); |
| else if (!usesMenuList() || multiple()) |
| - selectOption(nullptr); |
| + selectOption(nullptr, multiple() ? 0 : DeselectOtherOptions); |
| else |
| - selectOption(nextSelectableOption(nullptr)); |
| + selectOption(nextSelectableOption(nullptr), DeselectOtherOptions); |
| } |
| void HTMLSelectElement::optionInserted(HTMLOptionElement& option, bool optionIsSelected) |
| @@ -979,7 +979,7 @@ void HTMLSelectElement::optionInserted(HTMLOptionElement& option, bool optionIsS |
| ASSERT(option.ownerSelectElement() == this); |
| setRecalcListItems(); |
| if (optionIsSelected) { |
| - selectOption(&option); |
| + selectOption(&option, multiple() ? 0 : DeselectOtherOptions); |
| } else { |
| // No need to reset if we already have a selected option. |
| if (!m_lastOnChangeOption) |
| @@ -1021,8 +1021,6 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* option, SelectOptionFlag |
| void HTMLSelectElement::selectOption(HTMLOptionElement* element, int optionIndex, SelectOptionFlags flags) |
| { |
| TRACE_EVENT0("blink", "HTMLSelectElement::selectOption"); |
| - bool shouldDeselect = !m_multiple || (flags & DeselectOtherOptions); |
| - |
| ASSERT((!element && optionIndex < 0) || (element && optionIndex >= 0)); |
| // selectedIndex() is O(N). |
| @@ -1036,16 +1034,16 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* element, int optionIndex |
| } |
| // deselectItemsWithoutValidation() is O(N). |
| - if (shouldDeselect) |
| + if (flags & DeselectOtherOptions) |
| deselectItemsWithoutValidation(element); |
| // We should update active selection after finishing OPTION state change |
| // because setActiveSelectionAnchorIndex() stores OPTION's selection state. |
| if (element) { |
| // setActiveSelectionAnchor is O(N). |
| - if (!m_activeSelectionAnchor || shouldDeselect) |
| + if (!m_activeSelectionAnchor || !multiple() || flags & DeselectOtherOptions) |
| setActiveSelectionAnchor(element); |
| - if (!m_activeSelectionEnd || shouldDeselect) |
| + if (!m_activeSelectionEnd || !multiple() || flags & DeselectOtherOptions) |
| setActiveSelectionEnd(element); |
| } |
| @@ -1764,13 +1762,14 @@ void HTMLSelectElement::accessKeySetSelectedIndex(int index) |
| EventQueueScope scope; |
| // If this index is already selected, unselect. otherwise update the |
| // selected index. |
| + SelectOptionFlags flags = DispatchInputAndChangeEvent | (multiple() ? 0 : DeselectOtherOptions); |
| if (toHTMLOptionElement(element).selected()) { |
| if (usesMenuList()) |
| - selectOption(-1, DispatchInputAndChangeEvent); |
| + selectOption(-1, flags); |
| else |
| toHTMLOptionElement(element).setSelectedState(false); |
| } else { |
| - selectOption(index, DispatchInputAndChangeEvent); |
| + selectOption(index, flags); |
| } |
| toHTMLOptionElement(element).setDirty(true); |
| if (usesMenuList()) |