From 98cc7387886dd8fd939bf99c49365b2ec01642e9 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Sun, 4 Sep 2011 13:11:42 -0700 Subject: [PATCH] Backing out bc4b2d84f80a (bug 682017) --- mobile/chrome/content/browser.js | 48 ++++++++++++++++++++++++++++++ mobile/chrome/content/common-ui.js | 1 + 2 files changed, 49 insertions(+) diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index 5017a60eb9fa..41a57fba1fc0 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.keySender = new ContentCustomKeySender(Elements.browsers); let mouseModule = new MouseModule(); let gestureModule = new GestureModule(Elements.browsers); let scrollWheelModule = new ScrollwheelModule(Elements.browsers); @@ -1972,6 +1973,52 @@ const ContentTouchHandler = { } }; + +/** Watches for mouse events in chrome and sends them to content. */ +function ContentCustomKeySender(container) { + container.addEventListener("keypress", this, false); + container.addEventListener("keyup", this, false); + container.addEventListener("keydown", this, false); +} + +ContentCustomKeySender.prototype = { + handleEvent: function handleEvent(aEvent) { + if (Elements.contentShowing.getAttribute("disabled") == "true") + return; + + let browser = getBrowser(); + if (browser && browser.active && browser.getAttribute("remote") == "true") { + aEvent.stopPropagation(); + aEvent.preventDefault(); + + let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader; + fl.sendCrossProcessKeyEvent(aEvent.type, + aEvent.keyCode, + (aEvent.type != "keydown") ? aEvent.charCode : null, + this._parseModifiers(aEvent)); + } + }, + + _parseModifiers: function _parseModifiers(aEvent) { + const masks = Ci.nsIDOMNSEvent; + let mval = 0; + if (aEvent.shiftKey) + mval |= masks.SHIFT_MASK; + if (aEvent.ctrlKey) + mval |= masks.CONTROL_MASK; + if (aEvent.altKey) + mval |= masks.ALT_MASK; + if (aEvent.metaKey) + mval |= masks.META_MASK; + return mval; + }, + + toString: function toString() { + return "[ContentCustomKeySender] { }"; + } +}; + + /** * Utility class to handle manipulations of the identity indicators in the UI */ @@ -2870,6 +2917,7 @@ Tab.prototype = { let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader; fl.renderMode = Ci.nsIFrameLoader.RENDER_MODE_ASYNC_SCROLL; + fl.eventMode = Ci.nsIFrameLoader.EVENT_MODE_DONT_FORWARD_TO_CHILD; return browser; }, diff --git a/mobile/chrome/content/common-ui.js b/mobile/chrome/content/common-ui.js index 1b2c15323c7a..b3739834eefa 100644 --- a/mobile/chrome/content/common-ui.js +++ b/mobile/chrome/content/common-ui.js @@ -816,6 +816,7 @@ var FormHelperUI = { if (focusedElement && focusedElement.localName == "browser") return; + Browser.keySender.handleEvent(aEvent); break; case "SizeChanged":