Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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)) { | |
|
tkent
2014/05/27 00:52:10
nit: We prefer early exit. That is to say,
if
| |
| 230 HTMLOptionElement* optionElement = toHTMLOptionElement(element); | |
| 231 if (optionElement->selected()) { | |
|
tkent
2014/05/27 00:52:10
if (toHTMLOptionElement(element)->selected()) {
i
| |
| 232 ++selectedCount; | |
| 233 if (selectedCount == 1) { | |
| 234 firstSelectedIndex = i; | |
|
tkent
2014/05/27 00:52:10
if (++selectedCount == 1)
firstSelectedIndex =
| |
| 235 } | |
| 236 } | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 if (selectedCount == 1) { | |
| 241 ASSERT(0 <= firstSelectedIndex && firstSelectedIndex < size); | |
|
tkent
2014/05/27 00:52:10
Do not put two conditions with && into a single AS
| |
| 242 HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listI tems[firstSelectedIndex]); | |
| 243 ASSERT(selectedOptionElement->selected()); | |
| 244 text = selectedOptionElement->textIndentedToRespectGroupLabel(); | |
| 245 m_optionStyle = selectedOptionElement->renderStyle(); | |
| 246 } else { | |
| 247 Locale& locale = select->locale(); | |
|
tkent
2014/05/27 00:52:10
This code applies the else clause for selectedCoun
| |
| 248 String localizedNumberString = locale.convertToLocalizedNumber(Strin g::number(selectedCount)); | |
| 249 text = locale.queryString(blink::WebLocalizedString::SelectMenuListT ext, localizedNumberString); | |
| 250 ASSERT(!m_optionStyle); | |
| 251 } | |
| 252 } else { | |
| 253 const int i = select->optionToListIndex(optionIndex); | |
| 254 if (i >= 0 && i < size) { | |
| 255 Element* element = listItems[i]; | |
| 256 if (isHTMLOptionElement(*element)) { | |
| 257 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL abel(); | |
| 258 m_optionStyle = element->renderStyle(); | |
| 259 } | |
| 227 } | 260 } |
| 228 } | 261 } |
| 229 | 262 |
| 230 setText(text.stripWhiteSpace()); | 263 setText(text.stripWhiteSpace()); |
| 264 | |
| 231 didUpdateActiveOption(optionIndex); | 265 didUpdateActiveOption(optionIndex); |
| 232 } | 266 } |
| 233 | 267 |
| 234 void RenderMenuList::setText(const String& s) | 268 void RenderMenuList::setText(const String& s) |
| 235 { | 269 { |
| 236 if (s.isEmpty()) { | 270 if (s.isEmpty()) { |
| 237 if (!m_buttonText || !m_buttonText->isBR()) { | 271 if (!m_buttonText || !m_buttonText->isBR()) { |
| 238 // FIXME: We should not modify the structure of the render tree | 272 // FIXME: We should not modify the structure of the render tree |
| 239 // during layout. crbug.com/370462 | 273 // during layout. crbug.com/370462 |
| 240 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; | 274 DeprecatedDisableModifyRenderTreeStructureAsserts disabler; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 HTMLElement* element = listItems[listIndex]; | 605 HTMLElement* element = listItems[listIndex]; |
| 572 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed(); | 606 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed(); |
| 573 } | 607 } |
| 574 | 608 |
| 575 void RenderMenuList::setTextFromItem(unsigned listIndex) | 609 void RenderMenuList::setTextFromItem(unsigned listIndex) |
| 576 { | 610 { |
| 577 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); | 611 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); |
| 578 } | 612 } |
| 579 | 613 |
| 580 } | 614 } |
| OLD | NEW |