Bug 1114011 - for autocomplete with for minresultsforpopup > 1: entering match doesn't work properly. r=mak
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sat, 10 Jan 2015 13:48:24 +0200
changeset 223182 305c554e799427e6161709c07035737e4007e363
parent 223181 6ff9b0e3a59789fad59cb9fc1d9bb1748117c3af
child 223183 2ea97247b91ac2930e23e1d55b864c54950d288f
push id10769
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 14:15:52 +0000
treeherderfx-team@0e9765732906 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1114011
milestone37.0a1
Bug 1114011 - for autocomplete with for minresultsforpopup > 1: entering match doesn't work properly. r=mak
toolkit/components/autocomplete/nsAutoCompleteController.cpp
toolkit/content/tests/chrome/test_autocomplete4.xul
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -479,17 +479,23 @@ nsAutoCompleteController::HandleKeyNavig
 #ifndef XP_MACOSX
              || aKey == nsIDOMKeyEvent::DOM_VK_HOME
 #endif
             )
   {
     // The user hit a text-navigation key.
     bool isOpen = false;
     input->GetPopupOpen(&isOpen);
-    if (isOpen) {
+
+    // If minresultsforpopup > 1 and there's less matches than the minimum
+    // required, the popup is not open, but the search suggestion is showing
+    // inline, so we should proceed as if we had the popup.
+    uint32_t minResultsForPopup;
+    input->GetMinResultsForPopup(&minResultsForPopup);
+    if (isOpen || (mRowCount > 0 && mRowCount < minResultsForPopup)) {
       int32_t selectedIndex;
       popup->GetSelectedIndex(&selectedIndex);
       bool shouldComplete;
       input->GetCompleteDefaultIndex(&shouldComplete);
       if (selectedIndex >= 0) {
         // The pop-up is open and has a selection, take its value
         nsAutoString value;
         if (NS_SUCCEEDED(GetResultValueAt(selectedIndex, false, value))) {
--- a/toolkit/content/tests/chrome/test_autocomplete4.xul
+++ b/toolkit/content/tests/chrome/test_autocomplete4.xul
@@ -154,16 +154,24 @@ const tests = [
 
   { desc: "RIGHT key complete from middle",
     key: "VK_RIGHT",
     forceComplete: true,
     completeFromMiddle: true,
     result: "Result",
     start: 6, end: 6
   },
+  {
+    desc: "RIGHT key w/ minResultsForPopup=2",
+    key: "VK_RIGHT",
+    removeSelection: false,
+    minResultsForPopup: 2,
+    result: "Result",
+    start: 6, end: 6
+  },
 ];
 
 function nextTest() {
   if (!tests.length) {
     // No more tests to run, finish.
     setTimeout(function() {
       // Unregister the factory so that we don't get in the way of other tests
       componentManager.unregisterFactory(autoCompleteSimpleID, autoCompleteSimple);
@@ -180,16 +188,21 @@ function nextTest() {
   if (currentTest.key == "VK_HOME" && navigator.platform.indexOf("Mac") != -1)
     nextTest();
   else
     setTimeout(runCurrentTest, 0);
 }
 
 function runCurrentTest() {
   var autocomplete = $("autocomplete");
+  if ("minResultsForPopup" in currentTest)
+    autocomplete.setAttribute("minresultsforpopup", currentTest.minResultsForPopup)
+  else
+    autocomplete.removeAttribute("minresultsforpopup");
+
   autocomplete.focus();
 
   if (!currentTest.completeFromMiddle) {
     synthesizeKey("r", {});
     synthesizeKey("e", {});
   }
   else {
     synthesizeKey("l", {});