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