diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index 5017a60eb9f..60e85a0180a 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -182,6 +182,7 @@ var Browser = { /* handles web progress management for open browsers */ Elements.browsers.webProgress = new Browser.WebProgress(); + this.keyFilter = new KeyFilter(Elements.browsers); let mouseModule = new MouseModule(); let gestureModule = new GestureModule(Elements.browsers); let scrollWheelModule = new ScrollwheelModule(Elements.browsers); @@ -1225,14 +1226,19 @@ var Browser = { break; } - case "Browser:KeyPress": + case "Browser:KeyPress": { + let keyset = document.getElementById("mainKeyset"); + keyset.setAttribute("disabled", "false"); + if (json.preventDefault) + break; + let event = document.createEvent("KeyEvents"); event.initKeyEvent("keypress", true, true, null, json.ctrlKey, json.altKey, json.shiftKey, json.metaKey, json.keyCode, json.charCode); - document.getElementById("mainKeyset").dispatchEvent(event); + keyset.dispatchEvent(event); break; - + } case "Browser:ZoomToPoint:Return": if (json.zoomTo) { let rect = Rect.fromRect(json.zoomTo); @@ -1972,6 +1978,31 @@ const ContentTouchHandler = { } }; + +/** Prevent chrome from consuming key events before remote content has a chance. */ +function KeyFilter(container) { + container.addEventListener("keypress", this, false); + container.addEventListener("keyup", this, false); + container.addEventListener("keydown", this, false); +} + +KeyFilter.prototype = { + handleEvent: function handleEvent(aEvent) { + if (Elements.contentShowing.getAttribute("disabled") == "true") + return; + + let browser = getBrowser(); + if (browser && browser.active && browser.getAttribute("remote") == "true") { + document.getElementById("mainKeyset").setAttribute("disabled", "true"); + } + }, + + toString: function toString() { + return "[KeyFilter] { }"; + } +}; + + /** * Utility class to handle manipulations of the identity indicators in the UI */ diff --git a/mobile/chrome/content/common-ui.js b/mobile/chrome/content/common-ui.js index 23cf48c0634..ee169f3a838 100644 --- a/mobile/chrome/content/common-ui.js +++ b/mobile/chrome/content/common-ui.js @@ -827,6 +827,7 @@ var FormHelperUI = { if (focusedElement && focusedElement.localName == "browser") return; + Browser.keyFilter.handleEvent(aEvent); break; case "SizeChanged": diff --git a/mobile/chrome/content/content.js b/mobile/chrome/content/content.js index e72d77e166d..79ac4cbea57 100644 --- a/mobile/chrome/content/content.js +++ b/mobile/chrome/content/content.js @@ -299,16 +299,14 @@ let Content = { // let's send it back to the chrome process to have it handle shortcuts case "keypress": let timer = new Util.Timeout(function() { - if(aEvent.getPreventDefault()) - return; - let eventData = { ctrlKey: aEvent.ctrlKey, altKey: aEvent.altKey, shiftKey: aEvent.shiftKey, metaKey: aEvent.metaKey, keyCode: aEvent.keyCode, - charCode: aEvent.charCode + charCode: aEvent.charCode, + preventDefault: aEvent.getPreventDefault() }; sendAsyncMessage("Browser:KeyPress", eventData); });