Bug 540613 - Form helper does not come up selecting username/password fields on Wordpress [r=mfinkle]
--- 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)) {