Changeset 66929 in webkit


Ignore:
Timestamp:
Sep 7, 2010 4:33:59 PM (14 years ago)
Author:
Joseph Pecoraro
Message:

2010-09-03 Joseph Pecoraro <Joseph Pecoraro>

Reviewed by Darin Adler.

Provide a way to trigger a <select multiple> onchange event on changes
https://bugs.webkit.org/show_bug.cgi?id=45192

Test: LayoutTests/platform/mac/fast/objc/dom-html-select-activate.html

This provides a way for a WebKit client using the Obj-C DOM bindings to
trigger the "change" on a listbox select (<select multiple> or <select>
with size > 1). This is because when a select is rendered as a listbox
"change" events are triggered by mouse down events.

This adds -[DOMHTMLSelectElement _activateItemAtIndex:allowMultipleSelection:]
to allow for handling multiple selections if the select element is a
multi-select.

  • bindings/objc/DOMHTML.mm: (-[DOMHTMLSelectElement _activateItemAtIndex:allowMultipleSelection:]):
  • bindings/objc/DOMPrivate.h: unified the Category name. Was "FormsAutocomplete" now all are "FormAutocomplete".
  • dom/SelectElement.h:
  • html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::setSelectedIndexByUser): listboxs need to be treated specially to fire their "change" event.
  • html/HTMLSelectElement.h:
  • wml/WMLSelectElement.cpp: (WebCore::WMLSelectElement::setSelectedIndexByUser):
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r66928 r66929  
     12010-09-03  Joseph Pecoraro  <joepeck@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Provide a way to trigger a <select multiple> onchange event on changes
     6        https://bugs.webkit.org/show_bug.cgi?id=45192
     7
     8        Test: LayoutTests/platform/mac/fast/objc/dom-html-select-activate.html
     9
     10        This provides a way for a WebKit client using the Obj-C DOM bindings to
     11        trigger the "change" on a listbox select (<select multiple> or <select>
     12        with size > 1). This is because when a select is rendered as a listbox
     13        "change" events are triggered by mouse down events.
     14
     15        This adds -[DOMHTMLSelectElement _activateItemAtIndex:allowMultipleSelection:]
     16        to allow for handling multiple selections if the select element is a
     17        multi-select.
     18
     19        * bindings/objc/DOMHTML.mm:
     20        (-[DOMHTMLSelectElement _activateItemAtIndex:allowMultipleSelection:]):
     21        * bindings/objc/DOMPrivate.h: unified the Category name. Was "FormsAutocomplete" now all are "FormAutocomplete".
     22        * dom/SelectElement.h:
     23        * html/HTMLSelectElement.cpp:
     24        (WebCore::HTMLSelectElement::setSelectedIndexByUser): listboxs need to be treated specially to fire their "change" event.
     25        * html/HTMLSelectElement.h:
     26        * wml/WMLSelectElement.cpp:
     27        (WebCore::WMLSelectElement::setSelectedIndexByUser):
     28
    1292010-09-07  Simon Fraser  <simon.fraser@apple.com>
    230
  • trunk/WebCore/bindings/objc/DOMHTML.mm

    r65021 r66929  
    167167}
    168168
     169- (void)_activateItemAtIndex:(int)index allowMultipleSelection:(BOOL)allowMultipleSelection
     170{
     171    // Use the setSelectedIndexByUser function so a change event will be fired. <rdar://problem/6760590>
     172    // If this is a <select multiple> the allowMultipleSelection flag will allow setting multiple
     173    // selections without clearing the other selections.
     174    if (WebCore::HTMLSelectElement* select = core(self))
     175        select->setSelectedIndexByUser(index, true, true, allowMultipleSelection);
     176}
     177
    169178@end
    170179
  • trunk/WebCore/bindings/objc/DOMPrivate.h

    r51850 r66929  
    7070// Each one should eventually be replaced by public DOM API, and when that happens Safari will switch to implementations
    7171// using that public API, and these will be deleted.
    72 @interface DOMHTMLInputElement (FormsAutoFillTransition)
     72@interface DOMHTMLInputElement (FormAutoFillTransition)
    7373- (BOOL)_isAutofilled;
    7474- (BOOL)_isTextField;
     
    9393// replaceable by public DOM API, and when that happens Safari will switch to implementations using that public API,
    9494// and these will be deleted.
    95 @interface DOMHTMLSelectElement (FormsAutoFillTransition)
     95@interface DOMHTMLSelectElement (FormAutoFillTransition)
    9696- (void)_activateItemAtIndex:(int)index;
     97- (void)_activateItemAtIndex:(int)index allowMultipleSelection:(BOOL)allowMultipleSelection;
    9798@end
  • trunk/WebCore/dom/SelectElement.h

    r65021 r66929  
    6060    virtual int selectedIndex() const = 0;
    6161    virtual void setSelectedIndex(int index, bool deselect = true) = 0;
    62     virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false) = 0;
     62    virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false, bool allowMultipleSelection = false) = 0;
    6363
    6464    virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) = 0;
  • trunk/WebCore/html/HTMLSelectElement.cpp

    r65986 r66929  
    8686}
    8787
    88 void HTMLSelectElement::setSelectedIndexByUser(int optionIndex, bool deselect, bool fireOnChangeNow)
    89 {
     88void HTMLSelectElement::setSelectedIndexByUser(int optionIndex, bool deselect, bool fireOnChangeNow, bool allowMultipleSelection)
     89{
     90    // List box selects can fire onchange events through user interaction, such as
     91    // mousedown events. This allows that same behavior programmatically.
     92    if (!m_data.usesMenuList()) {
     93        updateSelectedState(m_data, this, optionIndex, allowMultipleSelection, false);
     94        if (fireOnChangeNow)
     95            listBoxOnChange();
     96        return;
     97    }
     98
    9099    // Bail out if this index is already the selected one, to avoid running unnecessary JavaScript that can mess up
    91100    // autofill, when there is no actual change (see https://bugs.webkit.org/show_bug.cgi?id=35256 and rdar://7467917 ).
  • trunk/WebCore/html/HTMLSelectElement.h

    r65986 r66929  
    4242    virtual int selectedIndex() const;
    4343    virtual void setSelectedIndex(int index, bool deselect = true);
    44     virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false);
     44    virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false, bool allowMultipleSelection = false);
    4545
    4646    unsigned length() const;
  • trunk/WebCore/wml/WMLSelectElement.cpp

    r66498 r66929  
    115115}
    116116
    117 void WMLSelectElement::setSelectedIndexByUser(int optionIndex, bool deselect, bool fireOnChangeNow)
    118 {
     117void WMLSelectElement::setSelectedIndexByUser(int optionIndex, bool deselect, bool fireOnChangeNow, bool allowMultipleSelection)
     118{
     119    UNUSED_PARAM(allowMultipleSelection);
    119120    SelectElement::setSelectedIndex(m_data, this, optionIndex, deselect, fireOnChangeNow, true);
    120121}
Note: See TracChangeset for help on using the changeset viewer.