Changeset 56116 in webkit


Ignore:
Timestamp:
Mar 17, 2010 10:25:06 AM (14 years ago)
Author:
tonikitoo@webkit.org
Message:

Multiselect Popup - SelectElement refactoring. https://bugs.webkit.org/show_bug.cgi?id=36124

Reviewed by Antti Koivisto.

As it is today it is not possible to the menulists popups to tell SelectElement
that more then one option is selected. If you select one the other ones
selected state will turn off.

For <select multiple> I needed to extend the API used by menulist popups. This
is the first step. Just refactoring SelectElement without any behavior change.
Separating code that will be reused in future patches.

  • dom/SelectElement.cpp:

(WebCore::SelectElement::updateSelectedState):
(WebCore::SelectElement::listBoxDefaultEventHandler):

  • dom/SelectElement.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56115 r56116  
     12010-03-16  Luiz Agostini  <luiz.agostini@openbossa.org>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        [Qt] Multiselect Popup - SelectElement refactoring.
     6        https://bugs.webkit.org/show_bug.cgi?id=36124
     7
     8        As it is today it is not possible to the menulists popups to tell SelectElement
     9        that more then one option is selected. If you select one the other ones
     10        selected state will turn off.
     11
     12        For <select multiple> I needed to extend the API used by menulist popups. This
     13        is the first step. Just refactoring SelectElement without any behavior change.
     14        Separating code that will be reused in future patches.
     15
     16        * dom/SelectElement.cpp:
     17        (WebCore::SelectElement::updateSelectedState):
     18        (WebCore::SelectElement::listBoxDefaultEventHandler):
     19        * dom/SelectElement.h:
     20
    1212010-03-17  Nate Chapin  <japhet@chromium.org>
    222
  • trunk/WebCore/dom/SelectElement.cpp

    r56041 r56116  
    648648}
    649649
     650void SelectElement::updateSelectedState(SelectElementData& data, Element* element, int listIndex,
     651                                        bool multi, bool shift)
     652{
     653    ASSERT(listIndex >= 0);
     654
     655    // Save the selection so it can be compared to the new selection when dispatching change events during mouseup, or after autoscroll finishes.
     656    saveLastSelection(data, element);
     657
     658    data.setActiveSelectionState(true);
     659
     660    bool shiftSelect = data.multiple() && shift;
     661    bool multiSelect = data.multiple() && multi && !shift;
     662
     663    Element* clickedElement = data.listItems(element)[listIndex];
     664    OptionElement* option = toOptionElement(clickedElement);
     665    if (option) {
     666        // Keep track of whether an active selection (like during drag selection), should select or deselect
     667        if (option->selected() && multi)
     668            data.setActiveSelectionState(false);
     669
     670        if (!data.activeSelectionState())
     671            option->setSelectedState(false);
     672    }
     673
     674    // If we're not in any special multiple selection mode, then deselect all other items, excluding the clicked option.
     675    // If no option was clicked, then this will deselect all items in the list.
     676    if (!shiftSelect && !multiSelect)
     677        deselectItems(data, element, clickedElement);
     678
     679    // If the anchor hasn't been set, and we're doing a single selection or a shift selection, then initialize the anchor to the first selected index.
     680    if (data.activeSelectionAnchorIndex() < 0 && !multiSelect)
     681        setActiveSelectionAnchorIndex(data, element, selectedIndex(data, element));
     682
     683    // Set the selection state of the clicked option
     684    if (option && !clickedElement->disabled())
     685        option->setSelectedState(true);
     686
     687    // If there was no selectedIndex() for the previous initialization, or
     688    // If we're doing a single selection, or a multiple selection (using cmd or ctrl), then initialize the anchor index to the listIndex that just got clicked.
     689    if (data.activeSelectionAnchorIndex() < 0 || !shiftSelect)
     690        setActiveSelectionAnchorIndex(data, element, listIndex);
     691
     692    setActiveSelectionEndIndex(data, listIndex);
     693    updateListBoxSelection(data, element, !multiSelect);
     694}
     695
    650696void SelectElement::listBoxDefaultEventHandler(SelectElementData& data, Element* element, Event* event, HTMLFormElement* htmlForm)
    651697{
     
    660706        int listIndex = toRenderListBox(element->renderer())->listIndexAtOffset(localOffset.x(), localOffset.y());
    661707        if (listIndex >= 0) {
    662             // Save the selection so it can be compared to the new selection when dispatching change events during mouseup, or after autoscroll finishes.
    663             saveLastSelection(data, element);
    664 
    665             data.setActiveSelectionState(true);
    666            
    667             bool multiSelectKeyPressed = false;
    668708#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN))
    669             multiSelectKeyPressed = mouseEvent->metaKey();
     709            updateSelectedState(data, element, listIndex, mouseEvent->metaKey(), mouseEvent->shiftKey());
    670710#else
    671             multiSelectKeyPressed = mouseEvent->ctrlKey();
     711            updateSelectedState(data, element, listIndex, mouseEvent->ctrlKey(), mouseEvent->shiftKey());
    672712#endif
    673 
    674             bool shiftSelect = data.multiple() && mouseEvent->shiftKey();
    675             bool multiSelect = data.multiple() && multiSelectKeyPressed && !mouseEvent->shiftKey();
    676 
    677             Element* clickedElement = listItems[listIndex];           
    678             OptionElement* option = toOptionElement(clickedElement);
    679             if (option) {
    680                 // Keep track of whether an active selection (like during drag selection), should select or deselect
    681                 if (option->selected() && multiSelectKeyPressed)
    682                     data.setActiveSelectionState(false);
    683 
    684                 if (!data.activeSelectionState())
    685                     option->setSelectedState(false);
    686             }
    687            
    688             // If we're not in any special multiple selection mode, then deselect all other items, excluding the clicked option.
    689             // If no option was clicked, then this will deselect all items in the list.
    690             if (!shiftSelect && !multiSelect)
    691                 deselectItems(data, element, clickedElement);
    692 
    693             // If the anchor hasn't been set, and we're doing a single selection or a shift selection, then initialize the anchor to the first selected index.
    694             if (data.activeSelectionAnchorIndex() < 0 && !multiSelect)
    695                 setActiveSelectionAnchorIndex(data, element, selectedIndex(data, element));
    696 
    697             // Set the selection state of the clicked option
    698             if (option && !clickedElement->disabled())
    699                 option->setSelectedState(true);
    700            
    701             // If there was no selectedIndex() for the previous initialization, or
    702             // If we're doing a single selection, or a multiple selection (using cmd or ctrl), then initialize the anchor index to the listIndex that just got clicked.
    703             if (listIndex >= 0 && (data.activeSelectionAnchorIndex() < 0 || !shiftSelect))
    704                 setActiveSelectionAnchorIndex(data, element, listIndex);
    705            
    706             setActiveSelectionEndIndex(data, listIndex);
    707             updateListBoxSelection(data, element, !multiSelect);
    708 
    709713            if (Frame* frame = element->document()->frame())
    710714                frame->eventHandler()->setMouseDownMayStartAutoscroll();
  • trunk/WebCore/dom/SelectElement.h

    r53761 r56116  
    9696    static void accessKeySetSelectedIndex(SelectElementData&, Element*, int index);
    9797    static unsigned optionCount(const SelectElementData&, const Element*);
     98
     99    static void updateSelectedState(SelectElementData& data, Element* element, int listIndex,
     100                                    bool multi, bool shift);
    98101 
    99102private:
Note: See TracChangeset for help on using the changeset viewer.