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

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

Issue 541693003: HTMLSelectElement does not include selected index/indices while saving state (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/html/HTMLSelectElementTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLSelectElement.cpp
diff --git a/Source/core/html/HTMLSelectElement.cpp b/Source/core/html/HTMLSelectElement.cpp
index 906812120075f2065568cbede9200c54123b4cd9..6e6b89fd0b8cc19ba3ae479245182f9d373b3d93 100644
--- a/Source/core/html/HTMLSelectElement.cpp
+++ b/Source/core/html/HTMLSelectElement.cpp
@@ -1039,6 +1039,7 @@ FormControlState HTMLSelectElement::saveFormControlState() const
if (!option->selected())
continue;
state.append(option->value());
+ state.append(String::number(i));
if (!multiple())
break;
}
@@ -1073,21 +1074,34 @@ void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
toHTMLOptionElement(items[i])->setSelectedState(false);
}
+ // The saved state should have at least one value and an index.
+ ASSERT(state.valueSize() >= 2);
if (!multiple()) {
- size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
- if (foundIndex != kNotFound)
- toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+ size_t index = state[1].toUInt();
+ if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTMLOptionElement(items[index])->value() == state[0]) {
+ toHTMLOptionElement(items[index])->setSelectedState(true);
+ } else {
+ size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
+ if (foundIndex != kNotFound)
+ toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+ }
} else {
size_t startIndex = 0;
- for (size_t i = 0; i < state.valueSize(); ++i) {
+ for (size_t i = 0; i < state.valueSize(); i+= 2) {
const String& value = state[i];
- size_t foundIndex = searchOptionsForValue(value, startIndex, itemsSize);
- if (foundIndex == kNotFound)
- foundIndex = searchOptionsForValue(value, 0, startIndex);
- if (foundIndex == kNotFound)
- continue;
- toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
- startIndex = foundIndex + 1;
+ const size_t index = state[i + 1].toUInt();
+ if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTMLOptionElement(items[index])->value() == value) {
+ toHTMLOptionElement(items[index])->setSelectedState(true);
+ startIndex = index + 1;
+ } else {
+ size_t foundIndex = searchOptionsForValue(value, startIndex, itemsSize);
+ if (foundIndex == kNotFound)
+ foundIndex = searchOptionsForValue(value, 0, startIndex);
+ if (foundIndex == kNotFound)
+ continue;
+ toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+ startIndex = foundIndex + 1;
+ }
}
}
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/html/HTMLSelectElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698