Add a new Page scrolling mode (issue 2638, 8952, 10907)

This implements a new Page scrolling mode, essentially bringing (and extending) the functionality from `PDFSinglePageViewer` into the regular `PDFViewer`-class. Compared to `PDFSinglePageViewer`, which as its name suggests will only display one page at a time, in the `PDFViewer`-implementation this new Page scrolling mode also support spreadModes properly (somewhat similar to e.g. Adobe Reader).

Given the size and scope of these changes, I've tried to focus on implementing the basic functionality. Hence there's room for further clean-up and/or improvements, including e.g. simplifying the CSS/JS related to PresentationMode and implementing easier page-switching with the mouse-wheel/arrow-keys.
This commit is contained in:
Jonas Jenwald 2021-10-07 14:04:41 +02:00
parent 3945965605
commit 511458fbbc
14 changed files with 296 additions and 244 deletions

View file

@ -57,6 +57,7 @@ const ScrollMode = {
VERTICAL: 0, // Default value.
HORIZONTAL: 1,
WRAPPED: 2,
PAGE: 3,
};
const SpreadMode = {
@ -952,21 +953,32 @@ function getActiveOrFocusedElement() {
* necessary Scroll/Spread modes (since SinglePage, TwoPageLeft,
* and TwoPageRight all suggests using non-continuous scrolling).
* @param {string} mode - The API PageLayout value.
* @returns {number} A value from {SpreadMode}.
* @returns {Object}
*/
function apiPageLayoutToSpreadMode(layout) {
function apiPageLayoutToViewerModes(layout) {
let scrollMode = ScrollMode.VERTICAL,
spreadMode = SpreadMode.NONE;
switch (layout) {
case "SinglePage":
scrollMode = ScrollMode.PAGE;
break;
case "OneColumn":
return SpreadMode.NONE;
case "TwoColumnLeft":
break;
case "TwoPageLeft":
return SpreadMode.ODD;
case "TwoColumnRight":
scrollMode = ScrollMode.PAGE;
/* falls through */
case "TwoColumnLeft":
spreadMode = SpreadMode.ODD;
break;
case "TwoPageRight":
return SpreadMode.EVEN;
scrollMode = ScrollMode.PAGE;
/* falls through */
case "TwoColumnRight":
spreadMode = SpreadMode.EVEN;
break;
}
return SpreadMode.NONE; // Default value.
return { scrollMode, spreadMode };
}
/**
@ -995,7 +1007,7 @@ function apiPageModeToSidebarView(mode) {
export {
animationStarted,
apiPageLayoutToSpreadMode,
apiPageLayoutToViewerModes,
apiPageModeToSidebarView,
approximateFraction,
AutomationEventBus,