2 * This file is part of the select element renderer in WebCore.
4 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
31 #ifndef RenderListBox_h
32 #define RenderListBox_h
34 #include "RenderBlock.h"
35 #include "ScrollableArea.h"
39 class RenderListBox : public RenderBlock, private ScrollableArea {
41 RenderListBox(Element*);
42 virtual ~RenderListBox();
44 void selectionChanged();
46 void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
48 int listIndexAtOffset(const LayoutSize&);
49 LayoutRect itemBoundingBoxRect(const LayoutPoint&, int index);
51 bool scrollToRevealElementAtListIndex(int index);
52 bool listIndexIsVisible(int index);
54 int scrollToward(const IntPoint&); // Returns the new index or -1 if no scroll occurred
59 virtual const char* renderName() const { return "RenderListBox"; }
61 virtual bool isListBox() const { return true; }
63 virtual void updateFromElement();
65 virtual bool hasControlClip() const { return true; }
66 virtual void paintObject(PaintInfo&, const LayoutPoint&);
67 virtual LayoutRect controlClipRect(const LayoutPoint&) const;
69 virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
71 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
72 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
74 virtual void computePreferredLogicalWidths();
75 virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
76 virtual void computeLogicalHeight();
78 virtual void layout();
80 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
82 virtual bool canBeProgramaticallyScrolled() const { return true; }
83 virtual void autoscroll();
84 virtual void stopAutoscroll();
86 virtual bool shouldPanScroll() const { return true; }
87 virtual void panScroll(const IntPoint&);
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);
97 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
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;
120 virtual ScrollableArea* enclosingScrollableArea() const;
121 virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
123 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
124 void scrollTo(int newOffset);
126 void setHasVerticalScrollbar(bool hasScrollbar);
127 PassRefPtr<Scrollbar> createScrollbar();
128 void destroyScrollbar();
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();
140 bool m_optionsChanged;
141 bool m_scrollToRevealSelectionAfterLayout;
146 RefPtr<Scrollbar> m_vBar;
149 inline RenderListBox* toRenderListBox(RenderObject* object)
151 ASSERT(!object || object->isListBox());
152 return static_cast<RenderListBox*>(object);
155 // This will catch anyone doing an unnecessary cast.
156 void toRenderListBox(const RenderListBox*);
158 } // namepace WebCore
160 #endif // RenderListBox_h