Commit 088420f8 authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

PDF Viewer: Handle space and shift+space key in Presentation mode.

Space advances to the next page, and shift+space to the previous.

Note that this CL is also partially fixing (as a side-effect) a
bug where the space key was incorrectly not handled at all in
fit-to-page/fit-to-height modes, even outside Presentation mode.

Bug: 1148478,1155088
Change-Id: I390616b661c8de1f886c36469cff8776df183134
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571152Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834282}
parent d439986d
......@@ -1070,33 +1070,18 @@ export class Viewport {
* @param {!KeyboardEvent} e
* @private
*/
pageUpHandler_(e) {
// Go to the previous page if we are fit-to-page or fit-to-height.
pageUpDownSpaceHandler_(e) {
const direction =
e.key === 'PageUp' || (e.key === ' ' && e.shiftKey) ? -1 : 1;
// Go to the previous/next page if we are fit-to-page or fit-to-height.
if (this.isPagedMode_()) {
this.goToPreviousPage();
// Since we do the movement of the page.
e.preventDefault();
} else if (
/** @type {!{fromScriptingAPI: (boolean|undefined)}} */ (e)
.fromScriptingAPI) {
this.position.y -= this.size.height;
}
}
/**
* @param {!KeyboardEvent} e
* @private
*/
pageDownHandler_(e) {
// Go to the next page if we are fit-to-page or fit-to-height.
if (this.isPagedMode_()) {
this.goToNextPage();
direction === 1 ? this.goToNextPage() : this.goToPreviousPage();
// Since we do the movement of the page.
e.preventDefault();
} else if (
/** @type {!{fromScriptingAPI: (boolean|undefined)}} */ (e)
.fromScriptingAPI) {
this.position.y += this.size.height;
this.position.y += direction * this.size.height;
}
}
......@@ -1178,18 +1163,10 @@ export class Viewport {
*/
handleDirectionalKeyEvent(e, formFieldFocused) {
switch (e.key) {
case '':
if (e.shiftKey) {
this.pageUpHandler_(e);
} else {
this.pageDownHandler_(e);
}
return true;
case ' ':
case 'PageUp':
this.pageUpHandler_(e);
return true;
case 'PageDown':
this.pageDownHandler_(e);
this.pageUpDownSpaceHandler_(e);
return true;
case 'ArrowLeft':
this.arrowLeftHandler_(e, formFieldFocused);
......
......@@ -69,10 +69,11 @@ const tests = [
chrome.test.succeed();
},
async function testArrowKeysUpdatePage() {
async function testKeysUpdatePage() {
await ensureFullscreen();
chrome.test.assertEq(0, viewer.viewport.getMostVisiblePage());
// Test arrow keys.
pressAndReleaseKeyOn(viewer, 0, '', 'ArrowDown');
chrome.test.assertEq(1, viewer.viewport.getMostVisiblePage());
......@@ -85,6 +86,20 @@ const tests = [
pressAndReleaseKeyOn(viewer, 0, '', 'ArrowLeft');
chrome.test.assertEq(0, viewer.viewport.getMostVisiblePage());
// Test Space key.
pressAndReleaseKeyOn(viewer, 0, '', ' ');
chrome.test.assertEq(1, viewer.viewport.getMostVisiblePage());
pressAndReleaseKeyOn(viewer, 0, 'shift', ' ');
chrome.test.assertEq(0, viewer.viewport.getMostVisiblePage());
// Test PageUp/PageDown keys.
pressAndReleaseKeyOn(viewer, 0, '', 'PageDown');
chrome.test.assertEq(1, viewer.viewport.getMostVisiblePage());
pressAndReleaseKeyOn(viewer, 0, '', 'PageUp');
chrome.test.assertEq(0, viewer.viewport.getMostVisiblePage());
chrome.test.succeed();
}
];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment