From ce9400dc8b7a3dc74f7c531e93120797a66bbc07 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Thu, 30 Jan 2014 16:54:12 +0100 Subject: [PATCH] Handle navigation keys when viewer is not focused Restrict the scrollbar hack to the keycode for "spacebar", since the bug only occurs in Firefox with spacebar. Keyboard navigation is only activated for the spacebar if the currently focused element is not a button. --- web/viewer.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index cb7051c92..794277b51 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -2160,19 +2160,15 @@ window.addEventListener('keydown', function keydown(evt) { // Some shortcuts should not get handled if a control/input element // is selected. var curElement = document.activeElement || document.querySelector(':focus'); - if (curElement && (curElement.tagName.toUpperCase() === 'INPUT' || - curElement.tagName.toUpperCase() === 'TEXTAREA' || - curElement.tagName.toUpperCase() === 'SELECT')) { + var curElementTagName = curElement && curElement.tagName.toUpperCase(); + if (curElementTagName === 'INPUT' || + curElementTagName === 'TEXTAREA' || + curElementTagName === 'SELECT') { // Make sure that the secondary toolbar is closed when Escape is pressed. if (evt.keyCode !== 27) { // 'Esc' return; } } -//#if (FIREFOX || MOZCENTRAL) -//// Workaround for issue in Firefox, that prevents scroll keys from working -//// when elements with 'tabindex' are focused. -//PDFView.container.blur(); -//#endif if (cmd === 0) { // no control key pressed at all. switch (evt.keyCode) { @@ -2248,6 +2244,29 @@ window.addEventListener('keydown', function keydown(evt) { PDFView.rotatePages(90); break; } + if (!handled && !PresentationMode.active) { + // 33=Page Up 34=Page Down 35=End 36=Home + // 37=Left 38=Up 39=Right 40=Down + if (evt.keyCode >= 33 && evt.keyCode <= 40 && + !PDFView.container.contains(curElement)) { + // The page container is not focused, but a page navigation key has been + // pressed. Change the focus to the viewer container to make sure that + // navigation by keyboard works as expected. + PDFView.container.focus(); + } + // 32=Spacebar + if (evt.keyCode === 32 && curElementTagName !== 'BUTTON') { +//#if !(FIREFOX || MOZCENTRAL) +//// Workaround for issue in Firefox, that prevents scroll keys from working +//// when elements with 'tabindex' are focused. (#3499) +// PDFView.container.blur(); +//#else + if (!PDFView.container.contains(curElement)) { + PDFView.container.focus(); + } +//#endif + } + } } if (cmd === 4) { // shift-key