Bug 966612 part.1 Print preview should handle Esc key with keydown event r=enndeakin

This commit is contained in:
Masayuki Nakano 2014-02-06 00:14:35 +09:00
Родитель 859a53a7f3
Коммит f3c74d2f8e
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -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();
}