Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: third_party/WebKit/Source/core/html/HTMLSelectElement.cpp

Issue 2572953002: SELECT element: Do not update popup menu content by touching selectedIndex (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2bfe488d7989e61865b059a5c649ee2de87bbb41..52a171c3824ed30bbf7a90a64aa6fafa6bbf69c3 100644
--- a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
@@ -981,11 +981,15 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* element,
SelectOptionFlags flags) {
TRACE_EVENT0("blink", "HTMLSelectElement::selectOption");
+ bool shouldUpdatePopup = false;
+
// selectedOption() is O(N).
if (isAutofilled() && selectedOption() != element)
setAutofilled(false);
if (element) {
+ if (!element->selected())
+ shouldUpdatePopup = true;
element->setSelectedState(true);
if (flags & MakeOptionDirty)
element->setDirty(true);
@@ -993,7 +997,7 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* element,
// deselectItemsWithoutValidation() is O(N).
if (flags & DeselectOtherOptions)
- deselectItemsWithoutValidation(element);
+ shouldUpdatePopup |= deselectItemsWithoutValidation(element);
// We should update active selection after finishing OPTION state change
// because setActiveSelectionAnchorIndex() stores OPTION's selection state.
@@ -1019,7 +1023,7 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* element,
if (LayoutObject* layoutObject = this->layoutObject())
layoutObject->updateFromElement();
// PopupMenu::updateFromElement() posts an O(N) task.
- if (popupIsVisible())
+ if (popupIsVisible() && shouldUpdatePopup)
m_popup->updateFromElement(PopupMenu::BySelectionChange);
scrollToSelection();
@@ -1072,17 +1076,23 @@ void HTMLSelectElement::dispatchBlurEvent(
sourceCapabilities);
}
-void HTMLSelectElement::deselectItemsWithoutValidation(
+// Returns true if selection state of any OPTIONs is changed.
+bool HTMLSelectElement::deselectItemsWithoutValidation(
HTMLOptionElement* excludeElement) {
if (!isMultiple() && usesMenuList() && m_lastOnChangeOption &&
m_lastOnChangeOption != excludeElement) {
m_lastOnChangeOption->setSelectedState(false);
- return;
+ return true;
}
+ bool didUpdateSelection = false;
for (const auto& option : optionList()) {
- if (option != excludeElement)
+ if (option != excludeElement) {
+ if (option->selected())
+ didUpdateSelection = true;
option->setSelectedState(false);
+ }
}
+ return didUpdateSelection;
}
FormControlState HTMLSelectElement::saveFormControlState() const {
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698