summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLSelectElement.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-06-25 13:35:59 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-06-25 13:35:59 +0200
commit79ad030d505ccf79cf10aa9f8189ca3e2f61f6f4 (patch)
tree0287b1a69d84492c901e8bc820e635e7133809a0 /Source/WebCore/html/HTMLSelectElement.cpp
parent682ab87480e7757346802ce7f54cfdbdfeb2339e (diff)
downloadqtwebkit-79ad030d505ccf79cf10aa9f8189ca3e2f61f6f4.tar.gz
Imported WebKit commit c4b613825abd39ac739a47d7b4410468fcef66dc (http://svn.webkit.org/repository/webkit/trunk@121147)
New snapshot that includes Win32 debug build fix (use SVGAllInOne)
Diffstat (limited to 'Source/WebCore/html/HTMLSelectElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLSelectElement.cpp60
1 files changed, 48 insertions, 12 deletions
diff --git a/Source/WebCore/html/HTMLSelectElement.cpp b/Source/WebCore/html/HTMLSelectElement.cpp
index a5d8ad2bc..04227aec6 100644
--- a/Source/WebCore/html/HTMLSelectElement.cpp
+++ b/Source/WebCore/html/HTMLSelectElement.cpp
@@ -919,14 +919,31 @@ FormControlState HTMLSelectElement::saveFormControlState() const
{
const Vector<HTMLElement*>& items = listItems();
size_t length = items.size();
- StringBuilder builder;
- builder.reserveCapacity(length);
+ FormControlState state;
for (unsigned i = 0; i < length; ++i) {
- HTMLElement* element = items[i];
- bool selected = element->hasTagName(optionTag) && toHTMLOptionElement(element)->selected();
- builder.append(selected ? 'X' : '.');
+ if (!items[i]->hasTagName(optionTag))
+ continue;
+ HTMLOptionElement* option = toHTMLOptionElement(items[i]);
+ if (!option->selected())
+ continue;
+ state.append(option->value());
+ if (!multiple())
+ break;
}
- return FormControlState(builder.toString());
+ return state;
+}
+
+size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t listIndexStart, size_t listIndexEnd) const
+{
+ const Vector<HTMLElement*>& items = listItems();
+ size_t loopEndIndex = std::min(items.size(), listIndexEnd);
+ for (size_t i = listIndexStart; i < loopEndIndex; ++i) {
+ if (!items[i]->hasLocalName(optionTag))
+ continue;
+ if (static_cast<HTMLOptionElement*>(items[i])->value() == value)
+ return i;
+ }
+ return notFound;
}
void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
@@ -934,13 +951,32 @@ void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
recalcListItems();
const Vector<HTMLElement*>& items = listItems();
- size_t length = items.size();
+ size_t itemsSize = items.size();
+ if (!itemsSize)
+ return;
- String mask = state.value();
- for (size_t i = 0; i < length; ++i) {
- HTMLElement* element = items[i];
- if (element->hasTagName(optionTag))
- toHTMLOptionElement(element)->setSelectedState(mask[i] == 'X');
+ for (size_t i = 0; i < itemsSize; ++i) {
+ if (!items[i]->hasLocalName(optionTag))
+ continue;
+ static_cast<HTMLOptionElement*>(items[i])->setSelectedState(false);
+ }
+
+ if (!multiple()) {
+ size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
+ if (foundIndex != notFound)
+ toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+ } else {
+ size_t startIndex = 0;
+ for (size_t i = 0; i < state.valueSize(); ++i) {
+ const String& value = state[i];
+ size_t foundIndex = searchOptionsForValue(value, startIndex, itemsSize);
+ if (foundIndex == notFound)
+ foundIndex = searchOptionsForValue(value, 0, startIndex);
+ if (foundIndex == notFound)
+ continue;
+ toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
+ startIndex = foundIndex + 1;
+ }
}
setOptionsChangedOnRenderer();