2 * This file is part of the select element renderer in WebCore.
4 * Copyright (C) 2006, 2007, 2009, 2014 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 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 "RenderBlockFlow.h"
35 #include "ScrollableArea.h"
39 class HTMLSelectElement;
41 class RenderListBox final : public RenderBlockFlow, public ScrollableArea {
43 RenderListBox(HTMLSelectElement&, Ref<RenderStyle>&&);
44 virtual ~RenderListBox();
46 HTMLSelectElement& selectElement() const;
48 void selectionChanged();
50 void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
52 int listIndexAtOffset(const LayoutSize&);
53 LayoutRect itemBoundingBoxRect(const LayoutPoint&, int index);
55 bool scrollToRevealElementAtListIndex(int index);
56 bool listIndexIsVisible(int index);
58 int scrollToward(const IntPoint&); // Returns the new index or -1 if no scroll occurred
62 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint()) override;
64 virtual bool scrolledToTop() const override;
65 virtual bool scrolledToBottom() const override;
66 virtual bool scrolledToLeft() const override;
67 virtual bool scrolledToRight() const override;
70 void element() const = delete;
72 virtual const char* renderName() const override { return "RenderListBox"; }
74 virtual bool isListBox() const override { return true; }
76 virtual void updateFromElement() override;
77 virtual bool hasControlClip() const override { return true; }
78 virtual void paintObject(PaintInfo&, const LayoutPoint&) override;
79 virtual LayoutRect controlClipRect(const LayoutPoint&) const override;
81 virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset) override;
83 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr) override;
85 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
86 virtual void computePreferredLogicalWidths() override;
87 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
88 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override;
90 virtual void layout() override;
92 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = nullptr) override;
94 virtual bool canBeProgramaticallyScrolled() const override { return true; }
95 virtual void autoscroll(const IntPoint&) override;
96 virtual void stopAutoscroll() override;
98 virtual bool shouldPanScroll() const { return true; }
99 virtual void panScroll(const IntPoint&) override;
101 virtual int verticalScrollbarWidth() const override;
102 virtual int scrollLeft() const override;
103 virtual int scrollTop() const override;
104 virtual int scrollWidth() const override;
105 virtual int scrollHeight() const override;
106 virtual void setScrollLeft(int) override;
107 virtual void setScrollTop(int) override;
109 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
111 // ScrollableArea interface.
112 virtual int scrollSize(ScrollbarOrientation) const override;
113 virtual int scrollPosition(Scrollbar*) const override;
114 virtual void setScrollOffset(const IntPoint&) override;
115 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) override;
116 virtual bool isActive() const override;
117 virtual bool isScrollCornerVisible() const override { return false; } // We don't support resize on list boxes yet. If we did these would have to change.
118 virtual IntRect scrollCornerRect() const override { return IntRect(); }
119 virtual void invalidateScrollCornerRect(const IntRect&) override { }
120 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const override;
121 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const override;
122 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const override;
123 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const override;
124 virtual Scrollbar* verticalScrollbar() const override { return m_vBar.get(); }
125 virtual IntSize contentsSize() const override;
126 virtual IntSize visibleSize() const override { return IntSize(width(), height()); }
127 virtual IntPoint lastKnownMousePosition() const override;
128 virtual bool isHandlingWheelEvent() const override;
129 virtual bool shouldSuspendScrollAnimations() const override;
130 virtual bool updatesScrollLayerPositionOnMainThread() const override { return true; }
131 virtual bool forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const override;
133 virtual ScrollableArea* enclosingScrollableArea() const override;
134 virtual bool isScrollableOrRubberbandable() override;
135 virtual bool hasScrollableOrRubberbandableAncestor() override;
136 virtual IntRect scrollableAreaBoundingBox() const override;
138 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
139 void scrollTo(int newOffset);
141 void setHasVerticalScrollbar(bool hasScrollbar);
142 PassRefPtr<Scrollbar> createScrollbar();
143 void destroyScrollbar();
145 LayoutUnit itemHeight() const;
146 void valueChanged(unsigned listIndex);
147 int numVisibleItems() const;
148 int numItems() const;
149 LayoutUnit listHeight() const;
150 void paintScrollbar(PaintInfo&, const LayoutPoint&);
151 void paintItemForeground(PaintInfo&, const LayoutPoint&, int listIndex);
152 void paintItemBackground(PaintInfo&, const LayoutPoint&, int listIndex);
153 void scrollToRevealSelection();
155 bool m_optionsChanged;
156 bool m_scrollToRevealSelectionAfterLayout;
161 RefPtr<Scrollbar> m_vBar;
164 } // namepace WebCore
166 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListBox, isListBox())
168 #endif // RenderListBox_h