Bug 1008244 Don't consume Enter key at keypress event when <select size=1> has focus but its dropdown list is closed r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 16 May 2014 18:45:25 +0900
changeset 183499 e5b1060172bea7860ca6cc040159cadf57d218d8
parent 183498 8475dbade7b3cb2f748e4deada61710325c28001
child 183500 10c6ee2c75240f6f3dfae13f3203c059f39a1a02
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs1008244
milestone32.0a1
Bug 1008244 Don't consume Enter key at keypress event when <select size=1> has focus but its dropdown list is closed r=smaug
layout/forms/nsListControlFrame.cpp
layout/forms/test/test_bug935876.html
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -2126,22 +2126,21 @@ nsListControlFrame::KeyDown(nsIDOMEvent*
     case NS_VK_DOWN:
     case NS_VK_RIGHT:
       AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
                                 static_cast<int32_t>(numOptions),
                                 1, 1);
       break;
     case NS_VK_RETURN:
       if (IsInDropDownMode()) {
-        // If the select element is a dropdown style, Enter key should be
-        // consumed everytime since Enter key may be pressed accidentally after
-        // the dropdown is closed by Enter key press.
-        aKeyEvent->PreventDefault();
+        if (mComboboxFrame->IsDroppedDown()) {
+          // If the select element is a dropdown style, Enter key should be
+          // consumed while the dropdown is open for security.
+          aKeyEvent->PreventDefault();
 
-        if (mComboboxFrame->IsDroppedDown()) {
           nsWeakFrame weakFrame(this);
           ComboboxFinish(mEndSelectionIndex);
           if (!weakFrame.IsAlive()) {
             return NS_OK;
           }
         }
         // XXX This is strange. On other browsers, "change" event is fired
         //     immediately after the selected item is changed rather than
--- a/layout/forms/test/test_bug935876.html
+++ b/layout/forms/test/test_bug935876.html
@@ -316,17 +316,17 @@ function runTests()
     for (var i = 0; i < 2; i++) {
       reset()
       synthesizeKey("VK_HOME", {});
       check(true, "Home key on combobox #" + i);
     }
 
     reset()
     synthesizeKey("VK_RETURN", {});
-    check(true, "Enter key on combobox");
+    check(false, "Enter key on combobox");
 
     reset()
     synthesizeKey("VK_ESCAPE", {});
     check(true, "Esc key on combobox");
 
     if (!kIsWin) {
       reset()
       synthesizeKey("VK_F4", {});