Skip to content

Commit

Permalink
Revert of HTMLSelectElement does not include selected index/indices w…
Browse files Browse the repository at this point in the history
…hile saving state (patchset #8 id:160001 of https://codereview.chromium.org/541693003/)

Reason for revert:
Looks like this test crashes consistently on Android Tests (dbg) starting at this build:
http://build.chromium.org/p/chromium.webkit/builders/Android%20Tests%20%28dbg%29/builds/21459


Original issue's description:
> HTMLSelectElement does not include selected index/indices while saving state
> 
> Since index is not part of the FormControl state for select, there is no
> way to restore it to proper index if there are duplicate values. This
> patch includes the index in the FormControl state for select.
> 
> BUG=401506
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=181883

[email protected],[email protected],[email protected]
NOTREECHECKS=true
NOTRY=true
BUG=401506

Review URL: https://codereview.chromium.org/566913002

git-svn-id: svn://svn.chromium.org/blink/trunk@181911 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information
mvano committed Sep 12, 2014
1 parent e92d30d commit 0d74e95
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 132 deletions.
1 change: 0 additions & 1 deletion Source/core/core.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,6 @@
'html/HTMLDimensionTest.cpp',
'html/HTMLFormControlElementTest.cpp',
'html/HTMLLinkElementSizesAttributeTest.cpp',
'html/HTMLSelectElementTest.cpp',
'html/HTMLTextFormControlElementTest.cpp',
'html/LinkRelAttributeTest.cpp',
'html/TimeRangesTest.cpp',
Expand Down
36 changes: 11 additions & 25 deletions Source/core/html/HTMLSelectElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ FormControlState HTMLSelectElement::saveFormControlState() const
if (!option->selected())
continue;
state.append(option->value());
state.append(String::number(i));
if (!multiple())
break;
}
Expand Down Expand Up @@ -1075,34 +1074,21 @@ 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 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);
}
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+= 2) {
for (size_t i = 0; i < state.valueSize(); ++i) {
const String& value = state[i];
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;
}
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;
}
}

Expand Down
105 changes: 0 additions & 105 deletions Source/core/html/HTMLSelectElementTest.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion Source/core/html/forms/FormController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static String formStateSignature()
// In the legacy version of serialized state, the first item was a name
// attribute value of a form control. The following string literal should
// contain some characters which are rarely used for name attribute values.
DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% Blink serialized form state version 9 \n\r=&"));
DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 8 \n\r=&"));
return signature;
}

Expand Down

0 comments on commit 0d74e95

Please sign in to comment.