From 64a4a2745591cf21e8cd38e653334dfd05de83fd Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Thu, 30 Jan 2014 15:26:51 +0100 Subject: [PATCH 1/2] Remove obsolete code from shortcut handler These lines were introduced in 612f59aa10eef2bf6559deddfb54b84a0a30c6bc when the only shortcuts were +/-/=/0 (to change zoom level). Back then, when the input fields were focused, using these keys would add these unwanted characters to the input field and change the zoom level of the viewer. Having both operations at the same time was an undesired event, so a check was inserted, to ignore shortcuts when the toolbar is focused. The #toolbar element doesn't exist any more, so these lines are obsolete. --- web/viewer.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 211ae6bab..cb7051c92 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -2168,12 +2168,6 @@ window.addEventListener('keydown', function keydown(evt) { return; } } - var controlsElement = document.getElementById('toolbar'); - while (curElement) { - if (curElement === controlsElement && !PresentationMode.active) - return; // ignoring if the 'toolbar' element is focused - curElement = curElement.parentNode; - } //#if (FIREFOX || MOZCENTRAL) //// Workaround for issue in Firefox, that prevents scroll keys from working //// when elements with 'tabindex' are focused. From ce9400dc8b7a3dc74f7c531e93120797a66bbc07 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Thu, 30 Jan 2014 16:54:12 +0100 Subject: [PATCH 2/2] 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