1/*
2 * This file is part of the select element renderer in WebCore.
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 *               2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB.  If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "core/rendering/RenderMenuList.h"
27
28#include "core/HTMLNames.h"
29#include "core/accessibility/AXMenuList.h"
30#include "core/accessibility/AXObjectCache.h"
31#include "core/css/CSSFontSelector.h"
32#include "core/css/resolver/StyleResolver.h"
33#include "core/dom/NodeRenderStyle.h"
34#include "core/frame/FrameHost.h"
35#include "core/frame/FrameView.h"
36#include "core/frame/LocalFrame.h"
37#include "core/frame/Settings.h"
38#include "core/html/HTMLOptGroupElement.h"
39#include "core/html/HTMLOptionElement.h"
40#include "core/html/HTMLSelectElement.h"
41#include "core/page/Chrome.h"
42#include "core/rendering/RenderBR.h"
43#include "core/rendering/RenderScrollbar.h"
44#include "core/rendering/RenderTheme.h"
45#include "core/rendering/RenderView.h"
46#include "platform/fonts/FontCache.h"
47#include "platform/geometry/IntSize.h"
48#include "platform/text/PlatformLocale.h"
49#include <math.h>
50
51namespace blink {
52
53using namespace HTMLNames;
54
55RenderMenuList::RenderMenuList(Element* element)
56    : RenderFlexibleBox(element)
57    , m_buttonText(nullptr)
58    , m_innerBlock(nullptr)
59    , m_optionsChanged(true)
60    , m_optionsWidth(0)
61    , m_lastActiveIndex(-1)
62    , m_popupIsVisible(false)
63{
64    ASSERT(isHTMLSelectElement(element));
65}
66
67RenderMenuList::~RenderMenuList()
68{
69    ASSERT(!m_popup);
70}
71
72void RenderMenuList::destroy()
73{
74    if (m_popup)
75        m_popup->disconnectClient();
76    m_popup = nullptr;
77    RenderFlexibleBox::destroy();
78}
79
80void RenderMenuList::trace(Visitor* visitor)
81{
82    visitor->trace(m_buttonText);
83    visitor->trace(m_innerBlock);
84    visitor->trace(m_popup);
85    RenderFlexibleBox::trace(visitor);
86}
87
88// FIXME: Instead of this hack we should add a ShadowRoot to <select> with no insertion point
89// to prevent children from rendering.
90bool RenderMenuList::isChildAllowed(RenderObject* object, RenderStyle*) const
91{
92    return object->isAnonymous() && !object->isRenderFullScreen();
93}
94
95void RenderMenuList::createInnerBlock()
96{
97    if (m_innerBlock) {
98        ASSERT(firstChild() == m_innerBlock);
99        ASSERT(!m_innerBlock->nextSibling());
100        return;
101    }
102
103    // Create an anonymous block.
104    ASSERT(!firstChild());
105    m_innerBlock = createAnonymousBlock();
106    adjustInnerStyle();
107    RenderFlexibleBox::addChild(m_innerBlock);
108}
109
110void RenderMenuList::adjustInnerStyle()
111{
112    RenderStyle* innerStyle = m_innerBlock->style();
113    innerStyle->setFlexGrow(1);
114    innerStyle->setFlexShrink(1);
115    // Use margin:auto instead of align-items:center to get safe centering, i.e.
116    // when the content overflows, treat it the same as align-items: flex-start.
117    // But we only do that for the cases where html.css would otherwise use center.
118    if (style()->alignItems() == ItemPositionCenter) {
119        innerStyle->setMarginTop(Length());
120        innerStyle->setMarginBottom(Length());
121        innerStyle->setAlignSelf(ItemPositionFlexStart);
122    }
123
124    innerStyle->setPaddingLeft(Length(RenderTheme::theme().popupInternalPaddingLeft(style()), Fixed));
125    innerStyle->setPaddingRight(Length(RenderTheme::theme().popupInternalPaddingRight(style()), Fixed));
126    innerStyle->setPaddingTop(Length(RenderTheme::theme().popupInternalPaddingTop(style()), Fixed));
127    innerStyle->setPaddingBottom(Length(RenderTheme::theme().popupInternalPaddingBottom(style()), Fixed));
128
129    if (m_optionStyle) {
130        if ((m_optionStyle->direction() != innerStyle->direction() || m_optionStyle->unicodeBidi() != innerStyle->unicodeBidi()))
131            m_innerBlock->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
132        innerStyle->setTextAlign(style()->isLeftToRightDirection() ? LEFT : RIGHT);
133        innerStyle->setDirection(m_optionStyle->direction());
134        innerStyle->setUnicodeBidi(m_optionStyle->unicodeBidi());
135    }
136}
137
138inline HTMLSelectElement* RenderMenuList::selectElement() const
139{
140    return toHTMLSelectElement(node());
141}
142
143void RenderMenuList::addChild(RenderObject* newChild, RenderObject* beforeChild)
144{
145    createInnerBlock();
146    m_innerBlock->addChild(newChild, beforeChild);
147    ASSERT(m_innerBlock == firstChild());
148
149    if (AXObjectCache* cache = document().existingAXObjectCache())
150        cache->childrenChanged(this);
151}
152
153void RenderMenuList::removeChild(RenderObject* oldChild)
154{
155    if (oldChild == m_innerBlock || !m_innerBlock) {
156        RenderFlexibleBox::removeChild(oldChild);
157        m_innerBlock = nullptr;
158    } else
159        m_innerBlock->removeChild(oldChild);
160}
161
162void RenderMenuList::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
163{
164    RenderBlock::styleDidChange(diff, oldStyle);
165
166    if (m_buttonText)
167        m_buttonText->setStyle(style());
168    if (m_innerBlock) // RenderBlock handled updating the anonymous block's style.
169        adjustInnerStyle();
170
171    bool fontChanged = !oldStyle || oldStyle->font() != style()->font();
172    if (fontChanged)
173        updateOptionsWidth();
174}
175
176void RenderMenuList::updateOptionsWidth()
177{
178    float maxOptionWidth = 0;
179    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
180    int size = listItems.size();
181    FontCachePurgePreventer fontCachePurgePreventer;
182
183    for (int i = 0; i < size; ++i) {
184        HTMLElement* element = listItems[i];
185        if (!isHTMLOptionElement(*element))
186            continue;
187
188        String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
189        applyTextTransform(style(), text, ' ');
190        if (RenderTheme::theme().popupOptionSupportsTextIndent()) {
191            // Add in the option's text indent.  We can't calculate percentage values for now.
192            float optionWidth = 0;
193            if (RenderStyle* optionStyle = element->renderStyle())
194                optionWidth += minimumValueForLength(optionStyle->textIndent(), 0);
195            if (!text.isEmpty())
196                optionWidth += style()->font().width(text);
197            maxOptionWidth = std::max(maxOptionWidth, optionWidth);
198        } else if (!text.isEmpty()) {
199            maxOptionWidth = std::max(maxOptionWidth, style()->font().width(text));
200        }
201    }
202
203    int width = static_cast<int>(ceilf(maxOptionWidth));
204    if (m_optionsWidth == width)
205        return;
206
207    m_optionsWidth = width;
208    if (parent())
209        setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
210}
211
212void RenderMenuList::updateFromElement()
213{
214    if (m_optionsChanged) {
215        updateOptionsWidth();
216        m_optionsChanged = false;
217    }
218
219    if (m_popupIsVisible) {
220        m_popup->updateFromElement();
221    } else {
222        if (selectElement()->suggestedIndex() >= 0)
223            setTextFromOption(selectElement()->suggestedIndex());
224        else
225            setTextFromOption(selectElement()->selectedIndex());
226    }
227}
228
229void RenderMenuList::setTextFromOption(int optionIndex)
230{
231    HTMLSelectElement* select = selectElement();
232    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select->listItems();
233    const int size = listItems.size();
234
235    String text = emptyString();
236    m_optionStyle.clear();
237
238    if (multiple()) {
239        unsigned selectedCount = 0;
240        int firstSelectedIndex = -1;
241        for (int i = 0; i < size; ++i) {
242            Element* element = listItems[i];
243            if (!isHTMLOptionElement(*element))
244                continue;
245
246            if (toHTMLOptionElement(element)->selected()) {
247                if (++selectedCount == 1)
248                    firstSelectedIndex = i;
249            }
250        }
251
252        if (selectedCount == 1) {
253            ASSERT(0 <= firstSelectedIndex);
254            ASSERT(firstSelectedIndex < size);
255            HTMLOptionElement* selectedOptionElement = toHTMLOptionElement(listItems[firstSelectedIndex]);
256            ASSERT(selectedOptionElement->selected());
257            text = selectedOptionElement->textIndentedToRespectGroupLabel();
258            m_optionStyle = selectedOptionElement->renderStyle();
259        } else {
260            Locale& locale = select->locale();
261            String localizedNumberString = locale.convertToLocalizedNumber(String::number(selectedCount));
262            text = locale.queryString(WebLocalizedString::SelectMenuListText, localizedNumberString);
263            ASSERT(!m_optionStyle);
264        }
265    } else {
266        const int i = select->optionToListIndex(optionIndex);
267        if (i >= 0 && i < size) {
268            Element* element = listItems[i];
269            if (isHTMLOptionElement(*element)) {
270                text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
271                m_optionStyle = element->renderStyle();
272            }
273        }
274    }
275
276    setText(text.stripWhiteSpace());
277
278    didUpdateActiveOption(optionIndex);
279}
280
281void RenderMenuList::setText(const String& s)
282{
283    if (s.isEmpty()) {
284        if (!m_buttonText || !m_buttonText->isBR()) {
285            // FIXME: We should not modify the structure of the render tree
286            // during layout. crbug.com/370462
287            DeprecatedDisableModifyRenderTreeStructureAsserts disabler;
288            if (m_buttonText)
289                m_buttonText->destroy();
290            m_buttonText = new RenderBR(&document());
291            m_buttonText->setStyle(style());
292            addChild(m_buttonText);
293        }
294    } else {
295        if (m_buttonText && !m_buttonText->isBR())
296            m_buttonText->setText(s.impl(), true);
297        else {
298            // FIXME: We should not modify the structure of the render tree
299            // during layout. crbug.com/370462
300            DeprecatedDisableModifyRenderTreeStructureAsserts disabler;
301            if (m_buttonText)
302                m_buttonText->destroy();
303            m_buttonText = new RenderText(&document(), s.impl());
304            m_buttonText->setStyle(style());
305            // We need to set the text explicitly though it was specified in the
306            // constructor because RenderText doesn't refer to the text
307            // specified in the constructor in a case of re-transforming.
308            m_buttonText->setText(s.impl(), true);
309            addChild(m_buttonText);
310        }
311        adjustInnerStyle();
312    }
313}
314
315String RenderMenuList::text() const
316{
317    return m_buttonText ? m_buttonText->text() : String();
318}
319
320LayoutRect RenderMenuList::controlClipRect(const LayoutPoint& additionalOffset) const
321{
322    // Clip to the intersection of the content box and the content box for the inner box
323    // This will leave room for the arrows which sit in the inner box padding,
324    // and if the inner box ever spills out of the outer box, that will get clipped too.
325    LayoutRect outerBox(additionalOffset.x() + borderLeft() + paddingLeft(),
326                   additionalOffset.y() + borderTop() + paddingTop(),
327                   contentWidth(),
328                   contentHeight());
329
330    LayoutRect innerBox(additionalOffset.x() + m_innerBlock->x() + m_innerBlock->paddingLeft(),
331                   additionalOffset.y() + m_innerBlock->y() + m_innerBlock->paddingTop(),
332                   m_innerBlock->contentWidth(),
333                   m_innerBlock->contentHeight());
334
335    return intersection(outerBox, innerBox);
336}
337
338void RenderMenuList::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
339{
340    maxLogicalWidth = std::max(m_optionsWidth, RenderTheme::theme().minimumMenuListSize(style())) + m_innerBlock->paddingLeft() + m_innerBlock->paddingRight();
341    if (!style()->width().isPercent())
342        minLogicalWidth = maxLogicalWidth;
343}
344
345void RenderMenuList::computePreferredLogicalWidths()
346{
347    m_minPreferredLogicalWidth = 0;
348    m_maxPreferredLogicalWidth = 0;
349    RenderStyle* styleToUse = style();
350
351    if (styleToUse->width().isFixed() && styleToUse->width().value() > 0)
352        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(styleToUse->width().value());
353    else
354        computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
355
356    if (styleToUse->minWidth().isFixed() && styleToUse->minWidth().value() > 0) {
357        m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value()));
358        m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value()));
359    }
360
361    if (styleToUse->maxWidth().isFixed()) {
362        m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value()));
363        m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value()));
364    }
365
366    LayoutUnit toAdd = borderAndPaddingWidth();
367    m_minPreferredLogicalWidth += toAdd;
368    m_maxPreferredLogicalWidth += toAdd;
369
370    clearPreferredLogicalWidthsDirty();
371}
372
373void RenderMenuList::showPopup()
374{
375    if (m_popupIsVisible)
376        return;
377
378    if (document().frameHost()->chrome().hasOpenedPopup())
379        return;
380
381    // Create m_innerBlock here so it ends up as the first child.
382    // This is important because otherwise we might try to create m_innerBlock
383    // inside the showPopup call and it would fail.
384    createInnerBlock();
385    if (!m_popup)
386        m_popup = document().frameHost()->chrome().createPopupMenu(*document().frame(), this);
387    m_popupIsVisible = true;
388
389    FloatQuad quad(localToAbsoluteQuad(FloatQuad(borderBoundingBox())));
390    IntSize size = pixelSnappedIntRect(frameRect()).size();
391    HTMLSelectElement* select = selectElement();
392    m_popup->show(quad, size, select->optionToListIndex(select->selectedIndex()));
393}
394
395void RenderMenuList::hidePopup()
396{
397    if (m_popup)
398        m_popup->hide();
399}
400
401void RenderMenuList::valueChanged(unsigned listIndex, bool fireOnChange)
402{
403    // Check to ensure a page navigation has not occurred while
404    // the popup was up.
405    Document& doc = toElement(node())->document();
406    if (&doc != doc.frame()->document())
407        return;
408
409    HTMLSelectElement* select = selectElement();
410    select->optionSelectedByUser(select->listToOptionIndex(listIndex), fireOnChange);
411}
412
413void RenderMenuList::listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow)
414{
415    selectElement()->listBoxSelectItem(listIndex, allowMultiplySelections, shift, fireOnChangeNow);
416}
417
418bool RenderMenuList::multiple() const
419{
420    return selectElement()->multiple();
421}
422
423void RenderMenuList::didSetSelectedIndex(int listIndex)
424{
425    didUpdateActiveOption(selectElement()->listToOptionIndex(listIndex));
426}
427
428void RenderMenuList::didUpdateActiveOption(int optionIndex)
429{
430    if (!document().existingAXObjectCache())
431        return;
432
433    if (m_lastActiveIndex == optionIndex)
434        return;
435    m_lastActiveIndex = optionIndex;
436
437    HTMLSelectElement* select = selectElement();
438    int listIndex = select->optionToListIndex(optionIndex);
439    if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size()))
440        return;
441    if (AXMenuList* menuList = toAXMenuList(document().axObjectCache()->get(this)))
442        menuList->didUpdateActiveOption(optionIndex);
443}
444
445String RenderMenuList::itemText(unsigned listIndex) const
446{
447    HTMLSelectElement* select = selectElement();
448    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select->listItems();
449    if (listIndex >= listItems.size())
450        return String();
451
452    String itemString;
453    Element* element = listItems[listIndex];
454    if (isHTMLOptGroupElement(*element))
455        itemString = toHTMLOptGroupElement(*element).groupLabelText();
456    else if (isHTMLOptionElement(*element))
457        itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLabel();
458
459    applyTextTransform(style(), itemString, ' ');
460    return itemString;
461}
462
463String RenderMenuList::itemAccessibilityText(unsigned listIndex) const
464{
465    // Allow the accessible name be changed if necessary.
466    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
467    if (listIndex >= listItems.size())
468        return String();
469    return listItems[listIndex]->fastGetAttribute(aria_labelAttr);
470}
471
472String RenderMenuList::itemToolTip(unsigned listIndex) const
473{
474    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
475    if (listIndex >= listItems.size())
476        return String();
477    return listItems[listIndex]->title();
478}
479
480bool RenderMenuList::itemIsEnabled(unsigned listIndex) const
481{
482    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
483    if (listIndex >= listItems.size())
484        return false;
485    HTMLElement* element = listItems[listIndex];
486    if (!isHTMLOptionElement(*element))
487        return false;
488
489    bool groupEnabled = true;
490    if (Element* parentElement = element->parentElement()) {
491        if (isHTMLOptGroupElement(*parentElement))
492            groupEnabled = !parentElement->isDisabledFormControl();
493    }
494    if (!groupEnabled)
495        return false;
496
497    return !element->isDisabledFormControl();
498}
499
500PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const
501{
502    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
503    if (listIndex >= listItems.size()) {
504        // If we are making an out of bounds access, then we want to use the style
505        // of a different option element (index 0). However, if there isn't an option element
506        // before at index 0, we fall back to the menu's style.
507        if (!listIndex)
508            return menuStyle();
509
510        // Try to retrieve the style of an option element we know exists (index 0).
511        listIndex = 0;
512    }
513    HTMLElement* element = listItems[listIndex];
514
515    Color itemBackgroundColor;
516    bool itemHasCustomBackgroundColor;
517    getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgroundColor);
518
519    RenderStyle* style = element->renderStyle() ? element->renderStyle() : element->computedStyle();
520    return style ? PopupMenuStyle(resolveColor(style, CSSPropertyColor), itemBackgroundColor, style->font(), style->visibility() == VISIBLE,
521        isHTMLOptionElement(*element) ? toHTMLOptionElement(*element).isDisplayNone() : style->display() == NONE,
522        style->textIndent(), style->direction(), isOverride(style->unicodeBidi()),
523        itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : PopupMenuStyle::DefaultBackgroundColor) : menuStyle();
524}
525
526void RenderMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackgroundColor, bool& itemHasCustomBackgroundColor) const
527{
528    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
529    if (listIndex >= listItems.size()) {
530        itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor);
531        itemHasCustomBackgroundColor = false;
532        return;
533    }
534    HTMLElement* element = listItems[listIndex];
535
536    Color backgroundColor;
537    if (element->renderStyle())
538        backgroundColor = resolveColor(element->renderStyle(), CSSPropertyBackgroundColor);
539    itemHasCustomBackgroundColor = backgroundColor.alpha();
540    // If the item has an opaque background color, return that.
541    if (!backgroundColor.hasAlpha()) {
542        itemBackgroundColor = backgroundColor;
543        return;
544    }
545
546    // Otherwise, the item's background is overlayed on top of the menu background.
547    backgroundColor = resolveColor(CSSPropertyBackgroundColor).blend(backgroundColor);
548    if (!backgroundColor.hasAlpha()) {
549        itemBackgroundColor = backgroundColor;
550        return;
551    }
552
553    // If the menu background is not opaque, then add an opaque white background behind.
554    itemBackgroundColor = Color(Color::white).blend(backgroundColor);
555}
556
557PopupMenuStyle RenderMenuList::menuStyle() const
558{
559    const RenderObject* o = m_innerBlock ? m_innerBlock.get() : this;
560    const RenderStyle* s = o->style();
561    return PopupMenuStyle(o->resolveColor(CSSPropertyColor), o->resolveColor(CSSPropertyBackgroundColor), s->font(), s->visibility() == VISIBLE,
562        s->display() == NONE, s->textIndent(), style()->direction(), isOverride(style()->unicodeBidi()));
563}
564
565LayoutUnit RenderMenuList::clientPaddingLeft() const
566{
567    return paddingLeft() + m_innerBlock->paddingLeft();
568}
569
570const int endOfLinePadding = 2;
571LayoutUnit RenderMenuList::clientPaddingRight() const
572{
573    if (style()->appearance() == MenulistPart || style()->appearance() == MenulistButtonPart) {
574        // For these appearance values, the theme applies padding to leave room for the
575        // drop-down button. But leaving room for the button inside the popup menu itself
576        // looks strange, so we return a small default padding to avoid having a large empty
577        // space appear on the side of the popup menu.
578        return endOfLinePadding;
579    }
580
581    // If the appearance isn't MenulistPart, then the select is styled (non-native), so
582    // we want to return the user specified padding.
583    return paddingRight() + m_innerBlock->paddingRight();
584}
585
586int RenderMenuList::listSize() const
587{
588    return selectElement()->listItems().size();
589}
590
591int RenderMenuList::selectedIndex() const
592{
593    HTMLSelectElement* select = selectElement();
594    return select->optionToListIndex(select->selectedIndex());
595}
596
597void RenderMenuList::popupDidHide()
598{
599    m_popupIsVisible = false;
600    // Ensure the text is updated which wasn't updated when the popup is visible.
601    updateFromElement();
602}
603
604bool RenderMenuList::itemIsSeparator(unsigned listIndex) const
605{
606    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
607    return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex]);
608}
609
610bool RenderMenuList::itemIsLabel(unsigned listIndex) const
611{
612    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
613    return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[listIndex]);
614}
615
616bool RenderMenuList::itemIsSelected(unsigned listIndex) const
617{
618    const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement()->listItems();
619    if (listIndex >= listItems.size())
620        return false;
621    HTMLElement* element = listItems[listIndex];
622    return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).selected();
623}
624
625void RenderMenuList::setTextFromItem(unsigned listIndex)
626{
627    setTextFromOption(selectElement()->listToOptionIndex(listIndex));
628}
629
630} // namespace blink
631