initial import
[vuplus_webkit] / 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 LayoutPoint&); // 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 canHaveChildren() const { return false; }
66
67     virtual bool hasControlClip() const { return true; }
68     virtual void paintObject(PaintInfo&, const LayoutPoint&);
69     virtual LayoutRect controlClipRect(const LayoutPoint&) const;
70
71     virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
72
73     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
74     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
75
76     virtual void computePreferredLogicalWidths();
77     virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
78     virtual void computeLogicalHeight();
79
80     virtual void layout();
81
82     virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&);
83
84     virtual bool canBeProgramaticallyScrolled() const { return true; }
85     virtual void autoscroll();
86     virtual void stopAutoscroll();
87
88     virtual bool shouldPanScroll() const { return true; }
89     virtual void panScroll(const IntPoint&);
90
91     virtual LayoutUnit verticalScrollbarWidth() const;
92     virtual LayoutUnit scrollLeft() const;
93     virtual LayoutUnit scrollTop() const;
94     virtual LayoutUnit scrollWidth() const;
95     virtual LayoutUnit scrollHeight() const;
96     virtual void setScrollLeft(LayoutUnit);
97     virtual void setScrollTop(LayoutUnit);
98
99     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
100
101     // ScrollableArea interface.
102     virtual LayoutUnit scrollSize(ScrollbarOrientation) const;
103     virtual LayoutUnit scrollPosition(Scrollbar*) const;
104     virtual void setScrollOffset(const LayoutPoint&);
105     virtual void invalidateScrollbarRect(Scrollbar*, const LayoutRect&);
106     virtual bool isActive() const;
107     virtual bool isScrollCornerVisible() const { return false; } // We don't support resize on list boxes yet. If we did these would have to change.
108     virtual LayoutRect scrollCornerRect() const { return LayoutRect(); }
109     virtual void invalidateScrollCornerRect(const LayoutRect&) { }
110     virtual LayoutRect convertFromScrollbarToContainingView(const Scrollbar*, const LayoutRect&) const;
111     virtual LayoutRect convertFromContainingViewToScrollbar(const Scrollbar*, const LayoutRect&) const;
112     virtual LayoutPoint convertFromScrollbarToContainingView(const Scrollbar*, const LayoutPoint&) const;
113     virtual LayoutPoint convertFromContainingViewToScrollbar(const Scrollbar*, const LayoutPoint&) const;
114     virtual Scrollbar* verticalScrollbar() const { return m_vBar.get(); }
115     virtual LayoutSize contentsSize() const;
116     virtual LayoutUnit visibleHeight() const;
117     virtual LayoutUnit visibleWidth() const;
118     virtual LayoutPoint currentMousePosition() const;
119     virtual bool shouldSuspendScrollAnimations() const;
120     virtual bool isOnActivePage() const;
121
122     virtual ScrollableArea* enclosingScrollableArea() const;
123
124     virtual void disconnectFromPage() { m_page = 0; }
125
126     // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
127     void scrollTo(int newOffset);
128
129     void setHasVerticalScrollbar(bool hasScrollbar);
130     PassRefPtr<Scrollbar> createScrollbar();
131     void destroyScrollbar();
132     
133     LayoutUnit itemHeight() const;
134     void valueChanged(unsigned listIndex);
135     int numVisibleItems() const;
136     int numItems() const;
137     LayoutUnit listHeight() const;
138     void paintScrollbar(PaintInfo&, const LayoutPoint&);
139     void paintItemForeground(PaintInfo&, const LayoutPoint&, int listIndex);
140     void paintItemBackground(PaintInfo&, const LayoutPoint&, int listIndex);
141     void scrollToRevealSelection();
142
143     bool m_optionsChanged;
144     bool m_scrollToRevealSelectionAfterLayout;
145     bool m_inAutoscroll;
146     int m_optionsWidth;
147     int m_indexOffset;
148
149     RefPtr<Scrollbar> m_vBar;
150
151     Page* m_page;
152 };
153
154 inline RenderListBox* toRenderListBox(RenderObject* object)
155
156     ASSERT(!object || object->isListBox());
157     return static_cast<RenderListBox*>(object);
158 }
159
160 // This will catch anyone doing an unnecessary cast.
161 void toRenderListBox(const RenderListBox*);
162
163 } // namepace WebCore
164
165 #endif // RenderListBox_h