Bug 1008244 - Don't consume Enter key at keypress event when <select size=1> has focus but its dropdown list is closed. r=smaug, a=sledru
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 16 May 2014 18:45:25 +0900
changeset 192319 ba6d1a086b1a
parent 192318 18d40554e01f
child 192320 4b8b6909705c
push id3567
push userryanvm@gmail.com
push date2014-05-20 15:05 +0000
Treeherderresults
reviewerssmaug, sledru
bugs1008244
milestone30.0
Bug 1008244 - Don't consume Enter key at keypress event when <select size=1> has focus but its dropdown list is closed. r=smaug, a=sledru
layout/forms/nsListControlFrame.cpp
layout/forms/test/test_bug935876.html
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -2130,22 +2130,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", {});