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

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

Issue 2149763003: SELECT element: Add HTMLSelectElement::selectedListIndex(). (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
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 edfa1c61e7b2bbb641948c0cfd806718ebb33027..5ca18ac916f25d24352a95b8c070180b0b38edb4 100644
--- a/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
@@ -873,6 +873,17 @@ void HTMLSelectElement::setSelectedIndex(int index)
selectOption(item(index), DeselectOtherOptions | MakeOptionDirty);
}
+int HTMLSelectElement::selectedListIndex() const
+{
+ int index = 0;
+ for (const auto& item : listItems()) {
+ if (isHTMLOptionElement(item) && toHTMLOptionElement(item)->selected())
+ return index;
+ ++index;
+ }
+ return -1;
+}
+
void HTMLSelectElement::setSuggestedOption(HTMLOptionElement* option)
{
if (m_suggestedOption == option)
@@ -1693,7 +1704,7 @@ HTMLOptionElement* HTMLSelectElement::lastSelectedOption() const
int HTMLSelectElement::indexOfSelectedOption() const
{
- return optionToListIndex(selectedIndex());
+ return selectedListIndex();
}
int HTMLSelectElement::optionCount() const
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | third_party/WebKit/Source/web/ExternalPopupMenu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698