Bug 579866 - [regression] Form fill interferes with custom input autocomplete arrow keys [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Mon, 19 Jul 2010 16:52:48 +0200
changeset 66373 fa60222212c217dc50574147bb2dbfed1a6b8028
parent 66372 0a43dfa18cd55e973454dd7b1bd5c2cbb424846f
child 66374 55afccb72da44f867664e6a30001e9aa6da9fe89
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
bugs579866
Bug 579866 - [regression] Form fill interferes with custom input autocomplete arrow keys [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/forms.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1558,16 +1558,17 @@ var FormHelperUI = {
     this._cmdPrevious.setAttribute("disabled", !aHasPrevious);
     this._cmdNext.setAttribute("disabled", !aHasNext);
 
     let lastElement = this._currentElement || null;
     this._currentElement = {
       name: aElement.name,
       value: aElement.value,
       maxLength: aElement.maxLength,
+      isAutocomplete: aElement.isAutocomplete,
       list: aElement.choices
     }
     this._updateContainer(lastElement, this._currentElement);
 
     this._zoom(Rect.fromRect(aElement.rect), Rect.fromRect(aElement.caretRect));
   },
 
   hide: function formHelperHide() {
@@ -1668,29 +1669,29 @@ var FormHelperUI = {
       fragment.appendChild(button);
     }
     autofill.appendChild(fragment);
     autofill.collapsed = !aSuggestions.length;
   },
 
   /** Retrieve the autocomplete list from the autocomplete service for an element */
   _getAutocompleteSuggestions: function _formHelperGetAutocompleteSuggestions(aElement) {
+    if (!aElement.isAutocomplete)
+      return [];
+
     let suggestions = [];
 
     let autocompleteService = Cc["@mozilla.org/satchel/form-autocomplete;1"].getService(Ci.nsIFormAutoComplete);
-    try {
-      let results = autocompleteService.autoCompleteSearch(aElement.name, aElement.value, aElement, null);
-      if (results.matchCount > 0) {
-        for (let i = 0; i < results.matchCount; i++) {
-          let value = results.getValueAt(i);
-          suggestions.push(value);
-        }
+    let results = autocompleteService.autoCompleteSearch(aElement.name, aElement.value, aElement, null);
+    if (results.matchCount > 0) {
+      for (let i = 0; i < results.matchCount; i++) {
+        let value = results.getValueAt(i);
+        suggestions.push(value);
       }
     }
-    catch(e) {}
 
     return suggestions;
   },
 
   /** Update the form helper container to reflect new element user is editing. */
   _updateContainer: function _formHelperUpdateContainer(aLastElement, aCurrentElement) {
     this._updateContainerForSelect(aLastElement, aCurrentElement);
 
--- a/mobile/chrome/content/forms.js
+++ b/mobile/chrome/content/forms.js
@@ -165,32 +165,32 @@ FormAssistant.prototype = {
 
   handleEvent: function formHelperHandleEvent(aEvent) {
     if (!this._enabled || !this.currentElement)
       return;
 
     let currentElement = this.currentElement;
     switch (aEvent.keyCode) {
       case aEvent.DOM_VK_DOWN:
-        if (currentElement instanceof HTMLInputElement && !currentWrapper.canAutocomplete()) {
+        if (currentElement instanceof HTMLInputElement && !this._isAutocomplete(currentElement)) {
           if (this._hasKeyListener(currentElement))
             return;
         }
         else if (currentElement instanceof HTMLTextAreaElement) {
           let existSelection = currentElement.selectionEnd - currentElement.selectionStart;
           let isEnd = (currentElement.textLength == currentElement.selectionEnd);
           if (!isEnd || existSelection)
             return;
         }
 
         this.currentIndex++;
         break;
 
       case aEvent.DOM_VK_UP:
-        if (currentElement instanceof HTMLInputElement && !currentWrapper.canAutocomplete()) {
+        if (currentElement instanceof HTMLInputElement && !this._isAutocomplete(currentElement)) {
           if (this._hasKeyListener(currentElement))
             return;
         }
         else if (currentElement instanceof HTMLTextAreaElement) {
           let existSelection = currentElement.selectionEnd - currentElement.selectionStart;
           let isStart = (currentElement.selectionEnd == 0);
           if (!isStart || existSelection)
             return;
@@ -198,28 +198,39 @@ FormAssistant.prototype = {
 
         this.currentIndex--;
         break;
 
       case aEvent.DOM_VK_RETURN:
         break;
 
       default:
-        if (aEvent.target instanceof HTMLInputElement) {
+        if (this._isAutocomplete(aEvent.target)) {
           sendAsyncMessage("FormAssist:AutoComplete", this._getJSON());
         }
         break;
     }
 
     let caretRect = this._getCaretRect();
     if (!caretRect.isEmpty()) {
       sendAsyncMessage("FormAssist:Update", { caretRect: caretRect });
     }
   },
 
+  _isAutocomplete: function formHelperIsAutocomplete(aElement) {
+    if (aElement instanceof HTMLInputElement) {
+      let autocomplete = aElement.getAttribute("autocomplete");
+      let allowedValues = ["off", "false", "disabled"];
+      if (allowedValues.indexOf(autocomplete) == -1)
+        return true;
+    }
+
+    return false;
+  },
+
   _isValidElement: function formHelperIsValidElement(aElement) {
     let formExceptions = {button: true, checkbox: true, file: true, image: true, radio: true, reset: true, submit: true};
     if (aElement instanceof HTMLInputElement && formExceptions[aElement.type])
       return false;
 
     if (aElement instanceof HTMLButtonElement ||
         (aElement.getAttribute("role") == "button" && aElement.hasAttribute("tabindex")))
       return false;
@@ -355,16 +366,17 @@ FormAssistant.prototype = {
     let list = getListForElement(element);
     return {
       current: {
         id: element.id,
         name: element.name,
         value: element.value,
         maxLength: element.maxLength,
         choices: list,
+        isAutocomplete: this._isAutocomplete(this.currentElement),
         rect: this._getRect(),
         caretRect: this._getCaretRect()
       },
       hasPrevious: !!this._elements[this._currentIndex - 1],
       hasNext: !!this._elements[this._currentIndex + 1]
     };
   },