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

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

Issue 1838183003: Fix problems on changing 'multiple' state SELECT element to 'single' state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a typo in a comment Created 4 years, 9 months 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
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 ba612d0c353f0e04e5568257887cd41a16d8d1f4..c66b4b1d6f54ea94680b719b20aa47f7fb2b50d5 100644
--- a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
@@ -444,18 +444,6 @@ void HTMLSelectElement::accessKeyAction(bool sendMouseEvents)
dispatchSimulatedClick(nullptr, sendMouseEvents ? SendMouseUpDownEvents : SendNoEvents);
}
-void HTMLSelectElement::setMultiple(bool multiple)
-{
- bool oldMultiple = this->multiple();
- int oldSelectedIndex = selectedIndex();
- setAttribute(multipleAttr, multiple ? emptyAtom : nullAtom);
-
- // Restore selectedIndex after changing the multiple flag to preserve
- // selection as single-line and multi-line has different defaults.
- if (oldMultiple != this->multiple())
- selectOption(oldSelectedIndex, DeselectOtherOptions);
-}
-
void HTMLSelectElement::setSize(unsigned size)
{
setUnsignedIntegralAttribute(sizeAttr, size);
@@ -1234,10 +1222,22 @@ void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value)
{
+ bool oldMultiple = m_multiple;
+ int oldSelectedIndex = selectedIndex();
m_multiple = !value.isNull();
setNeedsValidityCheck();
-
lazyReattachIfAttached();
+ // Restore selectedIndex after changing the multiple flag to preserve
+ // selection as single-line and multi-line has different defaults.
+ if (oldMultiple != m_multiple) {
+ // Preserving the first selection is compatible with Firefox and
+ // WebKit. However Edge seems to "ask for a reset" simply. As of 2016
+ // March, the HTML specification says nothing about this.
+ if (oldSelectedIndex >= 0)
+ selectOption(oldSelectedIndex, DeselectOtherOptions);
+ else
+ resetToDefaultSelection();
+ }
}
void HTMLSelectElement::appendToFormData(FormData& formData)
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | third_party/WebKit/Source/core/html/HTMLSelectElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698