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 "RenderBlock.h"
     35 #include "ScrollableArea.h"
     36 
     37 namespace WebCore {
     38 
     39 class RenderListBox : public RenderBlock, private ScrollableArea {
     40 public:
     41     RenderListBox(Element*);
     42     virtual ~RenderListBox();
     43 
     44     void selectionChanged();
     45 
     46     void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
     47 
     48     int listIndexAtOffset(int x, int y);
     49     IntRect itemBoundingBoxRect(int tx, int ty, int index);
     50 
     51     bool scrollToRevealElementAtListIndex(int index);
     52     bool listIndexIsVisible(int index);
     53 
     54     int scrollToward(const IntPoint&); // Returns the new index or -1 if no scroll occurred
     55 
     56     int size() const;
     57 
     58 private:
     59     virtual const char* renderName() const { return "RenderListBox"; }
     60 
     61     virtual bool isListBox() const { return true; }
     62 
     63     virtual void updateFromElement();
     64 
     65     virtual bool canHaveChildren() const { return false; }
     66 
     67     virtual bool hasControlClip() const { return true; }
     68     virtual void paintObject(PaintInfo&, int tx, int ty);
     69     virtual IntRect controlClipRect(int tx, int ty) const;
     70 
     71     virtual bool isPointInOverflowControl(HitTestResult&, int x, int y, int tx, int ty);
     72 
     73     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
     74     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
     75 
     76     virtual void computePreferredLogicalWidths();
     77     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
     78     virtual void computeLogicalHeight();
     79 
     80     virtual void layout();
     81 
     82     virtual void addFocusRingRects(Vector<IntRect>&, int tx, int ty);
     83 
     84     virtual bool canBeProgramaticallyScrolled(bool) const { return true; }
     85     virtual void autoscroll();
     86     virtual void stopAutoscroll();
     87 
     88     virtual bool shouldPanScroll() const { return true; }
     89     virtual void panScroll(const IntPoint&);
     90 
     91     virtual int verticalScrollbarWidth() const;
     92     virtual int scrollLeft() const;
     93     virtual int scrollTop() const;
     94     virtual int scrollWidth() const;
     95     virtual int scrollHeight() const;
     96     virtual void setScrollLeft(int);
     97     virtual void setScrollTop(int);
     98 
     99     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
    100 
    101     // ScrollableArea interface.
    102     virtual int scrollSize(ScrollbarOrientation orientation) const;
    103     virtual int scrollPosition(Scrollbar*) const;
    104     virtual void setScrollOffset(const IntPoint&);
    105     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
    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 IntRect scrollCornerRect() const { return IntRect(); }
    109     virtual void invalidateScrollCornerRect(const IntRect&) { }
    110     virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const;
    111     virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const;
    112     virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const;
    113     virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const;
    114     virtual Scrollbar* verticalScrollbar() const { return m_vBar.get(); }
    115     virtual IntSize contentsSize() const;
    116     virtual int visibleHeight() const;
    117     virtual int visibleWidth() const;
    118     virtual IntPoint currentMousePosition() const;
    119     virtual bool shouldSuspendScrollAnimations() const;
    120 
    121     virtual void disconnectFromPage() { m_page = 0; }
    122 
    123     // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
    124     void scrollTo(int newOffset);
    125 
    126     void setHasVerticalScrollbar(bool hasScrollbar);
    127     PassRefPtr<Scrollbar> createScrollbar();
    128     void destroyScrollbar();
    129 
    130     int itemHeight() const;
    131     void valueChanged(unsigned listIndex);
    132     int numVisibleItems() const;
    133     int numItems() const;
    134     int listHeight() const;
    135     void paintScrollbar(PaintInfo&, int tx, int ty);
    136     void paintItemForeground(PaintInfo&, int tx, int ty, int listIndex);
    137     void paintItemBackground(PaintInfo&, int tx, int ty, int listIndex);
    138     void scrollToRevealSelection();
    139 
    140     bool m_optionsChanged;
    141     bool m_scrollToRevealSelectionAfterLayout;
    142     bool m_inAutoscroll;
    143     int m_optionsWidth;
    144     int m_indexOffset;
    145 
    146     RefPtr<Scrollbar> m_vBar;
    147 
    148     Page* m_page;
    149 };
    150 
    151 inline RenderListBox* toRenderListBox(RenderObject* object)
    152 {
    153     ASSERT(!object || object->isListBox());
    154     return static_cast<RenderListBox*>(object);
    155 }
    156 
    157 // This will catch anyone doing an unnecessary cast.
    158 void toRenderListBox(const RenderListBox*);
    159 
    160 } // namepace WebCore
    161 
    162 #endif // RenderListBox_h
    163