Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderListBox.h
1 /*
2  * This file is part of the select element renderer in WebCore.
3  *
4  * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1.  Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer. 
12  * 2.  Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution. 
15  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16  *     its contributors may be used to endorse or promote products derived
17  *     from this software without specific prior written permission. 
18  *
19  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef RenderListBox_h
32 #define RenderListBox_h
33
34 #include "RenderBlock.h"
35 #include "ScrollableArea.h"
36
37 namespace WebCore {
38
39 class RenderListBox : public RenderBlock, private ScrollableArea {
40 public:
41     RenderListBox(Element*);
42     virtual ~RenderListBox();
43
44     void selectionChanged();
45
46     void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
47
48     int listIndexAtOffset(const LayoutSize&);
49     LayoutRect itemBoundingBoxRect(const LayoutPoint&, int index);
50
51     bool scrollToRevealElementAtListIndex(int index);
52     bool listIndexIsVisible(int index);
53
54     int scrollToward(const IntPoint&); // Returns the new index or -1 if no scroll occurred
55
56     int size() const;
57
58 private:
59     virtual const char* renderName() const { return "RenderListBox"; }
60
61     virtual bool isListBox() const { return true; }
62
63     virtual void updateFromElement();
64
65     virtual bool hasControlClip() const { return true; }
66     virtual void paintObject(PaintInfo&, const LayoutPoint&);
67     virtual LayoutRect controlClipRect(const LayoutPoint&) const;
68
69     virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
70
71     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
72     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
73
74     virtual void computePreferredLogicalWidths();
75     virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
76     virtual void computeLogicalHeight();
77
78     virtual void layout();
79
80     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
81
82     virtual bool canBeProgramaticallyScrolled() const { return true; }
83     virtual void autoscroll();
84     virtual void stopAutoscroll();
85
86     virtual bool shouldPanScroll() const { return true; }
87     virtual void panScroll(const IntPoint&);
88
89     virtual int verticalScrollbarWidth() const;
90     virtual int scrollLeft() const;
91     virtual int scrollTop() const;
92     virtual int scrollWidth() const;
93     virtual int scrollHeight() const;
94     virtual void setScrollLeft(int);
95     virtual void setScrollTop(int);
96
97     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
98
99     // ScrollableArea interface.
100     virtual int scrollSize(ScrollbarOrientation) const;
101     virtual int scrollPosition(Scrollbar*) const;
102     virtual void setScrollOffset(const IntPoint&);
103     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
104     virtual bool isActive() const;
105     virtual bool isScrollCornerVisible() const { return false; } // We don't support resize on list boxes yet. If we did these would have to change.
106     virtual IntRect scrollCornerRect() const { return IntRect(); }
107     virtual void invalidateScrollCornerRect(const IntRect&) { }
108     virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const;
109     virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const;
110     virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const;
111     virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const;
112     virtual Scrollbar* verticalScrollbar() const { return m_vBar.get(); }
113     virtual IntSize contentsSize() const;
114     virtual int visibleHeight() const;
115     virtual int visibleWidth() const;
116     virtual IntPoint currentMousePosition() const;
117     virtual bool shouldSuspendScrollAnimations() const;
118     virtual bool isOnActivePage() const;
119
120     virtual ScrollableArea* enclosingScrollableArea() const;
121     virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
122
123     // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
124     void scrollTo(int newOffset);
125
126     void setHasVerticalScrollbar(bool hasScrollbar);
127     PassRefPtr<Scrollbar> createScrollbar();
128     void destroyScrollbar();
129     
130     LayoutUnit itemHeight() const;
131     void valueChanged(unsigned listIndex);
132     int numVisibleItems() const;
133     int numItems() const;
134     LayoutUnit listHeight() const;
135     void paintScrollbar(PaintInfo&, const LayoutPoint&);
136     void paintItemForeground(PaintInfo&, const LayoutPoint&, int listIndex);
137     void paintItemBackground(PaintInfo&, const LayoutPoint&, int listIndex);
138     void scrollToRevealSelection();
139
140     bool m_optionsChanged;
141     bool m_scrollToRevealSelectionAfterLayout;
142     bool m_inAutoscroll;
143     int m_optionsWidth;
144     int m_indexOffset;
145
146     RefPtr<Scrollbar> m_vBar;
147 };
148
149 inline RenderListBox* toRenderListBox(RenderObject* object)
150
151     ASSERT(!object || object->isListBox());
152     return static_cast<RenderListBox*>(object);
153 }
154
155 // This will catch anyone doing an unnecessary cast.
156 void toRenderListBox(const RenderListBox*);
157
158 } // namepace WebCore
159
160 #endif // RenderListBox_h