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 "ScrollbarClient.h"
36
37namespace WebCore {
38
39class RenderListBox : public RenderBlock, private ScrollbarClient {
40public:
41    RenderListBox(Element*);
42    virtual ~RenderListBox();
43
44    void selectionChanged();
45
46    void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
47
48    int listIndexAtOffset(int x, int y);
49    IntRect itemBoundingBoxRect(int tx, int ty, 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
56private:
57    virtual const char* renderName() const { return "RenderListBox"; }
58
59    virtual bool isListBox() const { return true; }
60
61    virtual void updateFromElement();
62
63    virtual bool canHaveChildren() const { return false; }
64
65    virtual bool hasControlClip() const { return true; }
66    virtual void paintObject(PaintInfo&, int tx, int ty);
67    virtual IntRect controlClipRect(int tx, int ty) const;
68
69    virtual bool isPointInOverflowControl(HitTestResult&, int x, int y, int tx, int ty);
70
71    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f, Node** stopNode = 0);
72
73    virtual void calcPrefWidths();
74    virtual int baselinePosition(bool firstLine, bool isRootLineBox) const;
75    virtual void calcHeight();
76
77    virtual void layout();
78
79    virtual bool canBeProgramaticallyScrolled(bool) const { return true; }
80    virtual void autoscroll();
81    virtual void stopAutoscroll();
82
83    virtual bool shouldPanScroll() const { return true; }
84    virtual void panScroll(const IntPoint&);
85
86    virtual int verticalScrollbarWidth() const;
87    virtual int scrollLeft() const;
88    virtual int scrollTop() const;
89    virtual int scrollWidth() const;
90    virtual int scrollHeight() const;
91    virtual void setScrollLeft(int);
92    virtual void setScrollTop(int);
93
94    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
95
96    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
97
98    // ScrollbarClient interface.
99    virtual void valueChanged(Scrollbar*);
100    virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
101    virtual bool isActive() const;
102    virtual bool scrollbarCornerPresent() const { return false; } // We don't support resize on list boxes yet.  If we did this would have to change.
103    virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const;
104    virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const;
105    virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const;
106    virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const;
107
108    void setHasVerticalScrollbar(bool hasScrollbar);
109    PassRefPtr<Scrollbar> createScrollbar();
110    void destroyScrollbar();
111
112    int itemHeight() const;
113    void valueChanged(unsigned listIndex);
114    int size() const;
115    int numVisibleItems() const;
116    int numItems() const;
117    int listHeight() const;
118    void paintScrollbar(PaintInfo&, int tx, int ty);
119    void paintItemForeground(PaintInfo&, int tx, int ty, int listIndex);
120    void paintItemBackground(PaintInfo&, int tx, int ty, int listIndex);
121    void scrollToRevealSelection();
122
123    bool m_optionsChanged;
124    bool m_scrollToRevealSelectionAfterLayout;
125    bool m_inAutoscroll;
126    int m_optionsWidth;
127    int m_indexOffset;
128
129    RefPtr<Scrollbar> m_vBar;
130};
131
132inline RenderListBox* toRenderListBox(RenderObject* object)
133{
134    ASSERT(!object || object->isListBox());
135    return static_cast<RenderListBox*>(object);
136}
137
138// This will catch anyone doing an unnecessary cast.
139void toRenderListBox(const RenderListBox*);
140
141} // namepace WebCore
142
143#endif // RenderListBox_h
144