Changeset 40494 in webkit


Ignore:
Timestamp:
Feb 2, 2009 3:07:53 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-02-02 Jay Campan <jcampan@chromium.org>

Reviewed by Eric Seidel.

Clean up PopupMenuChromium a little.
https://bugs.webkit.org/show_bug.cgi?id=23653

No functional changes, only code cleanup, thus no tests.

  • platform/chromium/PopupMenuChromium.cpp: (WebCore::): (WebCore::PopupListBox::PopupListBox): (WebCore::PopupContainer::create): (WebCore::PopupContainer::PopupContainer): (WebCore::PopupContainer::showPopup): (WebCore::PopupListBox::handleKeyEvent): (WebCore::PopupListBox::isSelectableItem): (WebCore::PopupListBox::selectNextRow): (WebCore::PopupListBox::selectPreviousRow): (WebCore::PopupMenu::show):
  • platform/chromium/PopupMenuChromium.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r40493 r40494  
     12009-02-02  Jay Campan  <jcampan@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Clean up PopupMenuChromium a little.
     6        https://bugs.webkit.org/show_bug.cgi?id=23653
     7
     8        No functional changes, only code cleanup, thus no tests.
     9
     10        * platform/chromium/PopupMenuChromium.cpp:
     11        (WebCore::):
     12        (WebCore::PopupListBox::PopupListBox):
     13        (WebCore::PopupContainer::create):
     14        (WebCore::PopupContainer::PopupContainer):
     15        (WebCore::PopupContainer::showPopup):
     16        (WebCore::PopupListBox::handleKeyEvent):
     17        (WebCore::PopupListBox::isSelectableItem):
     18        (WebCore::PopupListBox::selectNextRow):
     19        (WebCore::PopupListBox::selectPreviousRow):
     20        (WebCore::PopupMenu::show):
     21        * platform/chromium/PopupMenuChromium.h:
     22
    1232009-02-02  Anders Carlsson  <andersca@apple.com>
    224
  • trunk/WebCore/platform/chromium/PopupMenuChromium.cpp

    r40269 r40494  
    7070static const TimeStamp kTypeAheadTimeoutMs = 1000;
    7171
     72// The settings used for the drop down menu.
     73// This is the delegate used if none is provided.
     74static const PopupContainerSettings dropDownSettings = {
     75    true, // focusOnShow
     76    true, // setTextOnIndexChange
     77    true, // acceptOnAbandon
     78    false // loopSelectionNavigation
     79};
     80
    7281// This class uses WebCore code to paint and handle events for a drop-down list
    7382// box ("combobox" on Windows).
     
    126135    bool isInterestedInEventForKey(int keyCode);
    127136
    128     // Sets whether the PopupMenuClient should be told to change its text when a
    129     // new item is selected (by using the arrow keys).  Default is true.
    130     void setTextOnIndexChange(bool value) { m_setTextOnIndexChange = value; }
    131 
    132     // Sets whether we should accept the selected index when the popup is
    133     // abandonned.
    134     void setAcceptOnAbandon(bool value) { m_shouldAcceptOnAbandon = value; }
    135 
    136     // Sets whether pressing the down/up arrow when the last/first row is
    137     // selected clears the selection on the first key press and then selects the
    138     // first/last row on the next key press.  If false, the selected row stays
    139     // the last/first row.
    140     void setLoopSelectionNavigation(bool value) { m_loopSelectionNavigation = value; }
    141 
    142137private:
    143138    friend class PopupContainer;
     
    160155    };
    161156
    162     PopupListBox(PopupMenuClient* client)
    163         : m_originalIndex(0)
     157    PopupListBox(PopupMenuClient* client, const PopupContainerSettings& settings)
     158        : m_settings(settings)
     159        , m_originalIndex(0)
    164160        , m_selectedIndex(0)
    165         , m_shouldAcceptOnAbandon(true)
    166161        , m_willAcceptOnAbandon(false)
    167162        , m_visibleRows(0)
     
    169164        , m_repeatingChar(0)
    170165        , m_lastCharTime(0)
    171         , m_setTextOnIndexChange(true)
    172         , m_loopSelectionNavigation(false)
    173166    {
    174167        setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
     
    229222    void selectNextRow();
    230223
     224    // The settings that specify the behavior for this Popup window.
     225    PopupContainerSettings m_settings;
     226
    231227    // This is the index of the item marked as "selected" - i.e. displayed in the widget on the
    232228    // page.
     
    238234    int m_selectedIndex;
    239235
    240     // Whether we should accept the selectedIndex as chosen when the popup is
    241     // "abandoned".  This value is set through its setter and is useful as
    242     // select popup menu and form autofill popup menu have different behaviors.
    243     bool m_shouldAcceptOnAbandon;
    244 
    245236    // True if we should accept the selectedIndex as chosen, even if the popup
    246237    // is "abandoned".  This is used for keyboard navigation, where we want the
    247     // selection to change immediately, and is only used if
    248     // m_shouldAcceptOnAbandon is true.
     238    // selection to change immediately, and is only used if the settings
     239    // acceptOnAbandon field is true.
    249240    bool m_willAcceptOnAbandon;
    250241
     
    278269    // The last time the user hit a key.  Used for typeAheadFind.
    279270    TimeStamp m_lastCharTime;
    280 
    281     bool m_setTextOnIndexChange;
    282 
    283     bool m_loopSelectionNavigation;
    284271};
    285272
     
    317304// static
    318305PassRefPtr<PopupContainer> PopupContainer::create(PopupMenuClient* client,
    319                                                   bool focusOnShow)
    320 {
    321     return adoptRef(new PopupContainer(client, focusOnShow));
    322 }
    323 
    324 PopupContainer::PopupContainer(PopupMenuClient* client, bool focusOnShow)
    325     : m_listBox(new PopupListBox(client)),
    326       m_focusOnShow(focusOnShow)
     306                                                  const PopupContainerSettings& settings)
     307{
     308    return adoptRef(new PopupContainer(client, settings));
     309}
     310
     311PopupContainer::PopupContainer(PopupMenuClient* client, const PopupContainerSettings& settings)
     312    : m_listBox(new PopupListBox(client, settings))
     313    , m_settings(settings)
    327314{
    328315    // FrameViews are created with a refcount of 1 so it needs releasing after we
     
    358345            widgetRect.move(0, -(widgetRect.height() + selectHeight));
    359346
    360         chromeClient->popupOpened(this, widgetRect, m_focusOnShow);
     347        chromeClient->popupOpened(this, widgetRect, m_settings.focusOnShow);
    361348    }
    362349
     
    494481    setFrameRect(popupRect);
    495482    showPopup(v);
    496 }
    497 
    498 void PopupContainer::setTextOnIndexChange(bool value)
    499 {
    500     listBox()->setTextOnIndexChange(value);
    501 }
    502 
    503 void PopupContainer::setAcceptOnAbandon(bool value)
    504 {
    505     listBox()->setAcceptOnAbandon(value);
    506 }
    507 
    508 void PopupContainer::setLoopSelectionNavigation(bool value)
    509 {
    510     listBox()->setLoopSelectionNavigation(value);
    511483}
    512484
     
    659631        // IE).  We change the original index so we revert to that when the
    660632        // popup is closed.
    661         if (m_shouldAcceptOnAbandon)
     633        if (m_settings.acceptOnAbandon)
    662634            m_willAcceptOnAbandon = true;
    663635
    664636        setOriginalIndex(m_selectedIndex);
    665         if (m_setTextOnIndexChange)
     637        if (m_settings.setTextOnIndexChange)
    666638            m_popupClient->setTextFromItem(m_selectedIndex);
    667     } else if (!m_setTextOnIndexChange && event.windowsVirtualKeyCode() == VKEY_TAB) {
     639    } else if (!m_settings.setTextOnIndexChange &&
     640               event.windowsVirtualKeyCode() == VKEY_TAB) {
    668641        // TAB is a special case as it should select the current item if any and
    669642        // advance focus.
     
    960933}
    961934
    962 bool PopupListBox::isSelectableItem(int index) {
     935bool PopupListBox::isSelectableItem(int index)
     936{
    963937    return m_items[index]->type == TypeOption && m_popupClient->itemIsEnabled(index);
    964938}
     
    974948void PopupListBox::selectNextRow()
    975949{
    976     if (!m_loopSelectionNavigation || m_selectedIndex != numItems() - 1) {
     950    if (!m_settings.loopSelectionNavigation || m_selectedIndex != numItems() - 1) {
    977951        adjustSelectedIndex(1);
    978952        return;
     
    985959void PopupListBox::selectPreviousRow()
    986960{
    987     if (!m_loopSelectionNavigation || m_selectedIndex > 0) {
     961    if (!m_settings.loopSelectionNavigation || m_selectedIndex > 0) {
    988962        adjustSelectedIndex(-1);
    989963        return;
     
    11571131void PopupMenu::show(const IntRect& r, FrameView* v, int index)
    11581132{
    1159     p.popup = PopupContainer::create(client(), true);
     1133    p.popup = PopupContainer::create(client(), dropDownSettings);
    11601134    p.popup->show(r, v, index);
    11611135}
  • trunk/WebCore/platform/chromium/PopupMenuChromium.h

    r40269 r40494  
    4545    // FIXME: Our FramelessScrollView classes should probably implement HostWindow!
    4646
    47     // This class holds a PopupListBox (see cpp file).  Its sole purpose is to be
     47    // The PopupContainer class holds a PopupListBox (see cpp file).  Its sole purpose is to be
    4848    // able to draw a border around its child.  All its paint/event handling is
    4949    // just forwarded to the child listBox (with the appropriate transforms).
     
    5353    // key events to it (through handleKeyEvent).
    5454
     55    struct PopupContainerSettings {
     56        // Whether the popup should get the focus when displayed.
     57        bool focusOnShow;
     58
     59        // Whether the PopupMenuClient should be told to change its text when a
     60        // new item is selected by using the arrow keys.
     61        bool setTextOnIndexChange;
     62
     63        // Whether the selection should be accepted when the popup menu is
     64        // closed (through ESC being pressed or the focus going away).
     65        // Note that when TAB is pressed, the selection is always accepted
     66        // regardless of this setting.
     67        bool acceptOnAbandon;
     68
     69        // Whether the we should move the selection to the first/last item when
     70        // the user presses down/up arrow keys and the last/first item is
     71        // selected.
     72        bool loopSelectionNavigation;
     73    };
     74
    5575    class PopupContainer : public FramelessScrollView, public RefCounted<PopupContainer>  {
    5676    public:
    57         static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool focusOnShow);
     77        static PassRefPtr<PopupContainer> create(PopupMenuClient*,
     78                                                 const PopupContainerSettings&);
    5879
    5980        // Whether a key event should be sent to this popup.
     
    85106        void layout();
    86107
    87         // Sets whether the PopupMenuClient should be told to change its text when a
    88         // new item is selected (by using the arrow keys).  Default is true.
    89         void setTextOnIndexChange(bool);
    90 
    91         // Sets whether the selection should be accepted when the popup menu is
    92         // closed (through ESC being pressed or the focus going away).  Default
    93         // is true.  Note that when TAB is pressed, the selection is always
    94         // accepted regardless of this setting.
    95         void setAcceptOnAbandon(bool);
    96 
    97         // Sets whether we should move the selection to the first/last item
    98         // when the user presses down/up arrow keys and the last/first item is
    99         // selected.  Default is false, causing the first/last item to stay
    100         // selected.
    101         void setLoopSelectionNavigation(bool);
    102 
    103108        PopupListBox* listBox() const { return m_listBox.get(); }
    104109
     
    109114        friend class WTF::RefCounted<PopupContainer>;
    110115
    111         PopupContainer(PopupMenuClient*, bool focusOnShow);
     116        PopupContainer(PopupMenuClient*, const PopupContainerSettings&);
    112117        ~PopupContainer();
    113118
     
    117122        RefPtr<PopupListBox> m_listBox;
    118123
    119         // Whether the window showing this popup should be focused when shown.
    120         bool m_focusOnShow;
     124        PopupContainerSettings m_settings;
    121125    };
    122126
Note: See TracChangeset for help on using the changeset viewer.