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 LayoutPoint&); // 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 canHaveChildren() const { return false; }
67 virtual bool hasControlClip() const { return true; }
68 virtual void paintObject(PaintInfo&, const LayoutPoint&);
69 virtual LayoutRect controlClipRect(const LayoutPoint&) const;
71 virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
73 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
74 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
76 virtual void computePreferredLogicalWidths();
77 virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
78 virtual void computeLogicalHeight();
80 virtual void layout();
82 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&);
84 virtual bool canBeProgramaticallyScrolled() const { return true; }
85 virtual void autoscroll();
86 virtual void stopAutoscroll();
88 virtual bool shouldPanScroll() const { return true; }
89 virtual void panScroll(const IntPoint&);
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);
99 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
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;
122 virtual ScrollableArea* enclosingScrollableArea() const;
124 virtual void disconnectFromPage() { m_page = 0; }
126 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
127 void scrollTo(int newOffset);
129 void setHasVerticalScrollbar(bool hasScrollbar);
130 PassRefPtr<Scrollbar> createScrollbar();
131 void destroyScrollbar();
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();
143 bool m_optionsChanged;
144 bool m_scrollToRevealSelectionAfterLayout;
149 RefPtr<Scrollbar> m_vBar;
154 inline RenderListBox* toRenderListBox(RenderObject* object)
156 ASSERT(!object || object->isListBox());
157 return static_cast<RenderListBox*>(object);
160 // This will catch anyone doing an unnecessary cast.
161 void toRenderListBox(const RenderListBox*);
163 } // namepace WebCore
165 #endif // RenderListBox_h