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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutMenuList.cpp

Issue 2141483002: SELECT element: Simplify the code by optionList(). (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/layout/LayoutMenuList.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutMenuList.cpp b/third_party/WebKit/Source/core/layout/LayoutMenuList.cpp
index b0e9753c109129aae787025b324afa14ccd1c8db..af5a325320d06d0f4df1d2dccd644c7f838f081e 100644
--- a/third_party/WebKit/Source/core/layout/LayoutMenuList.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutMenuList.cpp
@@ -157,12 +157,9 @@ void LayoutMenuList::updateOptionsWidth() const
{
float maxOptionWidth = 0;
- for (const auto& element : selectElement()->listItems()) {
- if (!isHTMLOptionElement(element))
- continue;
-
- String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
- const ComputedStyle* itemStyle = element->computedStyle() ? element->computedStyle() : style();
+ for (const auto& option : selectElement()->optionList()) {
+ String text = option->textIndentedToRespectGroupLabel();
+ const ComputedStyle* itemStyle = option->computedStyle() ? option->computedStyle() : style();
applyTextTransform(itemStyle, text, ' ');
TextRun textRun = constructTextRun(itemStyle->font(), text, *itemStyle);
@@ -184,26 +181,16 @@ void LayoutMenuList::updateFromElement()
m_optionStyle.clear();
if (select->multiple()) {
- const HeapVector<Member<HTMLElement>>& listItems = select->listItems();
- const int size = listItems.size();
unsigned selectedCount = 0;
- int firstSelectedIndex = -1;
- for (int i = 0; i < size; ++i) {
- Element* element = listItems[i];
- if (!isHTMLOptionElement(*element))
- continue;
-
- if (toHTMLOptionElement(element)->selected()) {
+ HTMLOptionElement* selectedOptionElement = nullptr;
+ for (const auto& option : select->optionList()) {
+ if (option->selected()) {
if (++selectedCount == 1)
- firstSelectedIndex = i;
+ selectedOptionElement = option;
}
}
if (selectedCount == 1) {
- ASSERT(0 <= firstSelectedIndex);
- ASSERT(firstSelectedIndex < size);
- HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listItems[firstSelectedIndex]);
- ASSERT(selectedOptionElement->selected());
text = selectedOptionElement->textIndentedToRespectGroupLabel();
m_optionStyle = selectedOptionElement->mutableComputedStyle();
} else {

Powered by Google App Engine
This is Rietveld 408576698