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

Side by Side 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, 6 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of the select element renderer in WebCore. 2 * This file is part of the select element renderer in WebCore.
3 * 3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
6 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 6 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 27 matching lines...) Expand all
38 #include "core/html/HTMLOptGroupElement.h" 38 #include "core/html/HTMLOptGroupElement.h"
39 #include "core/html/HTMLOptionElement.h" 39 #include "core/html/HTMLOptionElement.h"
40 #include "core/html/HTMLSelectElement.h" 40 #include "core/html/HTMLSelectElement.h"
41 #include "core/page/Chrome.h" 41 #include "core/page/Chrome.h"
42 #include "core/rendering/RenderBR.h" 42 #include "core/rendering/RenderBR.h"
43 #include "core/rendering/RenderScrollbar.h" 43 #include "core/rendering/RenderScrollbar.h"
44 #include "core/rendering/RenderTheme.h" 44 #include "core/rendering/RenderTheme.h"
45 #include "core/rendering/RenderView.h" 45 #include "core/rendering/RenderView.h"
46 #include "platform/fonts/FontCache.h" 46 #include "platform/fonts/FontCache.h"
47 #include "platform/geometry/IntSize.h" 47 #include "platform/geometry/IntSize.h"
48 #include "platform/text/PlatformLocale.h"
48 49
49 using namespace std; 50 using namespace std;
50 51
51 namespace WebCore { 52 namespace WebCore {
52 53
53 using namespace HTMLNames; 54 using namespace HTMLNames;
54 55
55 RenderMenuList::RenderMenuList(Element* element) 56 RenderMenuList::RenderMenuList(Element* element)
56 : RenderFlexibleBox(element) 57 : RenderFlexibleBox(element)
57 , m_buttonText(0) 58 , m_buttonText(0)
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 setTextFromOption(selectElement()->suggestedIndex()); 209 setTextFromOption(selectElement()->suggestedIndex());
209 else 210 else
210 setTextFromOption(selectElement()->selectedIndex()); 211 setTextFromOption(selectElement()->selectedIndex());
211 } 212 }
212 } 213 }
213 214
214 void RenderMenuList::setTextFromOption(int optionIndex) 215 void RenderMenuList::setTextFromOption(int optionIndex)
215 { 216 {
216 HTMLSelectElement* select = selectElement(); 217 HTMLSelectElement* select = selectElement();
217 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select ->listItems(); 218 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select ->listItems();
218 int size = listItems.size(); 219 const int size = listItems.size();
219 220
220 int i = select->optionToListIndex(optionIndex);
221 String text = emptyString(); 221 String text = emptyString();
222 if (i >= 0 && i < size) { 222 m_optionStyle.clear();
223 Element* element = listItems[i]; 223
224 if (isHTMLOptionElement(*element)) { 224 if (multiple()) {
225 text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel (); 225 unsigned selectedCount = 0;
226 m_optionStyle = element->renderStyle(); 226 int firstSelectedIndex = -1;
227 for (int i = 0; i < size; ++i) {
228 Element* element = listItems[i];
229 if (!isHTMLOptionElement(*element))
230 continue;
231
232 if (toHTMLOptionElement(element)->selected()) {
233 if (++selectedCount == 1)
234 firstSelectedIndex = i;
235 }
236 }
237
238 if (selectedCount == 1) {
239 ASSERT(0 <= firstSelectedIndex);
240 ASSERT(firstSelectedIndex < size);
241 HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listI tems[firstSelectedIndex]);
242 ASSERT(selectedOptionElement->selected());
243 text = selectedOptionElement->textIndentedToRespectGroupLabel();
244 m_optionStyle = selectedOptionElement->renderStyle();
245 } else {
246 Locale& locale = select->locale();
247 String localizedNumberString = locale.convertToLocalizedNumber(Strin g::number(selectedCount));
248 text = locale.queryString(blink::WebLocalizedString::SelectMenuListT ext, localizedNumberString);
249 ASSERT(!m_optionStyle);
250 }
251 } else {
252 const int i = select->optionToListIndex(optionIndex);
253 if (i >= 0 && i < size) {
254 Element* element = listItems[i];
255 if (isHTMLOptionElement(*element)) {
256 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL abel();
257 m_optionStyle = element->renderStyle();
258 }
227 } 259 }
228 } 260 }
229 261
230 setText(text.stripWhiteSpace()); 262 setText(text.stripWhiteSpace());
263
231 didUpdateActiveOption(optionIndex); 264 didUpdateActiveOption(optionIndex);
232 } 265 }
233 266
234 void RenderMenuList::setText(const String& s) 267 void RenderMenuList::setText(const String& s)
235 { 268 {
236 if (s.isEmpty()) { 269 if (s.isEmpty()) {
237 if (!m_buttonText || !m_buttonText->isBR()) { 270 if (!m_buttonText || !m_buttonText->isBR()) {
238 // FIXME: We should not modify the structure of the render tree 271 // FIXME: We should not modify the structure of the render tree
239 // during layout. crbug.com/370462 272 // during layout. crbug.com/370462
240 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; 273 DeprecatedDisableModifyRenderTreeStructureAsserts disabler;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 HTMLElement* element = listItems[listIndex]; 604 HTMLElement* element = listItems[listIndex];
572 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed(); 605 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed();
573 } 606 }
574 607
575 void RenderMenuList::setTextFromItem(unsigned listIndex) 608 void RenderMenuList::setTextFromItem(unsigned listIndex)
576 { 609 {
577 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); 610 setTextFromOption(selectElement()->listToOptionIndex(listIndex));
578 } 611 }
579 612
580 } 613 }
OLDNEW
« 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