diff --git a/toolkit/components/printing/content/printUtils.js b/toolkit/components/printing/content/printUtils.js index ab9e25927331..0e0c8fc7342b 100644 --- a/toolkit/components/printing/content/printUtils.js +++ b/toolkit/components/printing/content/printUtils.js @@ -243,6 +243,7 @@ var PrintUtils = { document.documentElement.setAttribute("onclose", "PrintUtils.exitPrintPreview(); return false;"); // disable chrome shortcuts... + window.addEventListener("keydown", this.onKeyDownPP, true); window.addEventListener("keypress", this.onKeyPressPP, true); var browser = this._callback.getPrintPreviewBrowser(); @@ -255,6 +256,7 @@ var PrintUtils = { exitPrintPreview: function () { + window.removeEventListener("keydown", this.onKeyDownPP, true); window.removeEventListener("keypress", this.onKeyPressPP, true); // restore the old close handler @@ -279,6 +281,14 @@ var PrintUtils = { this._callback.onExit(); }, + onKeyDownPP: function (aEvent) + { + // Esc exits the PP + if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) { + PrintUtils.exitPrintPreview(); + } + }, + onKeyPressPP: function (aEvent) { var closeKey; @@ -288,8 +298,8 @@ var PrintUtils = { closeKey = aEvent["DOM_VK_"+closeKey]; } catch (e) {} var isModif = aEvent.ctrlKey || aEvent.metaKey; - // ESC and Ctrl-W exits the PP - if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE || isModif && + // Ctrl-W exits the PP + if (isModif && (aEvent.charCode == closeKey || aEvent.charCode == closeKey + 32)) { PrintUtils.exitPrintPreview(); }