diff --git a/mobile/chrome/content/InputHandler.js b/mobile/chrome/content/InputHandler.js index 2b1f867912b4..7118a100fcda 100644 --- a/mobile/chrome/content/InputHandler.js +++ b/mobile/chrome/content/InputHandler.js @@ -130,13 +130,15 @@ function InputHandler(browserViewContainer) { window.addEventListener("click", this, true); /* these handle key strokes in the browser view (where page content appears) */ - browserViewContainer.addEventListener("keydown", this, true); - browserViewContainer.addEventListener("keyup", this, true); + browserViewContainer.addEventListener("keypress", this, false); + browserViewContainer.addEventListener("keyup", this, false); + browserViewContainer.addEventListener("keydown", this, false); browserViewContainer.addEventListener("DOMMouseScroll", this, true); browserViewContainer.addEventListener("MozMousePixelScroll", this, true); browserViewContainer.addEventListener("contextmenu", this, false); this.addModule(new MouseModule(this, browserViewContainer)); + this.addModule(new KeyModule(this, browserViewContainer)); this.addModule(new ScrollwheelModule(this, browserViewContainer)); } @@ -1129,6 +1131,39 @@ KineticController.prototype = { } }; + +/** + * Input module for basic key input. + */ +function KeyModule(owner, browserViewContainer) { + this._owner = owner; + this._browserViewContainer = browserViewContainer; +} + +KeyModule.prototype = { + getClickerFromElement: function getClickerFromElement(elem) { + for (; elem; elem = elem.parentNode) + if (elem.customKeySender) + break; + return (elem) ? elem : null; + }, + + handleEvent: function handleEvent(evInfo) { + if (evInfo.event.type == "keydown" || evInfo.event.type == "keyup" || evInfo.event.type == "keypress") { + let keyer = this._browserViewContainer.customKeySender; + if (keyer) { + keyer.dispatchKeyEvent(evInfo.event); + evInfo.event.preventDefault(); + evInfo.event.stopPropagation(); + } + } + }, + + /* We don't have much state to reset if we lose event focus */ + cancelPending: function cancelPending() {} +}; + + /** * Input module for basic scrollwheel input. Currently just zooms the browser * view accordingly. diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index c5688027416e..3aefa4057cc4 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -375,6 +375,7 @@ var Browser = { /* handles dispatching clicks on tiles into clicks in content or zooms */ container.customClicker = new ContentCustomClicker(bv); + container.customKeySender = new ContentCustomKeySender(bv); /* scrolling box that contains tiles */ let contentScrollbox = this.contentScrollbox = document.getElementById("content-scrollbox"); @@ -1975,6 +1976,28 @@ ContentCustomClicker.prototype = { } }; +/** Watches for mouse events in chrome and sends them to content. */ +function ContentCustomKeySender(browserView) { + this._browserView = browserView; +} + +ContentCustomKeySender.prototype = { + /** Dispatch a mouse event with chrome client coordinates. */ + dispatchKeyEvent: function _dispatchKeyEvent(event) { + let browser = this._browserView.getBrowser(); + if (browser) { + let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader; + try { + fl.sendCrossProcessKeyEvent(event.type, event.keyCode, event.charCode, event.modifiers); + } catch (e) {} + } + }, + + toString: function toString() { + return "[ContentCustomClicker] { }"; + } +}; + /** Watches for mouse click in content and redirect them to the best found target **/ const ElementTouchHelper = { get radius() {