Bug 646015 - Update autocomplete suggestions as you type on device [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Tue, 29 Mar 2011 16:40:33 +0200
changeset 67546 cb0925ae3475ec1e4c0a8d148a92790e932ea778
parent 67545 78e3c2a604fbe103e64ea973521050112bc1af5a
child 67547 aa6cf17c25db149874b7508c88a0e5b3d157bf9e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs646015
Bug 646015 - Update autocomplete suggestions as you type on device [r=mfinkle]
mobile/chrome/content/forms.js
--- a/mobile/chrome/content/forms.js
+++ b/mobile/chrome/content/forms.js
@@ -64,16 +64,21 @@ function FormAssistant() {
   addMessageListener("FormAssist:Closed", this);
   addMessageListener("FormAssist:Previous", this);
   addMessageListener("FormAssist:Next", this);
   addMessageListener("FormAssist:ChoiceSelect", this);
   addMessageListener("FormAssist:ChoiceChange", this);
   addMessageListener("FormAssist:AutoComplete", this);
   addMessageListener("Content:SetWindowSize", this);
 
+  /* Listen text events in order to update the autocomplete suggestions as soon
+   * a key is entered on device
+   */
+  addEventListener("text", this, false);
+
   addEventListener("keypress", this, true);
   addEventListener("keyup", this, false);
   addEventListener("focus", this, true);
   addEventListener("pageshow", this, false);
   addEventListener("pagehide", this, false);
 
   this._enabled = Services.prefs.getBoolPref("formhelper.enabled");
 };
@@ -326,16 +331,21 @@ FormAssistant.prototype = {
           return;
         }
 
         let focusedIndex = this._getIndexForElement(focusedElement);
         if (focusedIndex != -1 && this.currentIndex != focusedIndex)
           this.currentIndex = focusedIndex;
         break;
 
+      case "text":
+        if (this._isAutocomplete(aEvent.target))
+          sendAsyncMessage("FormAssist:AutoComplete", this._getJSON());
+        break;
+
       // key processing inside a select element are done during the keypress
       // handler, preventing this one to be fired cancel the selection change
       case "keypress":
         // There is no need to handle keys if there is not element currently
         // used by the form assistant
         if (!currentElement)
           return;