2012-09-01 07:48:21 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-02-09 07:32:15 +09:00
|
|
|
/* globals PDFBug, Stats */
|
2011-05-26 23:02:52 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
animationStarted,
|
2019-12-27 00:13:49 +09:00
|
|
|
AutoPrintRegExp,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
DEFAULT_SCALE_VALUE,
|
2020-02-27 01:16:30 +09:00
|
|
|
EventBus,
|
2020-09-23 13:59:19 +09:00
|
|
|
getActiveOrFocusedElement,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getPDFFileNameFromURL,
|
|
|
|
isValidRotation,
|
|
|
|
isValidScrollMode,
|
|
|
|
isValidSpreadMode,
|
|
|
|
MAX_SCALE,
|
|
|
|
MIN_SCALE,
|
|
|
|
noContextMenuHandler,
|
2020-08-13 03:30:45 +09:00
|
|
|
normalizeWheelEventDirection,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
parseQueryString,
|
|
|
|
PresentationModeState,
|
|
|
|
ProgressBar,
|
|
|
|
RendererType,
|
|
|
|
ScrollMode,
|
|
|
|
SpreadMode,
|
|
|
|
TextLayerMode,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./ui_utils.js";
|
|
|
|
import { AppOptions, OptionKind } from "./app_options.js";
|
2017-03-28 17:15:02 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
build,
|
2020-02-17 20:49:56 +09:00
|
|
|
createPromiseCapability,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getDocument,
|
|
|
|
getFilenameFromUrl,
|
|
|
|
GlobalWorkerOptions,
|
|
|
|
InvalidPDFException,
|
|
|
|
LinkTarget,
|
|
|
|
loadScript,
|
|
|
|
MissingPDFException,
|
|
|
|
OPS,
|
|
|
|
PDFWorker,
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
PermissionFlag,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
shadow,
|
|
|
|
UnexpectedResponseException,
|
|
|
|
UNSUPPORTED_FEATURES,
|
|
|
|
version,
|
|
|
|
} from "pdfjs-lib";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js";
|
|
|
|
import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue.js";
|
|
|
|
import { PDFSidebar, SidebarView } from "./pdf_sidebar.js";
|
|
|
|
import { OverlayManager } from "./overlay_manager.js";
|
|
|
|
import { PasswordPrompt } from "./password_prompt.js";
|
|
|
|
import { PDFAttachmentViewer } from "./pdf_attachment_viewer.js";
|
|
|
|
import { PDFDocumentProperties } from "./pdf_document_properties.js";
|
|
|
|
import { PDFFindBar } from "./pdf_find_bar.js";
|
|
|
|
import { PDFFindController } from "./pdf_find_controller.js";
|
|
|
|
import { PDFHistory } from "./pdf_history.js";
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
import { PDFLayerViewer } from "./pdf_layer_viewer.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { PDFLinkService } from "./pdf_link_service.js";
|
|
|
|
import { PDFOutlineViewer } from "./pdf_outline_viewer.js";
|
|
|
|
import { PDFPresentationMode } from "./pdf_presentation_mode.js";
|
|
|
|
import { PDFSidebarResizer } from "./pdf_sidebar_resizer.js";
|
|
|
|
import { PDFThumbnailViewer } from "./pdf_thumbnail_viewer.js";
|
|
|
|
import { PDFViewer } from "./pdf_viewer.js";
|
|
|
|
import { SecondaryToolbar } from "./secondary_toolbar.js";
|
|
|
|
import { Toolbar } from "./toolbar.js";
|
Remove the `disableCreateObjectURL` option from `web/app_options.js`
Prior to PR 11601, the `disableCreateObjectURL` option was present on `getDocument` in the API, since it was (potentially) used when decoding JPEG images natively in the browser. Hence setting this option, which was done automatically using compatibility-code, were in some browsers necessary in order for e.g. JPEG images to be correctly rendered.
The downside of the `disableCreateObjectURL` option is that memory usage increases significantly, since we're forced to build and use `data:` URIs (rather than `blob:` URLs).
However, at this point in time the `disableCreateObjectURL` option is only necessary for *some* (non-essential) functionality in the default viewer; in particular:
- The openfile functionality, used only when manually opening a new file in the default viewer.
- The download functionality, used when downloading either the PDF document itself or its attached files (if such exists).
- The print functionality, in the generic `PDFPrintService` implementation.
Hence neither the general PDF.js library, nor the *basic* functionality of the default viewer, depends on the `disableCreateObjectURL` option any more; which is why I'm thus proposing that we remove the option since using it is a performance footgun.
*Please note:* To not outright break currently "supported" browsers, which lack proper `URL.createObjectURL` support, this patch purposely keeps the compatibility-code to explicitly disable `URL.createObjectURL` usage *only* for browsers which are known to not work correctly.[1]
While it's certainly possible that there's additional, likely older, browsers with broken `URL.createObjectURL` support, the last time that these types of problems were reported was over *three* years ago.[2]
Hence in the *very* unlikely event that additional problems occur, as a result of these changes, we can either add a new case in the compatibility-code or simply declare the affected browser as unsupported.
---
[1] Which are IE11 (see issue 3977), and Google Chrome on iOS (see PR 8081).
[2] Given that `URL.createObjectURL` is used by default, you'd really expect more reports if these problems were widespread.
2020-08-06 19:43:59 +09:00
|
|
|
import { viewerCompatibilityParams } from "./viewer_compatibility.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { ViewHistory } from "./view_history.js";
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
const DEFAULT_SCALE_DELTA = 1.1;
|
2018-06-26 21:08:04 +09:00
|
|
|
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms
|
|
|
|
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
2018-12-12 21:46:47 +09:00
|
|
|
const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
2012-06-19 01:48:47 +09:00
|
|
|
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
const ViewOnLoad = {
|
|
|
|
UNKNOWN: -1,
|
|
|
|
PREVIOUS: 0, // Default value.
|
|
|
|
INITIAL: 1,
|
|
|
|
};
|
|
|
|
|
2020-11-15 21:29:50 +09:00
|
|
|
const ViewerCssTheme = {
|
|
|
|
AUTOMATIC: 0, // Default value.
|
|
|
|
LIGHT: 1,
|
|
|
|
DARK: 2,
|
|
|
|
};
|
|
|
|
|
2020-07-08 22:35:09 +09:00
|
|
|
// Keep these in sync with mozilla-central's Histograms.json.
|
|
|
|
const KNOWN_VERSIONS = [
|
|
|
|
"1.0",
|
|
|
|
"1.1",
|
|
|
|
"1.2",
|
|
|
|
"1.3",
|
|
|
|
"1.4",
|
|
|
|
"1.5",
|
|
|
|
"1.6",
|
|
|
|
"1.7",
|
|
|
|
"1.8",
|
|
|
|
"1.9",
|
|
|
|
"2.0",
|
|
|
|
"2.1",
|
|
|
|
"2.2",
|
|
|
|
"2.3",
|
|
|
|
];
|
|
|
|
// Keep these in sync with mozilla-central's Histograms.json.
|
|
|
|
const KNOWN_GENERATORS = [
|
|
|
|
"acrobat distiller",
|
|
|
|
"acrobat pdfwriter",
|
|
|
|
"adobe livecycle",
|
|
|
|
"adobe pdf library",
|
|
|
|
"adobe photoshop",
|
|
|
|
"ghostscript",
|
|
|
|
"tcpdf",
|
|
|
|
"cairo",
|
|
|
|
"dvipdfm",
|
|
|
|
"dvips",
|
|
|
|
"pdftex",
|
|
|
|
"pdfkit",
|
|
|
|
"itext",
|
|
|
|
"prince",
|
|
|
|
"quarkxpress",
|
|
|
|
"mac os x",
|
|
|
|
"microsoft",
|
|
|
|
"openoffice",
|
|
|
|
"oracle",
|
|
|
|
"luradocument",
|
|
|
|
"pdf-xchange",
|
|
|
|
"antenna house",
|
|
|
|
"aspose.cells",
|
|
|
|
"fpdf",
|
|
|
|
];
|
|
|
|
|
2020-01-15 22:26:47 +09:00
|
|
|
class DefaultExternalServices {
|
|
|
|
constructor() {
|
|
|
|
throw new Error("Cannot initialize DefaultExternalServices.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static updateFindControlState(data) {}
|
|
|
|
|
|
|
|
static updateFindMatchesCount(data) {}
|
|
|
|
|
|
|
|
static initPassiveLoading(callbacks) {}
|
|
|
|
|
|
|
|
static fallback(data, callback) {}
|
|
|
|
|
|
|
|
static reportTelemetry(data) {}
|
|
|
|
|
|
|
|
static createDownloadManager(options) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createDownloadManager");
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static createPreferences() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createPreferences");
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static createL10n(options) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createL10n");
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
|
|
|
|
2020-12-08 02:23:34 +09:00
|
|
|
static createScripting() {
|
|
|
|
throw new Error("Not implemented: createScripting");
|
|
|
|
}
|
|
|
|
|
2020-01-15 22:26:47 +09:00
|
|
|
static get supportsIntegratedFind() {
|
|
|
|
return shadow(this, "supportsIntegratedFind", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get supportsDocumentFonts() {
|
|
|
|
return shadow(this, "supportsDocumentFonts", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get supportedMouseWheelZoomModifierKeys() {
|
|
|
|
return shadow(this, "supportedMouseWheelZoomModifierKeys", {
|
|
|
|
ctrlKey: true,
|
|
|
|
metaKey: true,
|
|
|
|
});
|
|
|
|
}
|
2020-02-27 23:25:33 +09:00
|
|
|
|
|
|
|
static get isInAutomation() {
|
|
|
|
return shadow(this, "isInAutomation", false);
|
|
|
|
}
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const PDFViewerApplication = {
|
2011-10-02 03:54:37 +09:00
|
|
|
initialBookmark: document.location.hash.substring(1),
|
2020-02-17 20:49:56 +09:00
|
|
|
_initializedCapability: createPromiseCapability(),
|
2012-05-15 09:19:09 +09:00
|
|
|
fellback: false,
|
2016-04-22 01:39:11 +09:00
|
|
|
appConfig: null,
|
2012-06-02 06:17:09 +09:00
|
|
|
pdfDocument: null,
|
2015-10-23 22:49:02 +09:00
|
|
|
pdfLoadingTask: null,
|
2016-10-07 06:46:30 +09:00
|
|
|
printService: null,
|
2014-09-21 02:21:49 +09:00
|
|
|
/** @type {PDFViewer} */
|
2014-09-13 11:27:45 +09:00
|
|
|
pdfViewer: null,
|
2014-09-21 02:21:49 +09:00
|
|
|
/** @type {PDFThumbnailViewer} */
|
2014-09-13 04:48:44 +09:00
|
|
|
pdfThumbnailViewer: null,
|
2014-09-21 02:21:49 +09:00
|
|
|
/** @type {PDFRenderingQueue} */
|
2014-09-16 01:18:28 +09:00
|
|
|
pdfRenderingQueue: null,
|
2015-02-04 02:09:11 +09:00
|
|
|
/** @type {PDFPresentationMode} */
|
|
|
|
pdfPresentationMode: null,
|
2015-04-25 03:47:38 +09:00
|
|
|
/** @type {PDFDocumentProperties} */
|
|
|
|
pdfDocumentProperties: null,
|
2015-04-28 00:25:32 +09:00
|
|
|
/** @type {PDFLinkService} */
|
|
|
|
pdfLinkService: null,
|
2015-04-27 23:04:11 +09:00
|
|
|
/** @type {PDFHistory} */
|
|
|
|
pdfHistory: null,
|
2016-02-22 01:54:23 +09:00
|
|
|
/** @type {PDFSidebar} */
|
|
|
|
pdfSidebar: null,
|
Implement sidebar resizing for modern browsers, by utilizing CSS variables (issue 2072)
By making use of modern CSS features, in this case [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables), implementing sidebar resizing is actually quite simple. Not only will the amount of added code be fairly small, but it should also be easy to maintain since there's no need for complicated JavaScript hacks in order to update the CSS. Another benefit is that the JavaScript code doesn't need to make detailed assumptions about the exact structure of the HTML/CSS code.
Obviously this will not work in older browsers, such as IE, that lack support for CSS variables. In those cases sidebar resizing is simply disabled (via feature detection), and the resizing DOM element hidden, and the behaviour is thus *identical* to the current (fixed-width) sidebar.
However, considering the simplicity of the implementation, I really don't see why limiting this feature to "modern" browsers is a problem.
Finally, note that a few edge-cases meant that the patch is a bit larger than what the basic functionality would dictate. Among those is first of all proper RTL support, and secondly (automatic) resizing of the sidebar when the width of the *entire* viewer changes. Another, pre-existing, issue fixed here is the incomplete interface of `NullL10n`.
*Please note:* This patch has been successfully tested in both LTR and RTL viewer locales, in recent versions of Firefox and Chrome.
Fixes 2072.
2017-10-10 23:16:05 +09:00
|
|
|
/** @type {PDFSidebarResizer} */
|
|
|
|
pdfSidebarResizer: null,
|
2016-02-21 21:36:24 +09:00
|
|
|
/** @type {PDFOutlineViewer} */
|
|
|
|
pdfOutlineViewer: null,
|
|
|
|
/** @type {PDFAttachmentViewer} */
|
|
|
|
pdfAttachmentViewer: null,
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
/** @type {PDFLayerViewer} */
|
|
|
|
pdfLayerViewer: null,
|
2016-09-07 20:30:26 +09:00
|
|
|
/** @type {PDFCursorTools} */
|
|
|
|
pdfCursorTools: null,
|
2016-03-12 21:07:43 +09:00
|
|
|
/** @type {ViewHistory} */
|
|
|
|
store: null,
|
2016-04-14 06:21:05 +09:00
|
|
|
/** @type {DownloadManager} */
|
|
|
|
downloadManager: null,
|
2017-05-26 21:52:23 +09:00
|
|
|
/** @type {OverlayManager} */
|
|
|
|
overlayManager: null,
|
2017-04-17 20:21:11 +09:00
|
|
|
/** @type {Preferences} */
|
|
|
|
preferences: null,
|
2016-11-19 03:50:29 +09:00
|
|
|
/** @type {Toolbar} */
|
|
|
|
toolbar: null,
|
|
|
|
/** @type {SecondaryToolbar} */
|
|
|
|
secondaryToolbar: null,
|
2016-04-26 07:57:15 +09:00
|
|
|
/** @type {EventBus} */
|
|
|
|
eventBus: null,
|
2017-05-04 10:05:53 +09:00
|
|
|
/** @type {IL10n} */
|
|
|
|
l10n: null,
|
2014-09-22 20:41:17 +09:00
|
|
|
isInitialViewSet: false,
|
2017-06-17 20:14:36 +09:00
|
|
|
downloadComplete: false,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
isViewerEmbedded: window.parent !== window,
|
|
|
|
url: "",
|
|
|
|
baseUrl: "",
|
2017-03-28 06:37:14 +09:00
|
|
|
externalServices: DefaultExternalServices,
|
2020-12-06 20:30:33 +09:00
|
|
|
_boundEvents: Object.create(null),
|
|
|
|
documentInfo: null,
|
|
|
|
metadata: null,
|
2020-12-06 21:00:34 +09:00
|
|
|
_contentDispositionFilename: null,
|
|
|
|
_contentLength: null,
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
triggerDelayedFallback: null,
|
2020-08-04 02:44:04 +09:00
|
|
|
_saveInProgress: false,
|
2020-08-13 03:30:45 +09:00
|
|
|
_wheelUnusedTicks: 0,
|
2020-10-24 09:21:08 +09:00
|
|
|
_idleCallbacks: new Set(),
|
2020-12-06 21:57:24 +09:00
|
|
|
_scriptingInstance: null,
|
2020-11-18 22:59:57 +09:00
|
|
|
_mouseState: Object.create(null),
|
2012-06-19 01:48:47 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
// Called once when the document is loaded.
|
2018-07-31 00:41:39 +09:00
|
|
|
async initialize(appConfig) {
|
2017-04-17 20:21:11 +09:00
|
|
|
this.preferences = this.externalServices.createPreferences();
|
2016-12-08 21:30:21 +09:00
|
|
|
this.appConfig = appConfig;
|
2016-12-11 07:10:08 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
await this._readPreferences();
|
|
|
|
await this._parseHashParameters();
|
2020-11-15 21:29:50 +09:00
|
|
|
this._forceCssTheme();
|
2018-07-31 00:41:39 +09:00
|
|
|
await this._initializeL10n();
|
2016-12-08 22:44:12 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
this.isViewerEmbedded &&
|
|
|
|
AppOptions.get("externalLinkTarget") === LinkTarget.NONE
|
|
|
|
) {
|
2018-07-31 00:41:39 +09:00
|
|
|
// Prevent external links from "replacing" the viewer,
|
|
|
|
// when it's embedded in e.g. an <iframe> or an <object>.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
AppOptions.set("externalLinkTarget", LinkTarget.TOP);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
|
|
|
await this._initializeViewerComponents();
|
|
|
|
|
|
|
|
// Bind the various event handlers *after* the viewer has been
|
|
|
|
// initialized, to prevent errors if an event arrives too soon.
|
|
|
|
this.bindEvents();
|
|
|
|
this.bindWindowEvents();
|
|
|
|
|
|
|
|
// We can start UI localization now.
|
2019-12-27 08:22:32 +09:00
|
|
|
const appContainer = appConfig.appContainer || document.documentElement;
|
2018-07-31 00:41:39 +09:00
|
|
|
this.l10n.translate(appContainer).then(() => {
|
|
|
|
// Dispatch the 'localized' event on the `eventBus` once the viewer
|
|
|
|
// has been fully initialized and translated.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.eventBus.dispatch("localized", { source: this });
|
2016-12-11 07:10:08 +09:00
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
|
2020-02-17 20:49:56 +09:00
|
|
|
this._initializedCapability.resolve();
|
2016-12-11 07:10:08 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async _readPreferences() {
|
2020-04-20 20:09:33 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
AppOptions.get("disablePreferences")
|
|
|
|
) {
|
2018-11-29 19:31:49 +09:00
|
|
|
// Give custom implementations of the default viewer a simpler way to
|
|
|
|
// opt-out of having the `Preferences` override existing `AppOptions`.
|
|
|
|
return;
|
|
|
|
}
|
2018-07-31 00:41:39 +09:00
|
|
|
try {
|
Add an `AppOptions.setAll` method, and use it in `PDFViewerApplication._readPreferences`
Given that it's generally faster to call *one* function and have it loop through an object, rather than looping through an object and calling a function for every iteration, this patch will reduce the total time spent in `PDFViewerApplication._readPreferences` ever so slightly.
Also, over time we've been adding more and more preferences, rather than removing them, so using the new `AppOptions.setAll` method should be generally beneficial as well.
While the effect of these changes is quite small, it does reduces the time it takes for the preferences to be fully initialized. Given the amount of asynchronous code during viewer initialization, every bit of time that we can save should thus help.
Especially considering the recently added `viewerCssTheme` preference, which needs to be read very early to reduce the risk of the viewer UI "flashing" visibly as the theme changes, I figured that a couple of small patches reducing the time spend reading preferences cannot hurt.
2020-11-17 21:44:15 +09:00
|
|
|
AppOptions.setAll(await this.preferences.getAll());
|
2019-03-03 19:40:56 +09:00
|
|
|
} catch (reason) {
|
Add an `AppOptions.setAll` method, and use it in `PDFViewerApplication._readPreferences`
Given that it's generally faster to call *one* function and have it loop through an object, rather than looping through an object and calling a function for every iteration, this patch will reduce the total time spent in `PDFViewerApplication._readPreferences` ever so slightly.
Also, over time we've been adding more and more preferences, rather than removing them, so using the new `AppOptions.setAll` method should be generally beneficial as well.
While the effect of these changes is quite small, it does reduces the time it takes for the preferences to be fully initialized. Given the amount of asynchronous code during viewer initialization, every bit of time that we can save should thus help.
Especially considering the recently added `viewerCssTheme` preference, which needs to be read very early to reduce the risk of the viewer UI "flashing" visibly as the theme changes, I figured that a couple of small patches reducing the time spend reading preferences cannot hurt.
2020-11-17 21:44:15 +09:00
|
|
|
console.error(`_readPreferences: "${reason?.message}".`);
|
2019-03-03 19:40:56 +09:00
|
|
|
}
|
2016-12-11 07:10:08 +09:00
|
|
|
},
|
|
|
|
|
2017-11-13 18:17:25 +09:00
|
|
|
/**
|
2020-01-23 20:05:43 +09:00
|
|
|
* Potentially parse special debugging flags in the hash section of the URL.
|
2017-11-13 18:17:25 +09:00
|
|
|
* @private
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async _parseHashParameters() {
|
2020-07-24 01:06:02 +09:00
|
|
|
if (!AppOptions.get("pdfBugEnabled")) {
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const hash = document.location.hash.substring(1);
|
2020-01-23 20:05:43 +09:00
|
|
|
if (!hash) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const hashParams = parseQueryString(hash),
|
|
|
|
waitOn = [];
|
2017-11-13 18:17:25 +09:00
|
|
|
|
2020-04-17 19:06:27 +09:00
|
|
|
if ("disableworker" in hashParams && hashParams.disableworker === "true") {
|
2018-07-31 00:41:39 +09:00
|
|
|
waitOn.push(loadFakeWorker());
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablerange" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("disableRange", hashParams.disablerange === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablestream" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("disableStream", hashParams.disablestream === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disableautofetch" in hashParams) {
|
|
|
|
AppOptions.set(
|
|
|
|
"disableAutoFetch",
|
2020-04-17 19:06:27 +09:00
|
|
|
hashParams.disableautofetch === "true"
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablefontface" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablehistory" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("disableHistory", hashParams.disablehistory === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("webgl" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("enableWebGL", hashParams.webgl === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("verbosity" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("verbosity", hashParams.verbosity | 0);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("textlayer" in hashParams) {
|
2020-04-17 19:06:27 +09:00
|
|
|
switch (hashParams.textlayer) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "off":
|
|
|
|
AppOptions.set("textLayerMode", TextLayerMode.DISABLE);
|
2018-07-31 00:41:39 +09:00
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "visible":
|
|
|
|
case "shadow":
|
|
|
|
case "hover":
|
2019-12-27 08:22:32 +09:00
|
|
|
const viewer = this.appConfig.viewerContainer;
|
2020-04-17 19:06:27 +09:00
|
|
|
viewer.classList.add("textLayer-" + hashParams.textlayer);
|
2018-07-31 00:41:39 +09:00
|
|
|
break;
|
2017-05-04 10:05:53 +09:00
|
|
|
}
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("pdfbug" in hashParams) {
|
|
|
|
AppOptions.set("pdfBug", true);
|
[api-minor] Change `Font.exportData` to, by default, stop exporting properties which are completely unused on the main-thread and/or in the API (PR 11773 follow-up)
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API.
This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread.
With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself.
All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties:
- "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API.
Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory.
- "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread.
- "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text.
- "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API.
- "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API.
- "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API.
- "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API.
2020-04-03 18:51:46 +09:00
|
|
|
AppOptions.set("fontExtraProperties", true);
|
|
|
|
|
2020-04-17 19:06:27 +09:00
|
|
|
const enabled = hashParams.pdfbug.split(",");
|
2018-07-31 00:41:39 +09:00
|
|
|
waitOn.push(loadAndEnablePDFBug(enabled));
|
|
|
|
}
|
|
|
|
// It is not possible to change locale for the (various) extension builds.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
"locale" in hashParams
|
|
|
|
) {
|
2020-04-17 19:06:27 +09:00
|
|
|
AppOptions.set("locale", hashParams.locale);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2017-11-13 18:17:25 +09:00
|
|
|
|
2020-11-17 21:37:21 +09:00
|
|
|
if (waitOn.length === 0) {
|
|
|
|
return undefined;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return Promise.all(waitOn).catch(reason => {
|
2018-10-05 20:54:16 +09:00
|
|
|
console.error(`_parseHashParameters: "${reason.message}".`);
|
|
|
|
});
|
2017-11-13 18:17:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async _initializeL10n() {
|
2020-04-20 20:09:33 +09:00
|
|
|
this.l10n = this.externalServices.createL10n(
|
|
|
|
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
|
|
? { locale: AppOptions.get("locale") }
|
|
|
|
: null
|
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
const dir = await this.l10n.getDirection();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
document.getElementsByTagName("html")[0].dir = dir;
|
2017-05-04 10:05:53 +09:00
|
|
|
},
|
|
|
|
|
2020-11-15 21:29:50 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_forceCssTheme() {
|
|
|
|
const cssTheme = AppOptions.get("viewerCssTheme");
|
|
|
|
if (
|
|
|
|
cssTheme === ViewerCssTheme.AUTOMATIC ||
|
|
|
|
!Object.values(ViewerCssTheme).includes(cssTheme)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const styleSheet = document.styleSheets[0];
|
|
|
|
const cssRules = styleSheet?.cssRules || [];
|
|
|
|
for (let i = 0, ii = cssRules.length; i < ii; i++) {
|
|
|
|
const rule = cssRules[i];
|
|
|
|
if (
|
|
|
|
rule instanceof CSSMediaRule &&
|
|
|
|
rule.media?.[0] === "(prefers-color-scheme: dark)"
|
|
|
|
) {
|
|
|
|
if (cssTheme === ViewerCssTheme.LIGHT) {
|
|
|
|
styleSheet.deleteRule(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// cssTheme === ViewerCssTheme.DARK
|
|
|
|
const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(
|
|
|
|
rule.cssText
|
|
|
|
);
|
|
|
|
if (darkRules?.[1]) {
|
|
|
|
styleSheet.deleteRule(i);
|
|
|
|
styleSheet.insertRule(darkRules[1], i);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (reason) {
|
|
|
|
console.error(`_forceCssTheme: "${reason?.message}".`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-11 07:10:08 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async _initializeViewerComponents() {
|
|
|
|
const appConfig = this.appConfig;
|
2016-12-11 07:10:08 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const eventBus =
|
|
|
|
appConfig.eventBus ||
|
2020-02-27 23:25:33 +09:00
|
|
|
new EventBus({ isInAutomation: this.externalServices.isInAutomation });
|
2018-07-31 00:41:39 +09:00
|
|
|
this.eventBus = eventBus;
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2020-02-27 23:25:33 +09:00
|
|
|
this.overlayManager = new OverlayManager();
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfRenderingQueue = new PDFRenderingQueue();
|
2018-07-31 00:41:39 +09:00
|
|
|
pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
|
|
|
this.pdfRenderingQueue = pdfRenderingQueue;
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfLinkService = new PDFLinkService({
|
2018-07-31 00:41:39 +09:00
|
|
|
eventBus,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
externalLinkTarget: AppOptions.get("externalLinkTarget"),
|
|
|
|
externalLinkRel: AppOptions.get("externalLinkRel"),
|
2020-02-17 22:04:55 +09:00
|
|
|
ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
|
|
|
this.pdfLinkService = pdfLinkService;
|
2016-09-04 03:27:01 +09:00
|
|
|
|
Remove the `disableCreateObjectURL` option from `web/app_options.js`
Prior to PR 11601, the `disableCreateObjectURL` option was present on `getDocument` in the API, since it was (potentially) used when decoding JPEG images natively in the browser. Hence setting this option, which was done automatically using compatibility-code, were in some browsers necessary in order for e.g. JPEG images to be correctly rendered.
The downside of the `disableCreateObjectURL` option is that memory usage increases significantly, since we're forced to build and use `data:` URIs (rather than `blob:` URLs).
However, at this point in time the `disableCreateObjectURL` option is only necessary for *some* (non-essential) functionality in the default viewer; in particular:
- The openfile functionality, used only when manually opening a new file in the default viewer.
- The download functionality, used when downloading either the PDF document itself or its attached files (if such exists).
- The print functionality, in the generic `PDFPrintService` implementation.
Hence neither the general PDF.js library, nor the *basic* functionality of the default viewer, depends on the `disableCreateObjectURL` option any more; which is why I'm thus proposing that we remove the option since using it is a performance footgun.
*Please note:* To not outright break currently "supported" browsers, which lack proper `URL.createObjectURL` support, this patch purposely keeps the compatibility-code to explicitly disable `URL.createObjectURL` usage *only* for browsers which are known to not work correctly.[1]
While it's certainly possible that there's additional, likely older, browsers with broken `URL.createObjectURL` support, the last time that these types of problems were reported was over *three* years ago.[2]
Hence in the *very* unlikely event that additional problems occur, as a result of these changes, we can either add a new case in the compatibility-code or simply declare the affected browser as unsupported.
---
[1] Which are IE11 (see issue 3977), and Google Chrome on iOS (see PR 8081).
[2] Given that `URL.createObjectURL` is used by default, you'd really expect more reports if these problems were widespread.
2020-08-06 19:43:59 +09:00
|
|
|
const downloadManager = this.externalServices.createDownloadManager();
|
2018-07-31 00:41:39 +09:00
|
|
|
this.downloadManager = downloadManager;
|
|
|
|
|
2018-09-23 02:44:13 +09:00
|
|
|
const findController = new PDFFindController({
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
eventBus,
|
|
|
|
});
|
|
|
|
this.findController = findController;
|
|
|
|
|
2018-10-05 17:17:37 +09:00
|
|
|
const container = appConfig.mainContainer;
|
|
|
|
const viewer = appConfig.viewerContainer;
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfViewer = new PDFViewer({
|
|
|
|
container,
|
|
|
|
viewer,
|
|
|
|
eventBus,
|
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
downloadManager,
|
2018-09-23 02:44:13 +09:00
|
|
|
findController,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
renderer: AppOptions.get("renderer"),
|
|
|
|
enableWebGL: AppOptions.get("enableWebGL"),
|
2018-07-31 00:41:39 +09:00
|
|
|
l10n: this.l10n,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
textLayerMode: AppOptions.get("textLayerMode"),
|
|
|
|
imageResourcesPath: AppOptions.get("imageResourcesPath"),
|
|
|
|
renderInteractiveForms: AppOptions.get("renderInteractiveForms"),
|
|
|
|
enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
|
|
|
|
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
|
|
|
|
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
|
2020-10-29 03:16:56 +09:00
|
|
|
enableScripting: AppOptions.get("enableScripting"),
|
2020-11-18 22:59:57 +09:00
|
|
|
mouseState: this._mouseState,
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
|
|
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
|
|
|
pdfLinkService.setViewer(this.pdfViewer);
|
|
|
|
|
|
|
|
this.pdfThumbnailViewer = new PDFThumbnailViewer({
|
2019-02-24 21:12:23 +09:00
|
|
|
container: appConfig.sidebar.thumbnailView,
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
eventBus,
|
2018-07-31 00:41:39 +09:00
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
l10n: this.l10n,
|
|
|
|
});
|
|
|
|
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfHistory = new PDFHistory({
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
eventBus,
|
|
|
|
});
|
|
|
|
pdfLinkService.setHistory(this.pdfHistory);
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2019-07-21 20:42:03 +09:00
|
|
|
if (!this.supportsIntegratedFind) {
|
|
|
|
this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfDocumentProperties = new PDFDocumentProperties(
|
|
|
|
appConfig.documentProperties,
|
|
|
|
this.overlayManager,
|
|
|
|
eventBus,
|
|
|
|
this.l10n
|
|
|
|
);
|
2016-12-08 21:30:21 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfCursorTools = new PDFCursorTools({
|
|
|
|
container,
|
|
|
|
eventBus,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
cursorToolOnLoad: AppOptions.get("cursorToolOnLoad"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
2016-12-08 21:30:21 +09:00
|
|
|
|
2018-10-05 17:17:37 +09:00
|
|
|
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
2016-12-08 21:30:21 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.secondaryToolbar = new SecondaryToolbar(
|
|
|
|
appConfig.secondaryToolbar,
|
|
|
|
container,
|
|
|
|
eventBus
|
|
|
|
);
|
2016-12-08 21:30:21 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
if (this.supportsFullscreen) {
|
|
|
|
this.pdfPresentationMode = new PDFPresentationMode({
|
|
|
|
container,
|
|
|
|
pdfViewer: this.pdfViewer,
|
2017-04-28 19:02:42 +09:00
|
|
|
eventBus,
|
2018-07-31 00:41:39 +09:00
|
|
|
contextMenuItems: appConfig.fullscreen,
|
2016-09-04 03:27:01 +09:00
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2016-09-04 03:27:01 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.passwordPrompt = new PasswordPrompt(
|
|
|
|
appConfig.passwordOverlay,
|
|
|
|
this.overlayManager,
|
|
|
|
this.l10n
|
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
|
|
|
|
this.pdfOutlineViewer = new PDFOutlineViewer({
|
|
|
|
container: appConfig.sidebar.outlineView,
|
|
|
|
eventBus,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
});
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfAttachmentViewer = new PDFAttachmentViewer({
|
|
|
|
container: appConfig.sidebar.attachmentsView,
|
|
|
|
eventBus,
|
|
|
|
downloadManager,
|
2016-09-04 03:27:01 +09:00
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
this.pdfLayerViewer = new PDFLayerViewer({
|
|
|
|
container: appConfig.sidebar.layersView,
|
|
|
|
eventBus,
|
|
|
|
l10n: this.l10n,
|
|
|
|
});
|
|
|
|
|
2019-02-24 21:12:23 +09:00
|
|
|
this.pdfSidebar = new PDFSidebar({
|
|
|
|
elements: appConfig.sidebar,
|
|
|
|
pdfViewer: this.pdfViewer,
|
|
|
|
pdfThumbnailViewer: this.pdfThumbnailViewer,
|
|
|
|
eventBus,
|
|
|
|
l10n: this.l10n,
|
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfSidebarResizer = new PDFSidebarResizer(
|
|
|
|
appConfig.sidebarResizer,
|
|
|
|
eventBus,
|
|
|
|
this.l10n
|
|
|
|
);
|
2012-04-26 03:34:28 +09:00
|
|
|
},
|
2011-07-29 02:48:05 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
run(config) {
|
2016-04-22 01:39:11 +09:00
|
|
|
this.initialize(config).then(webViewerInitialized);
|
2016-04-02 00:29:44 +09:00
|
|
|
},
|
|
|
|
|
2020-02-17 20:49:56 +09:00
|
|
|
get initialized() {
|
|
|
|
return this._initializedCapability.settled;
|
|
|
|
},
|
|
|
|
|
|
|
|
get initializedPromise() {
|
|
|
|
return this._initializedCapability.promise;
|
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
zoomIn(ticks) {
|
2019-07-11 22:35:05 +09:00
|
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
let newScale = this.pdfViewer.currentScale;
|
2013-08-27 04:00:35 +09:00
|
|
|
do {
|
|
|
|
newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
|
|
|
newScale = Math.ceil(newScale * 10) / 10;
|
|
|
|
newScale = Math.min(MAX_SCALE, newScale);
|
2015-05-14 12:27:56 +09:00
|
|
|
} while (--ticks > 0 && newScale < MAX_SCALE);
|
2015-07-11 18:47:45 +09:00
|
|
|
this.pdfViewer.currentScaleValue = newScale;
|
2011-09-03 10:16:52 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
zoomOut(ticks) {
|
2019-07-11 22:35:05 +09:00
|
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
let newScale = this.pdfViewer.currentScale;
|
2013-08-27 04:00:35 +09:00
|
|
|
do {
|
|
|
|
newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
|
|
|
newScale = Math.floor(newScale * 10) / 10;
|
|
|
|
newScale = Math.max(MIN_SCALE, newScale);
|
2015-05-14 12:27:56 +09:00
|
|
|
} while (--ticks > 0 && newScale > MIN_SCALE);
|
2015-07-11 18:47:45 +09:00
|
|
|
this.pdfViewer.currentScaleValue = newScale;
|
2011-09-03 10:16:52 +09:00
|
|
|
},
|
|
|
|
|
2019-07-17 18:59:56 +09:00
|
|
|
zoomReset() {
|
2019-03-19 18:45:27 +09:00
|
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
|
|
|
|
},
|
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
get pagesCount() {
|
2016-08-07 20:10:50 +09:00
|
|
|
return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
2014-09-13 11:27:45 +09:00
|
|
|
},
|
2011-10-15 11:05:57 +09:00
|
|
|
|
2016-08-07 20:10:50 +09:00
|
|
|
get page() {
|
|
|
|
return this.pdfViewer.currentPageNumber;
|
2011-07-29 02:48:05 +09:00
|
|
|
},
|
|
|
|
|
2020-05-07 18:43:19 +09:00
|
|
|
set page(val) {
|
|
|
|
this.pdfViewer.currentPageNumber = val;
|
|
|
|
},
|
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
get supportsPrinting() {
|
|
|
|
return PDFPrintServiceFactory.instance.supportsPrinting;
|
2012-06-29 01:50:25 +09:00
|
|
|
},
|
|
|
|
|
2012-07-31 00:12:49 +09:00
|
|
|
get supportsFullscreen() {
|
2017-06-29 19:14:26 +09:00
|
|
|
let support;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
|
|
support =
|
|
|
|
document.fullscreenEnabled === true ||
|
|
|
|
document.mozFullScreenEnabled === true;
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
2019-12-27 08:22:32 +09:00
|
|
|
const doc = document.documentElement;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
support = !!(
|
|
|
|
doc.requestFullscreen ||
|
|
|
|
doc.mozRequestFullScreen ||
|
2020-09-06 00:00:52 +09:00
|
|
|
doc.webkitRequestFullScreen
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
document.fullscreenEnabled === false ||
|
|
|
|
document.mozFullScreenEnabled === false ||
|
2020-09-06 00:00:52 +09:00
|
|
|
document.webkitFullscreenEnabled === false
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
) {
|
2016-10-15 00:57:53 +09:00
|
|
|
support = false;
|
|
|
|
}
|
2013-03-02 05:54:02 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return shadow(this, "supportsFullscreen", support);
|
2012-07-31 00:12:49 +09:00
|
|
|
},
|
|
|
|
|
2012-10-06 05:59:13 +09:00
|
|
|
get supportsIntegratedFind() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return this.externalServices.supportsIntegratedFind;
|
2012-10-06 05:59:13 +09:00
|
|
|
},
|
|
|
|
|
2012-12-01 07:59:51 +09:00
|
|
|
get supportsDocumentFonts() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return this.externalServices.supportsDocumentFonts;
|
2012-12-01 07:59:51 +09:00
|
|
|
},
|
|
|
|
|
2013-07-19 01:28:59 +09:00
|
|
|
get loadingBar() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const bar = new ProgressBar("#loadingBar");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return shadow(this, "loadingBar", bar);
|
2013-07-19 01:28:59 +09:00
|
|
|
},
|
|
|
|
|
2015-06-02 20:17:02 +09:00
|
|
|
get supportedMouseWheelZoomModifierKeys() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
2015-06-02 20:17:02 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
initPassiveLoading() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
2020-01-08 21:57:31 +09:00
|
|
|
!PDFJSDev.test("MOZCENTRAL || CHROME")
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
) {
|
|
|
|
throw new Error("Not implemented: initPassiveLoading");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
this.externalServices.initPassiveLoading({
|
|
|
|
onOpenWithTransport(url, length, transport) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.open(url, { length, range: transport });
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
|
|
|
onOpenWithData(data) {
|
|
|
|
PDFViewerApplication.open(data);
|
|
|
|
},
|
2018-06-17 20:25:22 +09:00
|
|
|
onOpenWithURL(url, length, originalUrl) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let file = url,
|
|
|
|
args = null;
|
2017-06-29 19:14:26 +09:00
|
|
|
if (length !== undefined) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
args = { length };
|
2017-06-29 19:14:26 +09:00
|
|
|
}
|
2018-06-17 20:25:22 +09:00
|
|
|
if (originalUrl !== undefined) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
file = { url, originalUrl };
|
2017-06-29 19:14:26 +09:00
|
|
|
}
|
|
|
|
PDFViewerApplication.open(file, args);
|
|
|
|
},
|
|
|
|
onError(err) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get(
|
|
|
|
"loading_error",
|
|
|
|
null,
|
|
|
|
"An error occurred while loading the PDF."
|
|
|
|
)
|
|
|
|
.then(msg => {
|
|
|
|
PDFViewerApplication.error(msg, err);
|
|
|
|
});
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
|
|
|
onProgress(loaded, total) {
|
|
|
|
PDFViewerApplication.progress(loaded / total);
|
|
|
|
},
|
|
|
|
});
|
2012-08-01 02:21:07 +09:00
|
|
|
},
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
setTitleUsingUrl(url = "") {
|
2012-08-01 02:21:07 +09:00
|
|
|
this.url = url;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.baseUrl = url.split("#")[0];
|
|
|
|
let title = getPDFFileNameFromURL(url, "");
|
2017-02-06 08:46:12 +09:00
|
|
|
if (!title) {
|
|
|
|
try {
|
2017-03-28 17:15:02 +09:00
|
|
|
title = decodeURIComponent(getFilenameFromUrl(url)) || url;
|
2017-06-29 19:14:26 +09:00
|
|
|
} catch (ex) {
|
2017-02-06 08:46:12 +09:00
|
|
|
// decodeURIComponent may throw URIError,
|
|
|
|
// fall back to using the unprocessed url in that case
|
|
|
|
title = url;
|
|
|
|
}
|
2012-08-27 08:49:07 +09:00
|
|
|
}
|
2017-02-06 08:46:12 +09:00
|
|
|
this.setTitle(title);
|
2012-08-01 02:21:07 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
setTitle(title) {
|
2015-03-06 12:36:08 +09:00
|
|
|
if (this.isViewerEmbedded) {
|
|
|
|
// Embedded PDF viewers should not be changing their parent page's title.
|
|
|
|
return;
|
|
|
|
}
|
2012-11-29 04:02:56 +09:00
|
|
|
document.title = title;
|
|
|
|
},
|
|
|
|
|
2020-12-08 01:21:49 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_cancelIdleCallbacks() {
|
|
|
|
if (!this._idleCallbacks.size) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const callback of this._idleCallbacks) {
|
|
|
|
window.cancelIdleCallback(callback);
|
|
|
|
}
|
|
|
|
this._idleCallbacks.clear();
|
|
|
|
},
|
|
|
|
|
2020-12-08 01:54:44 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _destroyScriptingInstance() {
|
|
|
|
if (!this._scriptingInstance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { scripting, events } = this._scriptingInstance;
|
|
|
|
try {
|
|
|
|
await scripting.destroySandbox();
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
for (const [name, listener] of events) {
|
|
|
|
window.removeEventListener(name, listener);
|
|
|
|
}
|
|
|
|
events.clear();
|
|
|
|
|
|
|
|
this._scriptingInstance = null;
|
|
|
|
},
|
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
/**
|
|
|
|
* Closes opened PDF document.
|
|
|
|
* @returns {Promise} - Returns the promise, which is resolved when all
|
|
|
|
* destruction is completed.
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async close() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorWrapper = this.appConfig.errorWrapper.container;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorWrapper.setAttribute("hidden", "true");
|
2014-04-15 19:00:46 +09:00
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
if (!this.pdfLoadingTask) {
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
2020-12-08 01:54:44 +09:00
|
|
|
const promises = [];
|
2014-03-27 05:18:53 +09:00
|
|
|
|
2020-12-08 01:54:44 +09:00
|
|
|
promises.push(this.pdfLoadingTask.destroy());
|
2015-10-23 22:49:02 +09:00
|
|
|
this.pdfLoadingTask = null;
|
|
|
|
|
|
|
|
if (this.pdfDocument) {
|
|
|
|
this.pdfDocument = null;
|
2014-03-27 05:18:53 +09:00
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
this.pdfThumbnailViewer.setDocument(null);
|
|
|
|
this.pdfViewer.setDocument(null);
|
2018-09-30 19:11:27 +09:00
|
|
|
this.pdfLinkService.setDocument(null);
|
|
|
|
this.pdfDocumentProperties.setDocument(null);
|
2015-10-23 22:49:02 +09:00
|
|
|
}
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
webViewerResetPermissions();
|
2016-03-12 21:07:43 +09:00
|
|
|
this.store = null;
|
|
|
|
this.isInitialViewSet = false;
|
2017-06-17 20:14:36 +09:00
|
|
|
this.downloadComplete = false;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.url = "";
|
|
|
|
this.baseUrl = "";
|
2020-12-06 20:30:33 +09:00
|
|
|
this.documentInfo = null;
|
|
|
|
this.metadata = null;
|
2020-12-06 21:00:34 +09:00
|
|
|
this._contentDispositionFilename = null;
|
|
|
|
this._contentLength = null;
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
this.triggerDelayedFallback = null;
|
2020-08-04 02:44:04 +09:00
|
|
|
this._saveInProgress = false;
|
2020-12-08 01:21:49 +09:00
|
|
|
|
|
|
|
this._cancelIdleCallbacks();
|
2020-12-08 01:54:44 +09:00
|
|
|
promises.push(this._destroyScriptingInstance());
|
2020-12-06 21:57:24 +09:00
|
|
|
|
2016-02-22 01:54:23 +09:00
|
|
|
this.pdfSidebar.reset();
|
2016-02-21 21:36:24 +09:00
|
|
|
this.pdfOutlineViewer.reset();
|
|
|
|
this.pdfAttachmentViewer.reset();
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
this.pdfLayerViewer.reset();
|
2016-02-21 21:36:24 +09:00
|
|
|
|
2019-12-03 20:04:49 +09:00
|
|
|
if (this.pdfHistory) {
|
|
|
|
this.pdfHistory.reset();
|
|
|
|
}
|
2019-07-21 20:42:03 +09:00
|
|
|
if (this.findBar) {
|
|
|
|
this.findBar.reset();
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
this.toolbar.reset();
|
|
|
|
this.secondaryToolbar.reset();
|
2016-02-27 02:06:59 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFBug !== "undefined") {
|
2014-03-27 05:18:53 +09:00
|
|
|
PDFBug.cleanup();
|
|
|
|
}
|
2020-12-08 01:54:44 +09:00
|
|
|
return Promise.all(promises);
|
2014-03-27 05:18:53 +09:00
|
|
|
},
|
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
/**
|
|
|
|
* Opens PDF document specified by URL or array with additional arguments.
|
|
|
|
* @param {string|TypedArray|ArrayBuffer} file - PDF location or binary data.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {Object} [args] - Additional arguments for the getDocument call,
|
|
|
|
* e.g. HTTP headers ('httpHeaders') or alternative
|
|
|
|
* data transport ('range').
|
2015-10-23 22:49:02 +09:00
|
|
|
* @returns {Promise} - Returns the promise, which is resolved when document
|
|
|
|
* is opened.
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async open(file, args) {
|
2015-10-23 22:49:02 +09:00
|
|
|
if (this.pdfLoadingTask) {
|
|
|
|
// We need to destroy already opened document.
|
2018-07-31 00:41:39 +09:00
|
|
|
await this.close();
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
2018-02-17 23:33:57 +09:00
|
|
|
// Set the necessary global worker parameters, using the available options.
|
2019-02-13 22:00:23 +09:00
|
|
|
const workerParameters = AppOptions.getAll(OptionKind.WORKER);
|
2019-12-27 08:22:32 +09:00
|
|
|
for (const key in workerParameters) {
|
2018-02-17 23:33:57 +09:00
|
|
|
GlobalWorkerOptions[key] = workerParameters[key];
|
|
|
|
}
|
2014-03-27 05:18:53 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const parameters = Object.create(null);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof file === "string") {
|
|
|
|
// URL
|
2014-09-10 15:17:19 +09:00
|
|
|
this.setTitleUsingUrl(file);
|
|
|
|
parameters.url = file;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (file && "byteLength" in file) {
|
|
|
|
// ArrayBuffer
|
2014-09-10 15:17:19 +09:00
|
|
|
parameters.data = file;
|
|
|
|
} else if (file.url && file.originalUrl) {
|
|
|
|
this.setTitleUsingUrl(file.originalUrl);
|
|
|
|
parameters.url = file.url;
|
2012-05-15 03:45:07 +09:00
|
|
|
}
|
2018-02-17 23:33:57 +09:00
|
|
|
// Set the necessary API parameters, using the available options.
|
2019-02-13 22:00:23 +09:00
|
|
|
const apiParameters = AppOptions.getAll(OptionKind.API);
|
2019-12-27 08:22:32 +09:00
|
|
|
for (const key in apiParameters) {
|
2019-07-20 20:39:34 +09:00
|
|
|
let value = apiParameters[key];
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (key === "docBaseUrl" && !value) {
|
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
|
|
|
value = document.URL.split("#")[0];
|
2020-01-08 23:33:11 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
2019-07-20 20:39:34 +09:00
|
|
|
value = this.baseUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parameters[key] = value;
|
2018-02-17 23:33:57 +09:00
|
|
|
}
|
2020-11-20 22:17:23 +09:00
|
|
|
// Finally, update the API parameters with the arguments (if they exist).
|
2013-02-07 08:19:29 +09:00
|
|
|
if (args) {
|
2019-12-27 08:22:32 +09:00
|
|
|
for (const key in args) {
|
2020-11-20 22:17:23 +09:00
|
|
|
parameters[key] = args[key];
|
2013-02-07 08:19:29 +09:00
|
|
|
}
|
|
|
|
}
|
2011-07-29 02:48:05 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const loadingTask = getDocument(parameters);
|
2015-10-23 22:49:02 +09:00
|
|
|
this.pdfLoadingTask = loadingTask;
|
2015-10-21 22:54:31 +09:00
|
|
|
|
2017-05-09 20:17:39 +09:00
|
|
|
loadingTask.onPassword = (updateCallback, reason) => {
|
2019-08-21 06:43:24 +09:00
|
|
|
this.pdfLinkService.externalLinkEnabled = false;
|
2017-05-09 20:17:39 +09:00
|
|
|
this.passwordPrompt.setUpdateCallback(updateCallback, reason);
|
|
|
|
this.passwordPrompt.open();
|
2013-05-10 07:35:23 +09:00
|
|
|
};
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
loadingTask.onProgress = ({ loaded, total }) => {
|
2017-05-09 20:17:39 +09:00
|
|
|
this.progress(loaded / total);
|
2015-10-21 22:54:31 +09:00
|
|
|
};
|
2013-06-06 04:28:31 +09:00
|
|
|
|
2015-12-01 05:42:47 +09:00
|
|
|
// Listen for unsupported features to trigger the fallback UI.
|
|
|
|
loadingTask.onUnsupportedFeature = this.fallback.bind(this);
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return loadingTask.promise.then(
|
|
|
|
pdfDocument => {
|
|
|
|
this.load(pdfDocument);
|
|
|
|
},
|
|
|
|
exception => {
|
|
|
|
if (loadingTask !== this.pdfLoadingTask) {
|
|
|
|
return undefined; // Ignore errors for previously opened PDF files.
|
|
|
|
}
|
2017-11-23 21:44:26 +09:00
|
|
|
|
2020-09-29 22:45:05 +09:00
|
|
|
const message = exception?.message;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let loadingErrorMessage;
|
|
|
|
if (exception instanceof InvalidPDFException) {
|
|
|
|
// change error message also for other builds
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"invalid_file_error",
|
|
|
|
null,
|
|
|
|
"Invalid or corrupted PDF file."
|
|
|
|
);
|
|
|
|
} else if (exception instanceof MissingPDFException) {
|
|
|
|
// special message for missing PDF's
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"missing_file_error",
|
|
|
|
null,
|
|
|
|
"Missing PDF file."
|
|
|
|
);
|
|
|
|
} else if (exception instanceof UnexpectedResponseException) {
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"unexpected_response_error",
|
|
|
|
null,
|
|
|
|
"Unexpected server response."
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"loading_error",
|
|
|
|
null,
|
|
|
|
"An error occurred while loading the PDF."
|
|
|
|
);
|
|
|
|
}
|
2017-05-09 20:17:39 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return loadingErrorMessage.then(msg => {
|
|
|
|
this.error(msg, { message });
|
2020-04-22 20:35:45 +09:00
|
|
|
throw exception;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2011-07-29 02:48:05 +09:00
|
|
|
},
|
|
|
|
|
2020-08-26 18:38:50 +09:00
|
|
|
download({ sourceEventType = "download" } = {}) {
|
2014-03-14 12:23:47 +09:00
|
|
|
function downloadByUrl() {
|
2013-07-13 03:14:13 +09:00
|
|
|
downloadManager.downloadUrl(url, filename);
|
2013-03-25 02:25:57 +09:00
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const url = this.baseUrl;
|
2017-02-06 08:45:51 +09:00
|
|
|
// Use this.url instead of this.baseUrl to perform filename detection based
|
|
|
|
// on the reference fragment as ultimate fallback if needed.
|
2019-12-27 08:22:32 +09:00
|
|
|
const filename =
|
2020-12-06 21:00:34 +09:00
|
|
|
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
2019-12-27 08:22:32 +09:00
|
|
|
const downloadManager = this.downloadManager;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
downloadManager.onerror = err => {
|
2013-07-13 03:14:13 +09:00
|
|
|
// This error won't really be helpful because it's likely the
|
|
|
|
// fallback won't work either (or is already open).
|
2017-06-29 19:14:26 +09:00
|
|
|
this.error(`PDF failed to download: ${err}`);
|
2013-07-13 03:14:13 +09:00
|
|
|
};
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
// When the PDF document isn't ready, or the PDF file is still downloading,
|
|
|
|
// simply download using the URL.
|
|
|
|
if (!this.pdfDocument || !this.downloadComplete) {
|
2014-03-14 12:23:47 +09:00
|
|
|
downloadByUrl();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfDocument
|
|
|
|
.getData()
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function (data) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const blob = new Blob([data], { type: "application/pdf" });
|
2020-08-20 04:19:59 +09:00
|
|
|
downloadManager.download(blob, url, filename, sourceEventType);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
})
|
|
|
|
.catch(downloadByUrl); // Error occurred, try downloading with the URL.
|
2011-10-19 13:29:14 +09:00
|
|
|
},
|
|
|
|
|
2020-08-26 18:38:50 +09:00
|
|
|
save({ sourceEventType = "download" } = {}) {
|
2020-08-04 02:44:04 +09:00
|
|
|
if (this._saveInProgress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = this.baseUrl;
|
|
|
|
// Use this.url instead of this.baseUrl to perform filename detection based
|
|
|
|
// on the reference fragment as ultimate fallback if needed.
|
|
|
|
const filename =
|
2020-12-06 21:00:34 +09:00
|
|
|
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
2020-08-04 02:44:04 +09:00
|
|
|
const downloadManager = this.downloadManager;
|
|
|
|
downloadManager.onerror = err => {
|
|
|
|
// This error won't really be helpful because it's likely the
|
|
|
|
// fallback won't work either (or is already open).
|
|
|
|
this.error(`PDF failed to be saved: ${err}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
// When the PDF document isn't ready, or the PDF file is still downloading,
|
|
|
|
// simply download using the URL.
|
|
|
|
if (!this.pdfDocument || !this.downloadComplete) {
|
2020-08-20 04:19:59 +09:00
|
|
|
this.download({ sourceEventType });
|
2020-08-04 02:44:04 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-08 03:22:14 +09:00
|
|
|
if (this._scriptingInstance) {
|
|
|
|
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
|
|
|
id: "doc",
|
|
|
|
name: "WillSave",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:44:04 +09:00
|
|
|
this._saveInProgress = true;
|
|
|
|
this.pdfDocument
|
|
|
|
.saveDocument(this.pdfDocument.annotationStorage)
|
|
|
|
.then(data => {
|
|
|
|
const blob = new Blob([data], { type: "application/pdf" });
|
2020-08-20 04:19:59 +09:00
|
|
|
downloadManager.download(blob, url, filename, sourceEventType);
|
2020-12-08 03:22:14 +09:00
|
|
|
|
|
|
|
if (this._scriptingInstance) {
|
|
|
|
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
|
|
|
id: "doc",
|
|
|
|
name: "DidSave",
|
|
|
|
});
|
|
|
|
}
|
2020-08-04 02:44:04 +09:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2020-08-20 04:19:59 +09:00
|
|
|
this.download({ sourceEventType });
|
2020-08-13 19:48:51 +09:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this._saveInProgress = false;
|
|
|
|
});
|
2020-08-04 02:44:04 +09:00
|
|
|
},
|
|
|
|
|
2020-12-19 20:38:10 +09:00
|
|
|
downloadOrSave(options) {
|
|
|
|
if (this.pdfDocument?.annotationStorage.size > 0) {
|
|
|
|
this.save(options);
|
|
|
|
} else {
|
|
|
|
this.download(options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
/**
|
|
|
|
* For PDF documents that contain e.g. forms and javaScript, we should only
|
|
|
|
* trigger the fallback bar once the user has interacted with the page.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_delayedFallback(featureId) {
|
2020-07-08 22:35:09 +09:00
|
|
|
// Ensure that telemetry is always reported, since it's not guaranteed
|
|
|
|
// that the fallback bar will be shown (depends on user interaction).
|
|
|
|
this.externalServices.reportTelemetry({
|
|
|
|
type: "unsupportedFeature",
|
|
|
|
featureId,
|
|
|
|
});
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
|
2020-07-08 22:35:09 +09:00
|
|
|
if (!this.triggerDelayedFallback) {
|
|
|
|
this.triggerDelayedFallback = () => {
|
|
|
|
this.fallback(featureId);
|
|
|
|
this.triggerDelayedFallback = null;
|
|
|
|
};
|
2020-06-05 03:01:41 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
fallback(featureId) {
|
2020-07-08 22:35:09 +09:00
|
|
|
this.externalServices.reportTelemetry({
|
|
|
|
type: "unsupportedFeature",
|
|
|
|
featureId,
|
|
|
|
});
|
2020-06-02 02:28:30 +09:00
|
|
|
|
2020-07-08 22:35:09 +09:00
|
|
|
// Only trigger the fallback once so we don't spam the user with messages
|
|
|
|
// for one PDF.
|
|
|
|
if (this.fellback) {
|
|
|
|
return;
|
2015-04-26 08:49:37 +09:00
|
|
|
}
|
2020-07-08 22:35:09 +09:00
|
|
|
this.fellback = true;
|
|
|
|
this.externalServices.fallback(
|
|
|
|
{
|
|
|
|
featureId,
|
|
|
|
url: this.baseUrl,
|
|
|
|
},
|
|
|
|
function response(download) {
|
|
|
|
if (!download) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-26 18:38:50 +09:00
|
|
|
PDFViewerApplication.download({ sourceEventType: "download" });
|
2020-07-08 22:35:09 +09:00
|
|
|
}
|
|
|
|
);
|
2012-05-11 07:54:58 +09:00
|
|
|
},
|
|
|
|
|
2011-11-30 04:28:05 +09:00
|
|
|
/**
|
|
|
|
* Show the error box.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {string} message - A message that is human readable.
|
|
|
|
* @param {Object} [moreInfo] - Further information about the error that is
|
|
|
|
* more technical. Should have a 'message' and
|
|
|
|
* optionally a 'stack' property.
|
2011-11-30 04:28:05 +09:00
|
|
|
*/
|
2017-06-29 19:14:26 +09:00
|
|
|
error(message, moreInfo) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const moreInfoText = [
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_version_info",
|
|
|
|
{ version: version || "?", build: build || "?" },
|
|
|
|
"PDF.js v{{version}} (build: {{build}})"
|
|
|
|
),
|
|
|
|
];
|
2012-05-15 09:19:09 +09:00
|
|
|
if (moreInfo) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_message",
|
|
|
|
{ message: moreInfo.message },
|
|
|
|
"Message: {{message}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
if (moreInfo.stack) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_stack",
|
|
|
|
{ stack: moreInfo.stack },
|
|
|
|
"Stack: {{stack}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
} else {
|
|
|
|
if (moreInfo.filename) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_file",
|
|
|
|
{ file: moreInfo.filename },
|
|
|
|
"File: {{file}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
}
|
|
|
|
if (moreInfo.lineNumber) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_line",
|
|
|
|
{ line: moreInfo.lineNumber },
|
|
|
|
"Line: {{line}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 00:48:56 +09:00
|
|
|
|
2020-01-08 21:57:31 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorWrapperConfig = this.appConfig.errorWrapper;
|
|
|
|
const errorWrapper = errorWrapperConfig.container;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorWrapper.removeAttribute("hidden");
|
2011-11-29 09:55:09 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorMessage = errorWrapperConfig.errorMessage;
|
2016-10-15 00:57:53 +09:00
|
|
|
errorMessage.textContent = message;
|
2011-11-29 09:55:09 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const closeButton = errorWrapperConfig.closeButton;
|
2020-04-14 19:28:14 +09:00
|
|
|
closeButton.onclick = function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorWrapper.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
2011-11-30 04:28:05 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
|
|
|
|
const moreInfoButton = errorWrapperConfig.moreInfoButton;
|
|
|
|
const lessInfoButton = errorWrapperConfig.lessInfoButton;
|
2020-04-14 19:28:14 +09:00
|
|
|
moreInfoButton.onclick = function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorMoreInfo.removeAttribute("hidden");
|
|
|
|
moreInfoButton.setAttribute("hidden", "true");
|
|
|
|
lessInfoButton.removeAttribute("hidden");
|
|
|
|
errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
2020-04-14 19:28:14 +09:00
|
|
|
lessInfoButton.onclick = function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorMoreInfo.setAttribute("hidden", "true");
|
|
|
|
moreInfoButton.removeAttribute("hidden");
|
|
|
|
lessInfoButton.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
|
|
|
moreInfoButton.oncontextmenu = noContextMenuHandler;
|
|
|
|
lessInfoButton.oncontextmenu = noContextMenuHandler;
|
|
|
|
closeButton.oncontextmenu = noContextMenuHandler;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
moreInfoButton.removeAttribute("hidden");
|
|
|
|
lessInfoButton.setAttribute("hidden", "true");
|
|
|
|
Promise.all(moreInfoText).then(parts => {
|
|
|
|
errorMoreInfo.value = parts.join("\n");
|
2017-05-04 10:05:53 +09:00
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
Promise.all(moreInfoText).then(parts => {
|
|
|
|
console.error(message + "\n" + parts.join("\n"));
|
2017-08-28 20:49:40 +09:00
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
this.fallback();
|
|
|
|
}
|
2011-09-28 19:53:53 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
progress(level) {
|
2017-07-29 18:36:45 +09:00
|
|
|
if (this.downloadComplete) {
|
|
|
|
// Don't accidentally show the loading bar again when the entire file has
|
|
|
|
// already been fetched (only an issue when disableAutoFetch is enabled).
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const percent = Math.round(level * 100);
|
2013-04-24 02:00:31 +09:00
|
|
|
// When we transition from full request to range requests, it's possible
|
|
|
|
// that we discard some of the loaded data. This can cause the loading
|
|
|
|
// bar to move backwards. So prevent this by only updating the bar if it
|
|
|
|
// increases.
|
2014-09-22 20:41:17 +09:00
|
|
|
if (percent > this.loadingBar.percent || isNaN(percent)) {
|
|
|
|
this.loadingBar.percent = percent;
|
2014-08-17 08:06:03 +09:00
|
|
|
|
|
|
|
// When disableAutoFetch is enabled, it's not uncommon for the entire file
|
|
|
|
// to never be fetched (depends on e.g. the file structure). In this case
|
|
|
|
// the loading bar will not be completely filled, nor will it be hidden.
|
|
|
|
// To prevent displaying a partially filled loading bar permanently, we
|
|
|
|
// hide it when no data has been loaded during a certain amount of time.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const disableAutoFetch = this.pdfDocument
|
2020-04-17 19:06:27 +09:00
|
|
|
? this.pdfDocument.loadingParams.disableAutoFetch
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
: AppOptions.get("disableAutoFetch");
|
2018-02-18 06:08:45 +09:00
|
|
|
|
|
|
|
if (disableAutoFetch && percent) {
|
2014-08-17 08:06:03 +09:00
|
|
|
if (this.disableAutoFetchLoadingBarTimeout) {
|
|
|
|
clearTimeout(this.disableAutoFetchLoadingBarTimeout);
|
|
|
|
this.disableAutoFetchLoadingBarTimeout = null;
|
|
|
|
}
|
|
|
|
this.loadingBar.show();
|
|
|
|
|
2017-05-05 00:09:50 +09:00
|
|
|
this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
|
2014-08-17 08:06:03 +09:00
|
|
|
this.loadingBar.hide();
|
|
|
|
this.disableAutoFetchLoadingBarTimeout = null;
|
2017-05-05 00:09:50 +09:00
|
|
|
}, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
|
2014-08-17 08:06:03 +09:00
|
|
|
}
|
2013-04-24 02:00:31 +09:00
|
|
|
}
|
2011-09-28 19:53:53 +09:00
|
|
|
},
|
|
|
|
|
Remove the ability to pass a `scale` parameter in the (optional) `args` object parameter of `PDFViewerApplication.open(file, args)`
Since the very early days of the viewer, it's been possible to pass in a `scale` when opening a PDF file. However, most of the time it was/is actually being ignored, which limits its usefulness considerably.
In older versions of the viewer, if a document hash was present (i.e. `PDFViewerApplication.initialBookmark` being set) or if the document existed in the `ViewHistory`, the `scale` passed to `PDFViewerApplication.open` would thus always be ignored.
In addition to the above, in the current viewer there's even more cases where the `scale` parameter will be ignored: if a (valid) browser history entry exists on document load, or if the `defaultZoomValue` preference is set to a non-default value.
Hence the result is that in most situation, a `scale` passed to `PDFViewerApplication.open` will be completely ignored.
A much better, not to mention supported, way of setting the initial scale is by using the `defaultZoomLevel` preference. In comparision, this also has the advantage of being used in situations where the `scale` would be ignored.
All in all this leads to the current situation where we have code which is essentially dead, since no part of the viewer (by default) relies on it.
To clean up this code, and to avoid having to pass (basically) unused parameters around, I'd thus like to remove the ability to pass a `scale` to `PDFViewerApplication.open`.
2017-08-24 16:24:32 +09:00
|
|
|
load(pdfDocument) {
|
2012-06-02 06:17:09 +09:00
|
|
|
this.pdfDocument = pdfDocument;
|
|
|
|
|
2017-05-09 20:17:39 +09:00
|
|
|
pdfDocument.getDownloadInfo().then(() => {
|
|
|
|
this.downloadComplete = true;
|
|
|
|
this.loadingBar.hide();
|
|
|
|
|
|
|
|
firstPagePromise.then(() => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.eventBus.dispatch("documentloaded", { source: this });
|
2017-05-09 20:17:39 +09:00
|
|
|
});
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
2011-09-28 19:53:53 +09:00
|
|
|
|
2017-07-19 23:26:17 +09:00
|
|
|
// Since the `setInitialView` call below depends on this being resolved,
|
|
|
|
// fetch it early to avoid delaying initial rendering of the PDF document.
|
2020-04-14 19:28:14 +09:00
|
|
|
const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* Avoid breaking initial rendering; ignoring errors. */
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
const pageModePromise = pdfDocument.getPageMode().catch(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* Avoid breaking initial rendering; ignoring errors. */
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
const openActionPromise = pdfDocument.getOpenAction().catch(function () {
|
2020-02-28 22:54:07 +09:00
|
|
|
/* Avoid breaking initial rendering; ignoring errors. */
|
|
|
|
});
|
2017-07-19 23:26:17 +09:00
|
|
|
|
2016-11-19 03:50:29 +09:00
|
|
|
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
|
|
|
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
2012-10-11 02:26:41 +09:00
|
|
|
|
2017-05-09 20:17:39 +09:00
|
|
|
let baseDocumentUrl;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2016-10-15 00:57:53 +09:00
|
|
|
baseDocumentUrl = null;
|
2020-01-08 21:57:31 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
2016-10-01 19:05:07 +09:00
|
|
|
baseDocumentUrl = this.baseUrl;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (PDFJSDev.test("CHROME")) {
|
|
|
|
baseDocumentUrl = location.href.split("#")[0];
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2015-04-28 00:25:32 +09:00
|
|
|
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
2017-05-05 21:04:08 +09:00
|
|
|
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
2015-04-28 00:25:32 +09:00
|
|
|
|
2020-08-22 01:53:39 +09:00
|
|
|
const annotationStorage = pdfDocument.annotationStorage;
|
|
|
|
annotationStorage.onSetModified = function () {
|
|
|
|
window.addEventListener("beforeunload", beforeUnload);
|
|
|
|
};
|
|
|
|
annotationStorage.onResetModified = function () {
|
|
|
|
window.removeEventListener("beforeunload", beforeUnload);
|
|
|
|
};
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfViewer = this.pdfViewer;
|
2014-09-15 23:49:24 +09:00
|
|
|
pdfViewer.setDocument(pdfDocument);
|
Slightly improve the `BaseViewer.{firstPagePromise, onePageRendered, pagesPromise}` functionality
There's a couple of issues with this functionality:
- The respective `PromiseCapability` instances are not being reset, in `BaseViewer._resetView`, when the document is closed which is inconsistent with all other state.
- While the default viewer depends on these promises, and they thus ought to be considered part of e.g. the `PDFViewer` API-surface, they're not really defined in a particularily user-visible way (being that they're attached to the `BaseViewer` instance *inline* in `BaseViewer.setDocument`).
- There's some internal `BaseViewer` state, e.g. `BaseViewer._pageViewsReady`, which is tracked manually and could instead be tracked indirectly via the relevant `PromiseCapability`, thus reducing the need to track state *twice* since that's always best to avoid.
*Please note:* In the existing implementation, these promises are not defined *until* the `BaseViewer.setDocument` method has been called.
While it would've been simple to lift that restriction in this patch, I'm purposely choosing *not* to do so since this ensures that any Promise handlers added inside of `BaseViewer.setDocument` are always invoked *before* any external ones (and keeping that behaviour seems generally reasonable).
2020-03-07 21:11:51 +09:00
|
|
|
const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer;
|
2012-09-08 08:05:14 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfThumbnailViewer = this.pdfThumbnailViewer;
|
2016-01-23 21:56:56 +09:00
|
|
|
pdfThumbnailViewer.setDocument(pdfDocument);
|
2012-04-10 14:20:57 +09:00
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
const storedPromise = (this.store = new ViewHistory(
|
|
|
|
pdfDocument.fingerprint
|
|
|
|
))
|
|
|
|
.getMultiple({
|
|
|
|
page: null,
|
|
|
|
zoom: DEFAULT_SCALE_VALUE,
|
|
|
|
scrollLeft: "0",
|
|
|
|
scrollTop: "0",
|
|
|
|
rotation: null,
|
|
|
|
sidebarView: SidebarView.UNKNOWN,
|
|
|
|
scrollMode: ScrollMode.UNKNOWN,
|
|
|
|
spreadMode: SpreadMode.UNKNOWN,
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
/* Unable to read from storage; ignoring errors. */
|
|
|
|
return Object.create(null);
|
|
|
|
});
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstPagePromise.then(pdfPage => {
|
2017-05-09 20:17:39 +09:00
|
|
|
this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
2013-07-19 01:28:59 +09:00
|
|
|
|
2018-08-09 22:15:41 +09:00
|
|
|
Promise.all([
|
2019-09-08 21:13:50 +09:00
|
|
|
animationStarted,
|
2020-03-21 22:37:03 +09:00
|
|
|
storedPromise,
|
2019-09-08 21:13:50 +09:00
|
|
|
pageLayoutPromise,
|
|
|
|
pageModePromise,
|
2020-02-28 22:54:07 +09:00
|
|
|
openActionPromise,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
])
|
2020-03-21 22:37:03 +09:00
|
|
|
.then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
|
|
|
|
const viewOnLoad = AppOptions.get("viewOnLoad");
|
2018-06-26 21:08:00 +09:00
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
this._initializePdfHistory({
|
|
|
|
fingerprint: pdfDocument.fingerprint,
|
|
|
|
viewOnLoad,
|
|
|
|
initialDest: openAction && openAction.dest,
|
|
|
|
});
|
|
|
|
const initialBookmark = this.initialBookmark;
|
|
|
|
|
|
|
|
// Initialize the default values, from user preferences.
|
|
|
|
const zoom = AppOptions.get("defaultZoomValue");
|
|
|
|
let hash = zoom ? `zoom=${zoom}` : null;
|
|
|
|
|
|
|
|
let rotation = null;
|
|
|
|
let sidebarView = AppOptions.get("sidebarViewOnLoad");
|
|
|
|
let scrollMode = AppOptions.get("scrollModeOnLoad");
|
|
|
|
let spreadMode = AppOptions.get("spreadModeOnLoad");
|
|
|
|
|
|
|
|
if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
|
|
|
|
hash =
|
|
|
|
`page=${stored.page}&zoom=${zoom || stored.zoom},` +
|
|
|
|
`${stored.scrollLeft},${stored.scrollTop}`;
|
|
|
|
|
|
|
|
rotation = parseInt(stored.rotation, 10);
|
|
|
|
// Always let user preference take precedence over the view history.
|
|
|
|
if (sidebarView === SidebarView.UNKNOWN) {
|
|
|
|
sidebarView = stored.sidebarView | 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
if (scrollMode === ScrollMode.UNKNOWN) {
|
|
|
|
scrollMode = stored.scrollMode | 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
if (spreadMode === SpreadMode.UNKNOWN) {
|
|
|
|
spreadMode = stored.spreadMode | 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
}
|
|
|
|
// Always let the user preference/view history take precedence.
|
|
|
|
if (pageMode && sidebarView === SidebarView.UNKNOWN) {
|
|
|
|
sidebarView = apiPageModeToSidebarView(pageMode);
|
|
|
|
}
|
|
|
|
if (pageLayout && spreadMode === SpreadMode.UNKNOWN) {
|
|
|
|
spreadMode = apiPageLayoutToSpreadMode(pageLayout);
|
|
|
|
}
|
2018-06-26 21:08:00 +09:00
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
this.setInitialView(hash, {
|
|
|
|
rotation,
|
|
|
|
sidebarView,
|
|
|
|
scrollMode,
|
|
|
|
spreadMode,
|
|
|
|
});
|
|
|
|
this.eventBus.dispatch("documentinit", { source: this });
|
|
|
|
// Make all navigation keys work on document load,
|
|
|
|
// unless the viewer is embedded in a web page.
|
|
|
|
if (!this.isViewerEmbedded) {
|
|
|
|
pdfViewer.focus();
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
// Currently only the "copy"-permission is supported, hence we delay
|
|
|
|
// the `getPermissions` API call until *after* rendering has started.
|
|
|
|
this._initializePermissions(pdfDocument);
|
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
// For documents with different page sizes, once all pages are
|
|
|
|
// resolved, ensure that the correct location becomes visible on load.
|
|
|
|
// (To reduce the risk, in very large and/or slow loading documents,
|
|
|
|
// that the location changes *after* the user has started interacting
|
|
|
|
// with the viewer, wait for either `pagesPromise` or a timeout.)
|
|
|
|
await Promise.race([
|
|
|
|
pagesPromise,
|
|
|
|
new Promise(resolve => {
|
|
|
|
setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
if (!initialBookmark && !hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pdfViewer.hasEqualPageSizes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.initialBookmark = initialBookmark;
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-self-assign
|
|
|
|
pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
|
|
|
|
// Re-apply the initial document location.
|
|
|
|
this.setInitialView(hash);
|
|
|
|
})
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
.catch(() => {
|
|
|
|
// Ensure that the document is always completely initialized,
|
|
|
|
// even if there are any errors thrown above.
|
|
|
|
this.setInitialView();
|
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
// At this point, rendering of the initial page(s) should always have
|
|
|
|
// started (and may even have completed).
|
|
|
|
// To prevent any future issues, e.g. the document being completely
|
|
|
|
// blank on load, always trigger rendering here.
|
|
|
|
pdfViewer.update();
|
2018-05-15 12:10:33 +09:00
|
|
|
});
|
2013-03-09 11:08:37 +09:00
|
|
|
});
|
|
|
|
|
2020-04-05 17:59:10 +09:00
|
|
|
pagesPromise.then(() => {
|
|
|
|
this._initializeAutoPrint(pdfDocument, openActionPromise);
|
2012-04-10 14:20:57 +09:00
|
|
|
});
|
2011-12-01 10:04:45 +09:00
|
|
|
|
2019-09-08 21:13:50 +09:00
|
|
|
onePageRendered.then(() => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pdfDocument.getOutline().then(outline => {
|
|
|
|
this.pdfOutlineViewer.render({ outline });
|
2012-04-10 14:20:57 +09:00
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pdfDocument.getAttachments().then(attachments => {
|
|
|
|
this.pdfAttachmentViewer.render({ attachments });
|
2014-03-19 05:32:47 +09:00
|
|
|
});
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
// Ensure that the layers accurately reflects the current state in the
|
|
|
|
// viewer itself, rather than the default state provided by the API.
|
|
|
|
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
|
|
|
|
this.pdfLayerViewer.render({ optionalContentConfig, pdfDocument });
|
|
|
|
});
|
2020-10-24 09:21:08 +09:00
|
|
|
if ("requestIdleCallback" in window) {
|
|
|
|
const callback = window.requestIdleCallback(
|
|
|
|
() => {
|
|
|
|
this._collectTelemetry(pdfDocument);
|
|
|
|
this._idleCallbacks.delete(callback);
|
|
|
|
},
|
|
|
|
{ timeout: 1000 }
|
|
|
|
);
|
|
|
|
this._idleCallbacks.add(callback);
|
|
|
|
}
|
2020-11-05 21:22:35 +09:00
|
|
|
this._initializeJavaScript(pdfDocument);
|
2012-04-10 14:20:57 +09:00
|
|
|
});
|
|
|
|
|
2020-04-05 17:24:02 +09:00
|
|
|
this._initializePageLabels(pdfDocument);
|
2020-04-05 17:26:55 +09:00
|
|
|
this._initializeMetadata(pdfDocument);
|
2020-10-01 20:57:23 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializeJavaScript(pdfDocument) {
|
2020-12-06 21:19:14 +09:00
|
|
|
if (!AppOptions.get("enableScripting")) {
|
|
|
|
return;
|
2020-10-23 19:17:47 +09:00
|
|
|
}
|
2020-12-08 03:22:14 +09:00
|
|
|
const [objects, calculationOrder, docActions] = await Promise.all([
|
2020-12-06 21:19:14 +09:00
|
|
|
pdfDocument.getFieldObjects(),
|
|
|
|
pdfDocument.getCalculationOrderIds(),
|
2020-12-08 03:22:14 +09:00
|
|
|
pdfDocument.getJSActions(),
|
2020-12-06 21:19:14 +09:00
|
|
|
]);
|
|
|
|
|
2020-12-08 03:22:14 +09:00
|
|
|
if ((!objects && !docActions) || pdfDocument !== this.pdfDocument) {
|
|
|
|
// No FieldObjects were found in the document, no JS Actions at doc level
|
2020-12-06 21:19:14 +09:00
|
|
|
// or the document was closed while the data resolved.
|
2020-10-01 20:57:23 +09:00
|
|
|
return;
|
|
|
|
}
|
2020-12-08 03:22:14 +09:00
|
|
|
|
2020-12-08 02:23:34 +09:00
|
|
|
const scripting = this.externalServices.createScripting();
|
2020-12-06 21:57:24 +09:00
|
|
|
// Store a reference to the current scripting-instance, to allow destruction
|
|
|
|
// of the sandbox and removal of the event listeners at document closing.
|
|
|
|
this._scriptingInstance = { scripting, events: new Map() };
|
2020-12-06 20:42:56 +09:00
|
|
|
|
|
|
|
if (!this.documentInfo) {
|
|
|
|
// It should be *extremely* rare for metadata to not have been resolved
|
|
|
|
// when this code runs, but ensure that we handle that case here.
|
|
|
|
await new Promise(resolve => {
|
|
|
|
const metadataLoaded = () => {
|
|
|
|
this.eventBus._off("metadataloaded", metadataLoaded);
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
this.eventBus._on("metadataloaded", metadataLoaded);
|
|
|
|
});
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the metadata resolved.
|
|
|
|
}
|
|
|
|
}
|
2020-10-01 20:57:23 +09:00
|
|
|
|
2020-12-06 21:57:24 +09:00
|
|
|
const updateFromSandbox = event => {
|
2020-12-06 21:19:14 +09:00
|
|
|
const { detail } = event;
|
|
|
|
const { id, command, value } = detail;
|
2020-10-01 20:57:23 +09:00
|
|
|
if (!id) {
|
2020-12-06 21:19:14 +09:00
|
|
|
switch (command) {
|
2020-11-05 21:22:35 +09:00
|
|
|
case "clear":
|
|
|
|
console.clear();
|
|
|
|
break;
|
2020-10-01 20:57:23 +09:00
|
|
|
case "error":
|
2020-12-06 21:19:14 +09:00
|
|
|
console.error(value);
|
2020-10-01 20:57:23 +09:00
|
|
|
break;
|
2020-11-05 21:22:35 +09:00
|
|
|
case "layout":
|
2020-12-06 21:19:14 +09:00
|
|
|
this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(value);
|
2020-11-05 21:22:35 +09:00
|
|
|
return;
|
|
|
|
case "page-num":
|
2020-12-06 21:19:14 +09:00
|
|
|
this.pdfViewer.currentPageNumber = value + 1;
|
2020-11-05 21:22:35 +09:00
|
|
|
return;
|
|
|
|
case "print":
|
2020-12-08 03:22:14 +09:00
|
|
|
this.pdfViewer.pagesPromise.then(() => {
|
|
|
|
this.triggerPrinting();
|
|
|
|
});
|
|
|
|
return;
|
2020-11-05 21:22:35 +09:00
|
|
|
case "println":
|
2020-12-06 21:19:14 +09:00
|
|
|
console.log(value);
|
2020-11-05 21:22:35 +09:00
|
|
|
break;
|
|
|
|
case "zoom":
|
2020-12-06 21:19:14 +09:00
|
|
|
if (typeof value === "string") {
|
|
|
|
this.pdfViewer.currentScaleValue = value;
|
2020-11-05 21:22:35 +09:00
|
|
|
} else {
|
2020-12-06 21:19:14 +09:00
|
|
|
this.pdfViewer.currentScale = value;
|
2020-11-05 21:22:35 +09:00
|
|
|
}
|
2020-12-04 08:39:50 +09:00
|
|
|
break;
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const element = document.getElementById(id);
|
|
|
|
if (element) {
|
|
|
|
element.dispatchEvent(new CustomEvent("updateFromSandbox", { detail }));
|
|
|
|
} else {
|
|
|
|
if (value !== undefined && value !== null) {
|
2020-12-06 21:19:14 +09:00
|
|
|
// The element hasn't been rendered yet, use the AnnotationStorage.
|
|
|
|
pdfDocument.annotationStorage.setValue(id, value);
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
}
|
2020-12-06 21:57:24 +09:00
|
|
|
};
|
|
|
|
window.addEventListener("updateFromSandbox", updateFromSandbox);
|
|
|
|
// Ensure that the event listener can be removed at document closing.
|
|
|
|
this._scriptingInstance.events.set("updateFromSandbox", updateFromSandbox);
|
2020-10-01 20:57:23 +09:00
|
|
|
|
2020-12-06 21:57:24 +09:00
|
|
|
const dispatchEventInSandbox = event => {
|
2020-10-01 20:57:23 +09:00
|
|
|
scripting.dispatchEventInSandbox(event.detail);
|
2020-12-06 21:57:24 +09:00
|
|
|
};
|
|
|
|
window.addEventListener("dispatchEventInSandbox", dispatchEventInSandbox);
|
|
|
|
// Ensure that the event listener can be removed at document closing.
|
|
|
|
this._scriptingInstance.events.set(
|
|
|
|
"dispatchEventInSandbox",
|
|
|
|
dispatchEventInSandbox
|
|
|
|
);
|
2020-10-01 20:57:23 +09:00
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
const mouseDown = event => {
|
|
|
|
this._mouseState.isDown = true;
|
|
|
|
};
|
|
|
|
const mouseUp = event => {
|
|
|
|
this._mouseState.isDown = false;
|
|
|
|
};
|
|
|
|
window.addEventListener("mousedown", mouseDown);
|
|
|
|
this._scriptingInstance.events.set("mousedown", mouseDown);
|
|
|
|
window.addEventListener("mouseup", mouseUp);
|
|
|
|
this._scriptingInstance.events.set("mouseup", mouseUp);
|
|
|
|
|
2020-12-06 21:00:34 +09:00
|
|
|
if (!this._contentLength) {
|
|
|
|
// Always waiting for the entire PDF document to be loaded will, most
|
|
|
|
// likely, delay sandbox-creation too much in the general case for all
|
|
|
|
// PDF documents which are not provided as binary data to the API.
|
|
|
|
// Hence we'll simply have to trust that the `contentLength` (as provided
|
|
|
|
// by the server), when it exists, is accurate enough here.
|
|
|
|
const { length } = await pdfDocument.getDownloadInfo();
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the download info resolved.
|
|
|
|
}
|
|
|
|
this._contentLength = length;
|
|
|
|
}
|
2020-11-05 21:22:35 +09:00
|
|
|
const filename =
|
2020-12-06 21:00:34 +09:00
|
|
|
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
|
|
|
|
2020-12-04 08:39:50 +09:00
|
|
|
try {
|
|
|
|
await scripting.createSandbox({
|
|
|
|
objects,
|
|
|
|
calculationOrder,
|
|
|
|
appInfo: {
|
|
|
|
platform: navigator.platform,
|
|
|
|
language: navigator.language,
|
|
|
|
},
|
|
|
|
docInfo: {
|
|
|
|
...this.documentInfo,
|
|
|
|
baseURL: this.baseUrl,
|
|
|
|
filesize: this._contentLength,
|
|
|
|
filename,
|
|
|
|
metadata: this.metadata,
|
|
|
|
numPages: pdfDocument.numPages,
|
|
|
|
URL: this.url,
|
2020-12-08 03:22:14 +09:00
|
|
|
actions: docActions,
|
2020-12-04 08:39:50 +09:00
|
|
|
},
|
|
|
|
});
|
2020-12-19 01:20:40 +09:00
|
|
|
|
|
|
|
if (this.externalServices.isInAutomation) {
|
|
|
|
this.eventBus.dispatch("sandboxcreated", {
|
|
|
|
source: this,
|
|
|
|
});
|
|
|
|
}
|
2020-12-04 08:39:50 +09:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
this._destroyScriptingInstance();
|
|
|
|
}
|
2020-12-08 03:22:14 +09:00
|
|
|
|
|
|
|
scripting.dispatchEventInSandbox({
|
|
|
|
id: "doc",
|
|
|
|
name: "Open",
|
|
|
|
});
|
2020-04-05 17:26:55 +09:00
|
|
|
},
|
2020-04-05 17:24:02 +09:00
|
|
|
|
2020-10-24 09:21:08 +09:00
|
|
|
/**
|
|
|
|
* A place to fetch data for telemetry after one page is rendered and the
|
|
|
|
* viewer is idle.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _collectTelemetry(pdfDocument) {
|
|
|
|
const markInfo = await this.pdfDocument.getMarkInfo();
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // Document was closed while waiting for mark info.
|
|
|
|
}
|
|
|
|
const tagged = markInfo?.Marked || false;
|
|
|
|
this.externalServices.reportTelemetry({
|
|
|
|
type: "tagged",
|
|
|
|
tagged,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-04-05 17:59:10 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializeAutoPrint(pdfDocument, openActionPromise) {
|
|
|
|
const [openAction, javaScript] = await Promise.all([
|
|
|
|
openActionPromise,
|
|
|
|
pdfDocument.getJavaScript(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the auto print data resolved.
|
|
|
|
}
|
|
|
|
let triggerAutoPrint = false;
|
|
|
|
|
|
|
|
if (openAction && openAction.action === "Print") {
|
|
|
|
triggerAutoPrint = true;
|
|
|
|
}
|
2020-12-08 03:22:14 +09:00
|
|
|
if (javaScript && !AppOptions.get("enableScripting")) {
|
2020-04-05 17:59:10 +09:00
|
|
|
javaScript.some(js => {
|
|
|
|
if (!js) {
|
|
|
|
// Don't warn/fallback for empty JavaScript actions.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
console.warn("Warning: JavaScript is not supported");
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
this._delayedFallback(UNSUPPORTED_FEATURES.javaScript);
|
2020-04-05 17:59:10 +09:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!triggerAutoPrint) {
|
|
|
|
// Hack to support auto printing.
|
|
|
|
for (const js of javaScript) {
|
|
|
|
if (js && AutoPrintRegExp.test(js)) {
|
|
|
|
triggerAutoPrint = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (triggerAutoPrint) {
|
2020-09-30 22:02:11 +09:00
|
|
|
setTimeout(() => {
|
|
|
|
this.triggerPrinting();
|
2020-04-05 17:59:10 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializeMetadata(pdfDocument) {
|
|
|
|
const {
|
|
|
|
info,
|
|
|
|
metadata,
|
|
|
|
contentDispositionFilename,
|
2020-12-06 21:00:34 +09:00
|
|
|
contentLength,
|
2020-04-05 17:26:55 +09:00
|
|
|
} = await pdfDocument.getMetadata();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the metadata resolved.
|
|
|
|
}
|
|
|
|
this.documentInfo = info;
|
|
|
|
this.metadata = metadata;
|
2020-12-06 21:00:34 +09:00
|
|
|
this._contentDispositionFilename = contentDispositionFilename;
|
|
|
|
this._contentLength = contentLength;
|
2020-04-05 17:26:55 +09:00
|
|
|
|
|
|
|
// Provides some basic debug information
|
|
|
|
console.log(
|
2020-04-05 18:15:21 +09:00
|
|
|
`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` +
|
|
|
|
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
|
|
|
`(PDF.js: ${version || "-"}` +
|
|
|
|
`${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`
|
2020-04-05 17:26:55 +09:00
|
|
|
);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
let pdfTitle;
|
2020-04-17 19:06:27 +09:00
|
|
|
const infoTitle = info && info.Title;
|
2020-04-05 17:26:55 +09:00
|
|
|
if (infoTitle) {
|
|
|
|
pdfTitle = infoTitle;
|
|
|
|
}
|
|
|
|
const metadataTitle = metadata && metadata.get("dc:title");
|
|
|
|
if (metadataTitle) {
|
|
|
|
// Ghostscript can produce invalid 'dc:title' Metadata entries:
|
|
|
|
// - The title may be "Untitled" (fixes bug 1031612).
|
|
|
|
// - The title may contain incorrectly encoded characters, which thus
|
|
|
|
// looks broken, hence we ignore the Metadata entry when it
|
|
|
|
// contains characters from the Specials Unicode block
|
|
|
|
// (fixes bug 1605526).
|
|
|
|
if (
|
|
|
|
metadataTitle !== "Untitled" &&
|
|
|
|
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
|
|
|
|
) {
|
|
|
|
pdfTitle = metadataTitle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pdfTitle) {
|
|
|
|
this.setTitle(
|
|
|
|
`${pdfTitle} - ${contentDispositionFilename || document.title}`
|
|
|
|
);
|
|
|
|
} else if (contentDispositionFilename) {
|
|
|
|
this.setTitle(contentDispositionFilename);
|
|
|
|
}
|
2013-08-16 23:53:05 +09:00
|
|
|
|
2020-08-23 21:04:49 +09:00
|
|
|
if (info.IsXFAPresent && !info.IsAcroFormPresent) {
|
2020-08-13 01:17:58 +09:00
|
|
|
console.warn("Warning: XFA is not supported");
|
|
|
|
this._delayedFallback(UNSUPPORTED_FEATURES.forms);
|
|
|
|
} else if (
|
2020-08-23 21:04:49 +09:00
|
|
|
(info.IsAcroFormPresent || info.IsXFAPresent) &&
|
2020-08-13 01:17:58 +09:00
|
|
|
!this.pdfViewer.renderInteractiveForms
|
|
|
|
) {
|
2020-08-23 21:04:49 +09:00
|
|
|
console.warn("Warning: Interactive form support is not enabled");
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
this._delayedFallback(UNSUPPORTED_FEATURES.forms);
|
2020-04-05 17:26:55 +09:00
|
|
|
}
|
2020-01-02 04:41:15 +09:00
|
|
|
|
2020-07-08 22:35:09 +09:00
|
|
|
// Telemetry labels must be C++ variable friendly.
|
|
|
|
let versionId = "other";
|
|
|
|
if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
|
|
|
|
versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
|
|
|
|
}
|
|
|
|
let generatorId = "other";
|
|
|
|
if (info.Producer) {
|
|
|
|
const producer = info.Producer.toLowerCase();
|
|
|
|
KNOWN_GENERATORS.some(function (generator) {
|
|
|
|
if (!producer.includes(generator)) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-07 20:59:53 +09:00
|
|
|
generatorId = generator.replace(/[ .-]/g, "_");
|
2020-07-08 22:35:09 +09:00
|
|
|
return true;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
});
|
2020-04-05 17:26:55 +09:00
|
|
|
}
|
2020-07-08 22:35:09 +09:00
|
|
|
let formType = null;
|
2020-08-23 21:04:49 +09:00
|
|
|
if (info.IsXFAPresent) {
|
|
|
|
formType = "xfa";
|
|
|
|
} else if (info.IsAcroFormPresent) {
|
|
|
|
formType = "acroform";
|
2020-07-08 22:35:09 +09:00
|
|
|
}
|
|
|
|
this.externalServices.reportTelemetry({
|
|
|
|
type: "documentInfo",
|
|
|
|
version: versionId,
|
|
|
|
generator: generatorId,
|
|
|
|
formType,
|
|
|
|
});
|
2020-12-06 20:30:33 +09:00
|
|
|
|
|
|
|
this.eventBus.dispatch("metadataloaded", { source: this });
|
2012-04-10 14:20:57 +09:00
|
|
|
},
|
|
|
|
|
2020-04-05 17:24:02 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializePageLabels(pdfDocument) {
|
|
|
|
const labels = await pdfDocument.getPageLabels();
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the page labels resolved.
|
|
|
|
}
|
|
|
|
if (!labels || AppOptions.get("disablePageLabels")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const numLabels = labels.length;
|
|
|
|
if (numLabels !== this.pagesCount) {
|
|
|
|
console.error(
|
|
|
|
"The number of Page Labels does not match the number of pages in the document."
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let i = 0;
|
|
|
|
// Ignore page labels that correspond to standard page numbering.
|
|
|
|
while (i < numLabels && labels[i] === (i + 1).toString()) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i === numLabels) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { pdfViewer, pdfThumbnailViewer, toolbar } = this;
|
|
|
|
|
|
|
|
pdfViewer.setPageLabels(labels);
|
|
|
|
pdfThumbnailViewer.setPageLabels(labels);
|
|
|
|
|
|
|
|
// Changing toolbar page display to use labels and we need to set
|
|
|
|
// the label of the current page.
|
|
|
|
toolbar.setPagesCount(numLabels, true);
|
|
|
|
toolbar.setPageNumber(
|
|
|
|
pdfViewer.currentPageNumber,
|
|
|
|
pdfViewer.currentPageLabel
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-02-02 18:08:56 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
_initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null }) {
|
2020-04-05 18:15:21 +09:00
|
|
|
if (this.isViewerEmbedded || AppOptions.get("disableHistory")) {
|
2019-02-02 18:08:56 +09:00
|
|
|
// 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,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
updateUrl: AppOptions.get("historyUpdateUrl"),
|
2019-02-02 18:08:56 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
if (this.pdfHistory.initialBookmark) {
|
|
|
|
this.initialBookmark = this.pdfHistory.initialBookmark;
|
|
|
|
|
|
|
|
this.initialRotation = this.pdfHistory.initialRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always let the browser history/document hash take precedence.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
initialDest &&
|
|
|
|
!this.initialBookmark &&
|
|
|
|
viewOnLoad === ViewOnLoad.UNKNOWN
|
|
|
|
) {
|
2019-02-02 18:08:56 +09:00
|
|
|
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.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfHistory.push({ explicitDest: initialDest, pageNumber: null });
|
2019-02-02 18:08:56 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializePermissions(pdfDocument) {
|
|
|
|
const permissions = await pdfDocument.getPermissions();
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the permissions resolved.
|
|
|
|
}
|
|
|
|
if (!permissions || !AppOptions.get("enablePermissions")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Currently only the "copy"-permission is supported.
|
|
|
|
if (!permissions.includes(PermissionFlag.COPY)) {
|
|
|
|
this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
setInitialView(
|
|
|
|
storedHash,
|
|
|
|
{ rotation, sidebarView, scrollMode, spreadMode } = {}
|
|
|
|
) {
|
|
|
|
const setRotation = angle => {
|
2017-08-21 18:22:07 +09:00
|
|
|
if (isValidRotation(angle)) {
|
|
|
|
this.pdfViewer.pagesRotation = angle;
|
|
|
|
}
|
|
|
|
};
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
const setViewerModes = (scroll, spread) => {
|
|
|
|
if (isValidScrollMode(scroll)) {
|
2018-06-29 22:07:42 +09:00
|
|
|
this.pdfViewer.scrollMode = scroll;
|
2018-06-29 20:16:00 +09:00
|
|
|
}
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
if (isValidSpreadMode(spread)) {
|
2018-06-29 22:07:42 +09:00
|
|
|
this.pdfViewer.spreadMode = spread;
|
2018-06-29 20:16:00 +09:00
|
|
|
}
|
|
|
|
};
|
2014-09-22 20:41:17 +09:00
|
|
|
this.isInitialViewSet = true;
|
2017-04-22 20:42:41 +09:00
|
|
|
this.pdfSidebar.setInitialView(sidebarView);
|
2016-02-22 01:54:23 +09:00
|
|
|
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
setViewerModes(scrollMode, spreadMode);
|
|
|
|
|
2017-07-14 21:24:32 +09:00
|
|
|
if (this.initialBookmark) {
|
2017-08-21 18:56:49 +09:00
|
|
|
setRotation(this.initialRotation);
|
|
|
|
delete this.initialRotation;
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
this.pdfLinkService.setHash(this.initialBookmark);
|
2011-10-02 03:54:37 +09:00
|
|
|
this.initialBookmark = null;
|
2013-05-16 07:31:17 +09:00
|
|
|
} else if (storedHash) {
|
2017-08-21 18:22:07 +09:00
|
|
|
setRotation(rotation);
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
this.pdfLinkService.setHash(storedHash);
|
2011-12-29 10:18:55 +09:00
|
|
|
}
|
2012-01-26 12:52:10 +09:00
|
|
|
|
2016-11-19 03:50:29 +09:00
|
|
|
// Ensure that the correct page number is displayed in the UI,
|
|
|
|
// even if the active page didn't change during document load.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.toolbar.setPageNumber(
|
|
|
|
this.pdfViewer.currentPageNumber,
|
|
|
|
this.pdfViewer.currentPageLabel
|
|
|
|
);
|
2016-11-19 03:50:29 +09:00
|
|
|
this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
|
|
|
|
|
2015-03-15 04:07:17 +09:00
|
|
|
if (!this.pdfViewer.currentScaleValue) {
|
2012-01-26 12:52:10 +09:00
|
|
|
// Scale was not initialized: invalid bookmark or scale was not specified.
|
|
|
|
// Setting the default one.
|
2015-07-11 18:47:45 +09:00
|
|
|
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
|
2012-01-26 12:52:10 +09:00
|
|
|
}
|
2011-10-02 03:54:37 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
cleanup() {
|
2015-10-23 22:49:02 +09:00
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return; // run cleanup when document is loaded
|
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
this.pdfViewer.cleanup();
|
2014-09-13 04:48:44 +09:00
|
|
|
this.pdfThumbnailViewer.cleanup();
|
2016-11-19 04:03:49 +09:00
|
|
|
|
|
|
|
// We don't want to remove fonts used by active page SVGs.
|
|
|
|
if (this.pdfViewer.renderer !== RendererType.SVG) {
|
|
|
|
this.pdfDocument.cleanup();
|
|
|
|
}
|
2012-06-19 01:48:47 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
forceRendering() {
|
2020-09-30 22:02:11 +09:00
|
|
|
this.pdfRenderingQueue.printing = !!this.printService;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
|
2014-09-16 01:18:28 +09:00
|
|
|
this.pdfRenderingQueue.renderHighestPriority();
|
2012-06-19 01:48:47 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
beforePrint() {
|
2016-10-08 21:36:55 +09:00
|
|
|
if (this.printService) {
|
|
|
|
// There is no way to suppress beforePrint/afterPrint events,
|
|
|
|
// but PDFPrintService may generate double events -- this will ignore
|
|
|
|
// the second event that will be coming from native window.print().
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-29 01:50:25 +09:00
|
|
|
if (!this.supportsPrinting) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n
|
|
|
|
.get(
|
|
|
|
"printing_not_supported",
|
|
|
|
null,
|
2019-12-26 04:03:46 +09:00
|
|
|
"Warning: Printing is not fully supported by this browser."
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
)
|
|
|
|
.then(printMessage => {
|
|
|
|
this.error(printMessage);
|
|
|
|
});
|
2012-06-29 01:50:25 +09:00
|
|
|
return;
|
|
|
|
}
|
2013-03-09 11:08:37 +09:00
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
// The beforePrint is a sync method and we need to know layout before
|
|
|
|
// returning from this method. Ensure that we can get sizes of the pages.
|
|
|
|
if (!this.pdfViewer.pageViewsReady) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n
|
|
|
|
.get(
|
|
|
|
"printing_not_ready",
|
|
|
|
null,
|
|
|
|
"Warning: The PDF is not fully loaded for printing."
|
|
|
|
)
|
|
|
|
.then(notReadyMessage => {
|
2020-10-05 20:30:20 +09:00
|
|
|
// eslint-disable-next-line no-alert
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.alert(notReadyMessage);
|
|
|
|
});
|
2013-03-09 11:08:37 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pagesOverview = this.pdfViewer.getPagesOverview();
|
|
|
|
const printContainer = this.appConfig.printContainer;
|
2020-08-05 20:24:32 +09:00
|
|
|
const printResolution = AppOptions.get("printResolution");
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
const optionalContentConfigPromise = this.pdfViewer
|
|
|
|
.optionalContentConfigPromise;
|
2020-08-05 20:24:32 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const printService = PDFPrintServiceFactory.instance.createPrintService(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfDocument,
|
|
|
|
pagesOverview,
|
|
|
|
printContainer,
|
2020-08-05 20:24:32 +09:00
|
|
|
printResolution,
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
optionalContentConfigPromise,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n
|
|
|
|
);
|
2016-10-07 06:46:30 +09:00
|
|
|
this.printService = printService;
|
2014-09-16 01:18:28 +09:00
|
|
|
this.forceRendering();
|
2014-06-25 07:23:42 +09:00
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
printService.layout();
|
2014-06-15 05:55:21 +09:00
|
|
|
|
2020-07-08 22:35:09 +09:00
|
|
|
this.externalServices.reportTelemetry({
|
|
|
|
type: "print",
|
|
|
|
});
|
2012-06-29 01:50:25 +09:00
|
|
|
},
|
|
|
|
|
2019-08-24 18:48:33 +09:00
|
|
|
afterPrint() {
|
2016-10-07 06:46:30 +09:00
|
|
|
if (this.printService) {
|
|
|
|
this.printService.destroy();
|
|
|
|
this.printService = null;
|
2020-08-23 00:37:26 +09:00
|
|
|
|
|
|
|
if (this.pdfDocument) {
|
|
|
|
this.pdfDocument.annotationStorage.resetModified();
|
|
|
|
}
|
2014-03-09 20:20:32 +09:00
|
|
|
}
|
2014-09-16 01:18:28 +09:00
|
|
|
this.forceRendering();
|
2012-07-31 00:12:49 +09:00
|
|
|
},
|
|
|
|
|
2017-06-17 20:14:36 +09:00
|
|
|
rotatePages(delta) {
|
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
|
2017-08-19 21:23:40 +09:00
|
|
|
this.pdfViewer.pagesRotation = newRotation;
|
|
|
|
// Note that the thumbnail viewer is updated, and rendering is triggered,
|
|
|
|
// in the 'rotationchanging' event handler.
|
2012-09-14 05:23:44 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
requestPresentationMode() {
|
2015-02-04 02:09:11 +09:00
|
|
|
if (!this.pdfPresentationMode) {
|
2015-01-29 21:37:49 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-02-04 02:09:11 +09:00
|
|
|
this.pdfPresentationMode.request();
|
2015-01-29 21:37:49 +09:00
|
|
|
},
|
|
|
|
|
2020-09-30 22:02:11 +09:00
|
|
|
triggerPrinting() {
|
|
|
|
if (!this.supportsPrinting) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-08 03:22:14 +09:00
|
|
|
if (this._scriptingInstance) {
|
|
|
|
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
|
|
|
id: "doc",
|
|
|
|
name: "WillPrint",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-30 22:02:11 +09:00
|
|
|
window.print();
|
2020-12-08 03:22:14 +09:00
|
|
|
|
|
|
|
if (this._scriptingInstance) {
|
|
|
|
this._scriptingInstance.scripting.dispatchEventInSandbox({
|
|
|
|
id: "doc",
|
|
|
|
name: "DidPrint",
|
|
|
|
});
|
|
|
|
}
|
2020-09-30 22:02:11 +09:00
|
|
|
},
|
|
|
|
|
2017-06-14 04:11:29 +09:00
|
|
|
bindEvents() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const { eventBus, _boundEvents } = this;
|
2017-06-14 04:11:29 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.beforePrint = this.beforePrint.bind(this);
|
|
|
|
_boundEvents.afterPrint = this.afterPrint.bind(this);
|
2016-04-26 07:57:15 +09:00
|
|
|
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._on("resize", webViewerResize);
|
|
|
|
eventBus._on("hashchange", webViewerHashchange);
|
|
|
|
eventBus._on("beforeprint", _boundEvents.beforePrint);
|
|
|
|
eventBus._on("afterprint", _boundEvents.afterPrint);
|
|
|
|
eventBus._on("pagerendered", webViewerPageRendered);
|
|
|
|
eventBus._on("updateviewarea", webViewerUpdateViewarea);
|
|
|
|
eventBus._on("pagechanging", webViewerPageChanging);
|
|
|
|
eventBus._on("scalechanging", webViewerScaleChanging);
|
|
|
|
eventBus._on("rotationchanging", webViewerRotationChanging);
|
|
|
|
eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
|
|
|
|
eventBus._on("pagemode", webViewerPageMode);
|
|
|
|
eventBus._on("namedaction", webViewerNamedAction);
|
|
|
|
eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
|
|
|
|
eventBus._on("presentationmode", webViewerPresentationMode);
|
|
|
|
eventBus._on("print", webViewerPrint);
|
|
|
|
eventBus._on("download", webViewerDownload);
|
2020-08-20 04:19:59 +09:00
|
|
|
eventBus._on("save", webViewerSave);
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._on("firstpage", webViewerFirstPage);
|
|
|
|
eventBus._on("lastpage", webViewerLastPage);
|
|
|
|
eventBus._on("nextpage", webViewerNextPage);
|
|
|
|
eventBus._on("previouspage", webViewerPreviousPage);
|
|
|
|
eventBus._on("zoomin", webViewerZoomIn);
|
|
|
|
eventBus._on("zoomout", webViewerZoomOut);
|
|
|
|
eventBus._on("zoomreset", webViewerZoomReset);
|
|
|
|
eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
|
|
|
|
eventBus._on("scalechanged", webViewerScaleChanged);
|
|
|
|
eventBus._on("rotatecw", webViewerRotateCw);
|
|
|
|
eventBus._on("rotateccw", webViewerRotateCcw);
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
|
|
|
|
eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
|
|
|
|
eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
|
|
|
|
eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
|
|
|
|
eventBus._on("documentproperties", webViewerDocumentProperties);
|
|
|
|
eventBus._on("find", webViewerFind);
|
|
|
|
eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
|
|
|
|
eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
|
|
|
|
eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
|
2020-09-23 21:39:14 +09:00
|
|
|
|
|
|
|
if (AppOptions.get("pdfBug")) {
|
|
|
|
_boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
|
|
|
|
|
|
|
|
eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
|
|
|
|
eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._on("fileinputchange", webViewerFileInputChange);
|
2020-03-17 21:26:35 +09:00
|
|
|
eventBus._on("openfile", webViewerOpenFile);
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2016-12-09 00:28:40 +09:00
|
|
|
},
|
|
|
|
|
2017-06-14 04:11:29 +09:00
|
|
|
bindWindowEvents() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const { eventBus, _boundEvents } = this;
|
2016-12-09 00:28:40 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowResize = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("resize", { source: window });
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowHashChange = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("hashchange", {
|
2018-08-28 16:56:26 +09:00
|
|
|
source: window,
|
2016-12-09 00:28:40 +09:00
|
|
|
hash: document.location.hash.substring(1),
|
|
|
|
});
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowBeforePrint = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("beforeprint", { source: window });
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowAfterPrint = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("afterprint", { source: window });
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.addEventListener("visibilitychange", webViewerVisibilityChange);
|
|
|
|
window.addEventListener("wheel", webViewerWheel, { passive: false });
|
2020-08-13 04:09:42 +09:00
|
|
|
window.addEventListener("touchstart", webViewerTouchStart, {
|
|
|
|
passive: false,
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.addEventListener("click", webViewerClick);
|
|
|
|
window.addEventListener("keydown", webViewerKeyDown);
|
2020-06-02 02:28:30 +09:00
|
|
|
window.addEventListener("keyup", webViewerKeyUp);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.addEventListener("resize", _boundEvents.windowResize);
|
|
|
|
window.addEventListener("hashchange", _boundEvents.windowHashChange);
|
|
|
|
window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
|
|
|
window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
|
2017-06-14 04:11:29 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
unbindEvents() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const { eventBus, _boundEvents } = this;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._off("resize", webViewerResize);
|
|
|
|
eventBus._off("hashchange", webViewerHashchange);
|
|
|
|
eventBus._off("beforeprint", _boundEvents.beforePrint);
|
|
|
|
eventBus._off("afterprint", _boundEvents.afterPrint);
|
|
|
|
eventBus._off("pagerendered", webViewerPageRendered);
|
|
|
|
eventBus._off("updateviewarea", webViewerUpdateViewarea);
|
|
|
|
eventBus._off("pagechanging", webViewerPageChanging);
|
|
|
|
eventBus._off("scalechanging", webViewerScaleChanging);
|
|
|
|
eventBus._off("rotationchanging", webViewerRotationChanging);
|
|
|
|
eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
|
|
|
|
eventBus._off("pagemode", webViewerPageMode);
|
|
|
|
eventBus._off("namedaction", webViewerNamedAction);
|
|
|
|
eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
|
|
|
|
eventBus._off("presentationmode", webViewerPresentationMode);
|
|
|
|
eventBus._off("print", webViewerPrint);
|
|
|
|
eventBus._off("download", webViewerDownload);
|
2020-08-20 04:19:59 +09:00
|
|
|
eventBus._off("save", webViewerSave);
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._off("firstpage", webViewerFirstPage);
|
|
|
|
eventBus._off("lastpage", webViewerLastPage);
|
|
|
|
eventBus._off("nextpage", webViewerNextPage);
|
|
|
|
eventBus._off("previouspage", webViewerPreviousPage);
|
|
|
|
eventBus._off("zoomin", webViewerZoomIn);
|
|
|
|
eventBus._off("zoomout", webViewerZoomOut);
|
|
|
|
eventBus._off("zoomreset", webViewerZoomReset);
|
|
|
|
eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
|
|
|
|
eventBus._off("scalechanged", webViewerScaleChanged);
|
|
|
|
eventBus._off("rotatecw", webViewerRotateCw);
|
|
|
|
eventBus._off("rotateccw", webViewerRotateCcw);
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
|
|
|
|
eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
|
|
|
|
eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
|
|
|
|
eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
|
|
|
|
eventBus._off("documentproperties", webViewerDocumentProperties);
|
|
|
|
eventBus._off("find", webViewerFind);
|
|
|
|
eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
|
|
|
|
eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
|
|
|
|
eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
|
2020-09-23 21:39:14 +09:00
|
|
|
|
|
|
|
if (_boundEvents.reportPageStatsPDFBug) {
|
|
|
|
eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
|
|
|
|
eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
|
|
|
|
|
|
|
|
_boundEvents.reportPageStatsPDFBug = null;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._off("fileinputchange", webViewerFileInputChange);
|
2020-03-17 21:26:35 +09:00
|
|
|
eventBus._off("openfile", webViewerOpenFile);
|
2016-12-09 00:28:40 +09:00
|
|
|
}
|
2017-06-14 04:11:29 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.beforePrint = null;
|
|
|
|
_boundEvents.afterPrint = null;
|
2017-06-14 04:11:29 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
unbindWindowEvents() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const { _boundEvents } = this;
|
2017-06-29 19:14:26 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.removeEventListener("visibilitychange", webViewerVisibilityChange);
|
2020-03-25 22:53:08 +09:00
|
|
|
window.removeEventListener("wheel", webViewerWheel, { passive: false });
|
2020-08-13 04:09:42 +09:00
|
|
|
window.removeEventListener("touchstart", webViewerTouchStart, {
|
|
|
|
passive: false,
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.removeEventListener("click", webViewerClick);
|
|
|
|
window.removeEventListener("keydown", webViewerKeyDown);
|
2020-06-02 02:28:30 +09:00
|
|
|
window.removeEventListener("keyup", webViewerKeyUp);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.removeEventListener("resize", _boundEvents.windowResize);
|
|
|
|
window.removeEventListener("hashchange", _boundEvents.windowHashChange);
|
|
|
|
window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
|
|
|
window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
|
2017-06-14 04:11:29 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowResize = null;
|
|
|
|
_boundEvents.windowHashChange = null;
|
|
|
|
_boundEvents.windowBeforePrint = null;
|
|
|
|
_boundEvents.windowAfterPrint = null;
|
2016-12-09 00:28:40 +09:00
|
|
|
},
|
2020-08-13 03:30:45 +09:00
|
|
|
|
|
|
|
accumulateWheelTicks(ticks) {
|
|
|
|
// If the scroll direction changed, reset the accumulated wheel ticks.
|
|
|
|
if (
|
|
|
|
(this._wheelUnusedTicks > 0 && ticks < 0) ||
|
|
|
|
(this._wheelUnusedTicks < 0 && ticks > 0)
|
|
|
|
) {
|
|
|
|
this._wheelUnusedTicks = 0;
|
|
|
|
}
|
|
|
|
this._wheelUnusedTicks += ticks;
|
|
|
|
const wholeTicks =
|
|
|
|
Math.sign(this._wheelUnusedTicks) *
|
|
|
|
Math.floor(Math.abs(this._wheelUnusedTicks));
|
|
|
|
this._wheelUnusedTicks -= wholeTicks;
|
|
|
|
return wholeTicks;
|
|
|
|
},
|
2011-07-29 02:48:05 +09:00
|
|
|
};
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
let validateFileURL;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|
|
|
const HOSTED_VIEWER_ORIGINS = [
|
|
|
|
"null",
|
|
|
|
"http://mozilla.github.io",
|
|
|
|
"https://mozilla.github.io",
|
|
|
|
];
|
2020-04-14 19:28:14 +09:00
|
|
|
validateFileURL = function (file) {
|
2017-07-14 05:48:04 +09:00
|
|
|
if (file === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-15 00:57:53 +09:00
|
|
|
try {
|
2019-12-27 08:22:32 +09:00
|
|
|
const viewerOrigin = new URL(window.location.href).origin || "null";
|
2018-02-11 01:06:03 +09:00
|
|
|
if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
|
2016-10-15 00:57:53 +09:00
|
|
|
// Hosted or local viewer, allow for any file locations
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const { origin, protocol } = new URL(file, window.location.href);
|
2016-10-15 00:57:53 +09:00
|
|
|
// Removing of the following line will not guarantee that the viewer will
|
|
|
|
// start accepting URLs from foreign origin -- CORS headers on the remote
|
|
|
|
// server must be properly configured.
|
2018-02-23 20:48:52 +09:00
|
|
|
// IE10 / IE11 does not include an origin in `blob:`-URLs. So don't block
|
|
|
|
// any blob:-URL. The browser's same-origin policy will block requests to
|
|
|
|
// blob:-URLs from other origins, so this is safe.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (origin !== viewerOrigin && protocol !== "blob:") {
|
|
|
|
throw new Error("file origin does not match viewer's");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
} catch (ex) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const message = ex && ex.message;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get("loading_error", null, "An error occurred while loading the PDF.")
|
|
|
|
.then(loadingErrorMessage => {
|
|
|
|
PDFViewerApplication.error(loadingErrorMessage, { message });
|
|
|
|
});
|
2017-06-29 19:14:26 +09:00
|
|
|
throw ex;
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
|
|
|
};
|
2016-01-23 02:54:19 +09:00
|
|
|
}
|
|
|
|
|
2019-12-20 02:11:56 +09:00
|
|
|
async function loadFakeWorker() {
|
2018-06-07 20:52:40 +09:00
|
|
|
if (!GlobalWorkerOptions.workerSrc) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
GlobalWorkerOptions.workerSrc = AppOptions.get("workerSrc");
|
2018-06-07 20:52:40 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
2020-10-25 22:42:46 +09:00
|
|
|
window.pdfjsWorker = await import("pdfjs/core/worker.js");
|
2019-12-20 02:11:56 +09:00
|
|
|
return undefined;
|
2018-06-07 20:52:40 +09:00
|
|
|
}
|
|
|
|
return loadScript(PDFWorker.getWorkerSrc());
|
2018-01-20 02:16:17 +09:00
|
|
|
}
|
|
|
|
|
2016-05-10 08:18:43 +09:00
|
|
|
function loadAndEnablePDFBug(enabledTabs) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
2020-04-14 19:28:14 +09:00
|
|
|
return loadScript(appConfig.debuggerScriptPath).then(function () {
|
2018-06-07 20:52:40 +09:00
|
|
|
PDFBug.enable(enabledTabs);
|
2020-01-29 05:00:33 +09:00
|
|
|
PDFBug.init({ OPS }, appConfig.mainContainer);
|
2016-05-10 08:18:43 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-23 21:39:14 +09:00
|
|
|
function reportPageStatsPDFBug({ pageNumber }) {
|
|
|
|
if (typeof Stats === "undefined" || !Stats.enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const pageView = PDFViewerApplication.pdfViewer.getPageView(
|
|
|
|
/* index = */ pageNumber - 1
|
|
|
|
);
|
|
|
|
const pageStats = pageView && pageView.pdfPage && pageView.pdfPage.stats;
|
|
|
|
if (!pageStats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Stats.add(pageNumber, pageStats);
|
|
|
|
}
|
|
|
|
|
2014-04-04 02:20:53 +09:00
|
|
|
function webViewerInitialized() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
2017-06-29 19:14:26 +09:00
|
|
|
let file;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const queryString = document.location.search.substring(1);
|
|
|
|
const params = parseQueryString(queryString);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
file = "file" in params ? params.file : AppOptions.get("defaultUrl");
|
2016-10-15 00:57:53 +09:00
|
|
|
validateFileURL(file);
|
2020-01-08 21:57:31 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
[Firefox] Allow PDF attachments to, once again, be opened directly in the browser (bug 1632644)
Apparently the old link format used in MOZCENTRAL-builds, with the blob URL separated from the filename with a `?` character violates the specification; see https://bugzilla.mozilla.org/show_bug.cgi?id=1632644#c5
Obviously just removing the `?`-part of the URL would have worked, but that would also have meant that we'd no longer be able to provide the correct filename when the user attempts to download the opened PDF attachment.
To fix this we'll instead append the filename in the hash-part of the URL, which however required using a *custom* hash-parameter to avoid triggering the fallback "named destination" code-paths in the viewer.
Note that only changing the `web/pdf_attachment_viewer.js` file wasn't sufficient to fix the bug, and we also need to tweak the `webViewerInitialized` function in `web/app.js` since MOZCENTRAL-builds used to ignore *everything* in the URL hash.
This particular code is very old, but changing it *should* be completely safe given that the `PDFViewerApplication.setTitleUsingUrl` method since some time now stores both the original URL (in `this.url`) as well as one without the hash (in `this.baseUrl`). The latter one is already used everywhere where it matters, so this change seem fine to me.
This patch thus restores the original behaviour for PDF attachments in the MOZCENTRAL-build, by once again allowing them to be opened *directly* in the browser without downloading. (The fallback added in PR 11845 is obviously kept, since it seems generally useful to have.)
2020-05-20 18:27:29 +09:00
|
|
|
file = window.location.href;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (PDFJSDev.test("CHROME")) {
|
|
|
|
file = AppOptions.get("defaultUrl");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2013-08-15 06:36:40 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const fileInput = document.createElement("input");
|
2016-10-15 00:57:53 +09:00
|
|
|
fileInput.id = appConfig.openFileInputName;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fileInput.className = "fileInput";
|
|
|
|
fileInput.setAttribute("type", "file");
|
2016-10-15 00:57:53 +09:00
|
|
|
fileInput.oncontextmenu = noContextMenuHandler;
|
|
|
|
document.body.appendChild(fileInput);
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!window.File ||
|
|
|
|
!window.FileReader ||
|
|
|
|
!window.FileList ||
|
|
|
|
!window.Blob
|
|
|
|
) {
|
|
|
|
appConfig.toolbar.openFile.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
|
|
|
fileInput.value = null;
|
|
|
|
}
|
2017-09-16 20:05:01 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
fileInput.addEventListener("change", function (evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const files = evt.target.files;
|
2017-09-16 20:05:01 +09:00
|
|
|
if (!files || files.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
2018-08-28 16:56:26 +09:00
|
|
|
source: this,
|
2017-09-16 20:05:01 +09:00
|
|
|
fileInput: evt.target,
|
|
|
|
});
|
|
|
|
});
|
2018-06-10 22:39:06 +09:00
|
|
|
|
2020-03-07 12:37:22 +09:00
|
|
|
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
2020-04-14 19:28:14 +09:00
|
|
|
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
2018-06-10 22:39:06 +09:00
|
|
|
evt.preventDefault();
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
evt.dataTransfer.dropEffect = "move";
|
2018-06-10 22:39:06 +09:00
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
2018-06-10 22:39:06 +09:00
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const files = evt.dataTransfer.files;
|
|
|
|
if (!files || files.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
2018-08-28 16:56:26 +09:00
|
|
|
source: this,
|
2018-06-10 22:39:06 +09:00
|
|
|
fileInput: evt.dataTransfer,
|
|
|
|
});
|
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.openFile.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
|
2012-01-25 08:13:50 +09:00
|
|
|
}
|
2016-04-22 01:39:11 +09:00
|
|
|
|
2020-07-24 01:06:02 +09:00
|
|
|
if (!PDFViewerApplication.supportsDocumentFonts) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
AppOptions.set("disableFontFace", true);
|
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get(
|
|
|
|
"web_fonts_disabled",
|
|
|
|
null,
|
|
|
|
"Web fonts are disabled: unable to use embedded PDF fonts."
|
|
|
|
)
|
|
|
|
.then(msg => {
|
|
|
|
console.warn(msg);
|
|
|
|
});
|
2015-04-26 08:49:37 +09:00
|
|
|
}
|
2012-05-01 05:29:05 +09:00
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
if (!PDFViewerApplication.supportsPrinting) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.print.classList.add("hidden");
|
|
|
|
appConfig.secondaryToolbar.printButton.classList.add("hidden");
|
2012-07-10 08:04:55 +09:00
|
|
|
}
|
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
if (!PDFViewerApplication.supportsFullscreen) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.presentationModeButton.classList.add("hidden");
|
|
|
|
appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
|
2012-07-31 00:12:49 +09:00
|
|
|
}
|
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
if (PDFViewerApplication.supportsIntegratedFind) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.viewFind.classList.add("hidden");
|
2012-10-06 05:59:13 +09:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.mainContainer.addEventListener(
|
|
|
|
"transitionend",
|
2020-04-14 19:28:14 +09:00
|
|
|
function (evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (evt.target === /* mainContainer */ this) {
|
|
|
|
PDFViewerApplication.eventBus.dispatch("resize", { source: this });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2012-09-07 00:33:07 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
try {
|
2016-05-10 08:18:43 +09:00
|
|
|
webViewerOpenFileViaURL(file);
|
2018-07-31 00:41:39 +09:00
|
|
|
} catch (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get("loading_error", null, "An error occurred while loading the PDF.")
|
|
|
|
.then(msg => {
|
|
|
|
PDFViewerApplication.error(msg, reason);
|
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2016-05-10 08:18:43 +09:00
|
|
|
}
|
2012-08-16 00:17:30 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
let webViewerOpenFileViaURL;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFileViaURL = function (file) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (file && file.lastIndexOf("file:", 0) === 0) {
|
2016-10-15 00:57:53 +09:00
|
|
|
// file:-scheme. Load the contents in the main thread because QtWebKit
|
|
|
|
// cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded
|
|
|
|
// very quickly, so there is no need to set up progress event listeners.
|
|
|
|
PDFViewerApplication.setTitleUsingUrl(file);
|
2019-01-28 19:00:09 +09:00
|
|
|
const xhr = new XMLHttpRequest();
|
2020-04-14 19:28:14 +09:00
|
|
|
xhr.onload = function () {
|
2016-10-15 00:57:53 +09:00
|
|
|
PDFViewerApplication.open(new Uint8Array(xhr.response));
|
|
|
|
};
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
xhr.open("GET", file);
|
|
|
|
xhr.responseType = "arraybuffer";
|
2019-01-28 19:00:09 +09:00
|
|
|
xhr.send();
|
2016-10-15 00:57:53 +09:00
|
|
|
return;
|
2014-07-30 08:28:41 +09:00
|
|
|
}
|
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
if (file) {
|
|
|
|
PDFViewerApplication.open(file);
|
|
|
|
}
|
|
|
|
};
|
2020-01-08 21:57:31 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFileViaURL = function (file) {
|
2016-10-15 00:57:53 +09:00
|
|
|
PDFViewerApplication.setTitleUsingUrl(file);
|
|
|
|
PDFViewerApplication.initPassiveLoading();
|
|
|
|
};
|
|
|
|
} else {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFileViaURL = function (file) {
|
2016-10-15 00:57:53 +09:00
|
|
|
if (file) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: webViewerOpenFileViaURL");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
|
|
|
};
|
2014-02-28 02:45:02 +09:00
|
|
|
}
|
|
|
|
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
function webViewerResetPermissions() {
|
|
|
|
const { appConfig } = PDFViewerApplication;
|
|
|
|
if (!appConfig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Currently only the "copy"-permission is supported.
|
|
|
|
appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
|
|
|
}
|
|
|
|
|
2020-09-23 21:29:21 +09:00
|
|
|
function webViewerPageRendered({ pageNumber, timestamp, error }) {
|
2016-07-30 03:39:22 +09:00
|
|
|
// If the page is still visible when it has finished rendering,
|
|
|
|
// ensure that the page number input loading indicator is hidden.
|
|
|
|
if (pageNumber === PDFViewerApplication.page) {
|
2016-11-19 03:50:29 +09:00
|
|
|
PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
|
2016-07-30 03:39:22 +09:00
|
|
|
}
|
|
|
|
|
2016-02-22 01:54:23 +09:00
|
|
|
// Use the rendered page to set the corresponding thumbnail image.
|
|
|
|
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
2020-09-23 22:38:54 +09:00
|
|
|
const pageView = PDFViewerApplication.pdfViewer.getPageView(
|
|
|
|
/* index = */ pageNumber - 1
|
|
|
|
);
|
2019-12-27 08:22:32 +09:00
|
|
|
const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(
|
2020-09-23 22:38:54 +09:00
|
|
|
/* index = */ pageNumber - 1
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
2020-09-23 22:38:54 +09:00
|
|
|
if (pageView && thumbnailView) {
|
|
|
|
thumbnailView.setImage(pageView);
|
|
|
|
}
|
2015-01-28 05:13:34 +09:00
|
|
|
}
|
2012-08-08 08:52:22 +09:00
|
|
|
|
2020-09-23 21:29:21 +09:00
|
|
|
if (error) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get(
|
|
|
|
"rendering_error",
|
|
|
|
null,
|
|
|
|
"An error occurred while rendering the page."
|
|
|
|
)
|
|
|
|
.then(msg => {
|
2020-09-23 21:29:21 +09:00
|
|
|
PDFViewerApplication.error(msg, error);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
});
|
2014-09-16 04:57:12 +09:00
|
|
|
}
|
2012-08-08 08:52:22 +09:00
|
|
|
|
2020-07-08 22:35:09 +09:00
|
|
|
PDFViewerApplication.externalServices.reportTelemetry({
|
|
|
|
type: "pageInfo",
|
2020-09-23 21:29:21 +09:00
|
|
|
timestamp,
|
2020-07-08 22:35:09 +09:00
|
|
|
});
|
|
|
|
// It is a good time to report stream and font types.
|
|
|
|
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
2016-04-14 06:21:05 +09:00
|
|
|
PDFViewerApplication.externalServices.reportTelemetry({
|
2020-07-08 22:35:09 +09:00
|
|
|
type: "documentStats",
|
|
|
|
stats,
|
2016-04-14 06:21:05 +09:00
|
|
|
});
|
2020-07-08 22:35:09 +09:00
|
|
|
});
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2012-08-08 08:52:22 +09:00
|
|
|
|
2019-12-27 08:32:40 +09:00
|
|
|
function webViewerPageMode({ mode }) {
|
2015-08-05 05:57:51 +09:00
|
|
|
// Handle the 'pagemode' hash parameter, see also `PDFLinkService_setHash`.
|
2019-12-27 08:32:40 +09:00
|
|
|
let view;
|
2015-08-05 05:57:51 +09:00
|
|
|
switch (mode) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "thumbs":
|
2016-02-22 01:54:23 +09:00
|
|
|
view = SidebarView.THUMBS;
|
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "bookmarks":
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
case "outline": // non-standard
|
2016-02-22 01:54:23 +09:00
|
|
|
view = SidebarView.OUTLINE;
|
|
|
|
break;
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
case "attachments": // non-standard
|
2016-02-22 01:54:23 +09:00
|
|
|
view = SidebarView.ATTACHMENTS;
|
2015-08-05 05:57:51 +09:00
|
|
|
break;
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
case "layers": // non-standard
|
|
|
|
view = SidebarView.LAYERS;
|
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "none":
|
2016-02-22 01:54:23 +09:00
|
|
|
view = SidebarView.NONE;
|
2015-08-05 05:57:51 +09:00
|
|
|
break;
|
2016-02-22 01:54:23 +09:00
|
|
|
default:
|
|
|
|
console.error('Invalid "pagemode" hash parameter: ' + mode);
|
|
|
|
return;
|
2015-08-05 05:57:51 +09:00
|
|
|
}
|
2016-02-22 01:54:23 +09:00
|
|
|
PDFViewerApplication.pdfSidebar.switchView(view, /* forceOpen = */ true);
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2015-08-05 05:57:51 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerNamedAction(evt) {
|
2020-09-01 15:54:07 +09:00
|
|
|
// Processing a couple of named actions that might be useful, see also
|
|
|
|
// `PDFLinkService.executeNamedAction`.
|
|
|
|
switch (evt.action) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "GoToPage":
|
2016-09-01 20:23:18 +09:00
|
|
|
PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
2015-04-28 00:25:32 +09:00
|
|
|
break;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "Find":
|
2015-08-05 06:07:44 +09:00
|
|
|
if (!PDFViewerApplication.supportsIntegratedFind) {
|
|
|
|
PDFViewerApplication.findBar.toggle();
|
2015-04-28 00:25:32 +09:00
|
|
|
}
|
|
|
|
break;
|
2020-09-01 15:54:07 +09:00
|
|
|
|
|
|
|
case "Print":
|
2020-09-30 22:02:11 +09:00
|
|
|
PDFViewerApplication.triggerPrinting();
|
2020-09-01 15:54:07 +09:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "SaveAs":
|
|
|
|
webViewerSave();
|
|
|
|
break;
|
2015-04-28 00:25:32 +09:00
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2015-04-28 00:25:32 +09:00
|
|
|
|
2020-01-08 19:56:10 +09:00
|
|
|
function webViewerPresentationModeChanged({ active, switchInProgress }) {
|
|
|
|
let state = PresentationModeState.NORMAL;
|
|
|
|
if (switchInProgress) {
|
|
|
|
state = PresentationModeState.CHANGING;
|
|
|
|
} else if (active) {
|
|
|
|
state = PresentationModeState.FULLSCREEN;
|
|
|
|
}
|
|
|
|
PDFViewerApplication.pdfViewer.presentationModeState = state;
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2012-08-08 08:52:22 +09:00
|
|
|
|
2017-04-22 20:42:41 +09:00
|
|
|
function webViewerSidebarViewChanged(evt) {
|
2016-03-12 21:07:43 +09:00
|
|
|
PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled =
|
|
|
|
PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const store = PDFViewerApplication.store;
|
2017-04-22 20:42:41 +09:00
|
|
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
2016-03-12 21:07:43 +09:00
|
|
|
// Only update the storage when the document has been loaded *and* rendered.
|
2020-04-14 19:28:14 +09:00
|
|
|
store.set("sidebarView", evt.view).catch(function () {});
|
2016-03-12 21:07:43 +09:00
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2016-03-12 21:07:43 +09:00
|
|
|
|
2017-04-22 20:42:41 +09:00
|
|
|
function webViewerUpdateViewarea(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const location = evt.location,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
store = PDFViewerApplication.store;
|
2017-04-22 20:42:41 +09:00
|
|
|
|
|
|
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
store
|
|
|
|
.setMultiple({
|
|
|
|
page: location.pageNumber,
|
|
|
|
zoom: location.scale,
|
|
|
|
scrollLeft: location.left,
|
|
|
|
scrollTop: location.top,
|
|
|
|
rotation: location.rotation,
|
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.catch(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* unable to write to storage */
|
|
|
|
});
|
2016-03-12 21:07:43 +09:00
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
location.pdfOpenParams
|
|
|
|
);
|
2016-04-22 01:39:11 +09:00
|
|
|
PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
2013-05-16 07:31:17 +09:00
|
|
|
|
2014-07-18 20:53:04 +09:00
|
|
|
// Show/hide the loading indicator in the page number input element.
|
2019-12-27 08:22:32 +09:00
|
|
|
const currentPage = PDFViewerApplication.pdfViewer.getPageView(
|
2020-09-23 22:38:54 +09:00
|
|
|
/* index = */ PDFViewerApplication.page - 1
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
2020-09-23 22:38:54 +09:00
|
|
|
const loading =
|
|
|
|
(currentPage && currentPage.renderingState) !== RenderingStates.FINISHED;
|
2016-11-19 03:50:29 +09:00
|
|
|
PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-09-03 10:16:52 +09:00
|
|
|
|
2018-05-15 12:10:33 +09:00
|
|
|
function webViewerScrollModeChanged(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const store = PDFViewerApplication.store;
|
2018-05-15 12:10:33 +09:00
|
|
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
|
|
|
// Only update the storage when the document has been loaded *and* rendered.
|
2020-04-14 19:28:14 +09:00
|
|
|
store.set("scrollMode", evt.mode).catch(function () {});
|
2018-05-15 12:10:33 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function webViewerSpreadModeChanged(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const store = PDFViewerApplication.store;
|
2018-05-15 12:10:33 +09:00
|
|
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
|
|
|
// Only update the storage when the document has been loaded *and* rendered.
|
2020-04-14 19:28:14 +09:00
|
|
|
store.set("spreadMode", evt.mode).catch(function () {});
|
2018-05-15 12:10:33 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 07:57:15 +09:00
|
|
|
function webViewerResize() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const { pdfDocument, pdfViewer } = PDFViewerApplication;
|
2017-07-06 20:13:22 +09:00
|
|
|
if (!pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const currentScaleValue = pdfViewer.currentScaleValue;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
currentScaleValue === "auto" ||
|
|
|
|
currentScaleValue === "page-fit" ||
|
|
|
|
currentScaleValue === "page-width"
|
|
|
|
) {
|
2016-12-09 00:28:40 +09:00
|
|
|
// Note: the scale is constant for 'page-actual'.
|
2017-07-06 20:13:22 +09:00
|
|
|
pdfViewer.currentScaleValue = currentScaleValue;
|
2013-08-01 02:43:03 +09:00
|
|
|
}
|
2017-07-06 20:13:22 +09:00
|
|
|
pdfViewer.update();
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-09-03 10:16:52 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerHashchange(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const hash = evt.hash;
|
2017-07-14 21:24:32 +09:00
|
|
|
if (!hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!PDFViewerApplication.isInitialViewSet) {
|
|
|
|
PDFViewerApplication.initialBookmark = hash;
|
Re-write `PDFHistory` from scratch
This patch completely re-implements `PDFHistory` to get rid of various bugs currently present, and to hopefully make maintenance slightly easier. Most of the interface is similar to the existing one, but it should be somewhat simplified.
The new implementation should be more robust against failure, compared to the old one. Previously, it was too easy to end up in a state which basically caused the browser history to lock-up, preventing the user from navigating back/forward. (In the new implementation, the browser history should not be updated rather than breaking if things go wrong.)
Given that the code has to deal with various edge-cases, it's still not as simple as I would have liked, but it should now be somewhat easier to deal with.
The main source of complication in the code is actually that we allow the user to change the hash of a already loaded document (we'll no longer try to navigate back-and-forth in this case, since the next commit contains a workaround).
In the new code, there's also *a lot* more comments (perhaps too many?) to attempt to explain the logic. This is something that the old implementation was serverly lacking, which is a one of the reasons why it was so difficult to maintain.
One particular thing to note is that the new code uses the `pagehide` event rather than `beforeunload`, since the latter seems to be a bad idea based on https://bugzilla.mozilla.org/show_bug.cgi?id=1336763.
2017-07-16 20:39:39 +09:00
|
|
|
} else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
|
2017-07-14 21:24:32 +09:00
|
|
|
PDFViewerApplication.pdfLinkService.setHash(hash);
|
2013-05-16 07:31:17 +09:00
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-07-29 02:48:05 +09:00
|
|
|
|
2020-03-17 21:26:35 +09:00
|
|
|
let webViewerFileInputChange, webViewerOpenFile;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerFileInputChange = function (evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
PDFViewerApplication.pdfViewer &&
|
|
|
|
PDFViewerApplication.pdfViewer.isInPresentationMode
|
|
|
|
) {
|
2018-06-11 17:48:36 +09:00
|
|
|
return; // Opening a new PDF file isn't supported in Presentation Mode.
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const file = evt.fileInput.files[0];
|
2014-01-28 04:11:02 +09:00
|
|
|
|
Remove the `disableCreateObjectURL` option from `web/app_options.js`
Prior to PR 11601, the `disableCreateObjectURL` option was present on `getDocument` in the API, since it was (potentially) used when decoding JPEG images natively in the browser. Hence setting this option, which was done automatically using compatibility-code, were in some browsers necessary in order for e.g. JPEG images to be correctly rendered.
The downside of the `disableCreateObjectURL` option is that memory usage increases significantly, since we're forced to build and use `data:` URIs (rather than `blob:` URLs).
However, at this point in time the `disableCreateObjectURL` option is only necessary for *some* (non-essential) functionality in the default viewer; in particular:
- The openfile functionality, used only when manually opening a new file in the default viewer.
- The download functionality, used when downloading either the PDF document itself or its attached files (if such exists).
- The print functionality, in the generic `PDFPrintService` implementation.
Hence neither the general PDF.js library, nor the *basic* functionality of the default viewer, depends on the `disableCreateObjectURL` option any more; which is why I'm thus proposing that we remove the option since using it is a performance footgun.
*Please note:* To not outright break currently "supported" browsers, which lack proper `URL.createObjectURL` support, this patch purposely keeps the compatibility-code to explicitly disable `URL.createObjectURL` usage *only* for browsers which are known to not work correctly.[1]
While it's certainly possible that there's additional, likely older, browsers with broken `URL.createObjectURL` support, the last time that these types of problems were reported was over *three* years ago.[2]
Hence in the *very* unlikely event that additional problems occur, as a result of these changes, we can either add a new case in the compatibility-code or simply declare the affected browser as unsupported.
---
[1] Which are IE11 (see issue 3977), and Google Chrome on iOS (see PR 8081).
[2] Given that `URL.createObjectURL` is used by default, you'd really expect more reports if these problems were widespread.
2020-08-06 19:43:59 +09:00
|
|
|
if (!viewerCompatibilityParams.disableCreateObjectURL) {
|
2018-06-17 20:44:35 +09:00
|
|
|
let url = URL.createObjectURL(file);
|
|
|
|
if (file.name) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
url = { url, originalUrl: file.name };
|
2018-06-17 20:44:35 +09:00
|
|
|
}
|
|
|
|
PDFViewerApplication.open(url);
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
2018-06-17 20:44:35 +09:00
|
|
|
PDFViewerApplication.setTitleUsingUrl(file.name);
|
2016-10-15 00:57:53 +09:00
|
|
|
// Read the local file into a Uint8Array.
|
2019-12-27 08:22:32 +09:00
|
|
|
const fileReader = new FileReader();
|
2020-03-13 20:55:00 +09:00
|
|
|
fileReader.onload = function webViewerChangeFileReaderOnload(event) {
|
|
|
|
const buffer = event.target.result;
|
2017-06-29 19:14:26 +09:00
|
|
|
PDFViewerApplication.open(new Uint8Array(buffer));
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
|
|
|
fileReader.readAsArrayBuffer(file);
|
|
|
|
}
|
2014-01-28 04:11:02 +09:00
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
// URL does not reflect proper document location - hiding some icons.
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.viewBookmark.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.viewBookmarkButton.setAttribute(
|
|
|
|
"hidden",
|
|
|
|
"true"
|
|
|
|
);
|
|
|
|
appConfig.toolbar.download.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.downloadButton.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
2020-03-17 21:26:35 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFile = function (evt) {
|
2020-03-17 21:26:35 +09:00
|
|
|
const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
|
|
|
document.getElementById(openFileInputName).click();
|
|
|
|
};
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-07-29 02:48:05 +09:00
|
|
|
|
2016-04-29 05:04:09 +09:00
|
|
|
function webViewerPresentationMode() {
|
|
|
|
PDFViewerApplication.requestPresentationMode();
|
|
|
|
}
|
|
|
|
function webViewerPrint() {
|
2020-09-30 22:02:11 +09:00
|
|
|
PDFViewerApplication.triggerPrinting();
|
2016-04-29 05:04:09 +09:00
|
|
|
}
|
2020-08-20 04:19:59 +09:00
|
|
|
function webViewerDownload() {
|
2020-12-19 20:38:10 +09:00
|
|
|
PDFViewerApplication.downloadOrSave({ sourceEventType: "download" });
|
2020-08-20 04:19:59 +09:00
|
|
|
}
|
|
|
|
function webViewerSave() {
|
2020-12-19 20:38:10 +09:00
|
|
|
PDFViewerApplication.downloadOrSave({ sourceEventType: "save" });
|
2020-08-20 04:19:59 +09:00
|
|
|
}
|
2016-04-29 05:04:09 +09:00
|
|
|
function webViewerFirstPage() {
|
|
|
|
if (PDFViewerApplication.pdfDocument) {
|
|
|
|
PDFViewerApplication.page = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function webViewerLastPage() {
|
|
|
|
if (PDFViewerApplication.pdfDocument) {
|
|
|
|
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
function webViewerNextPage() {
|
|
|
|
PDFViewerApplication.page++;
|
|
|
|
}
|
|
|
|
function webViewerPreviousPage() {
|
|
|
|
PDFViewerApplication.page--;
|
|
|
|
}
|
|
|
|
function webViewerZoomIn() {
|
|
|
|
PDFViewerApplication.zoomIn();
|
|
|
|
}
|
|
|
|
function webViewerZoomOut() {
|
|
|
|
PDFViewerApplication.zoomOut();
|
|
|
|
}
|
2019-07-17 18:59:56 +09:00
|
|
|
function webViewerZoomReset() {
|
|
|
|
PDFViewerApplication.zoomReset();
|
2019-03-19 18:45:27 +09:00
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerPageNumberChanged(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfViewer = PDFViewerApplication.pdfViewer;
|
Attempt to tweak the error messages, in `BaseViewer`, for invalid pageNumbers/pageLabels (bug 1505824)
Rather than closing [bug 1505824](https://bugzilla.mozilla.org/show_bug.cgi?id=1505824) as WONTFIX (which is my preferred solution), given how *minor* this "problem" is, it's still possible to adjust the error messages a bit.
The main point here, which is relevant even if the changes in `BaseViewer` are ultimately rejected during review, is that we'll no longer attempt to call `BaseViewer.currentPageLabel` with an empty string from `webViewerPageNumberChanged` in `app.js`.
The other changes are:
- Stop printing an error in `BaseViewer._setCurrentPageNumber`, and have it return a boolean indicating if the page is within bounds.
- Have the `BaseViewer.{currentPageNumber, currentPageLabel}` setters print their own errors for invalid pages.
- Have the `BaseViewer.currentPageLabel` setter no longer depend, indirectly, on the `BaseViewer.currentPageNumber` setter.
- Improve a couple of other error messages.
2018-11-15 00:16:09 +09:00
|
|
|
// Note that for `<input type="number">` HTML elements, an empty string will
|
|
|
|
// be returned for non-number inputs; hence we simply do nothing in that case.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (evt.value !== "") {
|
2020-10-31 18:17:28 +09:00
|
|
|
PDFViewerApplication.pdfLinkService.goToPage(evt.value);
|
Attempt to tweak the error messages, in `BaseViewer`, for invalid pageNumbers/pageLabels (bug 1505824)
Rather than closing [bug 1505824](https://bugzilla.mozilla.org/show_bug.cgi?id=1505824) as WONTFIX (which is my preferred solution), given how *minor* this "problem" is, it's still possible to adjust the error messages a bit.
The main point here, which is relevant even if the changes in `BaseViewer` are ultimately rejected during review, is that we'll no longer attempt to call `BaseViewer.currentPageLabel` with an empty string from `webViewerPageNumberChanged` in `app.js`.
The other changes are:
- Stop printing an error in `BaseViewer._setCurrentPageNumber`, and have it return a boolean indicating if the page is within bounds.
- Have the `BaseViewer.{currentPageNumber, currentPageLabel}` setters print their own errors for invalid pages.
- Have the `BaseViewer.currentPageLabel` setter no longer depend, indirectly, on the `BaseViewer.currentPageNumber` setter.
- Improve a couple of other error messages.
2018-11-15 00:16:09 +09:00
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
|
|
|
|
// Ensure that the page number input displays the correct value, even if the
|
|
|
|
// value entered by the user was invalid (e.g. a floating point number).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
evt.value !== pdfViewer.currentPageNumber.toString() &&
|
|
|
|
evt.value !== pdfViewer.currentPageLabel
|
|
|
|
) {
|
2016-11-19 03:50:29 +09:00
|
|
|
PDFViewerApplication.toolbar.setPageNumber(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pdfViewer.currentPageNumber,
|
|
|
|
pdfViewer.currentPageLabel
|
|
|
|
);
|
2016-11-19 03:50:29 +09:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerScaleChanged(evt) {
|
|
|
|
PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
|
2016-11-19 03:50:29 +09:00
|
|
|
}
|
2016-04-29 05:04:09 +09:00
|
|
|
function webViewerRotateCw() {
|
|
|
|
PDFViewerApplication.rotatePages(90);
|
|
|
|
}
|
|
|
|
function webViewerRotateCcw() {
|
|
|
|
PDFViewerApplication.rotatePages(-90);
|
|
|
|
}
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
function webViewerOptionalContentConfig(evt) {
|
|
|
|
PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
|
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
function webViewerSwitchScrollMode(evt) {
|
2018-06-29 22:07:42 +09:00
|
|
|
PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
|
2018-05-15 12:10:32 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
function webViewerSwitchSpreadMode(evt) {
|
2018-06-29 22:07:42 +09:00
|
|
|
PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
|
2018-05-15 12:10:32 +09:00
|
|
|
}
|
2016-04-29 05:04:09 +09:00
|
|
|
function webViewerDocumentProperties() {
|
|
|
|
PDFViewerApplication.pdfDocumentProperties.open();
|
|
|
|
}
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerFind(evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.findController.executeCommand("find" + evt.type, {
|
2017-06-29 19:14:26 +09:00
|
|
|
query: evt.query,
|
|
|
|
phraseSearch: evt.phraseSearch,
|
|
|
|
caseSensitive: evt.caseSensitive,
|
2018-09-01 08:28:19 +09:00
|
|
|
entireWord: evt.entireWord,
|
2017-06-29 19:14:26 +09:00
|
|
|
highlightAll: evt.highlightAll,
|
|
|
|
findPrevious: evt.findPrevious,
|
2016-04-28 21:11:40 +09:00
|
|
|
});
|
|
|
|
}
|
2012-05-02 07:08:30 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerFindFromUrlHash(evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.findController.executeCommand("find", {
|
2017-06-29 19:14:26 +09:00
|
|
|
query: evt.query,
|
|
|
|
phraseSearch: evt.phraseSearch,
|
2016-05-26 22:24:58 +09:00
|
|
|
caseSensitive: false,
|
2018-09-01 08:28:19 +09:00
|
|
|
entireWord: false,
|
2016-05-26 22:24:58 +09:00
|
|
|
highlightAll: true,
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
findPrevious: false,
|
2016-05-26 22:24:58 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
function webViewerUpdateFindMatchesCount({ matchesCount }) {
|
2018-09-22 03:00:58 +09:00
|
|
|
if (PDFViewerApplication.supportsIntegratedFind) {
|
|
|
|
PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
|
|
|
|
} else {
|
|
|
|
PDFViewerApplication.findBar.updateResultsCount(matchesCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:28:02 +09:00
|
|
|
function webViewerUpdateFindControlState({
|
|
|
|
state,
|
|
|
|
previous,
|
|
|
|
matchesCount,
|
|
|
|
rawQuery,
|
|
|
|
}) {
|
2018-09-22 03:00:58 +09:00
|
|
|
if (PDFViewerApplication.supportsIntegratedFind) {
|
|
|
|
PDFViewerApplication.externalServices.updateFindControlState({
|
|
|
|
result: state,
|
|
|
|
findPrevious: previous,
|
|
|
|
matchesCount,
|
2020-08-20 17:28:02 +09:00
|
|
|
rawQuery,
|
2018-09-22 03:00:58 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerScaleChanging(evt) {
|
|
|
|
PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
|
2016-06-27 19:32:28 +09:00
|
|
|
|
2015-07-23 23:02:39 +09:00
|
|
|
PDFViewerApplication.pdfViewer.update();
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-07-30 01:17:04 +09:00
|
|
|
|
2017-08-19 21:23:40 +09:00
|
|
|
function webViewerRotationChanging(evt) {
|
|
|
|
PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
|
|
|
|
|
|
|
|
PDFViewerApplication.forceRendering();
|
|
|
|
// Ensure that the active page doesn't change during rotation.
|
|
|
|
PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
|
|
|
|
}
|
|
|
|
|
2020-09-23 22:38:54 +09:00
|
|
|
function webViewerPageChanging({ pageNumber, pageLabel }) {
|
|
|
|
PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
|
|
|
|
PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
|
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
- Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.
- Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.
- Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).
Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-22 22:32:14 +09:00
|
|
|
|
|
|
|
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
2020-09-23 22:38:54 +09:00
|
|
|
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
|
2012-04-14 06:14:05 +09:00
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-09-03 10:16:52 +09:00
|
|
|
|
2018-12-12 21:46:47 +09:00
|
|
|
function webViewerVisibilityChange(evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (document.visibilityState === "visible") {
|
2018-12-12 21:46:47 +09:00
|
|
|
// Ignore mouse wheel zooming during tab switches (bug 1503412).
|
|
|
|
setZoomDisabledTimeout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let zoomDisabledTimeout = null;
|
|
|
|
function setZoomDisabledTimeout() {
|
|
|
|
if (zoomDisabledTimeout) {
|
|
|
|
clearTimeout(zoomDisabledTimeout);
|
|
|
|
}
|
2020-04-14 19:28:14 +09:00
|
|
|
zoomDisabledTimeout = setTimeout(function () {
|
2018-12-12 21:46:47 +09:00
|
|
|
zoomDisabledTimeout = null;
|
|
|
|
}, WHEEL_ZOOM_DISABLED_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2016-12-09 00:28:40 +09:00
|
|
|
function webViewerWheel(evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const {
|
|
|
|
pdfViewer,
|
|
|
|
supportedMouseWheelZoomModifierKeys,
|
|
|
|
} = PDFViewerApplication;
|
2019-07-24 00:36:45 +09:00
|
|
|
|
2016-12-09 00:28:40 +09:00
|
|
|
if (pdfViewer.isInPresentationMode) {
|
2016-09-28 05:27:42 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
(evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey) ||
|
|
|
|
(evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey)
|
|
|
|
) {
|
2015-02-01 00:46:23 +09:00
|
|
|
// Only zoom the pages, not the entire viewer.
|
2014-10-16 05:03:13 +09:00
|
|
|
evt.preventDefault();
|
2016-04-08 04:03:04 +09:00
|
|
|
// NOTE: this check must be placed *after* preventDefault.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (zoomDisabledTimeout || document.visibilityState === "hidden") {
|
2016-04-08 04:03:04 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-07-03 06:20:37 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const previousScale = pdfViewer.currentScale;
|
2015-07-03 06:20:37 +09:00
|
|
|
|
2020-08-13 03:30:45 +09:00
|
|
|
const delta = normalizeWheelEventDirection(evt);
|
|
|
|
let ticks = 0;
|
|
|
|
if (
|
|
|
|
evt.deltaMode === WheelEvent.DOM_DELTA_LINE ||
|
|
|
|
evt.deltaMode === WheelEvent.DOM_DELTA_PAGE
|
|
|
|
) {
|
|
|
|
// For line-based devices, use one tick per event, because different
|
|
|
|
// OSs have different defaults for the number lines. But we generally
|
|
|
|
// want one "clicky" roll of the wheel (which produces one event) to
|
|
|
|
// adjust the zoom by one step.
|
|
|
|
if (Math.abs(delta) >= 1) {
|
|
|
|
ticks = Math.sign(delta);
|
|
|
|
} else {
|
|
|
|
// If we're getting fractional lines (I can't think of a scenario
|
|
|
|
// this might actually happen), be safe and use the accumulator.
|
|
|
|
ticks = PDFViewerApplication.accumulateWheelTicks(delta);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// pixel-based devices
|
|
|
|
const PIXELS_PER_LINE_SCALE = 30;
|
|
|
|
ticks = PDFViewerApplication.accumulateWheelTicks(
|
|
|
|
delta / PIXELS_PER_LINE_SCALE
|
|
|
|
);
|
|
|
|
}
|
2016-09-28 05:27:42 +09:00
|
|
|
|
|
|
|
if (ticks < 0) {
|
|
|
|
PDFViewerApplication.zoomOut(-ticks);
|
2020-08-13 03:30:45 +09:00
|
|
|
} else if (ticks > 0) {
|
2016-09-28 05:27:42 +09:00
|
|
|
PDFViewerApplication.zoomIn(ticks);
|
|
|
|
}
|
2015-07-03 06:20:37 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const currentScale = pdfViewer.currentScale;
|
2015-07-03 06:20:37 +09:00
|
|
|
if (previousScale !== currentScale) {
|
|
|
|
// After scaling the page via zoomIn/zoomOut, the position of the upper-
|
|
|
|
// left corner is restored. When the mouse wheel is used, the position
|
|
|
|
// under the cursor should be restored instead.
|
2019-12-27 08:22:32 +09:00
|
|
|
const scaleCorrectionFactor = currentScale / previousScale - 1;
|
|
|
|
const rect = pdfViewer.container.getBoundingClientRect();
|
|
|
|
const dx = evt.clientX - rect.left;
|
|
|
|
const dy = evt.clientY - rect.top;
|
2015-07-03 06:20:37 +09:00
|
|
|
pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
|
|
|
pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
|
|
|
}
|
2016-04-08 01:48:46 +09:00
|
|
|
} else {
|
2018-12-12 21:46:47 +09:00
|
|
|
setZoomDisabledTimeout();
|
2012-06-08 04:27:26 +09:00
|
|
|
}
|
2014-01-29 04:52:25 +09:00
|
|
|
}
|
|
|
|
|
2020-08-13 04:09:42 +09:00
|
|
|
function webViewerTouchStart(evt) {
|
|
|
|
if (evt.touches.length > 1) {
|
|
|
|
// Disable touch-based zooming, because the entire UI bits gets zoomed and
|
|
|
|
// that doesn't look great. If we do want to have a good touch-based
|
|
|
|
// zooming experience, we need to implement smooth zoom capability (probably
|
|
|
|
// using a CSS transform for faster visual response, followed by async
|
|
|
|
// re-rendering at the final zoom level) and do gesture detection on the
|
|
|
|
// touchmove events to drive it. Or if we want to settle for a less good
|
|
|
|
// experience we can make the touchmove events drive the existing step-zoom
|
|
|
|
// behaviour that the ctrl+mousewheel path takes.
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 00:28:40 +09:00
|
|
|
function webViewerClick(evt) {
|
2020-06-02 02:28:30 +09:00
|
|
|
// Avoid triggering the fallback bar when the user clicks on the
|
|
|
|
// toolbar or sidebar.
|
|
|
|
if (
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
PDFViewerApplication.triggerDelayedFallback &&
|
2020-06-02 02:28:30 +09:00
|
|
|
PDFViewerApplication.pdfViewer.containsElement(evt.target)
|
|
|
|
) {
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
PDFViewerApplication.triggerDelayedFallback();
|
2020-06-02 02:28:30 +09:00
|
|
|
}
|
|
|
|
|
2016-05-11 08:31:03 +09:00
|
|
|
if (!PDFViewerApplication.secondaryToolbar.isOpen) {
|
2016-04-29 05:04:09 +09:00
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
PDFViewerApplication.pdfViewer.containsElement(evt.target) ||
|
|
|
|
(appConfig.toolbar.container.contains(evt.target) &&
|
|
|
|
evt.target !== appConfig.secondaryToolbar.toggleButton)
|
|
|
|
) {
|
2016-05-11 08:31:03 +09:00
|
|
|
PDFViewerApplication.secondaryToolbar.close();
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
2016-12-09 00:28:40 +09:00
|
|
|
}
|
2012-10-06 11:55:47 +09:00
|
|
|
|
2020-06-02 02:28:30 +09:00
|
|
|
function webViewerKeyUp(evt) {
|
|
|
|
if (evt.keyCode === 9) {
|
Refactor/simplify the "delayedFallback" handling in the default viewer
There's a few things that could be improved in the current implementation, such as:
- It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.
- Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.
- Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.
- There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.
- The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
2020-07-04 18:29:46 +09:00
|
|
|
// The user is tabbing into the viewer. Trigger the fallback bar if it has
|
|
|
|
// not already been displayed.
|
|
|
|
if (PDFViewerApplication.triggerDelayedFallback) {
|
|
|
|
PDFViewerApplication.triggerDelayedFallback();
|
2020-06-02 02:28:30 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 00:28:40 +09:00
|
|
|
function webViewerKeyDown(evt) {
|
2017-05-26 21:52:23 +09:00
|
|
|
if (PDFViewerApplication.overlayManager.active) {
|
2013-09-25 00:46:54 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let handled = false,
|
|
|
|
ensureViewerFocused = false;
|
2019-12-27 08:22:32 +09:00
|
|
|
const cmd =
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
(evt.ctrlKey ? 1 : 0) |
|
|
|
|
(evt.altKey ? 2 : 0) |
|
|
|
|
(evt.shiftKey ? 4 : 0) |
|
|
|
|
(evt.metaKey ? 8 : 0);
|
2012-04-12 07:47:11 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfViewer = PDFViewerApplication.pdfViewer;
|
|
|
|
const isViewerInPresentationMode =
|
|
|
|
pdfViewer && pdfViewer.isInPresentationMode;
|
2015-01-29 21:37:49 +09:00
|
|
|
|
2012-04-12 07:47:11 +09:00
|
|
|
// First, handle the key bindings that are independent whether an input
|
|
|
|
// control is selected or not.
|
2013-03-12 01:04:43 +09:00
|
|
|
if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
|
|
|
|
// either CTRL or META key with optional SHIFT.
|
2012-04-12 07:47:11 +09:00
|
|
|
switch (evt.keyCode) {
|
2013-07-18 20:37:55 +09:00
|
|
|
case 70: // f
|
2020-09-29 17:37:33 +09:00
|
|
|
if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.findBar.open();
|
2012-10-06 05:59:13 +09:00
|
|
|
handled = true;
|
|
|
|
}
|
2012-09-12 01:30:44 +09:00
|
|
|
break;
|
2013-07-18 20:37:55 +09:00
|
|
|
case 71: // g
|
2014-09-22 20:41:17 +09:00
|
|
|
if (!PDFViewerApplication.supportsIntegratedFind) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const findState = PDFViewerApplication.findController.state;
|
2016-04-28 21:11:40 +09:00
|
|
|
if (findState) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.findController.executeCommand("findagain", {
|
2016-04-28 21:11:40 +09:00
|
|
|
query: findState.query,
|
2016-05-26 22:24:58 +09:00
|
|
|
phraseSearch: findState.phraseSearch,
|
2016-04-28 21:11:40 +09:00
|
|
|
caseSensitive: findState.caseSensitive,
|
2018-09-01 08:28:19 +09:00
|
|
|
entireWord: findState.entireWord,
|
2016-04-28 21:11:40 +09:00
|
|
|
highlightAll: findState.highlightAll,
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
findPrevious: cmd === 5 || cmd === 12,
|
2016-04-28 21:11:40 +09:00
|
|
|
});
|
|
|
|
}
|
2013-07-18 20:37:55 +09:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
2012-04-12 07:47:11 +09:00
|
|
|
case 61: // FF/Mac '='
|
|
|
|
case 107: // FF '+' and '='
|
|
|
|
case 187: // Chrome '+'
|
2012-12-11 06:39:35 +09:00
|
|
|
case 171: // FF with German keyboard
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
2014-10-16 05:03:13 +09:00
|
|
|
PDFViewerApplication.zoomIn();
|
|
|
|
}
|
2012-04-12 07:47:11 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
2012-09-11 01:28:45 +09:00
|
|
|
case 173: // FF/Mac '-'
|
2012-04-12 07:47:11 +09:00
|
|
|
case 109: // FF '-'
|
|
|
|
case 189: // Chrome '-'
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
2014-10-16 05:03:13 +09:00
|
|
|
PDFViewerApplication.zoomOut();
|
|
|
|
}
|
2012-04-12 07:47:11 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
|
|
|
case 48: // '0'
|
2012-12-12 07:59:33 +09:00
|
|
|
case 96: // '0' on Numpad of Swedish keyboard
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
2014-10-16 05:03:13 +09:00
|
|
|
// keeping it unhandled (to restore page zoom to 100%)
|
2020-04-14 19:28:14 +09:00
|
|
|
setTimeout(function () {
|
2014-10-16 05:03:13 +09:00
|
|
|
// ... and resetting the scale after browser adjusts its scale
|
2019-03-19 18:45:27 +09:00
|
|
|
PDFViewerApplication.zoomReset();
|
2014-10-16 05:03:13 +09:00
|
|
|
});
|
|
|
|
handled = false;
|
|
|
|
}
|
2012-04-12 07:47:11 +09:00
|
|
|
break;
|
2016-12-01 01:19:11 +09:00
|
|
|
|
|
|
|
case 38: // up arrow
|
|
|
|
if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
|
|
|
PDFViewerApplication.page = 1;
|
|
|
|
handled = true;
|
|
|
|
ensureViewerFocused = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 40: // down arrow
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
isViewerInPresentationMode ||
|
|
|
|
PDFViewerApplication.page < PDFViewerApplication.pagesCount
|
|
|
|
) {
|
2016-12-01 01:19:11 +09:00
|
|
|
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
|
|
|
handled = true;
|
|
|
|
ensureViewerFocused = true;
|
|
|
|
}
|
|
|
|
break;
|
2012-04-12 07:47:11 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Change the "download" keyboard shortcut (Ctrl+S) handling, in GENERIC/CHROME builds, to utilize the `EventBus` (issue 11657)
This improves the consistency of the "download" handling, in the default viewer, such that the `Toolbar`/`SecondaryToolbar` buttons *and* the keyboard shortcut are now handled in the same way (using the `EventBus`).
Given that the "download" keyboard shortcut handling is limited to GENERIC/CHROME builds and that the issue does raise a valid point about only being able to observe *some* downloads, these changes seem acceptable in this particular case.
Finally the pre-processor condition is adjusted to *explicitly*, rather than implicitly, list the affected build targets.
*Please note:* This patch should NOT be construed as carte blanche to simply convert all of the code in `webViewerKeyDown`, or elsewhere, to make use of the `EventBus` instead of direct function calls.
Any further changes, along the lines in this patch, would need to be evaluated on a case-by-case basis to determine if they are actually wanted, given that many/most existing cases in `webViewerKeyDown` should already be *indirectly* observable through the `EventBus` instance.
2020-04-20 22:48:34 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC || CHROME")) {
|
|
|
|
const { eventBus } = PDFViewerApplication;
|
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
// CTRL or META without shift
|
|
|
|
if (cmd === 1 || cmd === 8) {
|
|
|
|
switch (evt.keyCode) {
|
|
|
|
case 83: // s
|
Change the "download" keyboard shortcut (Ctrl+S) handling, in GENERIC/CHROME builds, to utilize the `EventBus` (issue 11657)
This improves the consistency of the "download" handling, in the default viewer, such that the `Toolbar`/`SecondaryToolbar` buttons *and* the keyboard shortcut are now handled in the same way (using the `EventBus`).
Given that the "download" keyboard shortcut handling is limited to GENERIC/CHROME builds and that the issue does raise a valid point about only being able to observe *some* downloads, these changes seem acceptable in this particular case.
Finally the pre-processor condition is adjusted to *explicitly*, rather than implicitly, list the affected build targets.
*Please note:* This patch should NOT be construed as carte blanche to simply convert all of the code in `webViewerKeyDown`, or elsewhere, to make use of the `EventBus` instead of direct function calls.
Any further changes, along the lines in this patch, would need to be evaluated on a case-by-case basis to determine if they are actually wanted, given that many/most existing cases in `webViewerKeyDown` should already be *indirectly* observable through the `EventBus` instance.
2020-04-20 22:48:34 +09:00
|
|
|
eventBus.dispatch("download", { source: window });
|
2016-10-15 00:57:53 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
2020-04-20 22:55:02 +09:00
|
|
|
|
|
|
|
case 79: // o
|
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|
|
|
eventBus.dispatch("openfile", { source: window });
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2014-02-28 00:08:43 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:28:06 +09:00
|
|
|
// CTRL+ALT or Option+Command
|
|
|
|
if (cmd === 3 || cmd === 10) {
|
|
|
|
switch (evt.keyCode) {
|
|
|
|
case 80: // p
|
2015-01-29 21:37:49 +09:00
|
|
|
PDFViewerApplication.requestPresentationMode();
|
2013-07-18 23:28:06 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
2013-11-12 13:47:03 +09:00
|
|
|
case 71: // g
|
|
|
|
// focuses input#pageNumber field
|
2016-04-22 01:39:11 +09:00
|
|
|
PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
2013-11-12 13:47:03 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
2013-07-18 23:28:06 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 07:47:11 +09:00
|
|
|
if (handled) {
|
2016-12-01 01:19:11 +09:00
|
|
|
if (ensureViewerFocused && !isViewerInPresentationMode) {
|
|
|
|
pdfViewer.focus();
|
|
|
|
}
|
2012-04-12 07:47:11 +09:00
|
|
|
evt.preventDefault();
|
2011-12-26 06:18:52 +09:00
|
|
|
return;
|
2012-04-12 07:47:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Some shortcuts should not get handled if a control/input element
|
|
|
|
// is selected.
|
2020-09-23 13:59:19 +09:00
|
|
|
const curElement = getActiveOrFocusedElement();
|
2019-12-27 08:22:32 +09:00
|
|
|
const curElementTagName = curElement && curElement.tagName.toUpperCase();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
curElementTagName === "INPUT" ||
|
|
|
|
curElementTagName === "TEXTAREA" ||
|
|
|
|
curElementTagName === "SELECT" ||
|
|
|
|
(curElement && curElement.isContentEditable)
|
|
|
|
) {
|
2013-09-05 06:48:31 +09:00
|
|
|
// Make sure that the secondary toolbar is closed when Escape is pressed.
|
2019-12-26 04:03:46 +09:00
|
|
|
if (evt.keyCode !== /* Esc = */ 27) {
|
2013-09-05 06:48:31 +09:00
|
|
|
return;
|
|
|
|
}
|
2012-10-02 06:32:02 +09:00
|
|
|
}
|
2012-04-11 01:55:52 +09:00
|
|
|
|
2019-12-26 04:03:46 +09:00
|
|
|
// No control key pressed at all.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (cmd === 0) {
|
|
|
|
let turnPage = 0,
|
|
|
|
turnOnlyIfPageFit = false;
|
2012-04-11 01:55:52 +09:00
|
|
|
switch (evt.keyCode) {
|
2012-10-06 11:55:47 +09:00
|
|
|
case 38: // up arrow
|
|
|
|
case 33: // pg up
|
2018-05-15 12:10:32 +09:00
|
|
|
// vertical scrolling using arrow/pg keys
|
|
|
|
if (pdfViewer.isVerticalScrollbarEnabled) {
|
|
|
|
turnOnlyIfPageFit = true;
|
|
|
|
}
|
|
|
|
turnPage = -1;
|
|
|
|
break;
|
2012-10-06 11:55:47 +09:00
|
|
|
case 8: // backspace
|
2018-05-15 12:10:32 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
|
|
|
turnOnlyIfPageFit = true;
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = -1;
|
|
|
|
break;
|
2012-04-11 01:55:52 +09:00
|
|
|
case 37: // left arrow
|
2012-12-14 05:10:21 +09:00
|
|
|
// horizontal scrolling using arrow keys
|
2015-01-29 21:37:49 +09:00
|
|
|
if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2018-05-15 12:10:32 +09:00
|
|
|
turnOnlyIfPageFit = true;
|
2012-12-14 05:10:21 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* falls through */
|
2012-04-11 01:55:52 +09:00
|
|
|
case 75: // 'k'
|
|
|
|
case 80: // 'p'
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = -1;
|
2012-04-11 01:55:52 +09:00
|
|
|
break;
|
2013-02-11 00:14:17 +09:00
|
|
|
case 27: // esc key
|
2016-05-11 08:31:03 +09:00
|
|
|
if (PDFViewerApplication.secondaryToolbar.isOpen) {
|
|
|
|
PDFViewerApplication.secondaryToolbar.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
handled = true;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!PDFViewerApplication.supportsIntegratedFind &&
|
|
|
|
PDFViewerApplication.findBar.opened
|
|
|
|
) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.findBar.close();
|
2013-02-11 00:14:17 +09:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
2012-10-06 11:55:47 +09:00
|
|
|
case 40: // down arrow
|
|
|
|
case 34: // pg down
|
2018-05-15 12:10:32 +09:00
|
|
|
// vertical scrolling using arrow/pg keys
|
|
|
|
if (pdfViewer.isVerticalScrollbarEnabled) {
|
|
|
|
turnOnlyIfPageFit = true;
|
|
|
|
}
|
|
|
|
turnPage = 1;
|
|
|
|
break;
|
|
|
|
case 13: // enter key
|
2012-10-06 11:55:47 +09:00
|
|
|
case 32: // spacebar
|
2018-05-15 12:10:32 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
|
|
|
turnOnlyIfPageFit = true;
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = 1;
|
|
|
|
break;
|
2012-04-11 01:55:52 +09:00
|
|
|
case 39: // right arrow
|
2012-12-14 05:10:21 +09:00
|
|
|
// horizontal scrolling using arrow keys
|
2015-01-29 21:37:49 +09:00
|
|
|
if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2018-05-15 12:10:32 +09:00
|
|
|
turnOnlyIfPageFit = true;
|
2012-12-14 05:10:21 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* falls through */
|
2012-04-11 01:55:52 +09:00
|
|
|
case 74: // 'j'
|
|
|
|
case 78: // 'n'
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = 1;
|
2012-04-11 01:55:52 +09:00
|
|
|
break;
|
2012-07-31 00:12:49 +09:00
|
|
|
|
2012-10-06 11:55:47 +09:00
|
|
|
case 36: // home
|
2015-01-29 21:37:49 +09:00
|
|
|
if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.page = 1;
|
2012-10-06 11:55:47 +09:00
|
|
|
handled = true;
|
2015-07-23 19:25:19 +09:00
|
|
|
ensureViewerFocused = true;
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 35: // end
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
isViewerInPresentationMode ||
|
|
|
|
PDFViewerApplication.page < PDFViewerApplication.pagesCount
|
|
|
|
) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2012-07-31 00:12:49 +09:00
|
|
|
handled = true;
|
2015-07-23 19:25:19 +09:00
|
|
|
ensureViewerFocused = true;
|
2012-07-31 00:12:49 +09:00
|
|
|
}
|
|
|
|
break;
|
2012-09-08 08:05:14 +09:00
|
|
|
|
2016-09-07 20:30:26 +09:00
|
|
|
case 83: // 's'
|
|
|
|
PDFViewerApplication.pdfCursorTools.switchTool(CursorTool.SELECT);
|
|
|
|
break;
|
2013-10-03 05:09:43 +09:00
|
|
|
case 72: // 'h'
|
2016-09-07 20:30:26 +09:00
|
|
|
PDFViewerApplication.pdfCursorTools.switchTool(CursorTool.HAND);
|
2013-10-03 05:09:43 +09:00
|
|
|
break;
|
2016-09-07 20:30:26 +09:00
|
|
|
|
2012-09-08 08:05:14 +09:00
|
|
|
case 82: // 'r'
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.rotatePages(90);
|
2012-09-08 08:05:14 +09:00
|
|
|
break;
|
2018-12-16 15:29:29 +09:00
|
|
|
|
|
|
|
case 115: // F4
|
|
|
|
PDFViewerApplication.pdfSidebar.toggle();
|
|
|
|
break;
|
2012-09-08 08:05:14 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
turnPage !== 0 &&
|
|
|
|
(!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")
|
|
|
|
) {
|
2018-05-15 12:10:32 +09:00
|
|
|
if (turnPage > 0) {
|
|
|
|
if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
|
|
|
PDFViewerApplication.page++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (PDFViewerApplication.page > 1) {
|
|
|
|
PDFViewerApplication.page--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handled = true;
|
|
|
|
}
|
2012-09-08 08:05:14 +09:00
|
|
|
}
|
|
|
|
|
2019-12-26 04:03:46 +09:00
|
|
|
// shift-key
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (cmd === 4) {
|
2012-09-08 08:05:14 +09:00
|
|
|
switch (evt.keyCode) {
|
2018-01-05 03:54:19 +09:00
|
|
|
case 13: // enter key
|
2013-06-27 05:25:47 +09:00
|
|
|
case 32: // spacebar
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!isViewerInPresentationMode &&
|
|
|
|
pdfViewer.currentScaleValue !== "page-fit"
|
|
|
|
) {
|
2013-06-27 05:25:47 +09:00
|
|
|
break;
|
|
|
|
}
|
2016-08-07 20:10:50 +09:00
|
|
|
if (PDFViewerApplication.page > 1) {
|
|
|
|
PDFViewerApplication.page--;
|
|
|
|
}
|
2013-06-27 05:25:47 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
|
|
|
|
2012-09-08 08:05:14 +09:00
|
|
|
case 82: // 'r'
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.rotatePages(-90);
|
2012-09-08 08:05:14 +09:00
|
|
|
break;
|
2012-04-11 01:55:52 +09:00
|
|
|
}
|
2011-09-03 10:16:52 +09:00
|
|
|
}
|
2011-12-19 04:42:06 +09:00
|
|
|
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!handled && !isViewerInPresentationMode) {
|
2014-02-27 21:33:35 +09:00
|
|
|
// 33=Page Up 34=Page Down 35=End 36=Home
|
|
|
|
// 37=Left 38=Up 39=Right 40=Down
|
|
|
|
// 32=Spacebar
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
(evt.keyCode >= 33 && evt.keyCode <= 40) ||
|
|
|
|
(evt.keyCode === 32 && curElementTagName !== "BUTTON")
|
|
|
|
) {
|
2015-07-23 19:25:19 +09:00
|
|
|
ensureViewerFocused = true;
|
2014-02-27 21:33:35 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 19:25:19 +09:00
|
|
|
if (ensureViewerFocused && !pdfViewer.containsElement(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.
|
|
|
|
pdfViewer.focus();
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:42:06 +09:00
|
|
|
if (handled) {
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
2016-12-09 00:28:40 +09:00
|
|
|
}
|
2012-07-31 00:12:49 +09:00
|
|
|
|
2020-08-22 01:53:39 +09:00
|
|
|
function beforeUnload(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.returnValue = "";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-03 20:48:18 +09:00
|
|
|
/**
|
|
|
|
* Converts API PageLayout values to the format used by `PDFViewer`.
|
|
|
|
* NOTE: This is supported to the extent that the viewer implements the
|
|
|
|
* 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}.
|
|
|
|
*/
|
|
|
|
function apiPageLayoutToSpreadMode(layout) {
|
|
|
|
switch (layout) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "SinglePage":
|
|
|
|
case "OneColumn":
|
2019-04-03 20:48:18 +09:00
|
|
|
return SpreadMode.NONE;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "TwoColumnLeft":
|
|
|
|
case "TwoPageLeft":
|
2019-04-03 20:48:18 +09:00
|
|
|
return SpreadMode.ODD;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "TwoColumnRight":
|
|
|
|
case "TwoPageRight":
|
2019-04-03 20:48:18 +09:00
|
|
|
return SpreadMode.EVEN;
|
|
|
|
}
|
|
|
|
return SpreadMode.NONE; // Default value.
|
|
|
|
}
|
|
|
|
|
2017-07-19 23:26:17 +09:00
|
|
|
/**
|
|
|
|
* Converts API PageMode values to the format used by `PDFSidebar`.
|
|
|
|
* NOTE: There's also a "FullScreen" parameter which is not possible to support,
|
|
|
|
* since the Fullscreen API used in browsers requires that entering
|
|
|
|
* fullscreen mode only occurs as a result of a user-initiated event.
|
|
|
|
* @param {string} mode - The API PageMode value.
|
|
|
|
* @returns {number} A value from {SidebarView}.
|
|
|
|
*/
|
|
|
|
function apiPageModeToSidebarView(mode) {
|
|
|
|
switch (mode) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseNone":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.NONE;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseThumbs":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.THUMBS;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseOutlines":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.OUTLINE;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseAttachments":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.ATTACHMENTS;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseOC":
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
return SidebarView.LAYERS;
|
2017-07-19 23:26:17 +09:00
|
|
|
}
|
|
|
|
return SidebarView.NONE; // Default value.
|
|
|
|
}
|
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
/* Abstract factory for the print service. */
|
2019-12-27 08:22:32 +09:00
|
|
|
const PDFPrintServiceFactory = {
|
2016-10-07 06:46:30 +09:00
|
|
|
instance: {
|
|
|
|
supportsPrinting: false,
|
2017-04-28 19:02:42 +09:00
|
|
|
createPrintService() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createPrintService");
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
|
|
|
},
|
2016-10-07 06:46:30 +09:00
|
|
|
};
|
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
PDFViewerApplication,
|
|
|
|
DefaultExternalServices,
|
|
|
|
PDFPrintServiceFactory,
|
|
|
|
};
|