Bug 540613 - Form helper does not come up selecting username/password fields on Wordpress [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Mon, 08 Nov 2010 11:53:42 +0100
changeset 66974 957fa0d27be77a6befbec62f44aa84bae0ecf041
parent 66973 733113252ca21b3b032929784e76979aa3a6f163
child 66975 39bdb94d185d96d95f51c3cf8ba50cfb02344506
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
bugs540613
Bug 540613 - Form helper does not come up selecting username/password fields on Wordpress [r=mfinkle]
mobile/chrome/content/content.js
mobile/chrome/content/forms.js
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -414,28 +414,30 @@ Content.prototype = {
 
         let event = content.document.createEvent("PopupEvents");
         event.initEvent("contextmenu", true, true);
         element.dispatchEvent(event);
         break;
       }
 
       case "Browser:MouseUp": {
+        this._formAssistant.focusSync = true;
         let element = elementFromPoint(x, y);
         if (modifiers == Ci.nsIDOMNSEvent.CONTROL_MASK) {
           let uri = Util.getHrefForElement(element);
           if (uri)
             sendAsyncMessage("Browser:OpenURI", { uri: uri });
         } else if (!this._formAssistant.open(element)) {
           sendAsyncMessage("FindAssist:Hide", { });
           this._sendMouseEvent("mousemove", element, x, y);
           this._sendMouseEvent("mousedown", element, x, y);
           this._sendMouseEvent("mouseup", element, x, y);
         }
         ContextHandler.reset();
+        this._formAssistant.focusSync = false;
         break;
       }
 
       case "Browser:SaveAs":
         if (json.type != Ci.nsIPrintSettings.kOutputFormatPDF)
           return;
 
         let printSettings = Cc["@mozilla.org/gfx/printsettings-service;1"]
--- a/mobile/chrome/content/forms.js
+++ b/mobile/chrome/content/forms.js
@@ -62,20 +62,24 @@ function FormAssistant() {
   addMessageListener("FormAssist:Next", this);
   addMessageListener("FormAssist:ChoiceSelect", this);
   addMessageListener("FormAssist:ChoiceChange", this);
   addMessageListener("FormAssist:AutoComplete", this);
 
   addEventListener("keyup", this, false);
   addEventListener("resize", this, false);
   addEventListener("focus", this, true);
+
+  this._enabled = Services.prefs.getBoolPref("formhelper.enabled");
 };
 
 FormAssistant.prototype = {
   _selectWrapper: null,
+  _currentIndex: -1,
+  _elements: [],
 
   get currentElement() {
     return this._elements[this._currentIndex];
   },
 
   get currentIndex() {
     return this._currentIndex;
   },
@@ -103,16 +107,18 @@ FormAssistant.prototype = {
     // * hover a disabled element
     if (!this._isValidElement(aElement)) {
       let passiveButtons = { button: true, checkbox: true, file: true, radio: true, reset: true };
       if ((aElement instanceof HTMLInputElement || aElement instanceof HTMLButtonElement) &&
           passiveButtons[aElement.type] && !aElement.disabled)
         return false;
 
       sendAsyncMessage("FormAssist:Hide", { });
+      this._currentIndex = -1;
+      this._elements = [];
       return this._open = false;
     }
 
     // Checking if the element is the current focused one while the form assistant is open
     // allow the user to reposition the caret into an input element
     if (this._open && aElement == this.currentElement) {
       //hack bug 604351
       // if the element is the same editable element and the VKB is closed, reopen it
@@ -193,26 +199,41 @@ FormAssistant.prototype = {
       if (["keyup", "keydown", "keypress"].indexOf(listener.type) != -1
           && !listener.inSystemEventGroup) {
         return true;
       }
     }
     return false;
   },
 
+  focusSync: false,
   handleEvent: function formHelperHandleEvent(aEvent) {
-    if (!this._enabled || !this.currentElement)
+    if (!this._enabled || (!this.currentElement && (aEvent.type != "focus" || !this.focusSync)))
       return;
 
     switch (aEvent.type) {
       case "resize":
         sendAsyncMessage("FormAssist:Resize");
         break;
       case "focus":
-        let focusedIndex = this._getIndexForElement(gFocusManager.focusedElement);
+        // if an element is focused while we're closed but the element can be handle
+        // by the assistant, try to activate it
+        let focusedElement = gFocusManager.focusedElement;
+        if (!this.currentElement) {
+          if (focusedElement && this._isValidElement(focusedElement)) {
+            let self = this;
+            let timer = new Util.Timeout(function() {
+              self.open(focusedElement);
+            });
+            timer.once(0);
+          }
+          return;
+        }
+
+        let focusedIndex = this._getIndexForElement(focusedElement);
         if (focusedIndex != -1 && this.currentIndex != focusedIndex)
           this.currentIndex = focusedIndex;
         break;
       case "keyup":
         let currentElement = this.currentElement;
         switch (aEvent.keyCode) {
           case aEvent.DOM_VK_DOWN:
             if (currentElement instanceof HTMLInputElement && !this._isAutocomplete(currentElement)) {