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 HTMLSelectElement;
41 class RenderListBox : public RenderBlock, private ScrollableArea {
43 RenderListBox(Element*);
44 virtual ~RenderListBox();
46 void selectionChanged();
48 void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
50 int listIndexAtOffset(const LayoutSize&);
51 LayoutRect itemBoundingBoxRect(const LayoutPoint&, int index);
53 bool scrollToRevealElementAtListIndex(int index);
54 bool listIndexIsVisible(int index);
56 int scrollToward(const IntPoint&); // Returns the new index or -1 if no scroll occurred
61 HTMLSelectElement* selectElement() const;
63 virtual const char* renderName() const { return "RenderListBox"; }
65 virtual bool isListBox() const { return true; }
67 virtual void updateFromElement();
68 virtual bool canBeReplacedWithInlineRunIn() const OVERRIDE;
69 virtual bool hasControlClip() const { return true; }
70 virtual void paintObject(PaintInfo&, const LayoutPoint&);
71 virtual LayoutRect controlClipRect(const LayoutPoint&) const;
73 virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
75 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
76 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
78 virtual void computePreferredLogicalWidths();
79 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
80 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
82 virtual void layout();
84 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
86 virtual bool canBeProgramaticallyScrolled() const { return true; }
87 virtual void autoscroll();
88 virtual void stopAutoscroll();
90 virtual bool shouldPanScroll() const { return true; }
91 virtual void panScroll(const IntPoint&);
93 virtual int verticalScrollbarWidth() const;
94 virtual int scrollLeft() const;
95 virtual int scrollTop() const;
96 virtual int scrollWidth() const;
97 virtual int scrollHeight() const;
98 virtual void setScrollLeft(int);
99 virtual void setScrollTop(int);
101 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
103 // ScrollableArea interface.
104 virtual int scrollSize(ScrollbarOrientation) const OVERRIDE;
105 virtual int scrollPosition(Scrollbar*) const OVERRIDE;
106 virtual void setScrollOffset(const IntPoint&) OVERRIDE;
107 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE;
108 virtual bool isActive() const OVERRIDE;
109 virtual bool isScrollCornerVisible() const OVERRIDE { return false; } // We don't support resize on list boxes yet. If we did these would have to change.
110 virtual IntRect scrollCornerRect() const OVERRIDE { return IntRect(); }
111 virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE { }
112 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const OVERRIDE;
113 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const OVERRIDE;
114 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const OVERRIDE;
115 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const OVERRIDE;
116 virtual Scrollbar* verticalScrollbar() const OVERRIDE { return m_vBar.get(); }
117 virtual IntSize contentsSize() const OVERRIDE;
118 virtual int visibleHeight() const OVERRIDE;
119 virtual int visibleWidth() const OVERRIDE;
120 virtual IntPoint lastKnownMousePosition() const OVERRIDE;
121 virtual bool shouldSuspendScrollAnimations() const OVERRIDE;
122 virtual bool scrollbarsCanBeActive() const OVERRIDE;
124 virtual ScrollableArea* enclosingScrollableArea() const OVERRIDE;
125 virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
127 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
128 void scrollTo(int newOffset);
130 void setHasVerticalScrollbar(bool hasScrollbar);
131 PassRefPtr<Scrollbar> createScrollbar();
132 void destroyScrollbar();
134 LayoutUnit itemHeight() const;
135 void valueChanged(unsigned listIndex);
136 int numVisibleItems() const;
137 int numItems() const;
138 LayoutUnit listHeight() const;
139 void paintScrollbar(PaintInfo&, const LayoutPoint&);
140 void paintItemForeground(PaintInfo&, const LayoutPoint&, int listIndex);
141 void paintItemBackground(PaintInfo&, const LayoutPoint&, int listIndex);
142 void scrollToRevealSelection();
144 bool m_optionsChanged;
145 bool m_scrollToRevealSelectionAfterLayout;
150 RefPtr<Scrollbar> m_vBar;
153 inline RenderListBox* toRenderListBox(RenderObject* object)
155 ASSERT(!object || object->isListBox());
156 return static_cast<RenderListBox*>(object);
159 // This will catch anyone doing an unnecessary cast.
160 void toRenderListBox(const RenderListBox*);
162 } // namepace WebCore
164 #endif // RenderListBox_h