1 /* 2 * This file is part of the select element renderer in WebCore. 3 * 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 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: 46 bool popupIsVisible() const { return m_popupIsVisible; } 47 void showPopup(); 48 void hidePopup(); 49 50 void setOptionsChanged(bool changed) { m_optionsChanged = changed; } 51 52 void didSetSelectedIndex(); 53 54 String text() const; 55 56 private: 57 virtual bool isMenuList() const { return true; } 58 59 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0); 60 virtual void removeChild(RenderObject*); 61 virtual bool createsAnonymousWrapper() const { return true; } 62 virtual bool canHaveChildren() const { return false; } 63 64 virtual void updateFromElement(); 65 66 virtual bool hasControlClip() const { return true; } 67 virtual IntRect controlClipRect(int tx, int ty) const; 68 69 virtual const char* renderName() const { return "RenderMenuList"; } 70 71 virtual void calcPrefWidths(); 72 73 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 74 75 // PopupMenuClient methods 76 virtual String itemText(unsigned listIndex) const; 77 virtual String itemToolTip(unsigned listIndex) const; 78 virtual bool itemIsEnabled(unsigned listIndex) const; 79 virtual PopupMenuStyle itemStyle(unsigned listIndex) const; 80 virtual PopupMenuStyle menuStyle() const; 81 virtual int clientInsetLeft() const; 82 virtual int clientInsetRight() const; 83 virtual int clientPaddingLeft() const; 84 virtual int clientPaddingRight() const; 85 virtual int listSize() const; 86 virtual int selectedIndex() const; 87 virtual void popupDidHide(); 88 virtual bool itemIsSeparator(unsigned listIndex) const; 89 virtual bool itemIsLabel(unsigned listIndex) const; 90 virtual bool itemIsSelected(unsigned listIndex) const; 91 virtual void setTextFromItem(unsigned listIndex); 92 virtual bool valueShouldChangeOnHotTrack() const { return true; } 93 virtual bool shouldPopOver() const { return !POPUP_MENU_PULLS_DOWN; } 94 virtual void valueChanged(unsigned listIndex, bool fireOnChange = true); 95 virtual FontSelector* fontSelector() const; 96 virtual HostWindow* hostWindow() const; 97 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize); 98 99 virtual bool hasLineIfEmpty() const { return true; } 100 101 Color itemBackgroundColor(unsigned listIndex) const; 102 103 void createInnerBlock(); 104 void adjustInnerStyle(); 105 void setText(const String&); 106 void setTextFromOption(int optionIndex); 107 void updateOptionsWidth(); 108 109 RenderText* m_buttonText; 110 RenderBlock* m_innerBlock; 111 112 bool m_optionsChanged; 113 int m_optionsWidth; 114 115 int m_lastSelectedIndex; 116 117 RefPtr<PopupMenu> m_popup; 118 bool m_popupIsVisible; 119 }; 120 121 inline RenderMenuList* toRenderMenuList(RenderObject* object) 122 { 123 ASSERT(!object || object->isMenuList()); 124 return static_cast<RenderMenuList*>(object); 125 } 126 127 // This will catch anyone doing an unnecessary cast. 128 void toRenderMenuList(const RenderMenuList*); 129 130 } 131 132 #endif 133