Home | History | Annotate | Download | only in rendering
      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/platform/ScrollableArea.h"
     35 #include "core/rendering/RenderBlock.h"
     36 
     37 namespace WebCore {
     38 
     39 class HTMLSelectElement;
     40 
     41 class RenderListBox FINAL : public RenderBlock, 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 canBeReplacedWithInlineRunIn() const OVERRIDE;
     69     virtual bool hasControlClip() const { return true; }
     70     virtual void paintObject(PaintInfo&, const LayoutPoint&);
     71     virtual LayoutRect controlClipRect(const LayoutPoint&) const;
     72 
     73     virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset);
     74 
     75     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
     76     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
     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;
     81     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
     82 
     83     virtual void layout();
     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 int lineStep(ScrollbarOrientation) const;
    128     virtual int pageStep(ScrollbarOrientation) const;
    129     virtual float pixelStep(ScrollbarOrientation) const;
    130 
    131 
    132     virtual ScrollableArea* enclosingScrollableArea() const OVERRIDE;
    133     virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
    134 
    135     // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
    136     void scrollTo(int newOffset);
    137 
    138     void setHasVerticalScrollbar(bool hasScrollbar);
    139     PassRefPtr<Scrollbar> createScrollbar();
    140     void destroyScrollbar();
    141 
    142     LayoutUnit itemHeight() const;
    143     void valueChanged(unsigned listIndex);
    144     int numVisibleItems() const;
    145     int numItems() const;
    146     LayoutUnit listHeight() const;
    147     void paintScrollbar(PaintInfo&, const LayoutPoint&);
    148     void paintItemForeground(PaintInfo&, const LayoutPoint&, int listIndex);
    149     void paintItemBackground(PaintInfo&, const LayoutPoint&, int listIndex);
    150     void scrollToRevealSelection();
    151 
    152     bool m_optionsChanged;
    153     bool m_scrollToRevealSelectionAfterLayout;
    154     bool m_inAutoscroll;
    155     int m_optionsWidth;
    156     int m_indexOffset;
    157 
    158     RefPtr<Scrollbar> m_vBar;
    159 };
    160 
    161 inline RenderListBox* toRenderListBox(RenderObject* object)
    162 {
    163     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isListBox());
    164     return static_cast<RenderListBox*>(object);
    165 }
    166 
    167 // This will catch anyone doing an unnecessary cast.
    168 void toRenderListBox(const RenderListBox*);
    169 
    170 } // namepace WebCore
    171 
    172 #endif // RenderListBox_h
    173