, m_shouldRecalcListItems(false)
, m_suggestedIndex(-1)
{
- ScriptWrappable::init(this);
}
PassRefPtrWillBeRawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document)
void HTMLSelectElement::addBeforeOptionAtIndex(HTMLElement* element, int beforeIndex, ExceptionState& exceptionState)
{
- HTMLElement* beforeElement = toHTMLElement(options()->item(beforeIndex));
+ HTMLOptionElement* beforeElement = options()->item(beforeIndex);
add(element, beforeElement, exceptionState);
}
if (Attribute* sizeAttribute = ensureUniqueElementData().attributes().find(sizeAttr))
sizeAttribute->setValue(attrSize);
}
- size = std::max(size, 1);
+ size = std::max(size, 0);
// Ensure that we've determined selectedness of the items at least once prior to changing the size.
if (oldSize != size)
return options()->namedItem(name);
}
-Element* HTMLSelectElement::item(unsigned index)
+HTMLOptionElement* HTMLSelectElement::item(unsigned index)
{
return options()->item(index);
}
if (index > maxSelectItems - 1)
index = maxSelectItems - 1;
int diff = index - length();
- RefPtrWillBeRawPtr<HTMLElement> before = nullptr;
+ RefPtrWillBeRawPtr<HTMLOptionElement> before = nullptr;
// Out of array bounds? First insert empty dummies.
if (diff > 0) {
setLength(index, exceptionState);
// Replace an existing entry?
} else if (diff < 0) {
- before = toHTMLElement(options()->item(index+1));
+ before = options()->item(index + 1);
remove(index);
}
// Finally add the new element.
m_activeSelectionAnchorIndex--;
if (listIndex <= m_activeSelectionEndIndex)
m_activeSelectionEndIndex--;
+ if (listIndex == selectedIndex())
+ setAutofilled(false);
}
void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)
if (!option->selected())
continue;
state.append(option->value());
+ state.append(String::number(i));
if (!multiple())
break;
}
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;
+ }
}
}