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

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

Issue 2147223004: SELECT element: Remove HTMLSelectElement::optionToListIndex(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 94922bfb342619096380c4468792186f57286601..bf57792a02f2e234759fbb7cca0bd093c7436cfa 100644
--- a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
@@ -143,11 +143,11 @@ bool HTMLSelectElement::hasPlaceholderLabelOption() const
if (multiple() || size() > 1)
return false;
- int listIndex = optionToListIndex(0);
- ASSERT(listIndex >= 0);
- if (listIndex < 0)
+ // TODO(tkent): This function is called in CSS selector matching. Using
+ // listItems() might have performance impact.
+ if (listItems().size() == 0 || !isHTMLOptionElement(listItems()[0]))
return false;
- return !listIndex && toHTMLOptionElement(listItems()[listIndex])->value().isEmpty();
+ return toHTMLOptionElement(listItems()[0])->value().isEmpty();
}
String HTMLSelectElement::validationMessage() const
@@ -241,9 +241,8 @@ void HTMLSelectElement::add(const HTMLOptionElementOrHTMLOptGroupElement& elemen
void HTMLSelectElement::remove(int optionIndex)
{
- int listIndex = optionToListIndex(optionIndex);
- if (listIndex >= 0)
- listItems()[listIndex]->remove(IGNORE_EXCEPTION);
+ if (HTMLOptionElement* option = item(optionIndex))
+ option->remove(IGNORE_EXCEPTION);
}
String HTMLSelectElement::value() const
@@ -1056,25 +1055,6 @@ void HTMLSelectElement::selectOption(HTMLOptionElement* element, SelectOptionFla
notifyFormStateChanged();
}
-int HTMLSelectElement::optionToListIndex(int optionIndex) const
-{
- const ListItems& items = listItems();
- int listSize = static_cast<int>(items.size());
- if (optionIndex < 0 || optionIndex >= listSize)
- return -1;
-
- int optionIndex2 = -1;
- for (int listIndex = 0; listIndex < listSize; ++listIndex) {
- if (isHTMLOptionElement(*items[listIndex])) {
- ++optionIndex2;
- if (optionIndex2 == optionIndex)
- return listIndex;
- }
- }
-
- return -1;
-}
-
void HTMLSelectElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusType type, InputDeviceCapabilities* sourceCapabilities)
{
// Save the selection so it can be compared to the new selection when
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698