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,
|
2021-03-05 08:15:03 +09:00
|
|
|
apiPageLayoutToSpreadMode,
|
|
|
|
apiPageModeToSidebarView,
|
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
|
|
|
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,
|
|
|
|
ProgressBar,
|
|
|
|
RendererType,
|
|
|
|
ScrollMode,
|
Add support for finding/highlighting the outlineItem, corresponding to the currently visible page, in the sidebar (issue 7557, bug 1253820, bug 1499050)
This implementation is inspired by the behaviour in (recent versions of) Adobe Reader, since it leads to reasonably simple and straightforward code as far as I'm concerned.
*Specifically:* We'll only consider *one* destination per page when finding/highlighting the current outline item, which is similar to e.g. Adobe Reader, and we choose the *first* outline item at the *lowest* level of the outline tree.
Given that this functionality requires not only parsing of the `outline`, but looking up *all* of the destinations in the document, this feature can when initialized have a non-trivial performance overhead for larger PDF documents.
In an attempt to reduce the performance impact, the following steps are taken here:
- The "find current outline item"-functionality will only be enabled once *one* page has rendered and *all* the pages have been loaded[1], to prevent it interfering with data regular fetching/parsing early on during document loading and viewer initialization.
- With the exception of a couple of small and simple `eventBus`-listeners, in `PDFOutlineViewer`, this new functionality is initialized *lazily* the first time that the user clicks on the `currentOutlineItem`-button.
- The entire "find current outline item"-functionality is disabled when `disableAutoFetch = true` is set, since it can easily lead to the setting becoming essentially pointless[2] by triggering *a lot* of data fetching from a relatively minor viewer-feature.
- Fetch the destinations *individually*, since that's generally more efficient than using `PDFDocumentProxy.getDestinations` to fetch them all at once. Despite making the overall parsing code *more* asynchronous, and leading to a lot more main/worker-thread message passing, in practice this seems faster for larger documents.
Finally, we'll now always highlight an outline item that the user manually clicked on, since only highlighting when the new "find current outline item"-functionality is used seemed inconsistent.
---
[1] Keep in mind that the `outline` itself already isn't fetched/parsed until at least *one* page has been rendered in the viewer.
[2] And also quite slow, since it can take a fair amount of time to fetch all of the necessary `destinations` data when `disableAutoFetch = true` is set.
2020-12-25 20:57:43 +09:00
|
|
|
SidebarView,
|
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
|
|
|
SpreadMode,
|
|
|
|
TextLayerMode,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./ui_utils.js";
|
2021-07-27 19:23:33 +09:00
|
|
|
import { AppOptions, compatibilityParams, 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,
|
2021-03-16 19:56:31 +09:00
|
|
|
getPdfFilenameFromUrl,
|
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,
|
|
|
|
InvalidPDFException,
|
2021-02-24 21:02:58 +09:00
|
|
|
isPdfFile,
|
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
|
|
|
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 { 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";
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
import { PDFScriptingManager } from "./pdf_scripting_manager.js";
|
Add support for finding/highlighting the outlineItem, corresponding to the currently visible page, in the sidebar (issue 7557, bug 1253820, bug 1499050)
This implementation is inspired by the behaviour in (recent versions of) Adobe Reader, since it leads to reasonably simple and straightforward code as far as I'm concerned.
*Specifically:* We'll only consider *one* destination per page when finding/highlighting the current outline item, which is similar to e.g. Adobe Reader, and we choose the *first* outline item at the *lowest* level of the outline tree.
Given that this functionality requires not only parsing of the `outline`, but looking up *all* of the destinations in the document, this feature can when initialized have a non-trivial performance overhead for larger PDF documents.
In an attempt to reduce the performance impact, the following steps are taken here:
- The "find current outline item"-functionality will only be enabled once *one* page has rendered and *all* the pages have been loaded[1], to prevent it interfering with data regular fetching/parsing early on during document loading and viewer initialization.
- With the exception of a couple of small and simple `eventBus`-listeners, in `PDFOutlineViewer`, this new functionality is initialized *lazily* the first time that the user clicks on the `currentOutlineItem`-button.
- The entire "find current outline item"-functionality is disabled when `disableAutoFetch = true` is set, since it can easily lead to the setting becoming essentially pointless[2] by triggering *a lot* of data fetching from a relatively minor viewer-feature.
- Fetch the destinations *individually*, since that's generally more efficient than using `PDFDocumentProxy.getDestinations` to fetch them all at once. Despite making the overall parsing code *more* asynchronous, and leading to a lot more main/worker-thread message passing, in practice this seems faster for larger documents.
Finally, we'll now always highlight an outline item that the user manually clicked on, since only highlighting when the new "find current outline item"-functionality is used seemed inconsistent.
---
[1] Keep in mind that the `outline` itself already isn't fetched/parsed until at least *one* page has been rendered in the viewer.
[2] And also quite slow, since it can take a fair amount of time to fetch all of the necessary `destinations` data when `disableAutoFetch = true` is set.
2020-12-25 20:57:43 +09:00
|
|
|
import { PDFSidebar } from "./pdf_sidebar.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
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";
|
|
|
|
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) {}
|
|
|
|
|
2020-12-31 04:48:40 +09:00
|
|
|
static async fallback(data) {}
|
2020-01-15 22:26:47 +09:00
|
|
|
|
|
|
|
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-20 20:24:26 +09:00
|
|
|
static createScripting(options) {
|
2020-12-08 02:23:34 +09:00
|
|
|
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(),
|
[GENERIC viewer] Display a warning message, using the `errorWrapper`, for documents with signatures (PR 13214 follow-up, issue 13215)
To simplify the overall implementation, given that it only applies to the GENERIC-viewer, this patch purposely re-uses the existing `errorWrapper`-functionality to display the message.
While that one is mostly intended for actual *errors*, by re-using it here we considerably reduce the amount of code/complexity necessary for supporting this new warning. It's obviously possible to re-factor/improve this later on, but the patch should do just fine here since it'll indeed inform users (of the GENERIC-viewer) about unverified signatures.
Finally this patch also tweaks the background-color of the `errorWrapper`, making it 20 percent lighter respectively darker (depending on the theme) to make it "stand out" a little bit *less*.[1] While it may perhaps be useful to re-style/re-factor the `errorWrapper`, this patch probably isn't the right place for doing that.
---
[1] Note how in the MOZCENTRAL-viewer, which instead uses the browser notification-bar, we're purposely using a neutral colour to not draw too much attention to the notification-bar.
2021-04-11 02:50:28 +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,
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
/** @type {PDFScriptingManager} */
|
|
|
|
pdfScriptingManager: 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,
|
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(),
|
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")) {
|
2021-08-09 20:16:02 +09:00
|
|
|
return;
|
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) {
|
2021-08-09 20:16:02 +09:00
|
|
|
return;
|
2020-01-23 20:05:43 +09:00
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
const params = parseQueryString(hash),
|
2020-01-23 20:05:43 +09:00
|
|
|
waitOn = [];
|
2017-11-13 18:17:25 +09:00
|
|
|
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.get("disableworker") === "true") {
|
2018-07-31 00:41:39 +09:00
|
|
|
waitOn.push(loadFakeWorker());
|
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("disablerange")) {
|
|
|
|
AppOptions.set("disableRange", params.get("disablerange") === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("disablestream")) {
|
|
|
|
AppOptions.set("disableStream", params.get("disablestream") === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("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.set(
|
|
|
|
"disableAutoFetch",
|
2021-08-01 05:15:30 +09:00
|
|
|
params.get("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
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("disablefontface")) {
|
|
|
|
AppOptions.set(
|
|
|
|
"disableFontFace",
|
|
|
|
params.get("disablefontface") === "true"
|
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("disablehistory")) {
|
|
|
|
AppOptions.set("disableHistory", params.get("disablehistory") === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("verbosity")) {
|
|
|
|
AppOptions.set("verbosity", params.get("verbosity") | 0);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("textlayer")) {
|
|
|
|
switch (params.get("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;
|
2021-08-01 05:15:30 +09:00
|
|
|
viewer.classList.add(`textLayer-${params.get("textlayer")}`);
|
2018-07-31 00:41:39 +09:00
|
|
|
break;
|
2017-05-04 10:05:53 +09:00
|
|
|
}
|
|
|
|
}
|
2021-08-01 05:15:30 +09:00
|
|
|
if (params.has("pdfbug")) {
|
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("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);
|
|
|
|
|
2021-08-01 05:15:30 +09:00
|
|
|
const enabled = params.get("pdfbug").split(",");
|
2021-08-18 22:59:30 +09:00
|
|
|
waitOn.push(initPDFBug(enabled));
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
|
|
|
// 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")) &&
|
2021-08-01 05:15:30 +09:00
|
|
|
params.has("locale")
|
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
|
|
|
) {
|
2021-08-01 05:15:30 +09:00
|
|
|
AppOptions.set("locale", params.get("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) {
|
2021-08-09 20:16:02 +09:00
|
|
|
return;
|
2020-11-17 21:37:21 +09:00
|
|
|
}
|
2021-08-09 20:16:02 +09:00
|
|
|
try {
|
|
|
|
await Promise.all(waitOn);
|
|
|
|
} catch (reason) {
|
2018-10-05 20:54:16 +09:00
|
|
|
console.error(`_parseHashParameters: "${reason.message}".`);
|
2021-08-09 20:16:02 +09:00
|
|
|
}
|
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 || [];
|
2021-04-29 04:00:28 +09:00
|
|
|
const mediaMatcher =
|
|
|
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")
|
|
|
|
? "-moz-toolbar-prefers-color-scheme"
|
|
|
|
: "prefers-color-scheme";
|
|
|
|
const mediaRule = `(${mediaMatcher}: dark)`;
|
|
|
|
const mediaRegex = new RegExp(
|
|
|
|
`^@media \\(${mediaMatcher}: dark\\) {\\n\\s*([\\w\\s-.,:;/\\\\{}()]+)\\n}$`
|
|
|
|
);
|
2020-11-15 21:29:50 +09:00
|
|
|
for (let i = 0, ii = cssRules.length; i < ii; i++) {
|
|
|
|
const rule = cssRules[i];
|
2021-04-29 04:00:28 +09:00
|
|
|
if (rule instanceof CSSMediaRule && rule.media?.[0] === mediaRule) {
|
2020-11-15 21:29:50 +09:00
|
|
|
if (cssTheme === ViewerCssTheme.LIGHT) {
|
|
|
|
styleSheet.deleteRule(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// cssTheme === ViewerCssTheme.DARK
|
2021-04-29 04:00:28 +09:00
|
|
|
const darkRules = mediaRegex.exec(rule.cssText);
|
2020-11-15 21:29:50 +09:00
|
|
|
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();
|
[api-minor] Add an option, in `PDFDocumentProxy.cleanup`, to allow fonts to remain attached to the DOM
As mentioned in the JSDoc comment, this should not be used unless you know what you're doing, since it will lead to increased memory usage. However, in some situations (e.g. SVG-rendering), we still want to be able to run general clean-up on both the main/worker-thread while keeping loaded fonts attached to the DOM.[1]
As part of these changes, `WorkerTransport.startCleanup` is converted to an async method and we'll also skip clean-up when destruction has started (since it's redundant).
---
[1] The SVG-rendering mode is obviously not officially supported, since it's both rather incomplete and inherently slower. However with recent changes, whereby we cache repeated images on the document rather than the page level, memory usage can be *a lot* worse than before if we never attempt to release e.g. cached image-data when the viewer is in SVG-rendering mode.
2021-04-02 19:26:39 +09:00
|
|
|
pdfRenderingQueue.onIdle = this._cleanup.bind(this);
|
2018-07-31 00:41:39 +09:00
|
|
|
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;
|
|
|
|
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
const pdfScriptingManager = new PDFScriptingManager({
|
|
|
|
eventBus,
|
|
|
|
sandboxBundleSrc:
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC || CHROME")
|
|
|
|
? AppOptions.get("sandboxBundleSrc")
|
|
|
|
: null,
|
|
|
|
scriptingFactory: this.externalServices,
|
|
|
|
docPropertiesLookup: this._scriptingDocProperties.bind(this),
|
|
|
|
});
|
|
|
|
this.pdfScriptingManager = pdfScriptingManager;
|
|
|
|
|
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,
|
2021-07-29 16:53:24 +09:00
|
|
|
scriptingManager:
|
|
|
|
AppOptions.get("enableScripting") && pdfScriptingManager,
|
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"),
|
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"),
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
annotationMode: AppOptions.get("annotationMode"),
|
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
|
|
|
imageResourcesPath: AppOptions.get("imageResourcesPath"),
|
|
|
|
enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
|
|
|
|
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
|
|
|
|
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
|
|
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
|
|
|
pdfLinkService.setViewer(this.pdfViewer);
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
pdfScriptingManager.setViewer(this.pdfViewer);
|
2018-07-31 00:41:39 +09:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-09-09 21:21:15 +09:00
|
|
|
// The browsing history is only enabled when the viewer is standalone,
|
|
|
|
// i.e. not when it is embedded in a web page.
|
|
|
|
if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) {
|
|
|
|
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,
|
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,
|
2021-02-03 23:48:40 +09:00
|
|
|
this.l10n,
|
|
|
|
this.isViewerEmbedded
|
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
|
|
|
|
|
|
|
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() {
|
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")) {
|
2021-01-31 21:45:14 +09:00
|
|
|
return shadow(this, "supportsFullscreen", document.fullscreenEnabled);
|
|
|
|
}
|
2021-08-28 00:45:34 +09:00
|
|
|
return shadow(
|
|
|
|
this,
|
|
|
|
"supportsFullscreen",
|
|
|
|
document.fullscreenEnabled ||
|
|
|
|
document.mozFullScreenEnabled ||
|
|
|
|
document.webkitFullscreenEnabled
|
2021-01-31 21:45:14 +09:00
|
|
|
);
|
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({
|
2021-02-10 22:06:32 +09:00
|
|
|
onOpenWithTransport: (url, length, transport) => {
|
|
|
|
this.open(url, { length, range: transport });
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
2021-02-24 21:02:58 +09:00
|
|
|
onOpenWithData: (data, contentDispositionFilename) => {
|
|
|
|
if (isPdfFile(contentDispositionFilename)) {
|
|
|
|
this._contentDispositionFilename = contentDispositionFilename;
|
|
|
|
}
|
2021-02-10 22:06:32 +09:00
|
|
|
this.open(data);
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
2021-02-10 22:06:32 +09:00
|
|
|
onOpenWithURL: (url, length, originalUrl) => {
|
2021-02-10 23:56:15 +09:00
|
|
|
const file = originalUrl !== undefined ? { url, originalUrl } : url;
|
|
|
|
const args = length !== undefined ? { length } : null;
|
|
|
|
|
2021-02-10 22:06:32 +09:00
|
|
|
this.open(file, args);
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
2021-02-10 22:06:32 +09:00
|
|
|
onError: err => {
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("loading_error").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
this._documentError(msg, err);
|
|
|
|
});
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
2021-02-10 22:06:32 +09:00
|
|
|
onProgress: (loaded, total) => {
|
|
|
|
this.progress(loaded / total);
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
|
|
|
});
|
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];
|
2021-03-16 19:56:31 +09:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2021-01-02 07:03:18 +09:00
|
|
|
get _docFilename() {
|
|
|
|
// Use `this.url` instead of `this.baseUrl` to perform filename detection
|
|
|
|
// based on the reference fragment as ultimate fallback if needed.
|
2021-03-16 19:56:31 +09:00
|
|
|
return this._contentDispositionFilename || getPdfFilenameFromUrl(this.url);
|
2021-01-02 07:03:18 +09:00
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
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() {
|
2021-02-08 03:53:43 +09:00
|
|
|
this._unblockDocumentLoadEvent();
|
|
|
|
|
2021-02-14 18:39:34 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
|
|
const { container } = this.appConfig.errorWrapper;
|
|
|
|
container.hidden = true;
|
|
|
|
}
|
2014-04-15 19:00:46 +09:00
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
if (!this.pdfLoadingTask) {
|
2021-04-03 22:36:34 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
|
|
this.pdfDocument?.annotationStorage.size > 0 &&
|
|
|
|
this._annotationStorageModified
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
// Trigger saving, to prevent data loss in forms; see issue 12257.
|
|
|
|
await this.save({ sourceEventType: "save" });
|
|
|
|
} catch (reason) {
|
|
|
|
// Ignoring errors, to ensure that document closing won't break.
|
|
|
|
}
|
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();
|
2021-06-23 21:00:54 +09:00
|
|
|
this.pdfLinkService.externalLinkEnabled = true;
|
[GENERIC viewer] Display a warning message, using the `errorWrapper`, for documents with signatures (PR 13214 follow-up, issue 13215)
To simplify the overall implementation, given that it only applies to the GENERIC-viewer, this patch purposely re-uses the existing `errorWrapper`-functionality to display the message.
While that one is mostly intended for actual *errors*, by re-using it here we considerably reduce the amount of code/complexity necessary for supporting this new warning. It's obviously possible to re-factor/improve this later on, but the patch should do just fine here since it'll indeed inform users (of the GENERIC-viewer) about unverified signatures.
Finally this patch also tweaks the background-color of the `errorWrapper`, making it 20 percent lighter respectively darker (depending on the theme) to make it "stand out" a little bit *less*.[1] While it may perhaps be useful to re-style/re-factor the `errorWrapper`, this patch probably isn't the right place for doing that.
---
[1] Note how in the MOZCENTRAL-viewer, which instead uses the browser notification-bar, we're purposely using a neutral colour to not draw too much attention to the notification-bar.
2021-04-11 02:50:28 +09:00
|
|
|
this._fellback = false;
|
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;
|
2020-08-04 02:44:04 +09:00
|
|
|
this._saveInProgress = false;
|
2020-12-08 01:21:49 +09:00
|
|
|
|
|
|
|
this._cancelIdleCallbacks();
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
promises.push(this.pdfScriptingManager.destroyPromise);
|
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
|
|
|
|
2021-08-28 00:29:00 +09:00
|
|
|
this.pdfHistory?.reset();
|
|
|
|
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();
|
|
|
|
}
|
2021-01-12 22:29:15 +09:00
|
|
|
await 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
|
|
|
|
2021-02-10 23:57:58 +09:00
|
|
|
let key = "loading_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
|
|
|
if (exception instanceof InvalidPDFException) {
|
2021-02-10 23:57:58 +09:00
|
|
|
key = "invalid_file_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
|
|
|
} else if (exception instanceof MissingPDFException) {
|
2021-02-10 23:57:58 +09:00
|
|
|
key = "missing_file_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
|
|
|
} else if (exception instanceof UnexpectedResponseException) {
|
2021-02-10 23:57:58 +09:00
|
|
|
key = "unexpected_response_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
|
|
|
}
|
2021-02-22 20:43:16 +09:00
|
|
|
return this.l10n.get(key).then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
this._documentError(msg, { message: exception?.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
|
|
|
},
|
|
|
|
|
2021-04-03 22:33:14 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_ensureDownloadComplete() {
|
|
|
|
if (this.pdfDocument && this.downloadComplete) {
|
|
|
|
return;
|
2013-03-25 02:25:57 +09:00
|
|
|
}
|
2021-04-03 22:33:14 +09:00
|
|
|
throw new Error("PDF document not downloaded.");
|
|
|
|
},
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2021-04-03 22:33:14 +09:00
|
|
|
async download({ sourceEventType = "download" } = {}) {
|
|
|
|
const url = this.baseUrl,
|
2021-01-02 07:03:18 +09:00
|
|
|
filename = this._docFilename;
|
2021-04-03 22:33:14 +09:00
|
|
|
try {
|
|
|
|
this._ensureDownloadComplete();
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2021-04-03 22:33:14 +09:00
|
|
|
const data = await this.pdfDocument.getData();
|
|
|
|
const blob = new Blob([data], { type: "application/pdf" });
|
2014-03-14 12:23:47 +09:00
|
|
|
|
2021-04-03 22:33:14 +09:00
|
|
|
await this.downloadManager.download(blob, url, filename, sourceEventType);
|
|
|
|
} catch (reason) {
|
|
|
|
// When the PDF document isn't ready, or the PDF file is still
|
|
|
|
// downloading, simply download using the URL.
|
|
|
|
await this.downloadManager.downloadUrl(url, filename);
|
|
|
|
}
|
2011-10-19 13:29:14 +09:00
|
|
|
},
|
|
|
|
|
2020-12-23 19:39:54 +09:00
|
|
|
async save({ sourceEventType = "download" } = {}) {
|
2020-08-04 02:44:04 +09:00
|
|
|
if (this._saveInProgress) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-03 22:33:14 +09:00
|
|
|
this._saveInProgress = true;
|
|
|
|
await this.pdfScriptingManager.dispatchWillSave();
|
2020-08-04 02:44:04 +09:00
|
|
|
|
2021-04-03 22:33:14 +09:00
|
|
|
const url = this.baseUrl,
|
2021-01-02 07:03:18 +09:00
|
|
|
filename = this._docFilename;
|
2021-04-03 22:33:14 +09:00
|
|
|
try {
|
|
|
|
this._ensureDownloadComplete();
|
2020-08-04 02:44:04 +09:00
|
|
|
|
[api-minor] Remove the manual passing of an `AnnotationStorage`-instance when calling various API-method
Note how we purposely don't expose the `AnnotationStorage`-class directly in the official API (see `src/pdf.js`), since trying to use *multiple* ones simultaneously doesn't really make sense (e.g. in the viewer).
Instead we lazily initialize, and cache, just *one* instance via `PDFDocumentProxy.annotationStorage` which should thus be available internally in the API itself without having to be manually passed to various methods.
To support these changes, the `AnnotationStorage`-instance initialization is moved into the `WorkerTransport`-class to allow both `PDFDocumentProxy` and `PDFPageProxy` to access it.
This patch implements the following simplifications:
- Remove the `annotationStorage`-parameter from `PDFDocumentProxy.saveDocument`, since it's already available internally.
Furthermore, while it's currently possible to call that method without an `AnnotationStorage`-instance, that really does *not* make any sense at all. In this case you're effectively reducing `PDFDocumentProxy.saveDocument` to a "regular" `PDFDocumentProxy.getData` call, but with *a lot* more overhead, which was obviously not the intention of the `PDFDocumentProxy.saveDocument`-method.
- Try to discourage third-party users from calling `PDFDocumentProxy.saveDocument` unconditionally, as a replacement for `PDFDocumentProxy.getData` (note the previous point).
- Replace the `annotationStorage`-parameter, in `PDFPageProxy.render`, with a boolean `includeAnnotationStorage`-parameter which simply indicates if the (internally available) `AnnotationStorage`-instance should be used during rendering (e.g. for printing).
- By removing the need to *manually* provide `annotationStorage`-parameters to various API-methods, using the API should become simpler (e.g. for third-parties) since you no longer need to worry about manually fetching and passing around this data.
2021-04-04 23:49:06 +09:00
|
|
|
const data = await this.pdfDocument.saveDocument();
|
2021-04-03 22:33:14 +09:00
|
|
|
const blob = new Blob([data], { type: "application/pdf" });
|
2020-12-08 03:22:14 +09:00
|
|
|
|
2021-04-03 22:33:14 +09:00
|
|
|
await this.downloadManager.download(blob, url, filename, sourceEventType);
|
|
|
|
} catch (reason) {
|
|
|
|
// When the PDF document isn't ready, or the PDF file is still
|
|
|
|
// downloading, simply fallback to a "regular" download.
|
|
|
|
await this.download({ sourceEventType });
|
|
|
|
} finally {
|
|
|
|
await this.pdfScriptingManager.dispatchDidSave();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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.
|
[GENERIC viewer] Display a warning message, using the `errorWrapper`, for documents with signatures (PR 13214 follow-up, issue 13215)
To simplify the overall implementation, given that it only applies to the GENERIC-viewer, this patch purposely re-uses the existing `errorWrapper`-functionality to display the message.
While that one is mostly intended for actual *errors*, by re-using it here we considerably reduce the amount of code/complexity necessary for supporting this new warning. It's obviously possible to re-factor/improve this later on, but the patch should do just fine here since it'll indeed inform users (of the GENERIC-viewer) about unverified signatures.
Finally this patch also tweaks the background-color of the `errorWrapper`, making it 20 percent lighter respectively darker (depending on the theme) to make it "stand out" a little bit *less*.[1] While it may perhaps be useful to re-style/re-factor the `errorWrapper`, this patch probably isn't the right place for doing that.
---
[1] Note how in the MOZCENTRAL-viewer, which instead uses the browser notification-bar, we're purposely using a neutral colour to not draw too much attention to the notification-bar.
2021-04-11 02:50:28 +09:00
|
|
|
if (this._fellback) {
|
2020-07-08 22:35:09 +09:00
|
|
|
return;
|
2015-04-26 08:49:37 +09:00
|
|
|
}
|
[GENERIC viewer] Display a warning message, using the `errorWrapper`, for documents with signatures (PR 13214 follow-up, issue 13215)
To simplify the overall implementation, given that it only applies to the GENERIC-viewer, this patch purposely re-uses the existing `errorWrapper`-functionality to display the message.
While that one is mostly intended for actual *errors*, by re-using it here we considerably reduce the amount of code/complexity necessary for supporting this new warning. It's obviously possible to re-factor/improve this later on, but the patch should do just fine here since it'll indeed inform users (of the GENERIC-viewer) about unverified signatures.
Finally this patch also tweaks the background-color of the `errorWrapper`, making it 20 percent lighter respectively darker (depending on the theme) to make it "stand out" a little bit *less*.[1] While it may perhaps be useful to re-style/re-factor the `errorWrapper`, this patch probably isn't the right place for doing that.
---
[1] Note how in the MOZCENTRAL-viewer, which instead uses the browser notification-bar, we're purposely using a neutral colour to not draw too much attention to the notification-bar.
2021-04-11 02:50:28 +09:00
|
|
|
this._fellback = true;
|
|
|
|
|
2020-12-31 04:48:40 +09:00
|
|
|
this.externalServices
|
|
|
|
.fallback({
|
2020-07-08 22:35:09 +09:00
|
|
|
featureId,
|
|
|
|
url: this.baseUrl,
|
2020-12-31 04:48:40 +09:00
|
|
|
})
|
|
|
|
.then(download => {
|
2020-07-08 22:35:09 +09:00
|
|
|
if (!download) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-31 04:48:40 +09:00
|
|
|
this.download({ sourceEventType: "download" });
|
|
|
|
});
|
2012-05-11 07:54:58 +09:00
|
|
|
},
|
|
|
|
|
2011-11-30 04:28:05 +09:00
|
|
|
/**
|
2021-02-08 03:53:43 +09:00
|
|
|
* Show the error box; used for errors affecting loading and/or parsing of
|
|
|
|
* the entire PDF document.
|
|
|
|
*/
|
|
|
|
_documentError(message, moreInfo = null) {
|
|
|
|
this._unblockDocumentLoadEvent();
|
|
|
|
|
|
|
|
this._otherError(message, moreInfo);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the error box; used for errors affecting e.g. only a single page.
|
|
|
|
*
|
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
|
|
|
*/
|
2021-02-08 03:53:43 +09:00
|
|
|
_otherError(message, moreInfo = null) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const moreInfoText = [
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("error_version_info", {
|
2021-02-10 23:57:58 +09:00
|
|
|
version: version || "?",
|
|
|
|
build: build || "?",
|
|
|
|
}),
|
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
|
|
|
];
|
2012-05-15 09:19:09 +09:00
|
|
|
if (moreInfo) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("error_message", { message: moreInfo.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
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
if (moreInfo.stack) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("error_stack", { stack: moreInfo.stack })
|
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
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
} else {
|
|
|
|
if (moreInfo.filename) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("error_file", { file: moreInfo.filename })
|
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
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
}
|
|
|
|
if (moreInfo.lineNumber) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("error_line", { line: moreInfo.lineNumber })
|
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
|
|
|
);
|
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;
|
2021-02-08 08:21:49 +09:00
|
|
|
errorWrapper.hidden = false;
|
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 () {
|
2021-02-08 08:21:49 +09:00
|
|
|
errorWrapper.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 () {
|
2021-02-08 08:21:49 +09:00
|
|
|
errorMoreInfo.hidden = false;
|
|
|
|
moreInfoButton.hidden = true;
|
|
|
|
lessInfoButton.hidden = 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
|
|
|
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 () {
|
2021-02-08 08:21:49 +09:00
|
|
|
errorMoreInfo.hidden = true;
|
|
|
|
moreInfoButton.hidden = false;
|
|
|
|
lessInfoButton.hidden = true;
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
|
|
|
moreInfoButton.oncontextmenu = noContextMenuHandler;
|
|
|
|
lessInfoButton.oncontextmenu = noContextMenuHandler;
|
|
|
|
closeButton.oncontextmenu = noContextMenuHandler;
|
2021-02-08 08:21:49 +09:00
|
|
|
moreInfoButton.hidden = false;
|
|
|
|
lessInfoButton.hidden = 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
|
|
|
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;
|
|
|
|
|
2021-01-07 18:22:02 +09:00
|
|
|
pdfDocument.getDownloadInfo().then(({ length }) => {
|
|
|
|
this._contentLength = length; // Ensure that the correct length is used.
|
2017-05-09 20:17:39 +09:00
|
|
|
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
|
|
|
|
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(
|
2021-07-02 23:36:27 +09:00
|
|
|
pdfDocument.fingerprints[0]
|
2020-03-21 22:37:03 +09:00
|
|
|
))
|
|
|
|
.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);
|
2020-12-19 20:49:12 +09:00
|
|
|
this._initializeAnnotationStorageCallbacks(pdfDocument);
|
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({
|
2021-07-02 23:36:27 +09:00
|
|
|
fingerprint: pdfDocument.fingerprints[0],
|
2020-03-21 22:37:03 +09:00
|
|
|
viewOnLoad,
|
2021-02-06 01:36:28 +09:00
|
|
|
initialDest: openAction?.dest,
|
2020-03-21 22:37:03 +09:00
|
|
|
});
|
|
|
|
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(() => {
|
2021-02-06 06:00:10 +09:00
|
|
|
this._unblockDocumentLoadEvent();
|
|
|
|
|
2020-04-05 17:59:10 +09:00
|
|
|
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 => {
|
2021-04-10 19:46:45 +09:00
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the outline resolved.
|
|
|
|
}
|
Add support for finding/highlighting the outlineItem, corresponding to the currently visible page, in the sidebar (issue 7557, bug 1253820, bug 1499050)
This implementation is inspired by the behaviour in (recent versions of) Adobe Reader, since it leads to reasonably simple and straightforward code as far as I'm concerned.
*Specifically:* We'll only consider *one* destination per page when finding/highlighting the current outline item, which is similar to e.g. Adobe Reader, and we choose the *first* outline item at the *lowest* level of the outline tree.
Given that this functionality requires not only parsing of the `outline`, but looking up *all* of the destinations in the document, this feature can when initialized have a non-trivial performance overhead for larger PDF documents.
In an attempt to reduce the performance impact, the following steps are taken here:
- The "find current outline item"-functionality will only be enabled once *one* page has rendered and *all* the pages have been loaded[1], to prevent it interfering with data regular fetching/parsing early on during document loading and viewer initialization.
- With the exception of a couple of small and simple `eventBus`-listeners, in `PDFOutlineViewer`, this new functionality is initialized *lazily* the first time that the user clicks on the `currentOutlineItem`-button.
- The entire "find current outline item"-functionality is disabled when `disableAutoFetch = true` is set, since it can easily lead to the setting becoming essentially pointless[2] by triggering *a lot* of data fetching from a relatively minor viewer-feature.
- Fetch the destinations *individually*, since that's generally more efficient than using `PDFDocumentProxy.getDestinations` to fetch them all at once. Despite making the overall parsing code *more* asynchronous, and leading to a lot more main/worker-thread message passing, in practice this seems faster for larger documents.
Finally, we'll now always highlight an outline item that the user manually clicked on, since only highlighting when the new "find current outline item"-functionality is used seemed inconsistent.
---
[1] Keep in mind that the `outline` itself already isn't fetched/parsed until at least *one* page has been rendered in the viewer.
[2] And also quite slow, since it can take a fair amount of time to fetch all of the necessary `destinations` data when `disableAutoFetch = true` is set.
2020-12-25 20:57:43 +09:00
|
|
|
this.pdfOutlineViewer.render({ outline, pdfDocument });
|
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 => {
|
2021-04-10 19:46:45 +09:00
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the attachments resolved.
|
|
|
|
}
|
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.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 => {
|
2021-04-10 19:46:45 +09:00
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the layers resolved.
|
|
|
|
}
|
[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.render({ optionalContentConfig, pdfDocument });
|
|
|
|
});
|
2021-02-14 18:39:42 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
|
|
"requestIdleCallback" in window
|
|
|
|
) {
|
2020-10-24 09:21:08 +09:00
|
|
|
const callback = window.requestIdleCallback(
|
|
|
|
() => {
|
|
|
|
this._collectTelemetry(pdfDocument);
|
|
|
|
this._idleCallbacks.delete(callback);
|
|
|
|
},
|
|
|
|
{ timeout: 1000 }
|
|
|
|
);
|
|
|
|
this._idleCallbacks.add(callback);
|
|
|
|
}
|
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
|
|
|
|
*/
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
async _scriptingDocProperties(pdfDocument) {
|
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 => {
|
2021-02-14 20:37:37 +09:00
|
|
|
this.eventBus._on("metadataloaded", resolve, { once: true });
|
2020-12-06 20:42:56 +09:00
|
|
|
});
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
return null; // The document was closed while the metadata resolved.
|
2020-12-06 20:42:56 +09:00
|
|
|
}
|
|
|
|
}
|
2021-01-07 18:22:02 +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.
|
|
|
|
await new Promise(resolve => {
|
2021-02-14 20:37:37 +09:00
|
|
|
this.eventBus._on("documentloaded", resolve, { once: true });
|
2021-01-07 18:22:02 +09:00
|
|
|
});
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
return null; // The document was closed while the downloadInfo resolved.
|
2021-01-07 18:22:02 +09:00
|
|
|
}
|
|
|
|
}
|
2020-10-01 20:57:23 +09:00
|
|
|
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
return {
|
|
|
|
...this.documentInfo,
|
|
|
|
baseURL: this.baseUrl,
|
|
|
|
filesize: this._contentLength,
|
|
|
|
filename: this._docFilename,
|
|
|
|
metadata: this.metadata?.getRaw(),
|
|
|
|
authors: this.metadata?.get("dc:creator"),
|
|
|
|
numPages: this.pagesCount,
|
|
|
|
URL: this.url,
|
2020-11-18 22:59:57 +09:00
|
|
|
};
|
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,
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
!this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null,
|
2020-04-05 17:59:10 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the auto print data resolved.
|
|
|
|
}
|
|
|
|
let triggerAutoPrint = false;
|
|
|
|
|
2020-12-21 19:43:54 +09:00
|
|
|
if (openAction?.action === "Print") {
|
2020-04-05 17:59:10 +09:00
|
|
|
triggerAutoPrint = true;
|
|
|
|
}
|
2020-12-21 19:43:54 +09:00
|
|
|
if (javaScript) {
|
2020-04-05 17:59:10 +09:00
|
|
|
javaScript.some(js => {
|
|
|
|
if (!js) {
|
|
|
|
// Don't warn/fallback for empty JavaScript actions.
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-16 17:08:13 +09:00
|
|
|
console.warn("Warning: JavaScript support is not enabled");
|
|
|
|
this.fallback(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-12-21 19:43:54 +09:00
|
|
|
this.triggerPrinting();
|
2020-04-05 17:59:10 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializeMetadata(pdfDocument) {
|
2021-05-16 17:58:34 +09:00
|
|
|
const { info, metadata, contentDispositionFilename, contentLength } =
|
|
|
|
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;
|
2021-02-24 21:02:58 +09:00
|
|
|
this._contentDispositionFilename ??= contentDispositionFilename;
|
2021-01-07 18:22:02 +09:00
|
|
|
this._contentLength ??= contentLength; // See `getDownloadInfo`-call above.
|
2020-04-05 17:26:55 +09:00
|
|
|
|
|
|
|
// Provides some basic debug information
|
|
|
|
console.log(
|
2021-07-02 23:36:27 +09:00
|
|
|
`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` +
|
2020-04-05 18:15:21 +09:00
|
|
|
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
2021-05-09 22:54:26 +09:00
|
|
|
`(PDF.js: ${version || "-"})`
|
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
|
|
|
|
2021-02-16 22:13:39 +09:00
|
|
|
let pdfTitle = info?.Title;
|
|
|
|
|
2021-02-06 01:36:28 +09:00
|
|
|
const metadataTitle = metadata?.get("dc:title");
|
2020-04-05 17:26:55 +09:00
|
|
|
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
|
|
|
|
2021-03-21 18:41:22 +09:00
|
|
|
if (
|
|
|
|
info.IsXFAPresent &&
|
|
|
|
!info.IsAcroFormPresent &&
|
|
|
|
// Note: `isPureXfa === true` implies that `enableXfa = true` was set.
|
|
|
|
!pdfDocument.isPureXfa
|
|
|
|
) {
|
2021-07-16 21:12:24 +09:00
|
|
|
console.warn("Warning: XFA support is not enabled");
|
2021-04-16 17:08:13 +09:00
|
|
|
this.fallback(UNSUPPORTED_FEATURES.forms);
|
2020-08-13 01:17:58 +09:00
|
|
|
} else if (
|
2020-08-23 21:04:49 +09:00
|
|
|
(info.IsAcroFormPresent || info.IsXFAPresent) &&
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
!this.pdfViewer.renderForms
|
2020-08-13 01:17:58 +09:00
|
|
|
) {
|
2020-08-23 21:04:49 +09:00
|
|
|
console.warn("Warning: Interactive form support is not enabled");
|
2021-04-16 17:08:13 +09:00
|
|
|
this.fallback(UNSUPPORTED_FEATURES.forms);
|
2020-04-05 17:26:55 +09:00
|
|
|
}
|
2020-01-02 04:41:15 +09:00
|
|
|
|
2021-04-10 23:53:17 +09:00
|
|
|
if (info.IsSignaturesPresent) {
|
|
|
|
console.warn("Warning: Digital signatures validation is not supported");
|
|
|
|
this.fallback(UNSUPPORTED_FEATURES.signatures);
|
|
|
|
}
|
|
|
|
|
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 }) {
|
2021-09-09 21:21:15 +09:00
|
|
|
if (!this.pdfHistory) {
|
2019-02-02 18:08:56 +09:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-19 20:49:12 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_initializeAnnotationStorageCallbacks(pdfDocument) {
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { annotationStorage } = pdfDocument;
|
|
|
|
|
2021-04-03 22:36:34 +09:00
|
|
|
annotationStorage.onSetModified = () => {
|
2020-12-19 20:49:12 +09:00
|
|
|
window.addEventListener("beforeunload", beforeUnload);
|
2021-04-03 22:36:34 +09:00
|
|
|
|
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|
|
|
this._annotationStorageModified = true;
|
|
|
|
}
|
2020-12-19 20:49:12 +09:00
|
|
|
};
|
2021-04-03 22:36:34 +09:00
|
|
|
annotationStorage.onResetModified = () => {
|
2020-12-19 20:49:12 +09:00
|
|
|
window.removeEventListener("beforeunload", beforeUnload);
|
2021-04-03 22:36:34 +09:00
|
|
|
|
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|
|
|
delete this._annotationStorageModified;
|
|
|
|
}
|
2020-12-19 20:49: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
|
|
|
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
|
|
|
},
|
|
|
|
|
[api-minor] Add an option, in `PDFDocumentProxy.cleanup`, to allow fonts to remain attached to the DOM
As mentioned in the JSDoc comment, this should not be used unless you know what you're doing, since it will lead to increased memory usage. However, in some situations (e.g. SVG-rendering), we still want to be able to run general clean-up on both the main/worker-thread while keeping loaded fonts attached to the DOM.[1]
As part of these changes, `WorkerTransport.startCleanup` is converted to an async method and we'll also skip clean-up when destruction has started (since it's redundant).
---
[1] The SVG-rendering mode is obviously not officially supported, since it's both rather incomplete and inherently slower. However with recent changes, whereby we cache repeated images on the document rather than the page level, memory usage can be *a lot* worse than before if we never attempt to release e.g. cached image-data when the viewer is in SVG-rendering mode.
2021-04-02 19:26:39 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_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.
|
[api-minor] Add an option, in `PDFDocumentProxy.cleanup`, to allow fonts to remain attached to the DOM
As mentioned in the JSDoc comment, this should not be used unless you know what you're doing, since it will lead to increased memory usage. However, in some situations (e.g. SVG-rendering), we still want to be able to run general clean-up on both the main/worker-thread while keeping loaded fonts attached to the DOM.[1]
As part of these changes, `WorkerTransport.startCleanup` is converted to an async method and we'll also skip clean-up when destruction has started (since it's redundant).
---
[1] The SVG-rendering mode is obviously not officially supported, since it's both rather incomplete and inherently slower. However with recent changes, whereby we cache repeated images on the document rather than the page level, memory usage can be *a lot* worse than before if we never attempt to release e.g. cached image-data when the viewer is in SVG-rendering mode.
2021-04-02 19:26:39 +09:00
|
|
|
this.pdfDocument.cleanup(
|
|
|
|
/* keepLoadedFonts = */ this.pdfViewer.renderer === RendererType.SVG
|
|
|
|
);
|
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;
|
2021-05-16 17:58:34 +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() {
|
2020-12-23 19:39:54 +09:00
|
|
|
// Given that the "beforeprint" browser event is synchronous, we
|
|
|
|
// unfortunately cannot await the scripting event dispatching here.
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
this.pdfScriptingManager.dispatchWillPrint();
|
2020-12-23 19:13:43 +09:00
|
|
|
|
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) {
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("printing_not_supported").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
this._otherError(msg);
|
|
|
|
});
|
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) {
|
2021-02-22 20:43:16 +09:00
|
|
|
this.l10n.get("printing_not_ready").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
// eslint-disable-next-line no-alert
|
|
|
|
window.alert(msg);
|
|
|
|
});
|
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");
|
2021-05-16 17:58:34 +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() {
|
2020-12-23 19:39:54 +09:00
|
|
|
// Given that the "afterprint" browser event is synchronous, we
|
|
|
|
// unfortunately cannot await the scripting event dispatching here.
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
this.pdfScriptingManager.dispatchDidPrint();
|
2020-12-23 19:13:43 +09:00
|
|
|
|
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
|
|
|
|
2021-08-28 00:29:00 +09:00
|
|
|
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) {
|
2021-03-28 21:12:13 +09:00
|
|
|
this.pdfViewer.pagesRotation += delta;
|
2017-08-19 21:23:40 +09:00
|
|
|
// 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() {
|
2021-08-28 00:29:00 +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;
|
|
|
|
}
|
|
|
|
window.print();
|
|
|
|
},
|
|
|
|
|
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
|
|
|
};
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
_boundEvents.windowUpdateFromSandbox = event => {
|
|
|
|
eventBus.dispatch("updatefromsandbox", {
|
|
|
|
source: window,
|
|
|
|
detail: event.detail,
|
|
|
|
});
|
|
|
|
};
|
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);
|
|
|
|
window.addEventListener("resize", _boundEvents.windowResize);
|
|
|
|
window.addEventListener("hashchange", _boundEvents.windowHashChange);
|
|
|
|
window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
|
|
|
window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
window.addEventListener(
|
|
|
|
"updatefromsandbox",
|
|
|
|
_boundEvents.windowUpdateFromSandbox
|
|
|
|
);
|
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);
|
|
|
|
window.removeEventListener("resize", _boundEvents.windowResize);
|
|
|
|
window.removeEventListener("hashchange", _boundEvents.windowHashChange);
|
|
|
|
window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
|
|
|
window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
window.removeEventListener(
|
|
|
|
"updatefromsandbox",
|
|
|
|
_boundEvents.windowUpdateFromSandbox
|
|
|
|
);
|
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;
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
_boundEvents.windowUpdateFromSandbox = 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;
|
|
|
|
},
|
2020-12-19 07:12:52 +09:00
|
|
|
|
2021-02-06 06:00:10 +09:00
|
|
|
/**
|
|
|
|
* Should be called *after* all pages have loaded, or if an error occurred,
|
|
|
|
* to unblock the "load" event; see https://bugzilla.mozilla.org/show_bug.cgi?id=1618553
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_unblockDocumentLoadEvent() {
|
|
|
|
if (document.blockUnblockOnload) {
|
|
|
|
document.blockUnblockOnload(false);
|
|
|
|
}
|
|
|
|
// Ensure that this method is only ever run once.
|
|
|
|
this._unblockDocumentLoadEvent = () => {};
|
|
|
|
},
|
|
|
|
|
2020-12-19 07:12:52 +09:00
|
|
|
/**
|
|
|
|
* Used together with the integration-tests, to enable awaiting full
|
|
|
|
* initialization of the scripting/sandbox.
|
|
|
|
*/
|
|
|
|
get scriptingReady() {
|
[api-minor] Move the viewer scripting initialization/handling into a new `PDFScriptingManager` class
The *main* purpose of this patch is to allow scripting to be used together with the viewer components, note the updated "simpleviewer"/"singlepageviewer" examples, in addition to the full default viewer.
Given how the scripting functionality is currently implemented in the default viewer, trying to re-use this with the standalone viewer components would be *very* hard and ideally you'd want it to work out-of-the-box.
For an initial implementation, in the default viewer, of the scripting functionality it probably made sense to simply dump all of the code in the `app.js` file, however that cannot be used with the viewer components.
To address this, the functionality is moved into a new `PDFScriptingManager` class which can thus be handled in the same way as all other viewer components (and e.g. be passed to the `BaseViewer`-implementations).
Obviously the scripting functionality needs quite a lot of data, during its initialization, and for the default viewer we want to maintain the current way of doing the lookups since that helps avoid a number of redundant API-calls.
To that end, the `PDFScriptingManager` implementation accepts (optional) factories/functions such that we can maintain the current behaviour for the default viewer. For the viewer components specifically, fallback code-paths are provided to ensure that scripting will "just work"[1].
Besides moving the viewer handling of the scripting code to its own file/class, this patch also takes the opportunity to re-factor the functionality into a number of helper methods to improve overall readability[2].
Note that it's definitely possible that the `PDFScriptingManager` class could be improved even further (e.g. for general re-use), since it's still heavily tailored to the default viewer use-case, however I believe that this patch is still a good step forward overall.
---
[1] Obviously *all* the relevant document properties might not be available in the viewer components use-case (e.g. the various URLs), but most things should work just fine.
[2] The old `PDFViewerApplication._initializeJavaScript` method, where everything was simply inlined, have over time (in my opinion) become quite large and somewhat difficult to *easily* reason about.
2021-03-05 08:15:18 +09:00
|
|
|
return this.pdfScriptingManager.ready;
|
2020-12-19 07:12:52 +09:00
|
|
|
},
|
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) {
|
2021-02-22 20:43:16 +09:00
|
|
|
PDFViewerApplication.l10n.get("loading_error").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
PDFViewerApplication._documentError(msg, { message: ex?.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");
|
2021-08-18 22:59:30 +09:00
|
|
|
return;
|
2018-06-07 20:52:40 +09:00
|
|
|
}
|
2021-08-18 22:59:30 +09:00
|
|
|
await loadScript(PDFWorker.workerSrc);
|
2018-01-20 02:16:17 +09:00
|
|
|
}
|
|
|
|
|
2021-08-18 22:59:30 +09:00
|
|
|
async function initPDFBug(enabledTabs) {
|
|
|
|
const { debuggerScriptPath, mainContainer } = PDFViewerApplication.appConfig;
|
|
|
|
await loadScript(debuggerScriptPath);
|
|
|
|
PDFBug.init({ OPS }, mainContainer, enabledTabs);
|
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
|
|
|
|
);
|
2021-02-06 01:36:28 +09:00
|
|
|
const pageStats = pageView?.pdfPage?.stats;
|
2020-09-23 21:39:14 +09:00
|
|
|
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);
|
2021-08-01 05:15:30 +09:00
|
|
|
file = params.get("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
|
|
|
|
) {
|
2021-02-08 08:21:49 +09:00
|
|
|
appConfig.toolbar.openFile.hidden = true;
|
|
|
|
appConfig.secondaryToolbar.openFileButton.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 {
|
2021-02-08 08:21:49 +09:00
|
|
|
appConfig.toolbar.openFile.hidden = true;
|
|
|
|
appConfig.secondaryToolbar.openFileButton.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);
|
2021-02-22 20:43:16 +09:00
|
|
|
PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
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) {
|
2021-02-22 20:43:16 +09:00
|
|
|
PDFViewerApplication.l10n.get("loading_error").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
PDFViewerApplication._documentError(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
|
|
|
|
2021-03-29 01:09:43 +09:00
|
|
|
function webViewerOpenFileViaURL(file) {
|
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2016-10-15 00:57:53 +09:00
|
|
|
if (file) {
|
|
|
|
PDFViewerApplication.open(file);
|
|
|
|
}
|
2021-03-29 01:09:43 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
2016-10-15 00:57:53 +09:00
|
|
|
PDFViewerApplication.setTitleUsingUrl(file);
|
|
|
|
PDFViewerApplication.initPassiveLoading();
|
2021-03-29 01:09:43 +09:00
|
|
|
} else {
|
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
|
|
|
}
|
2021-03-29 01:09:43 +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) {
|
2021-02-22 20:43:16 +09:00
|
|
|
PDFViewerApplication.l10n.get("rendering_error").then(msg => {
|
2021-02-10 23:57:58 +09:00
|
|
|
PDFViewerApplication._otherError(msg, error);
|
|
|
|
});
|
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-12-29 01:03:27 +09:00
|
|
|
function webViewerPresentationModeChanged(evt) {
|
|
|
|
PDFViewerApplication.pdfViewer.presentationModeState = evt.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;
|
2021-05-16 17:58:34 +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
|
|
|
);
|
2021-02-06 01:36:28 +09:00
|
|
|
const loading = 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;
|
2021-09-09 21:21:15 +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) {
|
2021-02-06 01:36:28 +09:00
|
|
|
if (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
|
|
|
|
2021-07-27 19:23:33 +09:00
|
|
|
if (!compatibilityParams.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;
|
2021-02-08 08:21:49 +09:00
|
|
|
appConfig.toolbar.viewBookmark.hidden = true;
|
|
|
|
appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
|
|
|
|
appConfig.toolbar.download.hidden = true;
|
|
|
|
appConfig.secondaryToolbar.downloadButton.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() {
|
Add previous/next-page functionality that takes scroll/spread-modes into account (issue 11946)
- For wrapped scrolling, we unfortunately need to do a fair bit of parsing of the *current* page layout. Compared to e.g. the spread-modes, where we can easily tell how the pages are laid out, with wrapped scrolling we cannot tell without actually checking. In particular documents with varying page sizes require some care, since we need to check all pages on the "row" of the current page are visible and that there aren't any "holes" present. Otherwise, in the general case, there's a risk that we'd skip over pages if we'd simply always advance to the previous/next "row" in wrapped scrolling.
- For horizontal scrolling, this patch simply maintains the current behaviour of advancing *one* page at a time. The reason for this is to prevent inconsistent behaviour for the next and previous cases, since those cannot be handled identically. For the next-case, it'd obviously be simple to advance to the first not completely visible page. However for the previous-case, we'd only be able to go back *one* page since it's not possible to (easily) determine the page layout of non-visible pages (documents with varying page sizes being a particular issue).
- For vertical scrolling, this patch maintains the current behaviour by default. When spread-modes are being used, we'll now attempt to advance to the next *spread*, rather than just the next page, whenever possible. To prevent skipping over a page, this two-page advance will only apply when both pages of the current spread are visible (to avoid breaking documents with varying page sizes) and when the second page in the current spread is fully visible *horizontally* (to handle larger zoom values).
In order to reduce the performance impact of these changes, note that the previous/next-functionality will only call `getVisibleElements` for the scroll/spread-modes where that's necessary and that "normal" vertical scrolling is thus unaffected by these changes.
To support these changes, the `getVisibleElements` helper function will now also include the `widthPercent` in addition to the existing `percent` property.
The `PDFViewer._updateHelper` method is changed slightly w.r.t. updating the `currentPageNumber` for the non-vertical/spread modes, i.e. won't affect "normal" vertical scrolling, since that helped simplify the overall calculation of the page advance.
Finally, these new `BaseViewer` methods also allow (some) simplification of previous/next-page functionality in various viewer components.
*Please note:* There's one thing that this patch does not attempt to change, namely disabling of the previous/next toolbarButtons respectively the firstPage/lastPage secondaryToolbarButtons. The reason for this is that doing so would add quite a bit of complexity in general, and if for some reason `BaseViewer._getPageAdvance` would get things wrong we could end up incorrectly disabling the buttons. Hence it seemed overall safer to *not* touch this, and accept that the buttons won't be `disabled` despite in some edge-cases no further scrolling being possible.
2021-01-16 02:45:12 +09:00
|
|
|
PDFViewerApplication.pdfViewer.nextPage();
|
2016-11-19 03:50:29 +09:00
|
|
|
}
|
|
|
|
function webViewerPreviousPage() {
|
Add previous/next-page functionality that takes scroll/spread-modes into account (issue 11946)
- For wrapped scrolling, we unfortunately need to do a fair bit of parsing of the *current* page layout. Compared to e.g. the spread-modes, where we can easily tell how the pages are laid out, with wrapped scrolling we cannot tell without actually checking. In particular documents with varying page sizes require some care, since we need to check all pages on the "row" of the current page are visible and that there aren't any "holes" present. Otherwise, in the general case, there's a risk that we'd skip over pages if we'd simply always advance to the previous/next "row" in wrapped scrolling.
- For horizontal scrolling, this patch simply maintains the current behaviour of advancing *one* page at a time. The reason for this is to prevent inconsistent behaviour for the next and previous cases, since those cannot be handled identically. For the next-case, it'd obviously be simple to advance to the first not completely visible page. However for the previous-case, we'd only be able to go back *one* page since it's not possible to (easily) determine the page layout of non-visible pages (documents with varying page sizes being a particular issue).
- For vertical scrolling, this patch maintains the current behaviour by default. When spread-modes are being used, we'll now attempt to advance to the next *spread*, rather than just the next page, whenever possible. To prevent skipping over a page, this two-page advance will only apply when both pages of the current spread are visible (to avoid breaking documents with varying page sizes) and when the second page in the current spread is fully visible *horizontally* (to handle larger zoom values).
In order to reduce the performance impact of these changes, note that the previous/next-functionality will only call `getVisibleElements` for the scroll/spread-modes where that's necessary and that "normal" vertical scrolling is thus unaffected by these changes.
To support these changes, the `getVisibleElements` helper function will now also include the `widthPercent` in addition to the existing `percent` property.
The `PDFViewer._updateHelper` method is changed slightly w.r.t. updating the `currentPageNumber` for the non-vertical/spread modes, i.e. won't affect "normal" vertical scrolling, since that helped simplify the overall calculation of the page advance.
Finally, these new `BaseViewer` methods also allow (some) simplification of previous/next-page functionality in various viewer components.
*Please note:* There's one thing that this patch does not attempt to change, namely disabling of the previous/next toolbarButtons respectively the firstPage/lastPage secondaryToolbarButtons. The reason for this is that doing so would add quite a bit of complexity in general, and if for some reason `BaseViewer._getPageAdvance` would get things wrong we could end up incorrectly disabling the buttons. Hence it seemed overall safer to *not* touch this, and accept that the buttons won't be `disabled` despite in some edge-cases no further scrolling being possible.
2021-01-16 02:45:12 +09:00
|
|
|
PDFViewerApplication.pdfViewer.previousPage();
|
2016-11-19 03:50:29 +09:00
|
|
|
}
|
|
|
|
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) {
|
2021-05-16 17:58:34 +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) {
|
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
|
|
|
|
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;
|
2021-02-06 01:36:28 +09:00
|
|
|
const isViewerInPresentationMode = 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();
|
2021-02-06 01:36:28 +09:00
|
|
|
const curElementTagName = 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" ||
|
2021-02-06 01:36:28 +09:00
|
|
|
curElement?.isContentEditable
|
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
|
|
|
) {
|
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) {
|
Add previous/next-page functionality that takes scroll/spread-modes into account (issue 11946)
- For wrapped scrolling, we unfortunately need to do a fair bit of parsing of the *current* page layout. Compared to e.g. the spread-modes, where we can easily tell how the pages are laid out, with wrapped scrolling we cannot tell without actually checking. In particular documents with varying page sizes require some care, since we need to check all pages on the "row" of the current page are visible and that there aren't any "holes" present. Otherwise, in the general case, there's a risk that we'd skip over pages if we'd simply always advance to the previous/next "row" in wrapped scrolling.
- For horizontal scrolling, this patch simply maintains the current behaviour of advancing *one* page at a time. The reason for this is to prevent inconsistent behaviour for the next and previous cases, since those cannot be handled identically. For the next-case, it'd obviously be simple to advance to the first not completely visible page. However for the previous-case, we'd only be able to go back *one* page since it's not possible to (easily) determine the page layout of non-visible pages (documents with varying page sizes being a particular issue).
- For vertical scrolling, this patch maintains the current behaviour by default. When spread-modes are being used, we'll now attempt to advance to the next *spread*, rather than just the next page, whenever possible. To prevent skipping over a page, this two-page advance will only apply when both pages of the current spread are visible (to avoid breaking documents with varying page sizes) and when the second page in the current spread is fully visible *horizontally* (to handle larger zoom values).
In order to reduce the performance impact of these changes, note that the previous/next-functionality will only call `getVisibleElements` for the scroll/spread-modes where that's necessary and that "normal" vertical scrolling is thus unaffected by these changes.
To support these changes, the `getVisibleElements` helper function will now also include the `widthPercent` in addition to the existing `percent` property.
The `PDFViewer._updateHelper` method is changed slightly w.r.t. updating the `currentPageNumber` for the non-vertical/spread modes, i.e. won't affect "normal" vertical scrolling, since that helped simplify the overall calculation of the page advance.
Finally, these new `BaseViewer` methods also allow (some) simplification of previous/next-page functionality in various viewer components.
*Please note:* There's one thing that this patch does not attempt to change, namely disabling of the previous/next toolbarButtons respectively the firstPage/lastPage secondaryToolbarButtons. The reason for this is that doing so would add quite a bit of complexity in general, and if for some reason `BaseViewer._getPageAdvance` would get things wrong we could end up incorrectly disabling the buttons. Hence it seemed overall safer to *not* touch this, and accept that the buttons won't be `disabled` despite in some edge-cases no further scrolling being possible.
2021-01-16 02:45:12 +09:00
|
|
|
pdfViewer.nextPage();
|
2018-05-15 12:10:32 +09:00
|
|
|
} else {
|
Add previous/next-page functionality that takes scroll/spread-modes into account (issue 11946)
- For wrapped scrolling, we unfortunately need to do a fair bit of parsing of the *current* page layout. Compared to e.g. the spread-modes, where we can easily tell how the pages are laid out, with wrapped scrolling we cannot tell without actually checking. In particular documents with varying page sizes require some care, since we need to check all pages on the "row" of the current page are visible and that there aren't any "holes" present. Otherwise, in the general case, there's a risk that we'd skip over pages if we'd simply always advance to the previous/next "row" in wrapped scrolling.
- For horizontal scrolling, this patch simply maintains the current behaviour of advancing *one* page at a time. The reason for this is to prevent inconsistent behaviour for the next and previous cases, since those cannot be handled identically. For the next-case, it'd obviously be simple to advance to the first not completely visible page. However for the previous-case, we'd only be able to go back *one* page since it's not possible to (easily) determine the page layout of non-visible pages (documents with varying page sizes being a particular issue).
- For vertical scrolling, this patch maintains the current behaviour by default. When spread-modes are being used, we'll now attempt to advance to the next *spread*, rather than just the next page, whenever possible. To prevent skipping over a page, this two-page advance will only apply when both pages of the current spread are visible (to avoid breaking documents with varying page sizes) and when the second page in the current spread is fully visible *horizontally* (to handle larger zoom values).
In order to reduce the performance impact of these changes, note that the previous/next-functionality will only call `getVisibleElements` for the scroll/spread-modes where that's necessary and that "normal" vertical scrolling is thus unaffected by these changes.
To support these changes, the `getVisibleElements` helper function will now also include the `widthPercent` in addition to the existing `percent` property.
The `PDFViewer._updateHelper` method is changed slightly w.r.t. updating the `currentPageNumber` for the non-vertical/spread modes, i.e. won't affect "normal" vertical scrolling, since that helped simplify the overall calculation of the page advance.
Finally, these new `BaseViewer` methods also allow (some) simplification of previous/next-page functionality in various viewer components.
*Please note:* There's one thing that this patch does not attempt to change, namely disabling of the previous/next toolbarButtons respectively the firstPage/lastPage secondaryToolbarButtons. The reason for this is that doing so would add quite a bit of complexity in general, and if for some reason `BaseViewer._getPageAdvance` would get things wrong we could end up incorrectly disabling the buttons. Hence it seemed overall safer to *not* touch this, and accept that the buttons won't be `disabled` despite in some edge-cases no further scrolling being possible.
2021-01-16 02:45:12 +09:00
|
|
|
pdfViewer.previousPage();
|
2018-05-15 12:10:32 +09:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
DefaultExternalServices,
|
|
|
|
PDFPrintServiceFactory,
|
2021-01-09 23:37:44 +09:00
|
|
|
PDFViewerApplication,
|
2017-03-28 08:07:27 +09:00
|
|
|
};
|