diff --git a/mobile/chrome/content/content.js b/mobile/chrome/content/content.js index cb91a7954a52..17587c70bde8 100644 --- a/mobile/chrome/content/content.js +++ b/mobile/chrome/content/content.js @@ -419,6 +419,7 @@ Content.prototype = { } case "Browser:MouseUp": { + this._formAssistant.focusSync = true; let element = elementFromPoint(x, y); if (modifiers == Ci.nsIDOMNSEvent.CONTROL_MASK) { let uri = Util.getHrefForElement(element); @@ -431,6 +432,7 @@ Content.prototype = { this._sendMouseEvent("mouseup", element, x, y); } ContextHandler.reset(); + this._formAssistant.focusSync = false; break; } diff --git a/mobile/chrome/content/forms.js b/mobile/chrome/content/forms.js index 356c7056cbbd..b41cebce4ec7 100644 --- a/mobile/chrome/content/forms.js +++ b/mobile/chrome/content/forms.js @@ -67,10 +67,14 @@ function FormAssistant() { 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]; @@ -108,6 +112,8 @@ FormAssistant.prototype = { return false; sendAsyncMessage("FormAssist:Hide", { }); + this._currentIndex = -1; + this._elements = []; return this._open = false; } @@ -198,8 +204,9 @@ FormAssistant.prototype = { 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) { @@ -207,7 +214,21 @@ FormAssistant.prototype = { 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;