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 "core/rendering/RenderBlockFlow.h" 35 #include "platform/scroll/ScrollableArea.h" 36 37 namespace WebCore { 38 39 class HTMLSelectElement; 40 41 class RenderListBox FINAL : public RenderBlockFlow, private ScrollableArea { 42 public: 43 explicit RenderListBox(Element*); 44 virtual ~RenderListBox(); 45 46 void selectionChanged(); 47 48 void setOptionsChanged(bool changed) { m_optionsChanged = changed; } 49 50 int listIndexAtOffset(const LayoutSize&) const; 51 LayoutRect itemBoundingBoxRect(const LayoutPoint&, int index) const; 52 53 bool scrollToRevealElementAtListIndex(int index); 54 55 int scrollToward(const IntPoint&); // Returns the new index or -1 if no scroll occurred 56 57 int size() const; 58 59 void repaintScrollbarIfNeeded(); 60 61 private: 62 HTMLSelectElement* selectElement() const; 63 64 virtual const char* renderName() const OVERRIDE { return "RenderListBox"; } 65 66 virtual bool isListBox() const OVERRIDE { return true; } 67 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE; 68 69 virtual void updateFromElement() OVERRIDE; 70 virtual bool hasControlClip() const OVERRIDE { return true; } 71 virtual void paintObject(PaintInfo&, const LayoutPoint&) OVERRIDE; 72 virtual LayoutRect controlClipRect(const LayoutPoint&) const OVERRIDE; 73 74 virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset) OVERRIDE; 75 76 virtual bool scroll(ScrollDirection, ScrollGranularity, float) OVERRIDE; 77 78 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE; 79 virtual void computePreferredLogicalWidths() OVERRIDE; 80 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE; 81 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE; 82 83 virtual void layout() OVERRIDE; 84 85 virtual void invalidateTreeAfterLayout(const RenderLayerModelObject&) OVERRIDE FINAL; 86 87 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE; 88 89 virtual bool canBeProgramaticallyScrolled() const OVERRIDE { return true; } 90 virtual void autoscroll(const IntPoint&) OVERRIDE; 91 virtual void stopAutoscroll() OVERRIDE; 92 93 virtual void panScroll(const IntPoint&) OVERRIDE; 94 95 virtual int verticalScrollbarWidth() const OVERRIDE; 96 virtual LayoutUnit scrollLeft() const OVERRIDE; 97 virtual LayoutUnit scrollTop() const OVERRIDE; 98 virtual LayoutUnit scrollWidth() const OVERRIDE; 99 virtual LayoutUnit scrollHeight() const OVERRIDE; 100 virtual void setScrollLeft(LayoutUnit) OVERRIDE; 101 virtual void setScrollTop(LayoutUnit) OVERRIDE; 102 103 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE; 104 105 // ScrollableArea interface. 106 virtual int scrollSize(ScrollbarOrientation) const OVERRIDE; 107 virtual IntPoint scrollPosition() const OVERRIDE; 108 virtual void setScrollOffset(const IntPoint&) OVERRIDE; 109 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE; 110 virtual bool isActive() const OVERRIDE; 111 virtual bool isScrollCornerVisible() const OVERRIDE { return false; } // We don't support resize on list boxes yet. If we did these would have to change. 112 virtual IntRect scrollCornerRect() const OVERRIDE { return IntRect(); } 113 virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE { } 114 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const OVERRIDE; 115 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const OVERRIDE; 116 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const OVERRIDE; 117 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const OVERRIDE; 118 virtual Scrollbar* verticalScrollbar() const OVERRIDE { return m_vBar.get(); } 119 virtual IntSize contentsSize() const OVERRIDE; 120 virtual int visibleHeight() const OVERRIDE; 121 virtual int visibleWidth() const OVERRIDE; 122 virtual IntPoint lastKnownMousePosition() const OVERRIDE; 123 virtual bool shouldSuspendScrollAnimations() const OVERRIDE; 124 virtual bool scrollbarsCanBeActive() const OVERRIDE; 125 virtual IntPoint minimumScrollPosition() const OVERRIDE; 126 virtual IntPoint maximumScrollPosition() const OVERRIDE; 127 virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE; 128 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; 129 virtual int lineStep(ScrollbarOrientation) const OVERRIDE; 130 virtual int pageStep(ScrollbarOrientation) const OVERRIDE; 131 virtual float pixelStep(ScrollbarOrientation) const OVERRIDE; 132 virtual IntRect scrollableAreaBoundingBox() const OVERRIDE; 133 134 LayoutRect itemBoundingBoxRectInternal(const LayoutPoint&, int index) const; 135 bool scrollToRevealElementAtListIndexInternal(int index); 136 137 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea. 138 void scrollTo(int newOffset); 139 140 void setHasVerticalScrollbar(bool hasScrollbar); 141 PassRefPtr<Scrollbar> createScrollbar(); 142 void destroyScrollbar(); 143 144 LayoutUnit itemHeight() const; 145 int numVisibleItems() const; 146 bool listIndexIsVisible(int index) const; 147 int numItems() const; 148 LayoutUnit listHeight() const; 149 int scrollbarLeft() 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(); 154 155 int renderListBoxIndexToListIndex(int index) const; 156 int listIndexToRenderListBoxIndex(int index) const; 157 158 bool m_optionsChanged; 159 bool m_scrollToRevealSelectionAfterLayout; 160 bool m_inAutoscroll; 161 int m_optionsWidth; 162 int m_indexOffset; 163 int m_listItemCount; 164 165 RefPtr<Scrollbar> m_vBar; 166 }; 167 168 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderListBox, isListBox()); 169 170 } // namepace WebCore 171 172 #endif // RenderListBox_h 173