diff --git a/mobile/app/mobile.js b/mobile/app/mobile.js index b3526067cb01..7a8606bb3c3e 100644 --- a/mobile/app/mobile.js +++ b/mobile/app/mobile.js @@ -642,3 +642,6 @@ pref("urlclassifier.updatecachemax", 4194304); pref("browser.safebrowsing.malware.reportURL", "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?client=%NAME%&hl=%LOCALE%&site="); #endif +// prevent focus to show/hide the virtual keyboard if the action is not +// initiated by a user +pref("content.ime.strict_policy", true); diff --git a/mobile/chrome/content/Util.js b/mobile/chrome/content/Util.js index daffeeaf1d3d..ef7e0f886bfd 100644 --- a/mobile/chrome/content/Util.js +++ b/mobile/chrome/content/Util.js @@ -180,6 +180,13 @@ let Util = { #else return (window.innerWidth <= window.innerHeight); #endif + }, + + get isKeyboardOpened() { + if (this.isParentProcess()) + return ViewableAreaObserver.isKeyboardOpened; + + return (sendSyncMessage("Content:IsKeyboardOpened", {}))[0]; } }; diff --git a/mobile/chrome/content/bindings/browser.js b/mobile/chrome/content/bindings/browser.js index 97a810d3f035..a0a3e94cfb10 100644 --- a/mobile/chrome/content/bindings/browser.js +++ b/mobile/chrome/content/bindings/browser.js @@ -5,8 +5,6 @@ let Ci = Components.interfaces; dump("!! remote browser loaded\n"); let WebProgressListener = { - _lastLocation: null, - init: function() { let flags = Ci.nsIWebProgress.NOTIFY_LOCATION | Ci.nsIWebProgress.NOTIFY_SECURITY | @@ -52,10 +50,6 @@ let WebProgressListener = { sendAsyncMessage("Content:LocationChange", json); - // Keep track of hash changes - this.hashChanged = (location == this._lastLocation); - this._lastLocation = location; - // When a new page is loaded fire a message for the first paint addEventListener("MozAfterPaint", function(aEvent) { removeEventListener("MozAfterPaint", arguments.callee, true); @@ -217,15 +211,6 @@ let DOMEvents = { persisted: aEvent.persisted }; - // Clear onload focus to prevent the VKB to be shown unexpectingly - // but only if the location has really changed and not only the - // fragment identifier - let contentWindowID = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID; - if (!WebProgressListener.hashChanged && contentWindowID == util.currentInnerWindowID) { - let focusManager = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); - focusManager.clearFocus(content); - } - sendAsyncMessage(aEvent.type, json); break; } diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index 9fef18cfcdb7..0cafd98c9be9 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -321,6 +321,7 @@ var Browser = { #if MOZ_PLATFORM_MAEMO == 6 os.addObserver(ViewableAreaObserver, "softkb-change", false); #endif + messageManager.addMessageListener("Content:IsKeyboardOpened", ViewableAreaObserver); window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = new nsBrowserAccess(); @@ -3038,6 +3039,10 @@ var ViewableAreaObserver = { #endif }, + receiveMessage: function receiveMessage(aMessage) { + return this.isKeyboardOpened; + }, + update: function va_update() { let oldHeight = parseInt(Browser.styles["viewable-height"].height); let oldWidth = parseInt(Browser.styles["viewable-width"].width); diff --git a/mobile/chrome/content/common-ui.js b/mobile/chrome/content/common-ui.js index b76144758cd4..b8726086b0b8 100644 --- a/mobile/chrome/content/common-ui.js +++ b/mobile/chrome/content/common-ui.js @@ -829,7 +829,7 @@ var FormHelperUI = { break; case "FormAssist:Resize": - if (!ViewableAreaObserver.isKeyboardOpened) + if (!Util.isKeyboardOpened) return; let element = json.current; @@ -841,7 +841,7 @@ var FormHelperUI = { break; case "FormAssist:Update": - if (!ViewableAreaObserver.isKeyboardOpened) + if (!Util.isKeyboardOpened) return; Browser.hideSidebars(); diff --git a/mobile/chrome/content/forms.js b/mobile/chrome/content/forms.js index 30cdd83afe54..d58040f28ea5 100644 --- a/mobile/chrome/content/forms.js +++ b/mobile/chrome/content/forms.js @@ -104,7 +104,7 @@ FormAssistant.prototype = { if (this._isVisibleElement(element)) { this._currentIndex = aIndex; - gFocusManager.setFocus(element, Ci.nsIFocusManager.FLAG_NOSCROLL); + gFocusManager.setFocus(element, Ci.nsIFocusManager.FLAG_NOSCROLL | Ci.nsIFocusManager.FLAG_BYMOUSE); // To ensure we get the current caret positionning of the focused // element we need to delayed a bit the event @@ -156,17 +156,16 @@ FormAssistant.prototype = { if (this._isEditable(aElement)) aElement = this._getTopLevelEditable(aElement); + // hack bug 604351 + // if the element is the same editable element and the VKB is closed, reopen it + if (aElement instanceof HTMLInputElement && aElement.mozIsTextField(false) && !Util.isKeyboardOpened) { + aElement.blur(); + gFocusManager.setFocus(aElement, Ci.nsIFocusManager.FLAG_NOSCROLL | Ci.nsIFocusManager.FLAG_BYMOUSE); + } + // 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 - let utils = Util.getWindowUtils(content); - if (utils.IMEStatus == utils.IME_STATUS_DISABLED && aElement instanceof HTMLInputElement && aElement.mozIsTextField(false)) { - aElement.blur(); - aElement.focus(); - } - // If the element is a