diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 7f5e4288c29..f2a005d520a 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -191,13 +191,13 @@ var shell = { audioManager.masterVolume = volume; }, - forwardKeyToHomescreen: function shell_forwardKeyToHomescreen(evt) { + forwardKeyToContent: function shell_forwardKeyToContent(evt) { let generatedEvent = content.document.createEvent('KeyboardEvent'); generatedEvent.initKeyEvent(evt.type, true, true, evt.view, evt.ctrlKey, evt.altKey, evt.shiftKey, evt.metaKey, evt.keyCode, evt.charCode); - content.dispatchEvent(generatedEvent); + content.document.documentElement.dispatchEvent(generatedEvent); }, handleEvent: function shell_handleEvent(evt) { @@ -205,30 +205,9 @@ var shell = { case 'keydown': case 'keyup': case 'keypress': - // If the home key is pressed, always forward it to the homescreen - if (evt.eventPhase == evt.CAPTURING_PHASE) { - if (evt.keyCode == evt.VK_DOM_HOME) { - window.setTimeout(this.forwardKeyToHomescreen, 0, evt); - evt.preventDefault(); - evt.stopPropagation(); - } - return; - } - - // If one of the other keys is used in an application and is - // cancelled via preventDefault, do nothing. - let homescreen = (evt.target.ownerDocument.defaultView == content); - if (!homescreen && evt.defaultPrevented) - return; - - // If one of the other keys is used in an application and is - // not used forward it to the homescreen - if (!homescreen) - window.setTimeout(this.forwardKeyToHomescreen, 0, evt); - // For debug purposes and because some of the APIs are not yet exposed // to the content, let's react on some of the keyup events. - if (evt.type == 'keyup') { + if (evt.type == 'keyup' && evt.eventPhase == evt.BUBBLING_PHASE) { switch (evt.keyCode) { case evt.DOM_VK_F5: if (Services.prefs.getBoolPref('b2g.keys.search.enabled')) @@ -244,6 +223,16 @@ var shell = { break; } } + + // Redirect the HOME key to System app and stop the applications from + // handling it. + let rootContentEvt = (evt.target.ownerDocument.defaultView == content); + if (!rootContentEvt && evt.eventPhase == evt.CAPTURING_PHASE && + evt.keyCode == evt.DOM_VK_HOME) { + this.forwardKeyToContent(evt); + evt.preventDefault(); + evt.stopImmediatePropagation(); + } break; case 'mozfullscreenchange':