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 * 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. 11 * 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. 16 * 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. 21 * 22 */ 23 24 #ifndef RenderMenuList_h 25 #define RenderMenuList_h 26 27 #include "core/platform/PopupMenu.h" 28 #include "core/platform/PopupMenuClient.h" 29 #include "core/platform/graphics/LayoutRect.h" 30 #include "core/rendering/RenderFlexibleBox.h" 31 32 namespace WebCore { 33 34 class HTMLSelectElement; 35 class RenderText; 36 37 class RenderMenuList FINAL : public RenderFlexibleBox, private PopupMenuClient { 38 39 public: 40 RenderMenuList(Element*); 41 virtual ~RenderMenuList(); 42 43 public: 44 bool popupIsVisible() const { return m_popupIsVisible; } 45 void showPopup(); 46 void hidePopup(); 47 48 void setOptionsChanged(bool changed) { m_optionsChanged = changed; } 49 50 void didSetSelectedIndex(int listIndex); 51 52 String text() const; 53 54 private: 55 HTMLSelectElement* selectElement() const; 56 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 63 virtual void updateFromElement(); 64 65 virtual LayoutRect controlClipRect(const LayoutPoint&) const; 66 virtual bool hasControlClip() const { return true; } 67 virtual bool canHaveGeneratedChildren() const OVERRIDE { return false; } 68 virtual bool canBeReplacedWithInlineRunIn() const OVERRIDE; 69 70 virtual const char* renderName() const { return "RenderMenuList"; } 71 72 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE; 73 virtual void computePreferredLogicalWidths() OVERRIDE; 74 75 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 76 77 virtual bool requiresForcedStyleRecalcPropagation() const { return true; } 78 79 // PopupMenuClient methods 80 virtual void valueChanged(unsigned listIndex, bool fireOnChange = true) OVERRIDE; 81 virtual void selectionChanged(unsigned, bool) OVERRIDE { } 82 virtual void selectionCleared() OVERRIDE { } 83 virtual String itemText(unsigned listIndex) const OVERRIDE; 84 virtual String itemLabel(unsigned listIndex) const OVERRIDE; 85 virtual String itemIcon(unsigned listIndex) const OVERRIDE; 86 virtual String itemToolTip(unsigned listIndex) const OVERRIDE; 87 virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE; 88 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE; 89 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE; 90 virtual PopupMenuStyle menuStyle() const OVERRIDE; 91 virtual int clientInsetLeft() const OVERRIDE; 92 virtual int clientInsetRight() const OVERRIDE; 93 virtual LayoutUnit clientPaddingLeft() const OVERRIDE; 94 virtual LayoutUnit clientPaddingRight() const OVERRIDE; 95 virtual int listSize() const OVERRIDE; 96 virtual int selectedIndex() const OVERRIDE; 97 virtual void popupDidHide() OVERRIDE; 98 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE; 99 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE; 100 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE; 101 virtual bool valueShouldChangeOnHotTrack() const OVERRIDE { return true; } 102 virtual void setTextFromItem(unsigned listIndex) OVERRIDE; 103 virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) OVERRIDE; 104 virtual bool multiple() const OVERRIDE; 105 virtual FontSelector* fontSelector() const OVERRIDE; 106 virtual HostWindow* hostWindow() const OVERRIDE; 107 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize) OVERRIDE; 108 109 virtual bool hasLineIfEmpty() const { return true; } 110 111 // Flexbox defines baselines differently than regular blocks. 112 // For backwards compatibility, menulists need to do the regular block behavior. 113 virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const OVERRIDE 114 { 115 return RenderBlock::baselinePosition(baseline, firstLine, direction, position); 116 } 117 virtual int firstLineBoxBaseline() const OVERRIDE { return RenderBlock::firstLineBoxBaseline(); } 118 virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return RenderBlock::inlineBlockBaseline(direction); } 119 120 void getItemBackgroundColor(unsigned listIndex, Color&, bool& itemHasCustomBackgroundColor) const; 121 122 void createInnerBlock(); 123 void adjustInnerStyle(); 124 void setText(const String&); 125 void setTextFromOption(int optionIndex); 126 void updateOptionsWidth(); 127 128 void didUpdateActiveOption(int optionIndex); 129 130 RenderText* m_buttonText; 131 RenderBlock* m_innerBlock; 132 133 bool m_optionsChanged; 134 int m_optionsWidth; 135 136 int m_lastActiveIndex; 137 138 RefPtr<RenderStyle> m_optionStyle; 139 140 RefPtr<PopupMenu> m_popup; 141 bool m_popupIsVisible; 142 }; 143 144 inline RenderMenuList* toRenderMenuList(RenderObject* object) 145 { 146 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isMenuList()); 147 return static_cast<RenderMenuList*>(object); 148 } 149 150 // This will catch anyone doing an unnecessary cast. 151 void toRenderMenuList(const RenderMenuList*); 152 153 } 154 155 #endif 156