Bug 1272012 - Support more keys to open and/or toggle a combobox dropdown menu. r=enndeakin
☠☠ backed out by dd37cbc7e543 ☠ ☠
authorMats Palmgren <mats@mozilla.com>
Wed, 25 May 2016 10:48:52 +0200
changeset 337917 8c804afcc86515350c902374a2fb3f62d9a45eac
parent 337916 1e79a41fdac1117b6b3f8f3834c9b9c2cf9bf881
child 337918 467b0d255265f75f321f2b45e92495a902f20b5e
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs1272012
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1272012 - Support more keys to open and/or toggle a combobox dropdown menu. r=enndeakin Up/Down should open the dropdown menu on OSX, but not close it. Spacebar should toggle the dropdown on OSX, but only if Alt, Ctrl or Cmd isn't pressed. Spacebar should open the dropdown on non-OSX platforms, but not close it, with or without key modifiers.
layout/forms/nsListControlFrame.cpp
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -2103,20 +2103,35 @@ nsListControlFrame::KeyDown(nsIDOMEvent*
   // XXXmats keyboard events, even tabbing, when preventDefault() is called
   // XXXmats in onkeydown. That seems sub-optimal though.
 
   const WidgetKeyboardEvent* keyEvent =
     aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
   MOZ_ASSERT(keyEvent,
     "DOM event must have WidgetKeyboardEvent for its internal event");
 
+  bool dropDownMenuOnUpDown;
+  bool dropDownMenuOnSpace;
+#ifdef XP_MACOSX
+  dropDownMenuOnUpDown = IsInDropDownMode() && !mComboboxFrame->IsDroppedDown();
+  dropDownMenuOnSpace = !keyEvent->IsAlt() && !keyEvent->IsControl() &&
+    !keyEvent->IsMeta();
+#else
+  dropDownMenuOnUpDown = keyEvent->IsAlt();
+  dropDownMenuOnSpace = IsInDropDownMode() && !mComboboxFrame->IsDroppedDown();
+#endif
+  if ((dropDownMenuOnUpDown &&
+       (keyEvent->mKeyCode == NS_VK_UP || keyEvent->mKeyCode == NS_VK_DOWN)) ||
+      (dropDownMenuOnSpace && keyEvent->mKeyCode == NS_VK_SPACE)) {
+    DropDownToggleKey(aKeyEvent);
+    if (keyEvent->DefaultPrevented()) {
+      return NS_OK;
+    }
+  }
   if (keyEvent->IsAlt()) {
-    if (keyEvent->mKeyCode == NS_VK_UP || keyEvent->mKeyCode == NS_VK_DOWN) {
-      DropDownToggleKey(aKeyEvent);
-    }
     return NS_OK;
   }
 
   // now make sure there are options or we are wasting our time
   RefPtr<dom::HTMLOptionsCollection> options = GetOptions();
   NS_ENSURE_TRUE(options, NS_ERROR_FAILURE);
 
   uint32_t numOptions = options->Length();