Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderMenuList.h
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 "LayoutTypes.h"
28 #include "PopupMenu.h"
29 #include "PopupMenuClient.h"
30 #include "RenderDeprecatedFlexibleBox.h"
31
32 #if PLATFORM(MAC)
33 #define POPUP_MENU_PULLS_DOWN 0
34 #else
35 #define POPUP_MENU_PULLS_DOWN 1
36 #endif
37
38 namespace WebCore {
39
40 class RenderText;
41
42 class RenderMenuList : public RenderDeprecatedFlexibleBox, private PopupMenuClient {
43
44 public:
45     RenderMenuList(Element*);
46     virtual ~RenderMenuList();
47
48 public:
49     bool popupIsVisible() const { return m_popupIsVisible; }
50     void showPopup();
51     void hidePopup();
52
53     void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
54
55     void didSetSelectedIndex(int listIndex);
56
57     String text() const;
58
59 private:
60     virtual bool isMenuList() const { return true; }
61
62     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
63     virtual void removeChild(RenderObject*);
64     virtual bool createsAnonymousWrapper() const { return true; }
65
66     virtual void updateFromElement();
67
68     virtual LayoutRect controlClipRect(const LayoutPoint&) const;
69     virtual bool hasControlClip() const { return true; }
70     virtual bool canHaveGeneratedChildren() const OVERRIDE { return false; }
71
72     virtual const char* renderName() const { return "RenderMenuList"; }
73
74     virtual void computePreferredLogicalWidths();
75
76     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
77
78     virtual bool requiresForcedStyleRecalcPropagation() const { return true; }
79
80     // PopupMenuClient methods
81     virtual void valueChanged(unsigned listIndex, bool fireOnChange = true) OVERRIDE;
82     virtual void selectionChanged(unsigned, bool) OVERRIDE { }
83     virtual void selectionCleared() OVERRIDE { }
84     virtual String itemText(unsigned listIndex) const OVERRIDE;
85     virtual String itemLabel(unsigned listIndex) const OVERRIDE;
86     virtual String itemIcon(unsigned listIndex) const OVERRIDE;
87     virtual String itemToolTip(unsigned listIndex) const OVERRIDE;
88     virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE;
89     virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
90     virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
91     virtual PopupMenuStyle menuStyle() const OVERRIDE;
92     virtual int clientInsetLeft() const OVERRIDE;
93     virtual int clientInsetRight() const OVERRIDE;
94     virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
95     virtual LayoutUnit clientPaddingRight() const OVERRIDE;
96     virtual int listSize() const OVERRIDE;
97     virtual int selectedIndex() const OVERRIDE;
98     virtual void popupDidHide() OVERRIDE;
99     virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
100     virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
101     virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
102     virtual bool shouldPopOver() const OVERRIDE { return !POPUP_MENU_PULLS_DOWN; }
103     virtual bool valueShouldChangeOnHotTrack() const OVERRIDE { return true; }
104     virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
105     virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) OVERRIDE;
106     virtual bool multiple() const OVERRIDE;
107     virtual FontSelector* fontSelector() const OVERRIDE;
108     virtual HostWindow* hostWindow() const OVERRIDE;
109     virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize) OVERRIDE;
110
111     virtual bool hasLineIfEmpty() const { return true; }
112
113     Color itemBackgroundColor(unsigned listIndex) const;
114
115     void createInnerBlock();
116     void adjustInnerStyle();
117     void setText(const String&);
118     void setTextFromOption(int optionIndex);
119     void updateOptionsWidth();
120
121     void didUpdateActiveOption(int optionIndex);
122
123     RenderText* m_buttonText;
124     RenderBlock* m_innerBlock;
125
126     bool m_optionsChanged;
127     int m_optionsWidth;
128
129     int m_lastActiveIndex;
130
131     RefPtr<RenderStyle> m_optionStyle;
132
133     RefPtr<PopupMenu> m_popup;
134     bool m_popupIsVisible;
135 };
136
137 inline RenderMenuList* toRenderMenuList(RenderObject* object)
138 {
139     ASSERT(!object || object->isMenuList());
140     return static_cast<RenderMenuList*>(object);
141 }
142
143 // This will catch anyone doing an unnecessary cast.
144 void toRenderMenuList(const RenderMenuList*);
145
146 }
147
148 #endif