2 * This file is part of the select element renderer in WebCore.
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.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef RenderMenuList_h
25 #define RenderMenuList_h
27 #include "core/rendering/RenderFlexibleBox.h"
28 #include "platform/PopupMenu.h"
29 #include "platform/PopupMenuClient.h"
30 #include "platform/geometry/LayoutRect.h"
34 class HTMLSelectElement;
37 class RenderMenuList FINAL : public RenderFlexibleBox, private PopupMenuClient {
40 RenderMenuList(Element*);
41 virtual ~RenderMenuList();
44 bool popupIsVisible() const { return m_popupIsVisible; }
48 void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
50 void didSetSelectedIndex(int listIndex);
55 HTMLSelectElement* selectElement() const;
57 virtual bool isMenuList() const OVERRIDE { return true; }
58 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
60 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
61 virtual void removeChild(RenderObject*) OVERRIDE;
62 virtual bool createsAnonymousWrapper() const OVERRIDE { return true; }
64 virtual void updateFromElement() OVERRIDE;
66 virtual LayoutRect controlClipRect(const LayoutPoint&) const OVERRIDE;
67 virtual bool hasControlClip() const OVERRIDE { return true; }
68 virtual bool canHaveGeneratedChildren() const OVERRIDE { return false; }
70 virtual const char* renderName() const OVERRIDE { return "RenderMenuList"; }
72 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
73 virtual void computePreferredLogicalWidths() OVERRIDE;
75 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
77 // PopupMenuClient methods
78 virtual void valueChanged(unsigned listIndex, bool fireOnChange = true) OVERRIDE;
79 virtual void selectionChanged(unsigned, bool) OVERRIDE { }
80 virtual void selectionCleared() OVERRIDE { }
81 virtual String itemText(unsigned listIndex) const OVERRIDE;
82 virtual String itemToolTip(unsigned listIndex) const OVERRIDE;
83 virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE;
84 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
85 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
86 virtual PopupMenuStyle menuStyle() const OVERRIDE;
87 virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
88 virtual LayoutUnit clientPaddingRight() const OVERRIDE;
89 virtual int listSize() const OVERRIDE;
90 virtual int selectedIndex() const OVERRIDE;
91 virtual void popupDidHide() OVERRIDE;
92 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
93 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
94 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
95 virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
96 virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) OVERRIDE;
97 virtual bool multiple() const OVERRIDE;
99 virtual bool hasLineIfEmpty() const OVERRIDE { return true; }
101 // Flexbox defines baselines differently than regular blocks.
102 // For backwards compatibility, menulists need to do the regular block behavior.
103 virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const OVERRIDE
105 return RenderBlock::baselinePosition(baseline, firstLine, direction, position);
107 virtual int firstLineBoxBaseline() const OVERRIDE { return RenderBlock::firstLineBoxBaseline(); }
108 virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return RenderBlock::inlineBlockBaseline(direction); }
110 void getItemBackgroundColor(unsigned listIndex, Color&, bool& itemHasCustomBackgroundColor) const;
112 void createInnerBlock();
113 void adjustInnerStyle();
114 void setText(const String&);
115 void setTextFromOption(int optionIndex);
116 void updateOptionsWidth();
118 void didUpdateActiveOption(int optionIndex);
120 RenderText* m_buttonText;
121 RenderBlock* m_innerBlock;
123 bool m_optionsChanged;
126 int m_lastActiveIndex;
128 RefPtr<RenderStyle> m_optionStyle;
130 RefPtr<PopupMenu> m_popup;
131 bool m_popupIsVisible;
134 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMenuList, isMenuList());