Merge pull request #10502 from Snuffleupagus/adjust-onLoad-prefs
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
This commit is contained in:
commit
c0d6e46e39
@ -81,6 +81,9 @@ limitations under the License.
|
|||||||
'disableTextLayer',
|
'disableTextLayer',
|
||||||
'enhanceTextSelection',
|
'enhanceTextSelection',
|
||||||
'textLayerMode',
|
'textLayerMode',
|
||||||
|
'showPreviousViewOnLoad',
|
||||||
|
'disablePageMode',
|
||||||
|
'viewOnLoad',
|
||||||
], function(items) {
|
], function(items) {
|
||||||
// Migration code for https://github.com/mozilla/pdf.js/pull/7635.
|
// Migration code for https://github.com/mozilla/pdf.js/pull/7635.
|
||||||
if (typeof items.enableHandToolOnLoad === 'boolean') {
|
if (typeof items.enableHandToolOnLoad === 'boolean') {
|
||||||
@ -113,6 +116,20 @@ limitations under the License.
|
|||||||
storageSync.remove(['disableTextLayer', 'enhanceTextSelection']);
|
storageSync.remove(['disableTextLayer', 'enhanceTextSelection']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Migration code for https://github.com/mozilla/pdf.js/pull/10502.
|
||||||
|
if (typeof items.showPreviousViewOnLoad === 'boolean') {
|
||||||
|
if (!items.showPreviousViewOnLoad) {
|
||||||
|
storageSync.set({
|
||||||
|
viewOnLoad: 1,
|
||||||
|
}, function() {
|
||||||
|
if (!chrome.runtime.lastError) {
|
||||||
|
storageSync.remove(['showPreviousViewOnLoad', 'disablePageMode']);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
storageSync.remove(['showPreviousViewOnLoad', 'disablePageMode']);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -43,6 +43,19 @@ body {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template id="viewOnLoad-template">
|
||||||
|
<div class="settings-row">
|
||||||
|
<label>
|
||||||
|
<span></span>
|
||||||
|
<select>
|
||||||
|
<option value="-1">Default</option>
|
||||||
|
<option value="0">Show previous position</option>
|
||||||
|
<option value="1">Show initial position</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template id="defaultZoomValue-template">
|
<template id="defaultZoomValue-template">
|
||||||
<div class="settings-row">
|
<div class="settings-row">
|
||||||
<label>
|
<label>
|
||||||
@ -71,6 +84,7 @@ body {
|
|||||||
<label>
|
<label>
|
||||||
<span></span>
|
<span></span>
|
||||||
<select>
|
<select>
|
||||||
|
<option value="-1">Default</option>
|
||||||
<option value="0">Do not show sidebar</option>
|
<option value="0">Do not show sidebar</option>
|
||||||
<option value="1">Show thumbnails in sidebar</option>
|
<option value="1">Show thumbnails in sidebar</option>
|
||||||
<option value="2">Show document outline in sidebar</option>
|
<option value="2">Show document outline in sidebar</option>
|
||||||
@ -125,6 +139,7 @@ body {
|
|||||||
<label>
|
<label>
|
||||||
<span></span>
|
<span></span>
|
||||||
<select>
|
<select>
|
||||||
|
<option value="-1">Default</option>
|
||||||
<option value="0">Vertical scrolling</option>
|
<option value="0">Vertical scrolling</option>
|
||||||
<option value="1">Horizontal scrolling</option>
|
<option value="1">Horizontal scrolling</option>
|
||||||
<option value="2">Wrapped scrolling</option>
|
<option value="2">Wrapped scrolling</option>
|
||||||
@ -138,6 +153,7 @@ body {
|
|||||||
<label>
|
<label>
|
||||||
<span></span>
|
<span></span>
|
||||||
<select>
|
<select>
|
||||||
|
<option value="-1">Default</option>
|
||||||
<option value="0">No spreads</option>
|
<option value="0">No spreads</option>
|
||||||
<option value="1">Odd spreads</option>
|
<option value="1">Odd spreads</option>
|
||||||
<option value="2">Even spreads</option>
|
<option value="2">Even spreads</option>
|
||||||
|
@ -2,11 +2,20 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"showPreviousViewOnLoad": {
|
"showPreviousViewOnLoad": {
|
||||||
"title": "Show previous position of PDF upon load",
|
"description": "DEPRECATED. Set viewOnLoad to 1 to disable showing the last page/position on load.",
|
||||||
"description": "Whether to view PDF documents in the last page and position upon opening the viewer.",
|
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
"viewOnLoad": {
|
||||||
|
"title": "View position on load",
|
||||||
|
"description": "The position in the document upon load.\n -1 = Default (uses OpenAction if available, otherwise equal to `viewOnLoad = 0`).\n 0 = The last viewed page/position.\n 1 = The initial page/position.",
|
||||||
|
"enum": [
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
"defaultZoomValue": {
|
"defaultZoomValue": {
|
||||||
"title": "Default zoom level",
|
"title": "Default zoom level",
|
||||||
"description": "Default zoom level of the viewer. Accepted values: 'auto', 'page-actual', 'page-width', 'page-height', 'page-fit', or a zoom level in percents.",
|
"description": "Default zoom level of the viewer. Accepted values: 'auto', 'page-actual', 'page-width', 'page-height', 'page-fit', or a zoom level in percents.",
|
||||||
@ -16,15 +25,16 @@
|
|||||||
},
|
},
|
||||||
"sidebarViewOnLoad": {
|
"sidebarViewOnLoad": {
|
||||||
"title": "Sidebar state on load",
|
"title": "Sidebar state on load",
|
||||||
"description": "Controls the state of the sidebar upon load.\n 0 = do not show sidebar.\n 1 = show thumbnails in sidebar.\n 2 = show document outline in sidebar.\n 3 = Show attachments in sidebar.",
|
"description": "Controls the state of the sidebar upon load.\n -1 = Default (uses PageMode if available, otherwise the last position if available/enabled).\n 0 = Do not show sidebar.\n 1 = Show thumbnails in sidebar.\n 2 = Show document outline in sidebar.\n 3 = Show attachments in sidebar.",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
-1,
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
],
|
],
|
||||||
"default": 0
|
"default": -1
|
||||||
},
|
},
|
||||||
"enableHandToolOnLoad": {
|
"enableHandToolOnLoad": {
|
||||||
"description": "DEPRECATED. Set cursorToolOnLoad to 1 to enable the hand tool by default.",
|
"description": "DEPRECATED. Set cursorToolOnLoad to 1 to enable the hand tool by default.",
|
||||||
@ -117,15 +127,12 @@
|
|||||||
],
|
],
|
||||||
"default": 0
|
"default": 0
|
||||||
},
|
},
|
||||||
"disableOpenActionDestination": {
|
|
||||||
"type": "boolean",
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
"disablePageLabels": {
|
"disablePageLabels": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"disablePageMode": {
|
"disablePageMode": {
|
||||||
|
"description": "DEPRECATED.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
@ -159,25 +166,27 @@
|
|||||||
},
|
},
|
||||||
"scrollModeOnLoad": {
|
"scrollModeOnLoad": {
|
||||||
"title": "Scroll mode on load",
|
"title": "Scroll mode on load",
|
||||||
"description": "Controls how the viewer scrolls upon load.\n 0 = Vertical scrolling.\n 1 = Horizontal scrolling.\n 2 = Wrapped scrolling.",
|
"description": "Controls how the viewer scrolls upon load.\n -1 = Default (uses the last position if available/enabled).\n 0 = Vertical scrolling.\n 1 = Horizontal scrolling.\n 2 = Wrapped scrolling.",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
-1,
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2
|
2
|
||||||
],
|
],
|
||||||
"default": 0
|
"default": -1
|
||||||
},
|
},
|
||||||
"spreadModeOnLoad": {
|
"spreadModeOnLoad": {
|
||||||
"title": "Spread mode on load",
|
"title": "Spread mode on load",
|
||||||
"description": "Whether the viewer should join pages into spreads upon load.\n 0 = No spreads.\n 1 = Odd spreads.\n 2 = Even spreads.",
|
"description": "Whether the viewer should join pages into spreads upon load.\n -1 = Default (uses the last position if available/enabled).\n 0 = No spreads.\n 1 = Odd spreads.\n 2 = Even spreads.",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
-1,
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2
|
2
|
||||||
],
|
],
|
||||||
"default": 0
|
"default": -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
126
web/app.js
126
web/app.js
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
animationStarted, DEFAULT_SCALE_VALUE, getGlobalEventBus,
|
animationStarted, DEFAULT_SCALE_VALUE, getGlobalEventBus,
|
||||||
getPDFFileNameFromURL, isValidRotation, MAX_SCALE, MIN_SCALE,
|
getPDFFileNameFromURL, isValidRotation, isValidScrollMode, isValidSpreadMode,
|
||||||
noContextMenuHandler, normalizeWheelEventDelta, parseQueryString,
|
MAX_SCALE, MIN_SCALE, noContextMenuHandler, normalizeWheelEventDelta,
|
||||||
PresentationModeState, ProgressBar, RendererType, TextLayerMode
|
parseQueryString, PresentationModeState, ProgressBar, RendererType,
|
||||||
|
ScrollMode, SpreadMode, TextLayerMode
|
||||||
} from './ui_utils';
|
} from './ui_utils';
|
||||||
import {
|
import {
|
||||||
build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||||
@ -52,6 +53,12 @@ const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms
|
|||||||
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
||||||
const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms
|
const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms
|
||||||
|
|
||||||
|
const ViewOnLoad = {
|
||||||
|
UNKNOWN: -1,
|
||||||
|
PREVIOUS: 0, // Default value.
|
||||||
|
INITIAL: 1,
|
||||||
|
};
|
||||||
|
|
||||||
const DefaultExternalServices = {
|
const DefaultExternalServices = {
|
||||||
updateFindControlState(data) {},
|
updateFindControlState(data) {},
|
||||||
updateFindMatchesCount(data) {},
|
updateFindMatchesCount(data) {},
|
||||||
@ -900,46 +907,29 @@ let PDFViewerApplication = {
|
|||||||
firstPagePromise.then((pdfPage) => {
|
firstPagePromise.then((pdfPage) => {
|
||||||
this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
||||||
|
|
||||||
if (!AppOptions.get('disableHistory') && !this.isViewerEmbedded) {
|
const storePromise = store.getMultiple({
|
||||||
// The browsing history is only enabled when the viewer is standalone,
|
|
||||||
// i.e. not when it is embedded in a web page.
|
|
||||||
this.pdfHistory.initialize({
|
|
||||||
fingerprint: pdfDocument.fingerprint,
|
|
||||||
resetHistory: !AppOptions.get('showPreviousViewOnLoad'),
|
|
||||||
updateUrl: AppOptions.get('historyUpdateUrl'),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.pdfHistory.initialBookmark) {
|
|
||||||
this.initialBookmark = this.pdfHistory.initialBookmark;
|
|
||||||
|
|
||||||
this.initialRotation = this.pdfHistory.initialRotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let storePromise = store.getMultiple({
|
|
||||||
page: null,
|
page: null,
|
||||||
zoom: DEFAULT_SCALE_VALUE,
|
zoom: DEFAULT_SCALE_VALUE,
|
||||||
scrollLeft: '0',
|
scrollLeft: '0',
|
||||||
scrollTop: '0',
|
scrollTop: '0',
|
||||||
rotation: null,
|
rotation: null,
|
||||||
sidebarView: SidebarView.NONE,
|
sidebarView: SidebarView.UNKNOWN,
|
||||||
scrollMode: null,
|
scrollMode: ScrollMode.UNKNOWN,
|
||||||
spreadMode: null,
|
spreadMode: SpreadMode.UNKNOWN,
|
||||||
}).catch(() => { /* Unable to read from storage; ignoring errors. */ });
|
}).catch(() => { /* Unable to read from storage; ignoring errors. */ });
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
storePromise, pageModePromise, openActionDestPromise,
|
storePromise, pageModePromise, openActionDestPromise,
|
||||||
]).then(async ([values = {}, pageMode, openActionDest]) => {
|
]).then(async ([values = {}, pageMode, openActionDest]) => {
|
||||||
if (openActionDest && !this.initialBookmark &&
|
const viewOnLoad = AppOptions.get('viewOnLoad');
|
||||||
!AppOptions.get('disableOpenActionDestination')) {
|
|
||||||
// Always let the browser history/document hash take precedence.
|
this._initializePdfHistory({
|
||||||
this.initialBookmark = JSON.stringify(openActionDest);
|
fingerprint: pdfDocument.fingerprint,
|
||||||
// TODO: Re-factor the `PDFHistory` initialization to remove this hack
|
viewOnLoad,
|
||||||
// that's currently necessary to prevent weird initial history state.
|
initialDest: openActionDest,
|
||||||
this.pdfHistory.push({ explicitDest: openActionDest,
|
});
|
||||||
pageNumber: null, });
|
|
||||||
}
|
|
||||||
const initialBookmark = this.initialBookmark;
|
const initialBookmark = this.initialBookmark;
|
||||||
|
|
||||||
// Initialize the default values, from user preferences.
|
// Initialize the default values, from user preferences.
|
||||||
const zoom = AppOptions.get('defaultZoomValue');
|
const zoom = AppOptions.get('defaultZoomValue');
|
||||||
let hash = zoom ? `zoom=${zoom}` : null;
|
let hash = zoom ? `zoom=${zoom}` : null;
|
||||||
@ -949,18 +939,25 @@ let PDFViewerApplication = {
|
|||||||
let scrollMode = AppOptions.get('scrollModeOnLoad');
|
let scrollMode = AppOptions.get('scrollModeOnLoad');
|
||||||
let spreadMode = AppOptions.get('spreadModeOnLoad');
|
let spreadMode = AppOptions.get('spreadModeOnLoad');
|
||||||
|
|
||||||
if (values.page && AppOptions.get('showPreviousViewOnLoad')) {
|
if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) {
|
||||||
hash = 'page=' + values.page + '&zoom=' + (zoom || values.zoom) +
|
hash = `page=${values.page}&zoom=${zoom || values.zoom},` +
|
||||||
',' + values.scrollLeft + ',' + values.scrollTop;
|
`${values.scrollLeft},${values.scrollTop}`;
|
||||||
|
|
||||||
rotation = parseInt(values.rotation, 10);
|
rotation = parseInt(values.rotation, 10);
|
||||||
sidebarView = sidebarView || (values.sidebarView | 0);
|
// Always let user preferences take precedence over the view history.
|
||||||
scrollMode = scrollMode || (values.scrollMode | 0);
|
if (sidebarView === SidebarView.UNKNOWN) {
|
||||||
spreadMode = spreadMode || (values.spreadMode | 0);
|
sidebarView = (values.sidebarView | 0);
|
||||||
}
|
}
|
||||||
if (pageMode && !AppOptions.get('disablePageMode')) {
|
if (scrollMode === ScrollMode.UNKNOWN) {
|
||||||
// Always let the user preference/history take precedence.
|
scrollMode = (values.scrollMode | 0);
|
||||||
sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
|
}
|
||||||
|
if (spreadMode === SpreadMode.UNKNOWN) {
|
||||||
|
spreadMode = (values.spreadMode | 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Always let the user preference/view history take precedence.
|
||||||
|
if (pageMode && sidebarView === SidebarView.UNKNOWN) {
|
||||||
|
sidebarView = apiPageModeToSidebarView(pageMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setInitialView(hash, {
|
this.setInitialView(hash, {
|
||||||
@ -1147,30 +1144,57 @@ let PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null, }) {
|
||||||
|
if (AppOptions.get('disableHistory') || this.isViewerEmbedded) {
|
||||||
|
// The browsing history is only enabled when the viewer is standalone,
|
||||||
|
// i.e. not when it is embedded in a web page.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.pdfHistory.initialize({
|
||||||
|
fingerprint,
|
||||||
|
resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
|
||||||
|
updateUrl: AppOptions.get('historyUpdateUrl'),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.pdfHistory.initialBookmark) {
|
||||||
|
this.initialBookmark = this.pdfHistory.initialBookmark;
|
||||||
|
|
||||||
|
this.initialRotation = this.pdfHistory.initialRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always let the browser history/document hash take precedence.
|
||||||
|
if (initialDest && !this.initialBookmark &&
|
||||||
|
viewOnLoad === ViewOnLoad.UNKNOWN) {
|
||||||
|
this.initialBookmark = JSON.stringify(initialDest);
|
||||||
|
// TODO: Re-factor the `PDFHistory` initialization to remove this hack
|
||||||
|
// that's currently necessary to prevent weird initial history state.
|
||||||
|
this.pdfHistory.push({ explicitDest: initialDest, pageNumber: null, });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
setInitialView(storedHash, { rotation, sidebarView,
|
setInitialView(storedHash, { rotation, sidebarView,
|
||||||
scrollMode, spreadMode, } = {}) {
|
scrollMode, spreadMode, } = {}) {
|
||||||
let setRotation = (angle) => {
|
const setRotation = (angle) => {
|
||||||
if (isValidRotation(angle)) {
|
if (isValidRotation(angle)) {
|
||||||
this.pdfViewer.pagesRotation = angle;
|
this.pdfViewer.pagesRotation = angle;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let setViewerModes = (scroll, spread) => {
|
const setViewerModes = (scroll, spread) => {
|
||||||
if (Number.isInteger(scroll)) {
|
if (isValidScrollMode(scroll)) {
|
||||||
this.pdfViewer.scrollMode = scroll;
|
this.pdfViewer.scrollMode = scroll;
|
||||||
}
|
}
|
||||||
if (Number.isInteger(spread)) {
|
if (isValidSpreadMode(spread)) {
|
||||||
this.pdfViewer.spreadMode = spread;
|
this.pdfViewer.spreadMode = spread;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Putting these before isInitialViewSet = true prevents these values from
|
|
||||||
// being stored in the document history (and overriding any future changes
|
|
||||||
// made to the corresponding global preferences), just this once.
|
|
||||||
setViewerModes(scrollMode, spreadMode);
|
|
||||||
|
|
||||||
this.isInitialViewSet = true;
|
this.isInitialViewSet = true;
|
||||||
this.pdfSidebar.setInitialView(sidebarView);
|
this.pdfSidebar.setInitialView(sidebarView);
|
||||||
|
|
||||||
|
setViewerModes(scrollMode, spreadMode);
|
||||||
|
|
||||||
if (this.initialBookmark) {
|
if (this.initialBookmark) {
|
||||||
setRotation(this.initialRotation);
|
setRotation(this.initialRotation);
|
||||||
delete this.initialRotation;
|
delete this.initialRotation;
|
||||||
|
@ -48,21 +48,11 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
disableOpenActionDestination: {
|
|
||||||
/** @type {boolean} */
|
|
||||||
value: true,
|
|
||||||
kind: OptionKind.VIEWER,
|
|
||||||
},
|
|
||||||
disablePageLabels: {
|
disablePageLabels: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
disablePageMode: {
|
|
||||||
/** @type {boolean} */
|
|
||||||
value: false,
|
|
||||||
kind: OptionKind.VIEWER,
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* The `disablePreferences` is, conditionally, defined below.
|
* The `disablePreferences` is, conditionally, defined below.
|
||||||
*/
|
*/
|
||||||
@ -106,7 +96,8 @@ const defaultOptions = {
|
|||||||
*/
|
*/
|
||||||
maxCanvasPixels: {
|
maxCanvasPixels: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: viewerCompatibilityParams.maxCanvasPixels || 16777216,
|
value: 16777216,
|
||||||
|
compatibility: viewerCompatibilityParams.maxCanvasPixels,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
pdfBugEnabled: {
|
pdfBugEnabled: {
|
||||||
@ -124,24 +115,19 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
showPreviousViewOnLoad: {
|
|
||||||
/** @type {boolean} */
|
|
||||||
value: true,
|
|
||||||
kind: OptionKind.VIEWER,
|
|
||||||
},
|
|
||||||
sidebarViewOnLoad: {
|
sidebarViewOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 0,
|
value: -1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
scrollModeOnLoad: {
|
scrollModeOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 0,
|
value: -1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
spreadModeOnLoad: {
|
spreadModeOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 0,
|
value: -1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
textLayerMode: {
|
textLayerMode: {
|
||||||
@ -154,6 +140,11 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
|
viewOnLoad: {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: 0,
|
||||||
|
kind: OptionKind.VIEWER,
|
||||||
|
},
|
||||||
|
|
||||||
cMapPacked: {
|
cMapPacked: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
@ -173,7 +164,8 @@ const defaultOptions = {
|
|||||||
},
|
},
|
||||||
disableCreateObjectURL: {
|
disableCreateObjectURL: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: apiCompatibilityParams.disableCreateObjectURL || false,
|
value: false,
|
||||||
|
compatibility: apiCompatibilityParams.disableCreateObjectURL,
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API,
|
||||||
},
|
},
|
||||||
disableFontFace: {
|
disableFontFace: {
|
||||||
@ -251,22 +243,27 @@ class AppOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get(name) {
|
static get(name) {
|
||||||
let defaultOption = defaultOptions[name], userOption = userOptions[name];
|
const userOption = userOptions[name];
|
||||||
if (userOption !== undefined) {
|
if (userOption !== undefined) {
|
||||||
return userOption;
|
return userOption;
|
||||||
}
|
}
|
||||||
return (defaultOption !== undefined ? defaultOption.value : undefined);
|
const defaultOption = defaultOptions[name];
|
||||||
|
if (defaultOption !== undefined) {
|
||||||
|
return (defaultOption.compatibility || defaultOption.value);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getAll(kind = null) {
|
static getAll(kind = null) {
|
||||||
let options = Object.create(null);
|
const options = Object.create(null);
|
||||||
for (let name in defaultOptions) {
|
for (const name in defaultOptions) {
|
||||||
let defaultOption = defaultOptions[name], userOption = userOptions[name];
|
const defaultOption = defaultOptions[name];
|
||||||
if (kind && defaultOption.kind !== kind) {
|
if (kind && kind !== defaultOption.kind) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
options[name] = (userOption !== undefined ?
|
const userOption = userOptions[name];
|
||||||
userOption : defaultOption.value);
|
options[name] = (userOption !== undefined ? userOption :
|
||||||
|
(defaultOption.compatibility || defaultOption.value));
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, getGlobalEventBus,
|
CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, getGlobalEventBus,
|
||||||
getVisibleElements, isPortraitOrientation, isValidRotation, MAX_AUTO_SCALE,
|
getVisibleElements, isPortraitOrientation, isValidRotation, isValidScrollMode,
|
||||||
moveToEndOfArray, NullL10n, PresentationModeState, RendererType,
|
isValidSpreadMode, MAX_AUTO_SCALE, moveToEndOfArray, NullL10n,
|
||||||
SCROLLBAR_PADDING, scrollIntoView, TextLayerMode, UNKNOWN_SCALE,
|
PresentationModeState, RendererType, SCROLLBAR_PADDING, scrollIntoView,
|
||||||
VERTICAL_PADDING, watchScroll
|
ScrollMode, SpreadMode, TextLayerMode, UNKNOWN_SCALE, VERTICAL_PADDING,
|
||||||
|
watchScroll
|
||||||
} from './ui_utils';
|
} from './ui_utils';
|
||||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||||
import { AnnotationLayerBuilder } from './annotation_layer_builder';
|
import { AnnotationLayerBuilder } from './annotation_layer_builder';
|
||||||
@ -29,18 +30,6 @@ import { TextLayerBuilder } from './text_layer_builder';
|
|||||||
|
|
||||||
const DEFAULT_CACHE_SIZE = 10;
|
const DEFAULT_CACHE_SIZE = 10;
|
||||||
|
|
||||||
const ScrollMode = {
|
|
||||||
VERTICAL: 0, // The default value.
|
|
||||||
HORIZONTAL: 1,
|
|
||||||
WRAPPED: 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
const SpreadMode = {
|
|
||||||
NONE: 0, // The default value.
|
|
||||||
ODD: 1,
|
|
||||||
EVEN: 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFViewerOptions
|
* @typedef {Object} PDFViewerOptions
|
||||||
* @property {HTMLDivElement} container - The container for the viewer element.
|
* @property {HTMLDivElement} container - The container for the viewer element.
|
||||||
@ -1084,7 +1073,7 @@ class BaseViewer {
|
|||||||
if (this._scrollMode === mode) {
|
if (this._scrollMode === mode) {
|
||||||
return; // The Scroll mode didn't change.
|
return; // The Scroll mode didn't change.
|
||||||
}
|
}
|
||||||
if (!Number.isInteger(mode) || !Object.values(ScrollMode).includes(mode)) {
|
if (!isValidScrollMode(mode)) {
|
||||||
throw new Error(`Invalid scroll mode: ${mode}`);
|
throw new Error(`Invalid scroll mode: ${mode}`);
|
||||||
}
|
}
|
||||||
this._scrollMode = mode;
|
this._scrollMode = mode;
|
||||||
@ -1130,7 +1119,7 @@ class BaseViewer {
|
|||||||
if (this._spreadMode === mode) {
|
if (this._spreadMode === mode) {
|
||||||
return; // The Spread mode didn't change.
|
return; // The Spread mode didn't change.
|
||||||
}
|
}
|
||||||
if (!Number.isInteger(mode) || !Object.values(SpreadMode).includes(mode)) {
|
if (!isValidSpreadMode(mode)) {
|
||||||
throw new Error(`Invalid spread mode: ${mode}`);
|
throw new Error(`Invalid spread mode: ${mode}`);
|
||||||
}
|
}
|
||||||
this._spreadMode = mode;
|
this._spreadMode = mode;
|
||||||
@ -1177,6 +1166,4 @@ class BaseViewer {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
BaseViewer,
|
BaseViewer,
|
||||||
ScrollMode,
|
|
||||||
SpreadMode,
|
|
||||||
};
|
};
|
||||||
|
@ -341,6 +341,8 @@ class ChromePreferences extends BasePreferences {
|
|||||||
enableHandToolOnLoad: false,
|
enableHandToolOnLoad: false,
|
||||||
disableTextLayer: false,
|
disableTextLayer: false,
|
||||||
enhanceTextSelection: false,
|
enhanceTextSelection: false,
|
||||||
|
showPreviousViewOnLoad: true,
|
||||||
|
disablePageMode: false,
|
||||||
}, this.defaults);
|
}, this.defaults);
|
||||||
|
|
||||||
chrome.storage.managed.get(defaultManagedPrefs, function(items) {
|
chrome.storage.managed.get(defaultManagedPrefs, function(items) {
|
||||||
@ -370,6 +372,13 @@ class ChromePreferences extends BasePreferences {
|
|||||||
delete items.disableTextLayer;
|
delete items.disableTextLayer;
|
||||||
delete items.enhanceTextSelection;
|
delete items.enhanceTextSelection;
|
||||||
|
|
||||||
|
// Migration code for https://github.com/mozilla/pdf.js/pull/10502.
|
||||||
|
if (!items.showPreviousViewOnLoad && !items.viewOnLoad) {
|
||||||
|
items.viewOnLoad = 1;
|
||||||
|
}
|
||||||
|
delete items.showPreviousViewOnLoad;
|
||||||
|
delete items.disablePageMode;
|
||||||
|
|
||||||
getPreferences(items);
|
getPreferences(items);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"showPreviousViewOnLoad": true,
|
"viewOnLoad": 0,
|
||||||
"defaultZoomValue": "",
|
"defaultZoomValue": "",
|
||||||
"sidebarViewOnLoad": 0,
|
"sidebarViewOnLoad": -1,
|
||||||
"cursorToolOnLoad": 0,
|
"cursorToolOnLoad": 0,
|
||||||
"enableWebGL": false,
|
"enableWebGL": false,
|
||||||
"eventBusDispatchToDOM": false,
|
"eventBusDispatchToDOM": false,
|
||||||
@ -16,10 +16,8 @@
|
|||||||
"renderer": "canvas",
|
"renderer": "canvas",
|
||||||
"renderInteractiveForms": false,
|
"renderInteractiveForms": false,
|
||||||
"enablePrintAutoRotate": false,
|
"enablePrintAutoRotate": false,
|
||||||
"disableOpenActionDestination": true,
|
|
||||||
"disablePageMode": false,
|
|
||||||
"disablePageLabels": false,
|
"disablePageLabels": false,
|
||||||
"historyUpdateUrl": false,
|
"historyUpdateUrl": false,
|
||||||
"scrollModeOnLoad": 0,
|
"scrollModeOnLoad": -1,
|
||||||
"spreadModeOnLoad": 0
|
"spreadModeOnLoad": -1
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,12 @@ import { RenderingStates } from './pdf_rendering_queue';
|
|||||||
const UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
|
const UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
|
||||||
|
|
||||||
const SidebarView = {
|
const SidebarView = {
|
||||||
|
UNKNOWN: -1,
|
||||||
NONE: 0,
|
NONE: 0,
|
||||||
THUMBS: 1,
|
THUMBS: 1, // Default value.
|
||||||
OUTLINE: 2,
|
OUTLINE: 2,
|
||||||
ATTACHMENTS: 3,
|
ATTACHMENTS: 3,
|
||||||
|
LAYERS: 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,18 +132,15 @@ class PDFSidebar {
|
|||||||
}
|
}
|
||||||
this.isInitialViewSet = true;
|
this.isInitialViewSet = true;
|
||||||
|
|
||||||
if (this.isOpen && view === SidebarView.NONE) {
|
// If the user has already manually opened the sidebar, immediately closing
|
||||||
|
// it would be bad UX; also ignore the "unknown" sidebar view value.
|
||||||
|
if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
|
||||||
this._dispatchEvent();
|
this._dispatchEvent();
|
||||||
// If the user has already manually opened the sidebar,
|
|
||||||
// immediately closing it would be bad UX.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let isViewPreserved = (view === this.visibleView);
|
|
||||||
this.switchView(view, /* forceOpen */ true);
|
|
||||||
|
|
||||||
if (isViewPreserved) {
|
|
||||||
// Prevent dispatching two back-to-back `sidebarviewchanged` events,
|
// Prevent dispatching two back-to-back `sidebarviewchanged` events,
|
||||||
// since `this.switchView` dispatched the event if the view changed.
|
// since `this._switchView` dispatched the event if the view changed.
|
||||||
|
if (!this._switchView(view, /* forceOpen */ true)) {
|
||||||
this._dispatchEvent();
|
this._dispatchEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,14 +152,24 @@ class PDFSidebar {
|
|||||||
* The default value is `false`.
|
* The default value is `false`.
|
||||||
*/
|
*/
|
||||||
switchView(view, forceOpen = false) {
|
switchView(view, forceOpen = false) {
|
||||||
if (view === SidebarView.NONE) {
|
this._switchView(view, forceOpen);
|
||||||
this.close();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
let isViewChanged = (view !== this.active);
|
|
||||||
|
/**
|
||||||
|
* @returns {boolean} Indicating if `this._dispatchEvent` was called.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_switchView(view, forceOpen = false) {
|
||||||
|
const isViewChanged = (view !== this.active);
|
||||||
let shouldForceRendering = false;
|
let shouldForceRendering = false;
|
||||||
|
|
||||||
switch (view) {
|
switch (view) {
|
||||||
|
case SidebarView.NONE:
|
||||||
|
if (this.isOpen) {
|
||||||
|
this.close();
|
||||||
|
return true; // Closing will trigger rendering and dispatch the event.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
case SidebarView.THUMBS:
|
case SidebarView.THUMBS:
|
||||||
this.thumbnailButton.classList.add('toggled');
|
this.thumbnailButton.classList.add('toggled');
|
||||||
this.outlineButton.classList.remove('toggled');
|
this.outlineButton.classList.remove('toggled');
|
||||||
@ -177,7 +186,7 @@ class PDFSidebar {
|
|||||||
break;
|
break;
|
||||||
case SidebarView.OUTLINE:
|
case SidebarView.OUTLINE:
|
||||||
if (this.outlineButton.disabled) {
|
if (this.outlineButton.disabled) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
this.thumbnailButton.classList.remove('toggled');
|
this.thumbnailButton.classList.remove('toggled');
|
||||||
this.outlineButton.classList.add('toggled');
|
this.outlineButton.classList.add('toggled');
|
||||||
@ -189,7 +198,7 @@ class PDFSidebar {
|
|||||||
break;
|
break;
|
||||||
case SidebarView.ATTACHMENTS:
|
case SidebarView.ATTACHMENTS:
|
||||||
if (this.attachmentsButton.disabled) {
|
if (this.attachmentsButton.disabled) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
this.thumbnailButton.classList.remove('toggled');
|
this.thumbnailButton.classList.remove('toggled');
|
||||||
this.outlineButton.classList.remove('toggled');
|
this.outlineButton.classList.remove('toggled');
|
||||||
@ -200,9 +209,8 @@ class PDFSidebar {
|
|||||||
this.attachmentsView.classList.remove('hidden');
|
this.attachmentsView.classList.remove('hidden');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error('PDFSidebar_switchView: "' + view +
|
console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
|
||||||
'" is an unsupported value.');
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Update the active view *after* it has been validated above,
|
// Update the active view *after* it has been validated above,
|
||||||
// in order to prevent setting it to an invalid state.
|
// in order to prevent setting it to an invalid state.
|
||||||
@ -210,7 +218,7 @@ class PDFSidebar {
|
|||||||
|
|
||||||
if (forceOpen && !this.isOpen) {
|
if (forceOpen && !this.isOpen) {
|
||||||
this.open();
|
this.open();
|
||||||
return; // NOTE: Opening will trigger rendering, and dispatch the event.
|
return true; // Opening will trigger rendering and dispatch the event.
|
||||||
}
|
}
|
||||||
if (shouldForceRendering) {
|
if (shouldForceRendering) {
|
||||||
this._forceRendering();
|
this._forceRendering();
|
||||||
@ -219,6 +227,7 @@ class PDFSidebar {
|
|||||||
this._dispatchEvent();
|
this._dispatchEvent();
|
||||||
}
|
}
|
||||||
this._hideUINotification(this.active);
|
this._hideUINotification(this.active);
|
||||||
|
return isViewChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
|
@ -13,10 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ScrollMode, SpreadMode } from './base_viewer';
|
import { SCROLLBAR_PADDING, ScrollMode, SpreadMode } from './ui_utils';
|
||||||
import { CursorTool } from './pdf_cursor_tools';
|
import { CursorTool } from './pdf_cursor_tools';
|
||||||
import { PDFSinglePageViewer } from './pdf_single_page_viewer';
|
import { PDFSinglePageViewer } from './pdf_single_page_viewer';
|
||||||
import { SCROLLBAR_PADDING } from './ui_utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SecondaryToolbarOptions
|
* @typedef {Object} SecondaryToolbarOptions
|
||||||
|
@ -41,6 +41,20 @@ const TextLayerMode = {
|
|||||||
ENABLE_ENHANCE: 2,
|
ENABLE_ENHANCE: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ScrollMode = {
|
||||||
|
UNKNOWN: -1,
|
||||||
|
VERTICAL: 0, // Default value.
|
||||||
|
HORIZONTAL: 1,
|
||||||
|
WRAPPED: 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
const SpreadMode = {
|
||||||
|
UNKNOWN: -1,
|
||||||
|
NONE: 0, // Default value.
|
||||||
|
ODD: 1,
|
||||||
|
EVEN: 2,
|
||||||
|
};
|
||||||
|
|
||||||
// Replaces {{arguments}} with their values.
|
// Replaces {{arguments}} with their values.
|
||||||
function formatL10nValue(text, args) {
|
function formatL10nValue(text, args) {
|
||||||
if (!args) {
|
if (!args) {
|
||||||
@ -602,6 +616,16 @@ function isValidRotation(angle) {
|
|||||||
return Number.isInteger(angle) && angle % 90 === 0;
|
return Number.isInteger(angle) && angle % 90 === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidScrollMode(mode) {
|
||||||
|
return (Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) &&
|
||||||
|
mode !== ScrollMode.UNKNOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidSpreadMode(mode) {
|
||||||
|
return (Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) &&
|
||||||
|
mode !== SpreadMode.UNKNOWN);
|
||||||
|
}
|
||||||
|
|
||||||
function isPortraitOrientation(size) {
|
function isPortraitOrientation(size) {
|
||||||
return size.width <= size.height;
|
return size.width <= size.height;
|
||||||
}
|
}
|
||||||
@ -863,10 +887,14 @@ export {
|
|||||||
SCROLLBAR_PADDING,
|
SCROLLBAR_PADDING,
|
||||||
VERTICAL_PADDING,
|
VERTICAL_PADDING,
|
||||||
isValidRotation,
|
isValidRotation,
|
||||||
|
isValidScrollMode,
|
||||||
|
isValidSpreadMode,
|
||||||
isPortraitOrientation,
|
isPortraitOrientation,
|
||||||
PresentationModeState,
|
PresentationModeState,
|
||||||
RendererType,
|
RendererType,
|
||||||
TextLayerMode,
|
TextLayerMode,
|
||||||
|
ScrollMode,
|
||||||
|
SpreadMode,
|
||||||
NullL10n,
|
NullL10n,
|
||||||
EventBus,
|
EventBus,
|
||||||
getGlobalEventBus,
|
getGlobalEventBus,
|
||||||
|
Loading…
Reference in New Issue
Block a user