Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 "core/rendering/RenderFlexibleBox.h"
28 #include "platform/PopupMenu.h"
29 #include "platform/PopupMenuClient.h"
30 #include "platform/geometry/LayoutRect.h"
31
32 namespace blink {
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     virtual void destroy() OVERRIDE;
43     virtual void trace(Visitor*) OVERRIDE;
44
45     bool popupIsVisible() const { return m_popupIsVisible; }
46     void showPopup();
47     void hidePopup();
48
49     void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
50
51     void didSetSelectedIndex(int listIndex);
52
53     String text() const;
54
55     virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
56
57 private:
58     HTMLSelectElement* selectElement() const;
59
60     virtual bool isMenuList() const OVERRIDE { return true; }
61     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
62
63     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
64     virtual void removeChild(RenderObject*) OVERRIDE;
65     virtual bool createsAnonymousWrapper() const OVERRIDE { return true; }
66
67     virtual void updateFromElement() OVERRIDE;
68
69     virtual LayoutRect controlClipRect(const LayoutPoint&) const OVERRIDE;
70     virtual bool hasControlClip() const OVERRIDE { return true; }
71     virtual bool canHaveGeneratedChildren() const OVERRIDE { return false; }
72
73     virtual const char* renderName() const OVERRIDE { return "RenderMenuList"; }
74
75     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
76     virtual void computePreferredLogicalWidths() OVERRIDE;
77
78     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
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 itemToolTip(unsigned listIndex) const OVERRIDE;
86     virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE;
87     virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
88     virtual PopupMenuStyle menuStyle() const OVERRIDE;
89     virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
90     virtual LayoutUnit clientPaddingRight() const OVERRIDE;
91     virtual int listSize() const OVERRIDE;
92     virtual int selectedIndex() const OVERRIDE;
93     virtual void popupDidHide() OVERRIDE;
94     virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
95     virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
96     virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
97     virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
98     virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) OVERRIDE;
99     virtual bool multiple() const OVERRIDE;
100
101     virtual bool hasLineIfEmpty() const OVERRIDE { return true; }
102
103     // Flexbox defines baselines differently than regular blocks.
104     // For backwards compatibility, menulists need to do the regular block behavior.
105     virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const OVERRIDE
106     {
107         return RenderBlock::baselinePosition(baseline, firstLine, direction, position);
108     }
109     virtual int firstLineBoxBaseline() const OVERRIDE { return RenderBlock::firstLineBoxBaseline(); }
110     virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return RenderBlock::inlineBlockBaseline(direction); }
111
112     void getItemBackgroundColor(unsigned listIndex, Color&, bool& itemHasCustomBackgroundColor) const;
113
114     void createInnerBlock();
115     void adjustInnerStyle();
116     void setText(const String&);
117     void setTextFromOption(int optionIndex);
118     void updateOptionsWidth();
119
120     void didUpdateActiveOption(int optionIndex);
121
122     RawPtrWillBeMember<RenderText> m_buttonText;
123     RawPtrWillBeMember<RenderBlock> m_innerBlock;
124
125     bool m_optionsChanged;
126     int m_optionsWidth;
127
128     int m_lastActiveIndex;
129
130     RefPtr<RenderStyle> m_optionStyle;
131
132     RefPtrWillBeMember<PopupMenu> m_popup;
133     bool m_popupIsVisible;
134 };
135
136 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMenuList, isMenuList());
137
138 }
139
140 #endif