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

Unified Diff: Source/core/rendering/RenderMenuList.cpp

Issue 302473003: Fix: Incorrect display of HTML select multiple tag on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase #2 Created 6 years, 7 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 | « LayoutTests/platform/mac/fast/forms/select/menulist-appearance-basic-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderMenuList.cpp
diff --git a/Source/core/rendering/RenderMenuList.cpp b/Source/core/rendering/RenderMenuList.cpp
index 1c93e0292dae2b4ca86b994d7e9ca8596cb6cf47..a040f574dbd10087959d5facd5e8df6d40e0f879 100644
--- a/Source/core/rendering/RenderMenuList.cpp
+++ b/Source/core/rendering/RenderMenuList.cpp
@@ -45,6 +45,7 @@
#include "core/rendering/RenderView.h"
#include "platform/fonts/FontCache.h"
#include "platform/geometry/IntSize.h"
+#include "platform/text/PlatformLocale.h"
using namespace std;
@@ -215,19 +216,51 @@ void RenderMenuList::setTextFromOption(int optionIndex)
{
HTMLSelectElement* select = selectElement();
const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select->listItems();
- int size = listItems.size();
+ const int size = listItems.size();
- int i = select->optionToListIndex(optionIndex);
String text = emptyString();
- if (i >= 0 && i < size) {
- Element* element = listItems[i];
- if (isHTMLOptionElement(*element)) {
- text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
- m_optionStyle = element->renderStyle();
+ m_optionStyle.clear();
+
+ if (multiple()) {
+ 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()) {
+ if (++selectedCount == 1)
+ firstSelectedIndex = i;
+ }
+ }
+
+ if (selectedCount == 1) {
+ ASSERT(0 <= firstSelectedIndex);
+ ASSERT(firstSelectedIndex < size);
+ HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listItems[firstSelectedIndex]);
+ ASSERT(selectedOptionElement->selected());
+ text = selectedOptionElement->textIndentedToRespectGroupLabel();
+ m_optionStyle = selectedOptionElement->renderStyle();
+ } else {
+ Locale& locale = select->locale();
+ String localizedNumberString = locale.convertToLocalizedNumber(String::number(selectedCount));
+ text = locale.queryString(blink::WebLocalizedString::SelectMenuListText, localizedNumberString);
+ ASSERT(!m_optionStyle);
+ }
+ } else {
+ const int i = select->optionToListIndex(optionIndex);
+ if (i >= 0 && i < size) {
+ Element* element = listItems[i];
+ if (isHTMLOptionElement(*element)) {
+ text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
+ m_optionStyle = element->renderStyle();
+ }
}
}
setText(text.stripWhiteSpace());
+
didUpdateActiveOption(optionIndex);
}
« no previous file with comments | « LayoutTests/platform/mac/fast/forms/select/menulist-appearance-basic-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698