Commit 2a51d857 authored by dtrebbien@gmail.com's avatar dtrebbien@gmail.com

Fix: Incorrect display of HTML select multiple tag on Android

This CL adds to RenderMenuList::setTextFromOption(int) so that when the
associated HTML <select> element has the multiple attribute, the <select>
element's options are iterated over and a count of the number of selected
options is determined. When the number of selected options is 0 or 2 or
more, then the RenderMenuList's text is set to "SELECTED_COUNT selected"
(e.g. "2 selected"). When exactly one option is selected, then the text
is set to the selected option's text.

This is similar to iOS. When 0 or 2 or more options are selected, then
the text of the menulist button is set to "SELECTED_COUNT Items". When
exactly one option is selected, then the text is set to the selected
option's text.

Depends on:
- https://codereview.chromium.org/280483002/
- https://codereview.chromium.org/295933003/

BUG=314704

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

git-svn-id: svn://svn.chromium.org/blink/trunk@175010 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 07eb110c
......@@ -1242,6 +1242,8 @@ crbug.com/374936 [ Mac ] svg/dynamic-updates/SVGImageElement-dom-width-attr.html
crbug.com/374936 [ Mac ] svg/dynamic-updates/SVGImageElement-svgdom-height-prop.html [ ImageOnlyFailure Pass ]
crbug.com/374936 [ Mac ] svg/dynamic-updates/SVGImageElement-svgdom-width-prop.html [ ImageOnlyFailure Pass ]
crbug.com/314704 fast/forms/select/menulist-appearance-basic.html [ NeedsRebaseline ]
crbug.com/313438 svg/custom/relative-sized-use-on-symbol.xhtml [ NeedsManualRebaseline ]
crbug.com/313438 svg/custom/relative-sized-use-without-attributes-on-symbol.xhtml [ NeedsManualRebaseline ]
......
......@@ -50,4 +50,66 @@ if (window.testRunner)
<!-- zoom -->
<select style="zoom: 1.5;"><option>foo</option></select>
<select style="zoom: 2;"><option>foo</option></select> <br>
<!-- multiple - on platforms that use menulist rendering for <select multiple> tags -->
<select multiple="multiple" style="width: 200px; height: 25px;">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
<br>
<select multiple="multiple" style="width: 200px; height: 25px;">
<option>Item 1</option>
<option selected="selected">Item 2</option>
<option>Item 3</option>
</select>
<br>
<select multiple="multiple" style="width: 200px; height: 25px;">
<option>Item 1</option>
<option selected="selected">Item 2</option>
<option selected="selected">Item 3</option>
</select>
<br>
<select multiple="multiple" style="width: 200px; height: 25px;">
<option selected="selected">Item 0.1</option>
<optgroup label="Group 1">
<option>Item 1.1</option>
<option>Item 1.2</option>
<option>Item 1.3</option>
</optgroup>
<optgroup label="Group 2">
<option>Item 2.1</option>
<option>Item 2.2</option>
<option selected="selected">Item 2.3</option>
</optgroup>
<optgroup label="Group 3">
<option selected="selected">Item 3.1</option>
<option>Item 3.2</option>
<option selected="selected">Item 3.3</option>
</optgroup>
<optgroup label="Group 4">
<option>Item 4.1</option>
<option selected="selected">Item 4.2</option>
<option>Item 4.3</option>
</optgroup>
<optgroup label="Group 5">
<option selected="selected">Item 5.1</option>
<option>Item 5.2</option>
<option>Item 5.3</option>
</optgroup>
<option selected="selected">Item 0.2</option>
</select>
<br>
<select multiple="multiple" style="width: 200px; height: 25px;">
<script type="text/javascript">
for (var i = 0; i < 1234; ++i) {
document.writeln(" <option selected='selected'>Item " + (i + 1) + "</option>");
}
</script>
</select>
</body>
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x285
RenderBlock {HTML} at (0,0) size 800x285
RenderBody {BODY} at (8,8) size 784x269
layer at (0,0) size 800x450
RenderBlock {HTML} at (0,0) size 800x450
RenderBody {BODY} at (8,8) size 784x434
RenderMenuList {SELECT} at (4,4) size 42x20 [bgcolor=#C0C0C0] [border: (1px solid #A9A9A9)]
RenderBlock (anonymous) at (1,1) size 40x18
RenderText at (4,1) size 17x16
......@@ -101,3 +101,21 @@ layer at (0,0) size 800x285
RenderText {#text} at (149,236) size 4x19
text run at (149,236) width 4: " "
RenderBR {BR} at (153,236) size 0x19
RenderListBox {SELECT} at (4,273) size 200x25 [bgcolor=#FFFFFF] [border: (1px solid #A9A9A9)]
RenderText {#text} at (208,280) size 4x19
text run at (208,280) width 4: " "
RenderBR {BR} at (212,280) size 0x19
RenderListBox {SELECT} at (4,306) size 200x25 [bgcolor=#FFFFFF] [border: (1px solid #A9A9A9)]
RenderText {#text} at (208,313) size 4x19
text run at (208,313) width 4: " "
RenderBR {BR} at (212,313) size 0x19
RenderListBox {SELECT} at (4,339) size 200x25 [bgcolor=#FFFFFF] [border: (1px solid #A9A9A9)]
RenderText {#text} at (208,346) size 4x19
text run at (208,346) width 4: " "
RenderBR {BR} at (212,346) size 0x19
RenderListBox {SELECT} at (4,372) size 200x25 [bgcolor=#FFFFFF] [border: (1px solid #A9A9A9)]
RenderText {#text} at (208,379) size 4x19
text run at (208,379) width 4: " "
RenderBR {BR} at (212,379) size 0x19
RenderListBox {SELECT} at (4,405) size 200x25 [bgcolor=#FFFFFF] [border: (1px solid #A9A9A9)]
RenderText {#text} at (0,0) size 0x0
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x245
RenderBlock {HTML} at (0,0) size 800x245
RenderBody {BODY} at (8,8) size 784x229
layer at (0,0) size 800x410
RenderBlock {HTML} at (0,0) size 800x410
RenderBody {BODY} at (8,8) size 784x394
RenderMenuList {SELECT} at (4,4) size 49x18 [bgcolor=#F8F8F8]
RenderBlock (anonymous) at (0,0) size 49x18
RenderText at (8,2) size 18x13
......@@ -101,3 +101,21 @@ layer at (0,0) size 800x245
RenderText {#text} at (203,196) size 4x18
text run at (203,196) width 4: " "
RenderBR {BR} at (207,196) size 0x18
RenderListBox {SELECT} at (4,233) size 200x25 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
RenderText {#text} at (208,241) size 4x18
text run at (208,241) width 4: " "
RenderBR {BR} at (212,241) size 0x18
RenderListBox {SELECT} at (4,266) size 200x25 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
RenderText {#text} at (208,274) size 4x18
text run at (208,274) width 4: " "
RenderBR {BR} at (212,274) size 0x18
RenderListBox {SELECT} at (4,299) size 200x25 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
RenderText {#text} at (208,307) size 4x18
text run at (208,307) width 4: " "
RenderBR {BR} at (212,307) size 0x18
RenderListBox {SELECT} at (4,332) size 200x25 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
RenderText {#text} at (208,340) size 4x18
text run at (208,340) width 4: " "
RenderBR {BR} at (212,340) size 0x18
RenderListBox {SELECT} at (4,365) size 200x25 [bgcolor=#FFFFFF] [border: (1px inset #808080)]
RenderText {#text} at (0,0) size 0x0
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment