Changeset 21045 in webkit


Ignore:
Timestamp:
Apr 23, 2007 2:15:48 PM (17 years ago)
Author:
adele
Message:

LayoutTests:

Reviewed by Hyatt & Adam.

Tests for <rdar://problem/4807799> REGRESSION: calling select() in onSearch handler doesn't work if you hit enter to trigger the event

  • fast/events/onchange-passwordfield-expected.txt:
  • fast/events/onchange-passwordfield.html:
  • fast/events/onchange-searchfield-expected.txt:
  • fast/events/onchange-searchfield.html:
  • fast/events/onchange-select-popup-expected.txt: Added.
  • fast/events/onchange-select-popup.html: Added.
  • fast/events/onchange-textfield-expected.txt:
  • fast/events/onchange-textfield.html:
  • fast/forms/onchange-enter-submit-expected.txt:

WebCore:

Reviewed by Hyatt & Adam.

Fix for <rdar://problem/4807799> REGRESSION: calling select() in onSearch handler doesn't work if you hit enter to trigger the event
Fix for <rdar://problem/5153970> onChange doesn't fire when focusing a popup, using type-ahead to select, and leaving

This previous behavior to blur controls when hitting enter was added to achieve the result of firing the change event. Firefox does not
fire blur- just the change event, so this fix will match Firefox behavior.

This also fixes a bug where we didn't fire the change event when using type-ahead selection with the popup menu.

  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::defaultEventHandler): Fire change event instead of blur event when hitting enter.
  • html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::dispatchFocusEvent): Now that we have type-ahead selection for popups that can be opened with the arrow keys, we should always save the last selection when a popup gets focus, so it can be compared to the current selection when it loses focus. (WebCore::HTMLSelectElement::dispatchBlurEvent): For the same reasons as above, we should fire onChange for all popups on blur.

(WebCore::HTMLSelectElement::menuListDefaultEventHandler): Fire change event instead of blur event when hitting enter. Removed an unnecessary

check for form() before calling menuListOnChange(). Removed an unnecessary check for renderer() and usesMenuList().

(WebCore::HTMLSelectElement::listBoxDefaultEventHandler): Remove call to blur. Since list boxes fire the change event immediately after an

action is taken, we don't need to fire anything after hitting enter.

(WebCore::HTMLSelectElement::menuListOnChange): Reset m_lastOnChangeIndex after firing the change event.

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r21027 r21045  
     12007-04-23  Adele Peterson  <adele@apple.com>
     2
     3        Reviewed by Hyatt & Adam.
     4
     5        Tests for <rdar://problem/4807799> REGRESSION: calling select() in onSearch handler doesn't work if you hit enter to trigger the event
     6
     7        * fast/events/onchange-passwordfield-expected.txt:
     8        * fast/events/onchange-passwordfield.html:
     9        * fast/events/onchange-searchfield-expected.txt:
     10        * fast/events/onchange-searchfield.html:
     11        * fast/events/onchange-select-popup-expected.txt: Added.
     12        * fast/events/onchange-select-popup.html: Added.
     13        * fast/events/onchange-textfield-expected.txt:
     14        * fast/events/onchange-textfield.html:
     15        * fast/forms/onchange-enter-submit-expected.txt:
     16
    1172007-04-23  Darin Adler  <darin@apple.com>
    218
  • trunk/LayoutTests/fast/events/onchange-passwordfield-expected.txt

    r18073 r21045  
    1 This test verifies that the ENTER key fires the change and then the blur event.
     1This test verifies that the ENTER key fires the change event.
    22
    33
    44PASS: change event fired.
    55
    6 PASS: blur event fired.
    76
    8 PASS: blur event fired last.
    9 
    10 
  • trunk/LayoutTests/fast/events/onchange-passwordfield.html

    r18073 r21045  
    1 <p>This test verifies that the ENTER key fires the change and then the blur event.</p>
     1<p>This test verifies that the ENTER key fires the change event.</p>
    22<hr>
    33<input id="input" type="password" onchange="changeHandler()" onblur="blurHandler()"></input>
     
    1212function changeHandler()
    1313{
    14     lastEvent = "change";
    1514    log ('PASS: change event fired.\n');
    1615}
     
    1817function blurHandler()
    1918{
    20     lastEvent = "blur";
    21     log ('PASS: blur event fired.\n');
     19    log ('blur event fired.\n');
    2220}
    2321
     
    3432input.dispatchEvent(enterEvent);
    3533
    36 // test that blur happened last
    37 if (lastEvent == "blur")
    38     log('PASS: blur event fired last.\n');
    3934</script>
  • trunk/LayoutTests/fast/events/onchange-searchfield-expected.txt

    r18248 r21045  
    1 This test verifies that the ENTER key fires the change and then the blur event.
     1This test verifies that the ENTER key fires the change event.
    22
    33
    44PASS: change event fired.
    55
    6 PASS: blur event fired.
    76
    8 PASS: blur event fired last.
    9 
    10 
  • trunk/LayoutTests/fast/events/onchange-searchfield.html

    r18073 r21045  
    1 <p>This test verifies that the ENTER key fires the change and then the blur event.</p>
     1<p>This test verifies that the ENTER key fires the change event.</p>
    22<hr>
    33<input id="input" type="search" onchange="changeHandler()" onblur="blurHandler()"></input>
     
    1212function changeHandler()
    1313{
    14     window.lastEvent = "change";
    1514    log ('PASS: change event fired.\n');
    1615}
     
    1817function blurHandler()
    1918{
    20     window.lastEvent = "blur";
    21     log ('PASS: blur event fired.\n');
     19    log ('blur event fired.\n');
    2220}
    2321
     
    2725// change the field
    2826document.getElementById('input').focus();
    29 document.execCommand("InsertText", false, "foo bar baz"); // Won't work until searchfield becomes a non-AppKit control
     27document.execCommand("InsertText", false, "foo bar baz");
    3028
    3129// hit enter
     
    3432input.dispatchEvent(enterEvent);
    3533
    36 // test that blur happened last
    37 if (window.lastEvent == "blur")
    38     log('PASS: blur event fired last.\n');
    3934</script>
  • trunk/LayoutTests/fast/events/onchange-textfield-expected.txt

    r18073 r21045  
    1 This test verifies that the ENTER key fires the change and then the blur event.
     1This test verifies that the ENTER key fires the change event.
    22
    33
    44PASS: change event fired.
    55
    6 PASS: blur event fired.
    76
    8 PASS: blur event fired last.
    9 
    10 
  • trunk/LayoutTests/fast/events/onchange-textfield.html

    r18073 r21045  
    1 <p>This test verifies that the ENTER key fires the change and then the blur event.</p>
     1<p>This test verifies that the ENTER key fires the change event.</p>
    22<hr>
    33<input id="input" type="text" onchange="changeHandler()" onblur="blurHandler()"></input>
     
    1212function changeHandler()
    1313{
    14     window.lastEvent = "change";
    1514    log ('PASS: change event fired.\n');
    1615}
     
    1817function blurHandler()
    1918{
    20     window.lastEvent = "blur";
    21     log ('PASS: blur event fired.\n');
     19    log ('blur event fired.\n');
    2220}
    2321
     
    3432input.dispatchEvent(enterEvent);
    3533
    36 // test that blur happened last
    37 if (window.lastEvent == "blur")
    38     log('PASS: blur event fired last.\n');
    3934</script>
  • trunk/LayoutTests/fast/forms/onchange-enter-submit-expected.txt

    r17562 r21045  
    22
    33text onchange
    4 text onblur
    54on submit
    65
  • trunk/WebCore/ChangeLog

    r21042 r21045  
     12007-04-23  Adele Peterson  <adele@apple.com>
     2
     3        Reviewed by Hyatt & Adam.
     4
     5        Fix for <rdar://problem/4807799> REGRESSION: calling select() in onSearch handler doesn't work if you hit enter to trigger the event
     6        Fix for <rdar://problem/5153970> onChange doesn't fire when focusing a popup, using type-ahead to select, and leaving
     7
     8        This previous behavior to blur controls when hitting enter was added to achieve the result of firing the change event.  Firefox does not
     9        fire blur- just the change event, so this fix will match Firefox behavior.
     10
     11        This also fixes a bug where we didn't fire the change event when using type-ahead selection with the popup menu.
     12
     13        * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::defaultEventHandler): Fire change event instead of blur event when hitting enter.
     14
     15        * html/HTMLSelectElement.cpp:
     16        (WebCore::HTMLSelectElement::dispatchFocusEvent): Now that we have type-ahead selection for popups that can be opened with the arrow keys,
     17         we should always save the last selection when a popup gets focus, so it can be compared to the current selection when it loses focus.
     18        (WebCore::HTMLSelectElement::dispatchBlurEvent): For the same reasons as above, we should fire onChange for all popups on blur.
     19
     20        (WebCore::HTMLSelectElement::menuListDefaultEventHandler): Fire change event instead of blur event when hitting enter.  Removed an unnecessary
     21         check for form() before calling menuListOnChange().  Removed an unnecessary check for renderer() and usesMenuList().
     22        (WebCore::HTMLSelectElement::listBoxDefaultEventHandler): Remove call to blur.  Since list boxes fire the change event immediately after an
     23         action is taken, we don't need to fire anything after hitting enter.
     24        (WebCore::HTMLSelectElement::menuListOnChange): Reset m_lastOnChangeIndex after firing the change event.
     25
    1262007-04-23  Anders Carlsson  <andersca@apple.com>
    227
  • trunk/WebCore/html/HTMLInputElement.cpp

    r21010 r21045  
    12821282            onSearch();
    12831283        }
    1284         blur();
    1285         // Form may never have been present, or may have been destroyed by the blur event.
     1284        // Fire onChange for text fields.
     1285        RenderObject* r = renderer();
     1286        if (r && r->isTextField() && r->isEdited()) {
     1287            onChange();
     1288            r->setEdited(false);
     1289        }
     1290        // Form may never have been present, or may have been destroyed by the change event.
    12861291        if (form())
    12871292            form()->submitClick(evt);
  • trunk/WebCore/html/HTMLSelectElement.cpp

    r20724 r21045  
    576576void HTMLSelectElement::dispatchFocusEvent()
    577577{
    578 #if !ARROW_KEYS_POP_MENU
    579578    if (usesMenuList())
    580579        // Save the selection so it can be compared to the new selection when we call onChange during dispatchBlurEvent.
    581580        saveLastSelection();
    582 #endif
    583581    HTMLGenericFormElement::dispatchFocusEvent();
    584582}
     
    586584void HTMLSelectElement::dispatchBlurEvent()
    587585{
    588 #if !ARROW_KEYS_POP_MENU
    589586    // We only need to fire onChange here for menu lists, because we fire onChange for list boxes whenever the selection change is actually made.
    590587    // This matches other browsers' behavior.
    591588    if (usesMenuList())
    592589        menuListOnChange();
    593 #endif
    594590    HTMLGenericFormElement::dispatchBlurEvent();
    595591}
     
    631627        bool handled = false;
    632628#if ARROW_KEYS_POP_MENU
    633         if (form() && keyIdentifier == "Enter") {
    634             blur();
    635             // Make sure the form hasn't been destroyed during the blur.
     629        if (keyIdentifier == "Enter") {
     630            menuListOnChange();
    636631            if (form())
    637632                form()->submitClick(evt);
    638633            handled = true;
    639634        }
    640         if ((keyIdentifier == "Down" || keyIdentifier == "Up" || keyIdentifier == "U+000020") && renderer() && usesMenuList()) {
     635        if (keyIdentifier == "Down" || keyIdentifier == "Up" || keyIdentifier == "U+000020") {
    641636            focus();
    642637            // Save the selection so it can be compared to the new selection when we call onChange during setSelectedIndex,
     
    763758        String keyIdentifier = static_cast<KeyboardEvent*>(evt)->keyIdentifier();
    764759
    765         if (form() && keyIdentifier == "Enter") {
    766             blur();
    767             // Make sure the form hasn't been destroyed during the blur.
     760        if (keyIdentifier == "Enter") {
    768761            if (form())
    769762                form()->submitClick(evt);
     
    858851{
    859852    ASSERT(usesMenuList());
    860     if (m_lastOnChangeIndex != selectedIndex())
     853    int selected = selectedIndex();
     854    if (m_lastOnChangeIndex != selected) {
    861855        onChange();
     856        m_lastOnChangeIndex = selected;
     857    }
    862858}
    863859
Note: See TracChangeset for help on using the changeset viewer.