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 2945 6ba832bb0dc0266446f2d8e2ed6e6c7f1b2a968e
parent 2944 3fc28e63d911caf64a00470013ec68c897847684
child 2946 d402e973b4c9cc1aff687376e53cea097fa2e6f1
push id2483
push uservnicolas@mozilla.com
push dateTue, 29 Mar 2011 14:42:43 +0000
reviewersmfinkle
bugs646015
Bug 646015 - Update autocomplete suggestions as you type on device [r=mfinkle]
chrome/content/forms.js
--- a/chrome/content/forms.js
+++ b/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;