1 /*
2 * This file is part of the select element renderer in WebCore.
3 *
4 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #ifndef RenderMenuList_h
24 #define RenderMenuList_h
25
26 #include "PopupMenuClient.h"
27 #include "RenderFlexibleBox.h"
28
29 #if PLATFORM(MAC)
30 #define POPUP_MENU_PULLS_DOWN 0
31 #else
32 #define POPUP_MENU_PULLS_DOWN 1
33 #endif
34
35 namespace WebCore {
36
37 class PopupMenu;
38 class RenderText;
39
40 class RenderMenuList : public RenderFlexibleBox, private PopupMenuClient {
41 public:
42 RenderMenuList(Element*);
43 virtual ~RenderMenuList();
44
45 public:
popupIsVisible()46 bool popupIsVisible() const { return m_popupIsVisible; }
47 void showPopup();
48 void hidePopup();
49
setOptionsChanged(bool changed)50 void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
51
52 String text() const;
53
54 private:
isMenuList()55 virtual bool isMenuList() const { return true; }
56
57 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
58 virtual void removeChild(RenderObject*);
createsAnonymousWrapper()59 virtual bool createsAnonymousWrapper() const { return true; }
canHaveChildren()60 virtual bool canHaveChildren() const { return false; }
61
62 virtual void updateFromElement();
63
hasControlClip()64 virtual bool hasControlClip() const { return true; }
65 virtual IntRect controlClipRect(int tx, int ty) const;
66
renderName()67 virtual const char* renderName() const { return "RenderMenuList"; }
68
69 virtual void calcPrefWidths();
70
71 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
72
73 // PopupMenuClient methods
74 virtual String itemText(unsigned listIndex) const;
75 virtual String itemToolTip(unsigned listIndex) const;
76 virtual bool itemIsEnabled(unsigned listIndex) const;
77 virtual PopupMenuStyle itemStyle(unsigned listIndex) const;
78 virtual PopupMenuStyle menuStyle() const;
79 virtual int clientInsetLeft() const;
80 virtual int clientInsetRight() const;
81 virtual int clientPaddingLeft() const;
82 virtual int clientPaddingRight() const;
83 virtual int listSize() const;
84 virtual int selectedIndex() const;
85 virtual bool itemIsSeparator(unsigned listIndex) const;
86 virtual bool itemIsLabel(unsigned listIndex) const;
87 virtual bool itemIsSelected(unsigned listIndex) const;
88 virtual void setTextFromItem(unsigned listIndex);
valueShouldChangeOnHotTrack()89 virtual bool valueShouldChangeOnHotTrack() const { return true; }
shouldPopOver()90 virtual bool shouldPopOver() const { return !POPUP_MENU_PULLS_DOWN; }
91 virtual void valueChanged(unsigned listIndex, bool fireOnChange = true);
92 virtual FontSelector* fontSelector() const;
93 virtual HostWindow* hostWindow() const;
94 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize);
95
hasLineIfEmpty()96 virtual bool hasLineIfEmpty() const { return true; }
97
98 Color itemBackgroundColor(unsigned listIndex) const;
99
100 void createInnerBlock();
101 void adjustInnerStyle();
102 void setText(const String&);
103 void setTextFromOption(int optionIndex);
104 void updateOptionsWidth();
105
106 RenderText* m_buttonText;
107 RenderBlock* m_innerBlock;
108
109 bool m_optionsChanged;
110 int m_optionsWidth;
111
112 RefPtr<PopupMenu> m_popup;
113 bool m_popupIsVisible;
114 };
115
toRenderMenuList(RenderObject * object)116 inline RenderMenuList* toRenderMenuList(RenderObject* object)
117 {
118 ASSERT(!object || object->isMenuList());
119 return static_cast<RenderMenuList*>(object);
120 }
121
122 // This will catch anyone doing an unnecessary cast.
123 void toRenderMenuList(const RenderMenuList*);
124
125 }
126
127 #endif
128