Changeset 19008 in webkit


Ignore:
Timestamp:
Jan 21, 2007 8:20:07 AM (17 years ago)
Author:
darin
Message:

Reviewed by Adam and Mitz.

Covered by existing test: fast/forms/listbox-selection.html

  • rendering/RenderListBox.h: Added override of layout(), made selectionChanged() no longer an inline. Added private scrollToRevealSelection(), m_scrollToRevealSelectionAfterLayout, and m_inAutoscroll.
  • rendering/RenderListBox.cpp: (WebCore::RenderListBox::RenderListBox): Initialize new data members. (WebCore::RenderListBox::updateFromElement): Remove scrolling code. (WebCore::RenderListBox::selectionChanged): Moved from header. Calls repaint and then scrollToRevealSelection, but if we need layout, instead schedules scrollToRevealSelection to be done after layout. (WebCore::RenderListBox::layout): Added. After calling base class, calls scrollToRevealSelection if the m_scrollToRevealSelectionAfterLayout is set. (WebCore::RenderListBox::scrollToRevealSelection): Added. Code was originally in updateFromElement. (WebCore::RenderListBox::autoscroll): Set m_inAutoscroll so that the selectionChanged function knows not to scroll. Also removed the repaint() here because updateListBoxSelection() takes care of repainting by calling selectionChanged().
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r19007 r19008  
     12007-01-21  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Adam and Mitz.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=12347
     6          REGRESSION: list box scrolling broken (fast/forms/listbox-selection.html)
     7
     8        Covered by existing test: fast/forms/listbox-selection.html
     9
     10        * rendering/RenderListBox.h: Added override of layout(), made selectionChanged()
     11        no longer an inline. Added private scrollToRevealSelection(),
     12        m_scrollToRevealSelectionAfterLayout, and m_inAutoscroll.
     13        * rendering/RenderListBox.cpp:
     14        (WebCore::RenderListBox::RenderListBox): Initialize new data members.
     15        (WebCore::RenderListBox::updateFromElement): Remove scrolling code.
     16        (WebCore::RenderListBox::selectionChanged): Moved from header. Calls repaint
     17        and then scrollToRevealSelection, but if we need layout, instead schedules
     18        scrollToRevealSelection to be done after layout.
     19        (WebCore::RenderListBox::layout): Added. After calling base class, calls
     20        scrollToRevealSelection if the m_scrollToRevealSelectionAfterLayout is set.
     21        (WebCore::RenderListBox::scrollToRevealSelection): Added. Code was originally
     22        in updateFromElement.
     23        (WebCore::RenderListBox::autoscroll): Set m_inAutoscroll so that the
     24        selectionChanged function knows not to scroll. Also removed the repaint()
     25        here because updateListBoxSelection() takes care of repainting by calling
     26        selectionChanged().
     27
    1282007-01-21  David Kilzer  <ddkilzer@webkit.org>
    2 
    3         Reviewed by NOBODY (no-svg build fix).
    429
    530        * page/EventHandler.cpp:
  • trunk/WebCore/rendering/RenderListBox.cpp

    r18989 r19008  
    7070    : RenderBlock(element)
    7171    , m_optionsChanged(true)
     72    , m_scrollToRevealSelectionAfterLayout(false)
     73    , m_inAutoscroll(false)
    7274    , m_optionsWidth(0)
    7375    , m_indexOffset(0)
     
    9092void RenderListBox::updateFromElement()
    9193{
    92     HTMLSelectElement* select = static_cast<HTMLSelectElement*>(node());
    93 
    9494    if (m_optionsChanged) {
    95         const Vector<HTMLElement*>& listItems = select->listItems();
     95        const Vector<HTMLElement*>& listItems = static_cast<HTMLSelectElement*>(node())->listItems();
    9696        int size = numItems();
    9797       
     
    121121        setNeedsLayoutAndMinMaxRecalc();
    122122    }
    123    
     123}
     124
     125void RenderListBox::selectionChanged()
     126{
     127    repaint();
     128    if (!m_inAutoscroll) {
     129        if (needsLayout())
     130            m_scrollToRevealSelectionAfterLayout = true;
     131        else
     132            scrollToRevealSelection();
     133    }
     134}
     135
     136void RenderListBox::layout()
     137{
     138    RenderBlock::layout();
     139    if (m_scrollToRevealSelectionAfterLayout)
     140        scrollToRevealSelection();
     141}
     142
     143void RenderListBox::scrollToRevealSelection()
     144{   
     145    HTMLSelectElement* select = static_cast<HTMLSelectElement*>(node());
     146
     147    m_scrollToRevealSelectionAfterLayout = false;
     148
    124149    int firstIndex = select->optionToListIndex(select->selectedIndex());
    125     int lastIndex = select->lastSelectedListIndex();
    126     if (firstIndex >= 0 && !listIndexIsVisible(firstIndex) && !listIndexIsVisible(lastIndex))
     150    if (firstIndex >= 0 && !listIndexIsVisible(select->lastSelectedListIndex()))
    127151        scrollToRevealElementAtListIndex(firstIndex);
    128152}
     
    378402        endIndex = listIndexAtOffset(offsetX, offsetY);
    379403
    380     HTMLSelectElement* select = static_cast<HTMLSelectElement*>(node());
    381     if (endIndex >= 0 && select) {
     404    if (endIndex >= 0) {
     405        HTMLSelectElement* select = static_cast<HTMLSelectElement*>(node());
     406        m_inAutoscroll = true;
    382407        if (!select->multiple())
    383408            select->setActiveSelectionAnchorIndex(endIndex);
    384409        select->setActiveSelectionEndIndex(endIndex);
    385410        select->updateListBoxSelection(!select->multiple());
    386         repaint();
     411        m_inAutoscroll = false;
    387412    }
    388413}
     
    394419
    395420bool RenderListBox::scrollToRevealElementAtListIndex(int index)
    396 {   
     421{
    397422    if (index < 0 || index >= numItems() || listIndexIsVisible(index))
    398423        return false;
  • trunk/WebCore/rendering/RenderListBox.h

    r18989 r19008  
    6565    virtual void calcHeight();
    6666
    67     void selectionChanged() { repaint(); }
     67    virtual void layout();
     68
     69    void selectionChanged();
    6870
    6971    void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
     
    101103    void paintItemBackground(PaintInfo&, int tx, int ty, int listIndex);
    102104    bool listIndexIsVisible(int index);
     105    void scrollToRevealSelection();
    103106
    104107    bool m_optionsChanged;
     108    bool m_scrollToRevealSelectionAfterLayout;
     109    bool m_inAutoscroll;
    105110    int m_optionsWidth;
    106111    int m_indexOffset;
Note: See TracChangeset for help on using the changeset viewer.