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