2012-09-01 07:48:21 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-02-09 07:32:15 +09:00
|
|
|
/* globals PDFBug, Stats */
|
2011-05-26 23:02:52 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
animationStarted,
|
2019-12-27 00:13:49 +09:00
|
|
|
AutoPrintRegExp,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
DEFAULT_SCALE_VALUE,
|
2020-02-27 01:16:30 +09:00
|
|
|
EventBus,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getPDFFileNameFromURL,
|
|
|
|
isValidRotation,
|
|
|
|
isValidScrollMode,
|
|
|
|
isValidSpreadMode,
|
|
|
|
MAX_SCALE,
|
|
|
|
MIN_SCALE,
|
|
|
|
noContextMenuHandler,
|
|
|
|
normalizeWheelEventDelta,
|
|
|
|
parseQueryString,
|
|
|
|
PresentationModeState,
|
|
|
|
ProgressBar,
|
|
|
|
RendererType,
|
|
|
|
ScrollMode,
|
|
|
|
SpreadMode,
|
|
|
|
TextLayerMode,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./ui_utils.js";
|
|
|
|
import { AppOptions, OptionKind } from "./app_options.js";
|
2017-03-28 17:15:02 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
build,
|
2020-02-17 20:49:56 +09:00
|
|
|
createPromiseCapability,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getDocument,
|
|
|
|
getFilenameFromUrl,
|
|
|
|
GlobalWorkerOptions,
|
|
|
|
InvalidPDFException,
|
|
|
|
LinkTarget,
|
|
|
|
loadScript,
|
|
|
|
MissingPDFException,
|
|
|
|
OPS,
|
|
|
|
PDFWorker,
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
PermissionFlag,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
shadow,
|
|
|
|
UnexpectedResponseException,
|
|
|
|
UNSUPPORTED_FEATURES,
|
|
|
|
version,
|
|
|
|
} from "pdfjs-lib";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js";
|
|
|
|
import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue.js";
|
|
|
|
import { PDFSidebar, SidebarView } from "./pdf_sidebar.js";
|
|
|
|
import { OverlayManager } from "./overlay_manager.js";
|
|
|
|
import { PasswordPrompt } from "./password_prompt.js";
|
|
|
|
import { PDFAttachmentViewer } from "./pdf_attachment_viewer.js";
|
|
|
|
import { PDFDocumentProperties } from "./pdf_document_properties.js";
|
|
|
|
import { PDFFindBar } from "./pdf_find_bar.js";
|
|
|
|
import { PDFFindController } from "./pdf_find_controller.js";
|
|
|
|
import { PDFHistory } from "./pdf_history.js";
|
|
|
|
import { PDFLinkService } from "./pdf_link_service.js";
|
|
|
|
import { PDFOutlineViewer } from "./pdf_outline_viewer.js";
|
|
|
|
import { PDFPresentationMode } from "./pdf_presentation_mode.js";
|
|
|
|
import { PDFSidebarResizer } from "./pdf_sidebar_resizer.js";
|
|
|
|
import { PDFThumbnailViewer } from "./pdf_thumbnail_viewer.js";
|
|
|
|
import { PDFViewer } from "./pdf_viewer.js";
|
|
|
|
import { SecondaryToolbar } from "./secondary_toolbar.js";
|
|
|
|
import { Toolbar } from "./toolbar.js";
|
|
|
|
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-01-15 22:26:47 +09:00
|
|
|
class DefaultExternalServices {
|
|
|
|
constructor() {
|
|
|
|
throw new Error("Cannot initialize DefaultExternalServices.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static updateFindControlState(data) {}
|
|
|
|
|
|
|
|
static updateFindMatchesCount(data) {}
|
|
|
|
|
|
|
|
static initPassiveLoading(callbacks) {}
|
|
|
|
|
|
|
|
static fallback(data, callback) {}
|
|
|
|
|
|
|
|
static reportTelemetry(data) {}
|
|
|
|
|
|
|
|
static createDownloadManager(options) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createDownloadManager");
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static createPreferences() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createPreferences");
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static createL10n(options) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createL10n");
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static get supportsIntegratedFind() {
|
|
|
|
return shadow(this, "supportsIntegratedFind", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get supportsDocumentFonts() {
|
|
|
|
return shadow(this, "supportsDocumentFonts", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get supportedMouseWheelZoomModifierKeys() {
|
|
|
|
return shadow(this, "supportedMouseWheelZoomModifierKeys", {
|
|
|
|
ctrlKey: true,
|
|
|
|
metaKey: true,
|
|
|
|
});
|
|
|
|
}
|
2020-02-27 23:25:33 +09:00
|
|
|
|
|
|
|
static get isInAutomation() {
|
|
|
|
return shadow(this, "isInAutomation", false);
|
|
|
|
}
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const PDFViewerApplication = {
|
2011-10-02 03:54:37 +09:00
|
|
|
initialBookmark: document.location.hash.substring(1),
|
2020-02-17 20:49:56 +09:00
|
|
|
_initializedCapability: createPromiseCapability(),
|
2012-05-15 09:19:09 +09:00
|
|
|
fellback: false,
|
2016-04-22 01:39:11 +09:00
|
|
|
appConfig: null,
|
2012-06-02 06:17:09 +09:00
|
|
|
pdfDocument: null,
|
2015-10-23 22:49:02 +09:00
|
|
|
pdfLoadingTask: null,
|
2016-10-07 06:46:30 +09:00
|
|
|
printService: null,
|
2014-09-21 02:21:49 +09:00
|
|
|
/** @type {PDFViewer} */
|
2014-09-13 11:27:45 +09:00
|
|
|
pdfViewer: null,
|
2014-09-21 02:21:49 +09:00
|
|
|
/** @type {PDFThumbnailViewer} */
|
2014-09-13 04:48:44 +09:00
|
|
|
pdfThumbnailViewer: null,
|
2014-09-21 02:21:49 +09:00
|
|
|
/** @type {PDFRenderingQueue} */
|
2014-09-16 01:18:28 +09:00
|
|
|
pdfRenderingQueue: null,
|
2015-02-04 02:09:11 +09:00
|
|
|
/** @type {PDFPresentationMode} */
|
|
|
|
pdfPresentationMode: null,
|
2015-04-25 03:47:38 +09:00
|
|
|
/** @type {PDFDocumentProperties} */
|
|
|
|
pdfDocumentProperties: null,
|
2015-04-28 00:25:32 +09:00
|
|
|
/** @type {PDFLinkService} */
|
|
|
|
pdfLinkService: null,
|
2015-04-27 23:04:11 +09:00
|
|
|
/** @type {PDFHistory} */
|
|
|
|
pdfHistory: null,
|
2016-02-22 01:54:23 +09:00
|
|
|
/** @type {PDFSidebar} */
|
|
|
|
pdfSidebar: null,
|
Implement sidebar resizing for modern browsers, by utilizing CSS variables (issue 2072)
By making use of modern CSS features, in this case [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables), implementing sidebar resizing is actually quite simple. Not only will the amount of added code be fairly small, but it should also be easy to maintain since there's no need for complicated JavaScript hacks in order to update the CSS. Another benefit is that the JavaScript code doesn't need to make detailed assumptions about the exact structure of the HTML/CSS code.
Obviously this will not work in older browsers, such as IE, that lack support for CSS variables. In those cases sidebar resizing is simply disabled (via feature detection), and the resizing DOM element hidden, and the behaviour is thus *identical* to the current (fixed-width) sidebar.
However, considering the simplicity of the implementation, I really don't see why limiting this feature to "modern" browsers is a problem.
Finally, note that a few edge-cases meant that the patch is a bit larger than what the basic functionality would dictate. Among those is first of all proper RTL support, and secondly (automatic) resizing of the sidebar when the width of the *entire* viewer changes. Another, pre-existing, issue fixed here is the incomplete interface of `NullL10n`.
*Please note:* This patch has been successfully tested in both LTR and RTL viewer locales, in recent versions of Firefox and Chrome.
Fixes 2072.
2017-10-10 23:16:05 +09:00
|
|
|
/** @type {PDFSidebarResizer} */
|
|
|
|
pdfSidebarResizer: null,
|
2016-02-21 21:36:24 +09:00
|
|
|
/** @type {PDFOutlineViewer} */
|
|
|
|
pdfOutlineViewer: null,
|
|
|
|
/** @type {PDFAttachmentViewer} */
|
|
|
|
pdfAttachmentViewer: null,
|
2016-09-07 20:30:26 +09:00
|
|
|
/** @type {PDFCursorTools} */
|
|
|
|
pdfCursorTools: null,
|
2016-03-12 21:07:43 +09:00
|
|
|
/** @type {ViewHistory} */
|
|
|
|
store: null,
|
2016-04-14 06:21:05 +09:00
|
|
|
/** @type {DownloadManager} */
|
|
|
|
downloadManager: null,
|
2017-05-26 21:52:23 +09:00
|
|
|
/** @type {OverlayManager} */
|
|
|
|
overlayManager: null,
|
2017-04-17 20:21:11 +09:00
|
|
|
/** @type {Preferences} */
|
|
|
|
preferences: null,
|
2016-11-19 03:50:29 +09:00
|
|
|
/** @type {Toolbar} */
|
|
|
|
toolbar: null,
|
|
|
|
/** @type {SecondaryToolbar} */
|
|
|
|
secondaryToolbar: null,
|
2016-04-26 07:57:15 +09:00
|
|
|
/** @type {EventBus} */
|
|
|
|
eventBus: null,
|
2017-05-04 10:05:53 +09:00
|
|
|
/** @type {IL10n} */
|
|
|
|
l10n: null,
|
2014-09-22 20:41:17 +09:00
|
|
|
isInitialViewSet: false,
|
2017-06-17 20:14:36 +09:00
|
|
|
downloadComplete: false,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
isViewerEmbedded: window.parent !== window,
|
|
|
|
url: "",
|
|
|
|
baseUrl: "",
|
2017-03-28 06:37:14 +09:00
|
|
|
externalServices: DefaultExternalServices,
|
2017-06-14 04:11:29 +09:00
|
|
|
_boundEvents: {},
|
2018-01-17 00:24:36 +09:00
|
|
|
contentDispositionFilename: null,
|
2012-06-19 01:48:47 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
// Called once when the document is loaded.
|
2018-07-31 00:41:39 +09:00
|
|
|
async initialize(appConfig) {
|
2017-04-17 20:21:11 +09:00
|
|
|
this.preferences = this.externalServices.createPreferences();
|
2016-12-08 21:30:21 +09:00
|
|
|
this.appConfig = appConfig;
|
2016-12-11 07:10:08 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
await this._readPreferences();
|
|
|
|
await this._parseHashParameters();
|
|
|
|
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() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (AppOptions.get("disablePreferences") === true) {
|
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 {
|
|
|
|
const prefs = await this.preferences.getAll();
|
2018-11-29 19:31:49 +09:00
|
|
|
for (const name in prefs) {
|
2018-07-24 03:12:30 +09:00
|
|
|
AppOptions.set(name, prefs[name]);
|
|
|
|
}
|
2019-03-03 19:40:56 +09:00
|
|
|
} catch (reason) {
|
|
|
|
console.error(`_readPreferences: "${reason.message}".`);
|
|
|
|
}
|
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() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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") &&
|
|
|
|
!AppOptions.get("pdfBugEnabled")
|
|
|
|
) {
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const hash = document.location.hash.substring(1);
|
2020-01-23 20:05:43 +09:00
|
|
|
if (!hash) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const hashParams = parseQueryString(hash),
|
|
|
|
waitOn = [];
|
2017-11-13 18:17:25 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (
|
|
|
|
"disableworker" in hashParams &&
|
|
|
|
hashParams["disableworker"] === "true"
|
|
|
|
) {
|
2018-07-31 00:41:39 +09:00
|
|
|
waitOn.push(loadFakeWorker());
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablerange" in hashParams) {
|
|
|
|
AppOptions.set("disableRange", hashParams["disablerange"] === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablestream" in hashParams) {
|
|
|
|
AppOptions.set("disableStream", hashParams["disablestream"] === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disableautofetch" in hashParams) {
|
|
|
|
AppOptions.set(
|
|
|
|
"disableAutoFetch",
|
|
|
|
hashParams["disableautofetch"] === "true"
|
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablefontface" in hashParams) {
|
|
|
|
AppOptions.set(
|
|
|
|
"disableFontFace",
|
|
|
|
hashParams["disablefontface"] === "true"
|
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("disablehistory" in hashParams) {
|
|
|
|
AppOptions.set("disableHistory", hashParams["disablehistory"] === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("webgl" in hashParams) {
|
|
|
|
AppOptions.set("enableWebGL", hashParams["webgl"] === "true");
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("verbosity" in hashParams) {
|
|
|
|
AppOptions.set("verbosity", hashParams["verbosity"] | 0);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("textlayer" in hashParams) {
|
|
|
|
switch (hashParams["textlayer"]) {
|
|
|
|
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;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
viewer.classList.add("textLayer-" + hashParams["textlayer"]);
|
2018-07-31 00:41:39 +09:00
|
|
|
break;
|
2017-05-04 10:05:53 +09:00
|
|
|
}
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("pdfbug" in hashParams) {
|
|
|
|
AppOptions.set("pdfBug", true);
|
[api-minor] Change `Font.exportData` to, by default, stop exporting properties which are completely unused on the main-thread and/or in the API (PR 11773 follow-up)
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API.
This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread.
With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself.
All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties:
- "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API.
Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory.
- "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread.
- "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text.
- "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API.
- "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API.
- "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API.
- "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API.
2020-04-03 18:51:46 +09:00
|
|
|
AppOptions.set("fontExtraProperties", true);
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const enabled = hashParams["pdfbug"].split(",");
|
2018-07-31 00:41:39 +09:00
|
|
|
waitOn.push(loadAndEnablePDFBug(enabled));
|
|
|
|
}
|
|
|
|
// It is not possible to change locale for the (various) extension builds.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
"locale" in hashParams
|
|
|
|
) {
|
|
|
|
AppOptions.set("locale", hashParams["locale"]);
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2017-11-13 18:17:25 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return Promise.all(waitOn).catch(reason => {
|
2018-10-05 20:54:16 +09:00
|
|
|
console.error(`_parseHashParameters: "${reason.message}".`);
|
|
|
|
});
|
2017-11-13 18:17:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async _initializeL10n() {
|
2018-02-13 22:22:14 +09:00
|
|
|
this.l10n = this.externalServices.createL10n({
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
locale: AppOptions.get("locale"),
|
2018-02-13 22:22:14 +09:00
|
|
|
});
|
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
|
|
|
},
|
|
|
|
|
2016-12-11 07:10:08 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async _initializeViewerComponents() {
|
|
|
|
const appConfig = this.appConfig;
|
2016-12-11 07:10:08 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const eventBus =
|
|
|
|
appConfig.eventBus ||
|
2020-02-27 23:25:33 +09:00
|
|
|
new EventBus({ isInAutomation: this.externalServices.isInAutomation });
|
2018-07-31 00:41:39 +09:00
|
|
|
this.eventBus = eventBus;
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2020-02-27 23:25:33 +09:00
|
|
|
this.overlayManager = new OverlayManager();
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfRenderingQueue = new PDFRenderingQueue();
|
2018-07-31 00:41:39 +09:00
|
|
|
pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
|
|
|
this.pdfRenderingQueue = pdfRenderingQueue;
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfLinkService = new PDFLinkService({
|
2018-07-31 00:41:39 +09:00
|
|
|
eventBus,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
externalLinkTarget: AppOptions.get("externalLinkTarget"),
|
|
|
|
externalLinkRel: AppOptions.get("externalLinkRel"),
|
2020-02-17 22:04:55 +09:00
|
|
|
ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
|
|
|
this.pdfLinkService = pdfLinkService;
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const downloadManager = this.externalServices.createDownloadManager({
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
disableCreateObjectURL: AppOptions.get("disableCreateObjectURL"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
|
|
|
this.downloadManager = downloadManager;
|
|
|
|
|
2018-09-23 02:44:13 +09:00
|
|
|
const findController = new PDFFindController({
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
eventBus,
|
|
|
|
});
|
|
|
|
this.findController = findController;
|
|
|
|
|
2018-10-05 17:17:37 +09:00
|
|
|
const container = appConfig.mainContainer;
|
|
|
|
const viewer = appConfig.viewerContainer;
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfViewer = new PDFViewer({
|
|
|
|
container,
|
|
|
|
viewer,
|
|
|
|
eventBus,
|
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
downloadManager,
|
2018-09-23 02:44:13 +09:00
|
|
|
findController,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
renderer: AppOptions.get("renderer"),
|
|
|
|
enableWebGL: AppOptions.get("enableWebGL"),
|
2018-07-31 00:41:39 +09:00
|
|
|
l10n: this.l10n,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
textLayerMode: AppOptions.get("textLayerMode"),
|
|
|
|
imageResourcesPath: AppOptions.get("imageResourcesPath"),
|
|
|
|
renderInteractiveForms: AppOptions.get("renderInteractiveForms"),
|
|
|
|
enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
|
|
|
|
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
|
|
|
|
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
|
|
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
|
|
|
pdfLinkService.setViewer(this.pdfViewer);
|
|
|
|
|
|
|
|
this.pdfThumbnailViewer = new PDFThumbnailViewer({
|
2019-02-24 21:12:23 +09:00
|
|
|
container: appConfig.sidebar.thumbnailView,
|
2018-07-31 00:41:39 +09:00
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
l10n: this.l10n,
|
|
|
|
});
|
|
|
|
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfHistory = new PDFHistory({
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
eventBus,
|
|
|
|
});
|
|
|
|
pdfLinkService.setHistory(this.pdfHistory);
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2019-07-21 20:42:03 +09:00
|
|
|
if (!this.supportsIntegratedFind) {
|
|
|
|
this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfDocumentProperties = new PDFDocumentProperties(
|
|
|
|
appConfig.documentProperties,
|
|
|
|
this.overlayManager,
|
|
|
|
eventBus,
|
|
|
|
this.l10n
|
|
|
|
);
|
2016-12-08 21:30:21 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfCursorTools = new PDFCursorTools({
|
|
|
|
container,
|
|
|
|
eventBus,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
cursorToolOnLoad: AppOptions.get("cursorToolOnLoad"),
|
2018-07-31 00:41:39 +09:00
|
|
|
});
|
2016-12-08 21:30:21 +09:00
|
|
|
|
2018-10-05 17:17:37 +09:00
|
|
|
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
2016-12-08 21:30:21 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.secondaryToolbar = new SecondaryToolbar(
|
|
|
|
appConfig.secondaryToolbar,
|
|
|
|
container,
|
|
|
|
eventBus
|
|
|
|
);
|
2016-12-08 21:30:21 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
if (this.supportsFullscreen) {
|
|
|
|
this.pdfPresentationMode = new PDFPresentationMode({
|
|
|
|
container,
|
|
|
|
pdfViewer: this.pdfViewer,
|
2017-04-28 19:02:42 +09:00
|
|
|
eventBus,
|
2018-07-31 00:41:39 +09:00
|
|
|
contextMenuItems: appConfig.fullscreen,
|
2016-09-04 03:27:01 +09:00
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2016-09-04 03:27:01 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.passwordPrompt = new PasswordPrompt(
|
|
|
|
appConfig.passwordOverlay,
|
|
|
|
this.overlayManager,
|
|
|
|
this.l10n
|
|
|
|
);
|
2018-07-31 00:41:39 +09:00
|
|
|
|
|
|
|
this.pdfOutlineViewer = new PDFOutlineViewer({
|
|
|
|
container: appConfig.sidebar.outlineView,
|
|
|
|
eventBus,
|
|
|
|
linkService: pdfLinkService,
|
|
|
|
});
|
2016-09-04 03:27:01 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
this.pdfAttachmentViewer = new PDFAttachmentViewer({
|
|
|
|
container: appConfig.sidebar.attachmentsView,
|
|
|
|
eventBus,
|
|
|
|
downloadManager,
|
2016-09-04 03:27:01 +09:00
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
|
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
|
|
|
|
2014-09-13 11:27:45 +09:00
|
|
|
set page(val) {
|
2016-08-07 20:10:50 +09:00
|
|
|
this.pdfViewer.currentPageNumber = val;
|
2011-07-29 02:48:05 +09:00
|
|
|
},
|
|
|
|
|
2016-08-07 20:10:50 +09:00
|
|
|
get page() {
|
|
|
|
return this.pdfViewer.currentPageNumber;
|
2011-07-29 02:48:05 +09:00
|
|
|
},
|
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
get printing() {
|
|
|
|
return !!this.printService;
|
|
|
|
},
|
2015-02-01 06:43:30 +09:00
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
get supportsPrinting() {
|
|
|
|
return PDFPrintServiceFactory.instance.supportsPrinting;
|
2012-06-29 01:50:25 +09:00
|
|
|
},
|
|
|
|
|
2012-07-31 00:12:49 +09:00
|
|
|
get supportsFullscreen() {
|
2017-06-29 19:14:26 +09:00
|
|
|
let support;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
|
|
support =
|
|
|
|
document.fullscreenEnabled === true ||
|
|
|
|
document.mozFullScreenEnabled === true;
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
2019-12-27 08:22:32 +09:00
|
|
|
const doc = document.documentElement;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
support = !!(
|
|
|
|
doc.requestFullscreen ||
|
|
|
|
doc.mozRequestFullScreen ||
|
|
|
|
doc.webkitRequestFullScreen ||
|
|
|
|
doc.msRequestFullscreen
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
document.fullscreenEnabled === false ||
|
|
|
|
document.mozFullScreenEnabled === false ||
|
|
|
|
document.webkitFullscreenEnabled === false ||
|
|
|
|
document.msFullscreenEnabled === false
|
|
|
|
) {
|
2016-10-15 00:57:53 +09:00
|
|
|
support = false;
|
|
|
|
}
|
2013-03-02 05:54:02 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return shadow(this, "supportsFullscreen", support);
|
2012-07-31 00:12:49 +09:00
|
|
|
},
|
|
|
|
|
2012-10-06 05:59:13 +09:00
|
|
|
get supportsIntegratedFind() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return this.externalServices.supportsIntegratedFind;
|
2012-10-06 05:59:13 +09:00
|
|
|
},
|
|
|
|
|
2012-12-01 07:59:51 +09:00
|
|
|
get supportsDocumentFonts() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return this.externalServices.supportsDocumentFonts;
|
2012-12-01 07:59:51 +09:00
|
|
|
},
|
|
|
|
|
2013-07-19 01:28:59 +09:00
|
|
|
get loadingBar() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const bar = new ProgressBar("#loadingBar");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return shadow(this, "loadingBar", bar);
|
2013-07-19 01:28:59 +09:00
|
|
|
},
|
|
|
|
|
2015-06-02 20:17:02 +09:00
|
|
|
get supportedMouseWheelZoomModifierKeys() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
2015-06-02 20:17:02 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
initPassiveLoading() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
2020-01-08 21:57:31 +09:00
|
|
|
!PDFJSDev.test("MOZCENTRAL || CHROME")
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
) {
|
|
|
|
throw new Error("Not implemented: initPassiveLoading");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
this.externalServices.initPassiveLoading({
|
|
|
|
onOpenWithTransport(url, length, transport) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.open(url, { length, range: transport });
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
|
|
|
onOpenWithData(data) {
|
|
|
|
PDFViewerApplication.open(data);
|
|
|
|
},
|
2018-06-17 20:25:22 +09:00
|
|
|
onOpenWithURL(url, length, originalUrl) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let file = url,
|
|
|
|
args = null;
|
2017-06-29 19:14:26 +09:00
|
|
|
if (length !== undefined) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
args = { length };
|
2017-06-29 19:14:26 +09:00
|
|
|
}
|
2018-06-17 20:25:22 +09:00
|
|
|
if (originalUrl !== undefined) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
file = { url, originalUrl };
|
2017-06-29 19:14:26 +09:00
|
|
|
}
|
|
|
|
PDFViewerApplication.open(file, args);
|
|
|
|
},
|
|
|
|
onError(err) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get(
|
|
|
|
"loading_error",
|
|
|
|
null,
|
|
|
|
"An error occurred while loading the PDF."
|
|
|
|
)
|
|
|
|
.then(msg => {
|
|
|
|
PDFViewerApplication.error(msg, err);
|
|
|
|
});
|
2017-06-29 19:14:26 +09:00
|
|
|
},
|
|
|
|
onProgress(loaded, total) {
|
|
|
|
PDFViewerApplication.progress(loaded / total);
|
|
|
|
},
|
|
|
|
});
|
2012-08-01 02:21:07 +09:00
|
|
|
},
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
setTitleUsingUrl(url = "") {
|
2012-08-01 02:21:07 +09:00
|
|
|
this.url = url;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.baseUrl = url.split("#")[0];
|
|
|
|
let title = getPDFFileNameFromURL(url, "");
|
2017-02-06 08:46:12 +09:00
|
|
|
if (!title) {
|
|
|
|
try {
|
2017-03-28 17:15:02 +09:00
|
|
|
title = decodeURIComponent(getFilenameFromUrl(url)) || url;
|
2017-06-29 19:14:26 +09:00
|
|
|
} catch (ex) {
|
2017-02-06 08:46:12 +09:00
|
|
|
// decodeURIComponent may throw URIError,
|
|
|
|
// fall back to using the unprocessed url in that case
|
|
|
|
title = url;
|
|
|
|
}
|
2012-08-27 08:49:07 +09:00
|
|
|
}
|
2017-02-06 08:46:12 +09:00
|
|
|
this.setTitle(title);
|
2012-08-01 02:21:07 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
setTitle(title) {
|
2015-03-06 12:36:08 +09:00
|
|
|
if (this.isViewerEmbedded) {
|
|
|
|
// Embedded PDF viewers should not be changing their parent page's title.
|
|
|
|
return;
|
|
|
|
}
|
2012-11-29 04:02:56 +09:00
|
|
|
document.title = title;
|
|
|
|
},
|
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
/**
|
|
|
|
* Closes opened PDF document.
|
|
|
|
* @returns {Promise} - Returns the promise, which is resolved when all
|
|
|
|
* destruction is completed.
|
|
|
|
*/
|
2018-07-31 00:41:39 +09:00
|
|
|
async close() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorWrapper = this.appConfig.errorWrapper.container;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorWrapper.setAttribute("hidden", "true");
|
2014-04-15 19:00:46 +09:00
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
if (!this.pdfLoadingTask) {
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const promise = this.pdfLoadingTask.destroy();
|
2015-10-23 22:49:02 +09:00
|
|
|
this.pdfLoadingTask = null;
|
|
|
|
|
|
|
|
if (this.pdfDocument) {
|
|
|
|
this.pdfDocument = null;
|
2014-03-27 05:18:53 +09:00
|
|
|
|
2015-10-23 22:49:02 +09:00
|
|
|
this.pdfThumbnailViewer.setDocument(null);
|
|
|
|
this.pdfViewer.setDocument(null);
|
2018-09-30 19:11:27 +09:00
|
|
|
this.pdfLinkService.setDocument(null);
|
|
|
|
this.pdfDocumentProperties.setDocument(null);
|
2015-10-23 22:49:02 +09:00
|
|
|
}
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
webViewerResetPermissions();
|
2016-03-12 21:07:43 +09:00
|
|
|
this.store = null;
|
|
|
|
this.isInitialViewSet = false;
|
2017-06-17 20:14:36 +09:00
|
|
|
this.downloadComplete = false;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.url = "";
|
|
|
|
this.baseUrl = "";
|
2018-01-17 00:24:36 +09:00
|
|
|
this.contentDispositionFilename = null;
|
2014-03-27 05:18:53 +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();
|
|
|
|
|
2019-12-03 20:04:49 +09:00
|
|
|
if (this.pdfHistory) {
|
|
|
|
this.pdfHistory.reset();
|
|
|
|
}
|
2019-07-21 20:42:03 +09:00
|
|
|
if (this.findBar) {
|
|
|
|
this.findBar.reset();
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
this.toolbar.reset();
|
|
|
|
this.secondaryToolbar.reset();
|
2016-02-27 02:06:59 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFBug !== "undefined") {
|
2014-03-27 05:18:53 +09:00
|
|
|
PDFBug.cleanup();
|
|
|
|
}
|
2015-10-23 22:49:02 +09:00
|
|
|
return promise;
|
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
|
|
|
}
|
2016-10-01 19:05:07 +09:00
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
if (args) {
|
2019-12-27 08:22:32 +09:00
|
|
|
for (const key in args) {
|
2019-07-21 18:38:17 +09:00
|
|
|
const value = args[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 === "length") {
|
2019-07-21 18:38:17 +09:00
|
|
|
this.pdfDocumentProperties.setFileSize(value);
|
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
|
|
|
}
|
2019-07-21 18:38:17 +09:00
|
|
|
parameters[key] = value;
|
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
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const message = exception && exception.message;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let loadingErrorMessage;
|
|
|
|
if (exception instanceof InvalidPDFException) {
|
|
|
|
// change error message also for other builds
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"invalid_file_error",
|
|
|
|
null,
|
|
|
|
"Invalid or corrupted PDF file."
|
|
|
|
);
|
|
|
|
} else if (exception instanceof MissingPDFException) {
|
|
|
|
// special message for missing PDF's
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"missing_file_error",
|
|
|
|
null,
|
|
|
|
"Missing PDF file."
|
|
|
|
);
|
|
|
|
} else if (exception instanceof UnexpectedResponseException) {
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"unexpected_response_error",
|
|
|
|
null,
|
|
|
|
"Unexpected server response."
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
loadingErrorMessage = this.l10n.get(
|
|
|
|
"loading_error",
|
|
|
|
null,
|
|
|
|
"An error occurred while loading the PDF."
|
|
|
|
);
|
|
|
|
}
|
2017-05-09 20:17:39 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return loadingErrorMessage.then(msg => {
|
|
|
|
this.error(msg, { message });
|
|
|
|
throw new Error(msg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2011-07-29 02:48:05 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
download() {
|
2014-03-14 12:23:47 +09:00
|
|
|
function downloadByUrl() {
|
2013-07-13 03:14:13 +09:00
|
|
|
downloadManager.downloadUrl(url, filename);
|
2013-03-25 02:25:57 +09:00
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const url = this.baseUrl;
|
2017-02-06 08:45:51 +09:00
|
|
|
// Use this.url instead of this.baseUrl to perform filename detection based
|
|
|
|
// on the reference fragment as ultimate fallback if needed.
|
2019-12-27 08:22:32 +09:00
|
|
|
const filename =
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
2019-12-27 08:22:32 +09:00
|
|
|
const downloadManager = this.downloadManager;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
downloadManager.onerror = err => {
|
2013-07-13 03:14:13 +09:00
|
|
|
// This error won't really be helpful because it's likely the
|
|
|
|
// fallback won't work either (or is already open).
|
2017-06-29 19:14:26 +09:00
|
|
|
this.error(`PDF failed to download: ${err}`);
|
2013-07-13 03:14:13 +09:00
|
|
|
};
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
// When the PDF document isn't ready, or the PDF file is still downloading,
|
|
|
|
// simply download using the URL.
|
|
|
|
if (!this.pdfDocument || !this.downloadComplete) {
|
2014-03-14 12:23:47 +09:00
|
|
|
downloadByUrl();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfDocument
|
|
|
|
.getData()
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function (data) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const blob = new Blob([data], { type: "application/pdf" });
|
|
|
|
downloadManager.download(blob, url, filename);
|
|
|
|
})
|
|
|
|
.catch(downloadByUrl); // Error occurred, try downloading with the URL.
|
2011-10-19 13:29:14 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
fallback(featureId) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (
|
Ensure that the viewer telemetry reporting, and fallback code, runs in development mode and GENERIC builds
While only the `MOZCENTRAL` builds will actually do anything meaningful with the telemetry data, none of the code in question actually runs *at all* in e.g. development mode.[1]
This seems bad since it essentially means that this code is completely untested, despite being quite important for the built-in Firefox PDF viewer, and this thus ought to be fixed.
In this case, the explanation for the current state of the code should be "for historical reasons". Before the viewer was split into the current components and before the pre-processor was improved, back when all code resided in the `web/viewer.js` file, the telemetry reporting was done with *direct* `FirefoxCom` calls. However, with the dummy `DefaultExternalServices.reportTelemetry` method there's nothing actually preventing attempting to report telemetry in any type of build.
NOTE: By running this code in GENERIC builds as well, in addition to just locally, the *viewer* part of telemetry reporting becomes tested e.g. in preview builds too which should help with reviewing.
---
[1] When fixing bug 1606566, I had to edit the relevant `PDFJSDev` checks to be able to actually test the changes locally.
2020-01-20 19:37:54 +09:00
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
) {
|
2016-10-15 00:57:53 +09:00
|
|
|
// Only trigger the fallback once so we don't spam the user with messages
|
|
|
|
// for one PDF.
|
|
|
|
if (this.fellback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.fellback = 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
|
|
|
this.externalServices.fallback(
|
|
|
|
{
|
|
|
|
featureId,
|
|
|
|
url: this.baseUrl,
|
|
|
|
},
|
|
|
|
function response(download) {
|
|
|
|
if (!download) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PDFViewerApplication.download();
|
2016-10-01 19:05: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
|
|
|
);
|
2015-04-26 08:49:37 +09:00
|
|
|
}
|
2012-05-11 07:54:58 +09:00
|
|
|
},
|
|
|
|
|
2011-11-30 04:28:05 +09:00
|
|
|
/**
|
|
|
|
* Show the error box.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @param {string} message - A message that is human readable.
|
|
|
|
* @param {Object} [moreInfo] - Further information about the error that is
|
|
|
|
* more technical. Should have a 'message' and
|
|
|
|
* optionally a 'stack' property.
|
2011-11-30 04:28:05 +09:00
|
|
|
*/
|
2017-06-29 19:14:26 +09:00
|
|
|
error(message, moreInfo) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const moreInfoText = [
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_version_info",
|
|
|
|
{ version: version || "?", build: build || "?" },
|
|
|
|
"PDF.js v{{version}} (build: {{build}})"
|
|
|
|
),
|
|
|
|
];
|
2012-05-15 09:19:09 +09:00
|
|
|
if (moreInfo) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_message",
|
|
|
|
{ message: moreInfo.message },
|
|
|
|
"Message: {{message}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
if (moreInfo.stack) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_stack",
|
|
|
|
{ stack: moreInfo.stack },
|
|
|
|
"Stack: {{stack}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
} else {
|
|
|
|
if (moreInfo.filename) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_file",
|
|
|
|
{ file: moreInfo.filename },
|
|
|
|
"File: {{file}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
}
|
|
|
|
if (moreInfo.lineNumber) {
|
2017-05-04 10:05:53 +09:00
|
|
|
moreInfoText.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n.get(
|
|
|
|
"error_line",
|
|
|
|
{ line: moreInfo.lineNumber },
|
|
|
|
"Line: {{line}}"
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 09:19:09 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 00:48:56 +09:00
|
|
|
|
2020-01-08 21:57:31 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorWrapperConfig = this.appConfig.errorWrapper;
|
|
|
|
const errorWrapper = errorWrapperConfig.container;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorWrapper.removeAttribute("hidden");
|
2011-11-29 09:55:09 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorMessage = errorWrapperConfig.errorMessage;
|
2016-10-15 00:57:53 +09:00
|
|
|
errorMessage.textContent = message;
|
2011-11-29 09:55:09 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const closeButton = errorWrapperConfig.closeButton;
|
2020-04-14 19:28:14 +09:00
|
|
|
closeButton.onclick = function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorWrapper.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
2011-11-30 04:28:05 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
|
|
|
|
const moreInfoButton = errorWrapperConfig.moreInfoButton;
|
|
|
|
const lessInfoButton = errorWrapperConfig.lessInfoButton;
|
2020-04-14 19:28:14 +09:00
|
|
|
moreInfoButton.onclick = function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorMoreInfo.removeAttribute("hidden");
|
|
|
|
moreInfoButton.setAttribute("hidden", "true");
|
|
|
|
lessInfoButton.removeAttribute("hidden");
|
|
|
|
errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
2020-04-14 19:28:14 +09:00
|
|
|
lessInfoButton.onclick = function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
errorMoreInfo.setAttribute("hidden", "true");
|
|
|
|
moreInfoButton.removeAttribute("hidden");
|
|
|
|
lessInfoButton.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
|
|
|
moreInfoButton.oncontextmenu = noContextMenuHandler;
|
|
|
|
lessInfoButton.oncontextmenu = noContextMenuHandler;
|
|
|
|
closeButton.oncontextmenu = noContextMenuHandler;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
moreInfoButton.removeAttribute("hidden");
|
|
|
|
lessInfoButton.setAttribute("hidden", "true");
|
|
|
|
Promise.all(moreInfoText).then(parts => {
|
|
|
|
errorMoreInfo.value = parts.join("\n");
|
2017-05-04 10:05:53 +09:00
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
Promise.all(moreInfoText).then(parts => {
|
|
|
|
console.error(message + "\n" + parts.join("\n"));
|
2017-08-28 20:49:40 +09:00
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
this.fallback();
|
|
|
|
}
|
2011-09-28 19:53:53 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
progress(level) {
|
2017-07-29 18:36:45 +09:00
|
|
|
if (this.downloadComplete) {
|
|
|
|
// Don't accidentally show the loading bar again when the entire file has
|
|
|
|
// already been fetched (only an issue when disableAutoFetch is enabled).
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const percent = Math.round(level * 100);
|
2013-04-24 02:00:31 +09:00
|
|
|
// When we transition from full request to range requests, it's possible
|
|
|
|
// that we discard some of the loaded data. This can cause the loading
|
|
|
|
// bar to move backwards. So prevent this by only updating the bar if it
|
|
|
|
// increases.
|
2014-09-22 20:41:17 +09:00
|
|
|
if (percent > this.loadingBar.percent || isNaN(percent)) {
|
|
|
|
this.loadingBar.percent = percent;
|
2014-08-17 08:06:03 +09:00
|
|
|
|
|
|
|
// When disableAutoFetch is enabled, it's not uncommon for the entire file
|
|
|
|
// to never be fetched (depends on e.g. the file structure). In this case
|
|
|
|
// the loading bar will not be completely filled, nor will it be hidden.
|
|
|
|
// To prevent displaying a partially filled loading bar permanently, we
|
|
|
|
// hide it when no data has been loaded during a certain amount of time.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const disableAutoFetch = this.pdfDocument
|
|
|
|
? this.pdfDocument.loadingParams["disableAutoFetch"]
|
|
|
|
: AppOptions.get("disableAutoFetch");
|
2018-02-18 06:08:45 +09:00
|
|
|
|
|
|
|
if (disableAutoFetch && percent) {
|
2014-08-17 08:06:03 +09:00
|
|
|
if (this.disableAutoFetchLoadingBarTimeout) {
|
|
|
|
clearTimeout(this.disableAutoFetchLoadingBarTimeout);
|
|
|
|
this.disableAutoFetchLoadingBarTimeout = null;
|
|
|
|
}
|
|
|
|
this.loadingBar.show();
|
|
|
|
|
2017-05-05 00:09:50 +09:00
|
|
|
this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
|
2014-08-17 08:06:03 +09:00
|
|
|
this.loadingBar.hide();
|
|
|
|
this.disableAutoFetchLoadingBarTimeout = null;
|
2017-05-05 00:09:50 +09:00
|
|
|
}, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
|
2014-08-17 08:06:03 +09:00
|
|
|
}
|
2013-04-24 02:00:31 +09:00
|
|
|
}
|
2011-09-28 19:53:53 +09:00
|
|
|
},
|
|
|
|
|
Remove the ability to pass a `scale` parameter in the (optional) `args` object parameter of `PDFViewerApplication.open(file, args)`
Since the very early days of the viewer, it's been possible to pass in a `scale` when opening a PDF file. However, most of the time it was/is actually being ignored, which limits its usefulness considerably.
In older versions of the viewer, if a document hash was present (i.e. `PDFViewerApplication.initialBookmark` being set) or if the document existed in the `ViewHistory`, the `scale` passed to `PDFViewerApplication.open` would thus always be ignored.
In addition to the above, in the current viewer there's even more cases where the `scale` parameter will be ignored: if a (valid) browser history entry exists on document load, or if the `defaultZoomValue` preference is set to a non-default value.
Hence the result is that in most situation, a `scale` passed to `PDFViewerApplication.open` will be completely ignored.
A much better, not to mention supported, way of setting the initial scale is by using the `defaultZoomLevel` preference. In comparision, this also has the advantage of being used in situations where the `scale` would be ignored.
All in all this leads to the current situation where we have code which is essentially dead, since no part of the viewer (by default) relies on it.
To clean up this code, and to avoid having to pass (basically) unused parameters around, I'd thus like to remove the ability to pass a `scale` to `PDFViewerApplication.open`.
2017-08-24 16:24:32 +09:00
|
|
|
load(pdfDocument) {
|
2012-06-02 06:17:09 +09:00
|
|
|
this.pdfDocument = pdfDocument;
|
|
|
|
|
2017-05-09 20:17:39 +09:00
|
|
|
pdfDocument.getDownloadInfo().then(() => {
|
|
|
|
this.downloadComplete = true;
|
|
|
|
this.loadingBar.hide();
|
|
|
|
|
|
|
|
firstPagePromise.then(() => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.eventBus.dispatch("documentloaded", { source: this });
|
2017-05-09 20:17:39 +09:00
|
|
|
});
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
2011-09-28 19:53:53 +09:00
|
|
|
|
2017-07-19 23:26:17 +09:00
|
|
|
// Since the `setInitialView` call below depends on this being resolved,
|
|
|
|
// fetch it early to avoid delaying initial rendering of the PDF document.
|
2020-04-14 19:28:14 +09:00
|
|
|
const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* Avoid breaking initial rendering; ignoring errors. */
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
const pageModePromise = pdfDocument.getPageMode().catch(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* Avoid breaking initial rendering; ignoring errors. */
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
const openActionPromise = pdfDocument.getOpenAction().catch(function () {
|
2020-02-28 22:54:07 +09:00
|
|
|
/* Avoid breaking initial rendering; ignoring errors. */
|
|
|
|
});
|
2017-07-19 23:26:17 +09:00
|
|
|
|
2016-11-19 03:50:29 +09:00
|
|
|
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
|
|
|
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
2012-10-11 02:26:41 +09:00
|
|
|
|
2017-05-09 20:17:39 +09:00
|
|
|
let baseDocumentUrl;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2016-10-15 00:57:53 +09:00
|
|
|
baseDocumentUrl = null;
|
2020-01-08 21:57:31 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
2016-10-01 19:05:07 +09:00
|
|
|
baseDocumentUrl = this.baseUrl;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (PDFJSDev.test("CHROME")) {
|
|
|
|
baseDocumentUrl = location.href.split("#")[0];
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2015-04-28 00:25:32 +09:00
|
|
|
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
2017-05-05 21:04:08 +09:00
|
|
|
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
2015-04-28 00:25:32 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfViewer = this.pdfViewer;
|
2014-09-15 23:49:24 +09:00
|
|
|
pdfViewer.setDocument(pdfDocument);
|
Slightly improve the `BaseViewer.{firstPagePromise, onePageRendered, pagesPromise}` functionality
There's a couple of issues with this functionality:
- The respective `PromiseCapability` instances are not being reset, in `BaseViewer._resetView`, when the document is closed which is inconsistent with all other state.
- While the default viewer depends on these promises, and they thus ought to be considered part of e.g. the `PDFViewer` API-surface, they're not really defined in a particularily user-visible way (being that they're attached to the `BaseViewer` instance *inline* in `BaseViewer.setDocument`).
- There's some internal `BaseViewer` state, e.g. `BaseViewer._pageViewsReady`, which is tracked manually and could instead be tracked indirectly via the relevant `PromiseCapability`, thus reducing the need to track state *twice* since that's always best to avoid.
*Please note:* In the existing implementation, these promises are not defined *until* the `BaseViewer.setDocument` method has been called.
While it would've been simple to lift that restriction in this patch, I'm purposely choosing *not* to do so since this ensures that any Promise handlers added inside of `BaseViewer.setDocument` are always invoked *before* any external ones (and keeping that behaviour seems generally reasonable).
2020-03-07 21:11:51 +09:00
|
|
|
const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer;
|
2012-09-08 08:05:14 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfThumbnailViewer = this.pdfThumbnailViewer;
|
2016-01-23 21:56:56 +09:00
|
|
|
pdfThumbnailViewer.setDocument(pdfDocument);
|
2012-04-10 14:20:57 +09:00
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
const storedPromise = (this.store = new ViewHistory(
|
|
|
|
pdfDocument.fingerprint
|
|
|
|
))
|
|
|
|
.getMultiple({
|
|
|
|
page: null,
|
|
|
|
zoom: DEFAULT_SCALE_VALUE,
|
|
|
|
scrollLeft: "0",
|
|
|
|
scrollTop: "0",
|
|
|
|
rotation: null,
|
|
|
|
sidebarView: SidebarView.UNKNOWN,
|
|
|
|
scrollMode: ScrollMode.UNKNOWN,
|
|
|
|
spreadMode: SpreadMode.UNKNOWN,
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
/* Unable to read from storage; ignoring errors. */
|
|
|
|
return Object.create(null);
|
|
|
|
});
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstPagePromise.then(pdfPage => {
|
2017-05-09 20:17:39 +09:00
|
|
|
this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
2013-07-19 01:28:59 +09:00
|
|
|
|
2018-08-09 22:15:41 +09:00
|
|
|
Promise.all([
|
2019-09-08 21:13:50 +09:00
|
|
|
animationStarted,
|
2020-03-21 22:37:03 +09:00
|
|
|
storedPromise,
|
2019-09-08 21:13:50 +09:00
|
|
|
pageLayoutPromise,
|
|
|
|
pageModePromise,
|
2020-02-28 22:54:07 +09:00
|
|
|
openActionPromise,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
])
|
2020-03-21 22:37:03 +09:00
|
|
|
.then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
|
|
|
|
const viewOnLoad = AppOptions.get("viewOnLoad");
|
2018-06-26 21:08:00 +09:00
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
this._initializePdfHistory({
|
|
|
|
fingerprint: pdfDocument.fingerprint,
|
|
|
|
viewOnLoad,
|
|
|
|
initialDest: openAction && openAction.dest,
|
|
|
|
});
|
|
|
|
const initialBookmark = this.initialBookmark;
|
|
|
|
|
|
|
|
// Initialize the default values, from user preferences.
|
|
|
|
const zoom = AppOptions.get("defaultZoomValue");
|
|
|
|
let hash = zoom ? `zoom=${zoom}` : null;
|
|
|
|
|
|
|
|
let rotation = null;
|
|
|
|
let sidebarView = AppOptions.get("sidebarViewOnLoad");
|
|
|
|
let scrollMode = AppOptions.get("scrollModeOnLoad");
|
|
|
|
let spreadMode = AppOptions.get("spreadModeOnLoad");
|
|
|
|
|
|
|
|
if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
|
|
|
|
hash =
|
|
|
|
`page=${stored.page}&zoom=${zoom || stored.zoom},` +
|
|
|
|
`${stored.scrollLeft},${stored.scrollTop}`;
|
|
|
|
|
|
|
|
rotation = parseInt(stored.rotation, 10);
|
|
|
|
// Always let user preference take precedence over the view history.
|
|
|
|
if (sidebarView === SidebarView.UNKNOWN) {
|
|
|
|
sidebarView = stored.sidebarView | 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
if (scrollMode === ScrollMode.UNKNOWN) {
|
|
|
|
scrollMode = stored.scrollMode | 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
if (spreadMode === SpreadMode.UNKNOWN) {
|
|
|
|
spreadMode = stored.spreadMode | 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
}
|
|
|
|
// Always let the user preference/view history take precedence.
|
|
|
|
if (pageMode && sidebarView === SidebarView.UNKNOWN) {
|
|
|
|
sidebarView = apiPageModeToSidebarView(pageMode);
|
|
|
|
}
|
|
|
|
if (pageLayout && spreadMode === SpreadMode.UNKNOWN) {
|
|
|
|
spreadMode = apiPageLayoutToSpreadMode(pageLayout);
|
|
|
|
}
|
2018-06-26 21:08:00 +09:00
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
this.setInitialView(hash, {
|
|
|
|
rotation,
|
|
|
|
sidebarView,
|
|
|
|
scrollMode,
|
|
|
|
spreadMode,
|
|
|
|
});
|
|
|
|
this.eventBus.dispatch("documentinit", { source: this });
|
|
|
|
// Make all navigation keys work on document load,
|
|
|
|
// unless the viewer is embedded in a web page.
|
|
|
|
if (!this.isViewerEmbedded) {
|
|
|
|
pdfViewer.focus();
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
}
|
2020-03-21 22:37:03 +09:00
|
|
|
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
// Currently only the "copy"-permission is supported, hence we delay
|
|
|
|
// the `getPermissions` API call until *after* rendering has started.
|
|
|
|
this._initializePermissions(pdfDocument);
|
|
|
|
|
2020-03-21 22:37:03 +09:00
|
|
|
// For documents with different page sizes, once all pages are
|
|
|
|
// resolved, ensure that the correct location becomes visible on load.
|
|
|
|
// (To reduce the risk, in very large and/or slow loading documents,
|
|
|
|
// that the location changes *after* the user has started interacting
|
|
|
|
// with the viewer, wait for either `pagesPromise` or a timeout.)
|
|
|
|
await Promise.race([
|
|
|
|
pagesPromise,
|
|
|
|
new Promise(resolve => {
|
|
|
|
setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
if (!initialBookmark && !hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pdfViewer.hasEqualPageSizes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.initialBookmark = initialBookmark;
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-self-assign
|
|
|
|
pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
|
|
|
|
// Re-apply the initial document location.
|
|
|
|
this.setInitialView(hash);
|
|
|
|
})
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
.catch(() => {
|
|
|
|
// Ensure that the document is always completely initialized,
|
|
|
|
// even if there are any errors thrown above.
|
|
|
|
this.setInitialView();
|
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
// At this point, rendering of the initial page(s) should always have
|
|
|
|
// started (and may even have completed).
|
|
|
|
// To prevent any future issues, e.g. the document being completely
|
|
|
|
// blank on load, always trigger rendering here.
|
|
|
|
pdfViewer.update();
|
2018-05-15 12:10:33 +09:00
|
|
|
});
|
2013-03-09 11:08:37 +09:00
|
|
|
});
|
|
|
|
|
2020-04-05 17:59:10 +09:00
|
|
|
pagesPromise.then(() => {
|
|
|
|
this._initializeAutoPrint(pdfDocument, openActionPromise);
|
2012-04-10 14:20:57 +09:00
|
|
|
});
|
2011-12-01 10:04:45 +09:00
|
|
|
|
2019-09-08 21:13:50 +09:00
|
|
|
onePageRendered.then(() => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pdfDocument.getOutline().then(outline => {
|
|
|
|
this.pdfOutlineViewer.render({ outline });
|
2012-04-10 14:20:57 +09:00
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pdfDocument.getAttachments().then(attachments => {
|
|
|
|
this.pdfAttachmentViewer.render({ attachments });
|
2014-03-19 05:32:47 +09:00
|
|
|
});
|
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-04-05 17:24:02 +09:00
|
|
|
|
2020-04-05 17:59:10 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializeAutoPrint(pdfDocument, openActionPromise) {
|
|
|
|
const [openAction, javaScript] = await Promise.all([
|
|
|
|
openActionPromise,
|
|
|
|
pdfDocument.getJavaScript(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the auto print data resolved.
|
|
|
|
}
|
|
|
|
let triggerAutoPrint = false;
|
|
|
|
|
|
|
|
if (openAction && openAction.action === "Print") {
|
|
|
|
triggerAutoPrint = true;
|
|
|
|
}
|
|
|
|
if (javaScript) {
|
|
|
|
javaScript.some(js => {
|
|
|
|
if (!js) {
|
|
|
|
// Don't warn/fallback for empty JavaScript actions.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
console.warn("Warning: JavaScript is not supported");
|
|
|
|
this.fallback(UNSUPPORTED_FEATURES.javaScript);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!triggerAutoPrint) {
|
|
|
|
// Hack to support auto printing.
|
|
|
|
for (const js of javaScript) {
|
|
|
|
if (js && AutoPrintRegExp.test(js)) {
|
|
|
|
triggerAutoPrint = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.supportsPrinting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (triggerAutoPrint) {
|
2020-04-14 19:28:14 +09:00
|
|
|
setTimeout(function () {
|
2020-04-05 17:59:10 +09:00
|
|
|
window.print();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializeMetadata(pdfDocument) {
|
|
|
|
const {
|
|
|
|
info,
|
|
|
|
metadata,
|
|
|
|
contentDispositionFilename,
|
|
|
|
} = 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;
|
|
|
|
this.contentDispositionFilename = contentDispositionFilename;
|
|
|
|
|
|
|
|
// Provides some basic debug information
|
|
|
|
console.log(
|
2020-04-05 18:15:21 +09:00
|
|
|
`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` +
|
|
|
|
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
|
|
|
`(PDF.js: ${version || "-"}` +
|
|
|
|
`${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`
|
2020-04-05 17:26:55 +09:00
|
|
|
);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
let pdfTitle;
|
2012-04-10 14:20:57 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
const infoTitle = info && info["Title"];
|
|
|
|
if (infoTitle) {
|
|
|
|
pdfTitle = infoTitle;
|
|
|
|
}
|
|
|
|
const metadataTitle = metadata && metadata.get("dc:title");
|
|
|
|
if (metadataTitle) {
|
|
|
|
// Ghostscript can produce invalid 'dc:title' Metadata entries:
|
|
|
|
// - The title may be "Untitled" (fixes bug 1031612).
|
|
|
|
// - The title may contain incorrectly encoded characters, which thus
|
|
|
|
// looks broken, hence we ignore the Metadata entry when it
|
|
|
|
// contains characters from the Specials Unicode block
|
|
|
|
// (fixes bug 1605526).
|
|
|
|
if (
|
|
|
|
metadataTitle !== "Untitled" &&
|
|
|
|
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
|
|
|
|
) {
|
|
|
|
pdfTitle = metadataTitle;
|
|
|
|
}
|
|
|
|
}
|
2018-01-13 17:01:50 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
if (pdfTitle) {
|
|
|
|
this.setTitle(
|
|
|
|
`${pdfTitle} - ${contentDispositionFilename || document.title}`
|
|
|
|
);
|
|
|
|
} else if (contentDispositionFilename) {
|
|
|
|
this.setTitle(contentDispositionFilename);
|
|
|
|
}
|
2013-08-16 23:53:05 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
if (info.IsAcroFormPresent) {
|
|
|
|
console.warn("Warning: AcroForm/XFA is not supported");
|
|
|
|
this.fallback(UNSUPPORTED_FEATURES.forms);
|
|
|
|
}
|
2020-01-02 04:41:15 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
|
|
|
) {
|
|
|
|
// Telemetry labels must be C++ variable friendly.
|
|
|
|
let versionId = "other";
|
|
|
|
// 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",
|
|
|
|
];
|
|
|
|
if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
|
|
|
|
versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
|
|
|
|
}
|
2020-01-03 07:19:14 +09:00
|
|
|
|
2020-04-05 17:26:55 +09:00
|
|
|
let generatorId = "other";
|
|
|
|
// 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",
|
|
|
|
];
|
|
|
|
if (info.Producer) {
|
|
|
|
const producer = info.Producer.toLowerCase();
|
2020-04-14 19:28:14 +09:00
|
|
|
KNOWN_GENERATORS.some(function (generator) {
|
2020-04-05 17:26:55 +09:00
|
|
|
if (!producer.includes(generator)) {
|
|
|
|
return false;
|
2020-01-08 19:56:10 +09:00
|
|
|
}
|
2020-04-05 17:26:55 +09:00
|
|
|
generatorId = generator.replace(/[ .\-]/g, "_");
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let formType = null;
|
|
|
|
if (info.IsAcroFormPresent) {
|
|
|
|
formType = info.IsXFAPresent ? "xfa" : "acroform";
|
|
|
|
}
|
|
|
|
this.externalServices.reportTelemetry({
|
|
|
|
type: "documentInfo",
|
|
|
|
version: versionId,
|
|
|
|
generator: generatorId,
|
|
|
|
formType,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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
|
|
|
}
|
2012-04-10 14:20:57 +09:00
|
|
|
},
|
|
|
|
|
2020-04-05 17:24:02 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializePageLabels(pdfDocument) {
|
|
|
|
const labels = await pdfDocument.getPageLabels();
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the page labels resolved.
|
|
|
|
}
|
|
|
|
if (!labels || AppOptions.get("disablePageLabels")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const numLabels = labels.length;
|
|
|
|
if (numLabels !== this.pagesCount) {
|
|
|
|
console.error(
|
|
|
|
"The number of Page Labels does not match the number of pages in the document."
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let i = 0;
|
|
|
|
// Ignore page labels that correspond to standard page numbering.
|
|
|
|
while (i < numLabels && labels[i] === (i + 1).toString()) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i === numLabels) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { pdfViewer, pdfThumbnailViewer, toolbar } = this;
|
|
|
|
|
|
|
|
pdfViewer.setPageLabels(labels);
|
|
|
|
pdfThumbnailViewer.setPageLabels(labels);
|
|
|
|
|
|
|
|
// Changing toolbar page display to use labels and we need to set
|
|
|
|
// the label of the current page.
|
|
|
|
toolbar.setPagesCount(numLabels, true);
|
|
|
|
toolbar.setPageNumber(
|
|
|
|
pdfViewer.currentPageNumber,
|
|
|
|
pdfViewer.currentPageLabel
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-02-02 18:08:56 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
_initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null }) {
|
2020-04-05 18:15:21 +09:00
|
|
|
if (this.isViewerEmbedded || AppOptions.get("disableHistory")) {
|
2019-02-02 18:08:56 +09:00
|
|
|
// The browsing history is only enabled when the viewer is standalone,
|
|
|
|
// i.e. not when it is embedded in a web page.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.pdfHistory.initialize({
|
|
|
|
fingerprint,
|
|
|
|
resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
updateUrl: AppOptions.get("historyUpdateUrl"),
|
2019-02-02 18:08:56 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
if (this.pdfHistory.initialBookmark) {
|
|
|
|
this.initialBookmark = this.pdfHistory.initialBookmark;
|
|
|
|
|
|
|
|
this.initialRotation = this.pdfHistory.initialRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always let the browser history/document hash take precedence.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
initialDest &&
|
|
|
|
!this.initialBookmark &&
|
|
|
|
viewOnLoad === ViewOnLoad.UNKNOWN
|
|
|
|
) {
|
2019-02-02 18:08:56 +09:00
|
|
|
this.initialBookmark = JSON.stringify(initialDest);
|
|
|
|
// TODO: Re-factor the `PDFHistory` initialization to remove this hack
|
|
|
|
// that's currently necessary to prevent weird initial history state.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfHistory.push({ explicitDest: initialDest, pageNumber: null });
|
2019-02-02 18:08:56 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _initializePermissions(pdfDocument) {
|
|
|
|
const permissions = await pdfDocument.getPermissions();
|
|
|
|
|
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
|
return; // The document was closed while the permissions resolved.
|
|
|
|
}
|
|
|
|
if (!permissions || !AppOptions.get("enablePermissions")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Currently only the "copy"-permission is supported.
|
|
|
|
if (!permissions.includes(PermissionFlag.COPY)) {
|
|
|
|
this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
setInitialView(
|
|
|
|
storedHash,
|
|
|
|
{ rotation, sidebarView, scrollMode, spreadMode } = {}
|
|
|
|
) {
|
|
|
|
const setRotation = angle => {
|
2017-08-21 18:22:07 +09:00
|
|
|
if (isValidRotation(angle)) {
|
|
|
|
this.pdfViewer.pagesRotation = angle;
|
|
|
|
}
|
|
|
|
};
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
const setViewerModes = (scroll, spread) => {
|
|
|
|
if (isValidScrollMode(scroll)) {
|
2018-06-29 22:07:42 +09:00
|
|
|
this.pdfViewer.scrollMode = scroll;
|
2018-06-29 20:16:00 +09:00
|
|
|
}
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
if (isValidSpreadMode(spread)) {
|
2018-06-29 22:07:42 +09:00
|
|
|
this.pdfViewer.spreadMode = spread;
|
2018-06-29 20:16:00 +09:00
|
|
|
}
|
|
|
|
};
|
2014-09-22 20:41:17 +09:00
|
|
|
this.isInitialViewSet = true;
|
2017-04-22 20:42:41 +09:00
|
|
|
this.pdfSidebar.setInitialView(sidebarView);
|
2016-02-22 01:54:23 +09:00
|
|
|
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
setViewerModes(scrollMode, spreadMode);
|
|
|
|
|
2017-07-14 21:24:32 +09:00
|
|
|
if (this.initialBookmark) {
|
2017-08-21 18:56:49 +09:00
|
|
|
setRotation(this.initialRotation);
|
|
|
|
delete this.initialRotation;
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
this.pdfLinkService.setHash(this.initialBookmark);
|
2011-10-02 03:54:37 +09:00
|
|
|
this.initialBookmark = null;
|
2013-05-16 07:31:17 +09:00
|
|
|
} else if (storedHash) {
|
2017-08-21 18:22:07 +09:00
|
|
|
setRotation(rotation);
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
this.pdfLinkService.setHash(storedHash);
|
2011-12-29 10:18:55 +09:00
|
|
|
}
|
2012-01-26 12:52:10 +09:00
|
|
|
|
2016-11-19 03:50:29 +09:00
|
|
|
// Ensure that the correct page number is displayed in the UI,
|
|
|
|
// even if the active page didn't change during document load.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.toolbar.setPageNumber(
|
|
|
|
this.pdfViewer.currentPageNumber,
|
|
|
|
this.pdfViewer.currentPageLabel
|
|
|
|
);
|
2016-11-19 03:50:29 +09:00
|
|
|
this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
|
|
|
|
|
2015-03-15 04:07:17 +09:00
|
|
|
if (!this.pdfViewer.currentScaleValue) {
|
2012-01-26 12:52:10 +09:00
|
|
|
// Scale was not initialized: invalid bookmark or scale was not specified.
|
|
|
|
// Setting the default one.
|
2015-07-11 18:47:45 +09:00
|
|
|
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
|
2012-01-26 12:52:10 +09:00
|
|
|
}
|
2011-10-02 03:54:37 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
cleanup() {
|
2015-10-23 22:49:02 +09:00
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return; // run cleanup when document is loaded
|
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
this.pdfViewer.cleanup();
|
2014-09-13 04:48:44 +09:00
|
|
|
this.pdfThumbnailViewer.cleanup();
|
2016-11-19 04:03:49 +09:00
|
|
|
|
|
|
|
// We don't want to remove fonts used by active page SVGs.
|
|
|
|
if (this.pdfViewer.renderer !== RendererType.SVG) {
|
|
|
|
this.pdfDocument.cleanup();
|
|
|
|
}
|
2012-06-19 01:48:47 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
forceRendering() {
|
2014-09-16 01:18:28 +09:00
|
|
|
this.pdfRenderingQueue.printing = this.printing;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
|
2014-09-16 01:18:28 +09:00
|
|
|
this.pdfRenderingQueue.renderHighestPriority();
|
2012-06-19 01:48:47 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
beforePrint() {
|
2016-10-08 21:36:55 +09:00
|
|
|
if (this.printService) {
|
|
|
|
// There is no way to suppress beforePrint/afterPrint events,
|
|
|
|
// but PDFPrintService may generate double events -- this will ignore
|
|
|
|
// the second event that will be coming from native window.print().
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-29 01:50:25 +09:00
|
|
|
if (!this.supportsPrinting) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n
|
|
|
|
.get(
|
|
|
|
"printing_not_supported",
|
|
|
|
null,
|
2019-12-26 04:03:46 +09:00
|
|
|
"Warning: Printing is not fully supported by this browser."
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
)
|
|
|
|
.then(printMessage => {
|
|
|
|
this.error(printMessage);
|
|
|
|
});
|
2012-06-29 01:50:25 +09:00
|
|
|
return;
|
|
|
|
}
|
2013-03-09 11:08:37 +09:00
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
// The beforePrint is a sync method and we need to know layout before
|
|
|
|
// returning from this method. Ensure that we can get sizes of the pages.
|
|
|
|
if (!this.pdfViewer.pageViewsReady) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.l10n
|
|
|
|
.get(
|
|
|
|
"printing_not_ready",
|
|
|
|
null,
|
|
|
|
"Warning: The PDF is not fully loaded for printing."
|
|
|
|
)
|
|
|
|
.then(notReadyMessage => {
|
|
|
|
window.alert(notReadyMessage);
|
|
|
|
});
|
2013-03-09 11:08:37 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pagesOverview = this.pdfViewer.getPagesOverview();
|
|
|
|
const printContainer = this.appConfig.printContainer;
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (
|
Ensure that the viewer telemetry reporting, and fallback code, runs in development mode and GENERIC builds
While only the `MOZCENTRAL` builds will actually do anything meaningful with the telemetry data, none of the code in question actually runs *at all* in e.g. development mode.[1]
This seems bad since it essentially means that this code is completely untested, despite being quite important for the built-in Firefox PDF viewer, and this thus ought to be fixed.
In this case, the explanation for the current state of the code should be "for historical reasons". Before the viewer was split into the current components and before the pre-processor was improved, back when all code resided in the `web/viewer.js` file, the telemetry reporting was done with *direct* `FirefoxCom` calls. However, with the dummy `DefaultExternalServices.reportTelemetry` method there's nothing actually preventing attempting to report telemetry in any type of build.
NOTE: By running this code in GENERIC builds as well, in addition to just locally, the *viewer* part of telemetry reporting becomes tested e.g. in preview builds too which should help with reviewing.
---
[1] When fixing bug 1606566, I had to edit the relevant `PDFJSDev` checks to be able to actually test the changes locally.
2020-01-20 19:37:54 +09:00
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
) {
|
2016-10-15 00:57:53 +09:00
|
|
|
this.externalServices.reportTelemetry({
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
type: "print",
|
2016-10-15 00:57:53 +09:00
|
|
|
});
|
2015-04-30 02:09:58 +09:00
|
|
|
}
|
2012-06-29 01:50:25 +09:00
|
|
|
},
|
|
|
|
|
2019-08-24 18:48:33 +09:00
|
|
|
afterPrint() {
|
2016-10-07 06:46:30 +09:00
|
|
|
if (this.printService) {
|
|
|
|
this.printService.destroy();
|
|
|
|
this.printService = null;
|
2014-03-09 20:20:32 +09:00
|
|
|
}
|
2014-09-16 01:18:28 +09:00
|
|
|
this.forceRendering();
|
2012-07-31 00:12:49 +09:00
|
|
|
},
|
|
|
|
|
2017-06-17 20:14:36 +09:00
|
|
|
rotatePages(delta) {
|
|
|
|
if (!this.pdfDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
|
2017-08-19 21:23:40 +09:00
|
|
|
this.pdfViewer.pagesRotation = newRotation;
|
|
|
|
// Note that the thumbnail viewer is updated, and rendering is triggered,
|
|
|
|
// in the 'rotationchanging' event handler.
|
2012-09-14 05:23:44 +09:00
|
|
|
},
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
requestPresentationMode() {
|
2015-02-04 02:09:11 +09:00
|
|
|
if (!this.pdfPresentationMode) {
|
2015-01-29 21:37:49 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-02-04 02:09:11 +09:00
|
|
|
this.pdfPresentationMode.request();
|
2015-01-29 21:37:49 +09:00
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
Re-factor the `EventBus` to allow servicing of "external" event listeners *after* the viewer components have updated
Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.
Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).
---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.
[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
2020-02-27 07:33:27 +09:00
|
|
|
eventBus._on("fileinputchange", webViewerFileInputChange);
|
2020-03-17 21:26:35 +09:00
|
|
|
eventBus._on("openfile", webViewerOpenFile);
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2016-12-09 00:28:40 +09:00
|
|
|
},
|
|
|
|
|
2017-06-14 04:11:29 +09:00
|
|
|
bindWindowEvents() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const { eventBus, _boundEvents } = this;
|
2016-12-09 00:28:40 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowResize = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("resize", { source: window });
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowHashChange = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("hashchange", {
|
2018-08-28 16:56:26 +09:00
|
|
|
source: window,
|
2016-12-09 00:28:40 +09:00
|
|
|
hash: document.location.hash.substring(1),
|
|
|
|
});
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowBeforePrint = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("beforeprint", { source: window });
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowAfterPrint = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventBus.dispatch("afterprint", { source: window });
|
2017-06-14 04:11:29 +09:00
|
|
|
};
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
window.addEventListener("visibilitychange", webViewerVisibilityChange);
|
|
|
|
window.addEventListener("wheel", webViewerWheel, { passive: false });
|
|
|
|
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);
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 });
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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);
|
2017-06-14 04:11:29 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
_boundEvents.windowResize = null;
|
|
|
|
_boundEvents.windowHashChange = null;
|
|
|
|
_boundEvents.windowBeforePrint = null;
|
|
|
|
_boundEvents.windowAfterPrint = null;
|
2016-12-09 00:28:40 +09:00
|
|
|
},
|
2011-07-29 02:48:05 +09:00
|
|
|
};
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
let validateFileURL;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|
|
|
const HOSTED_VIEWER_ORIGINS = [
|
|
|
|
"null",
|
|
|
|
"http://mozilla.github.io",
|
|
|
|
"https://mozilla.github.io",
|
|
|
|
];
|
2020-04-14 19:28:14 +09:00
|
|
|
validateFileURL = function (file) {
|
2017-07-14 05:48:04 +09:00
|
|
|
if (file === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-15 00:57:53 +09:00
|
|
|
try {
|
2019-12-27 08:22:32 +09:00
|
|
|
const viewerOrigin = new URL(window.location.href).origin || "null";
|
2018-02-11 01:06:03 +09:00
|
|
|
if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
|
2016-10-15 00:57:53 +09:00
|
|
|
// Hosted or local viewer, allow for any file locations
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const { origin, protocol } = new URL(file, window.location.href);
|
2016-10-15 00:57:53 +09:00
|
|
|
// Removing of the following line will not guarantee that the viewer will
|
|
|
|
// start accepting URLs from foreign origin -- CORS headers on the remote
|
|
|
|
// server must be properly configured.
|
2018-02-23 20:48:52 +09:00
|
|
|
// IE10 / IE11 does not include an origin in `blob:`-URLs. So don't block
|
|
|
|
// any blob:-URL. The browser's same-origin policy will block requests to
|
|
|
|
// blob:-URLs from other origins, so this is safe.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (origin !== viewerOrigin && protocol !== "blob:") {
|
|
|
|
throw new Error("file origin does not match viewer's");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
} catch (ex) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const message = ex && ex.message;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get("loading_error", null, "An error occurred while loading the PDF.")
|
|
|
|
.then(loadingErrorMessage => {
|
|
|
|
PDFViewerApplication.error(loadingErrorMessage, { message });
|
|
|
|
});
|
2017-06-29 19:14:26 +09:00
|
|
|
throw ex;
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
|
|
|
};
|
2016-01-23 02:54:19 +09:00
|
|
|
}
|
|
|
|
|
2019-12-20 02:11:56 +09:00
|
|
|
async function loadFakeWorker() {
|
2018-06-07 20:52:40 +09:00
|
|
|
if (!GlobalWorkerOptions.workerSrc) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
GlobalWorkerOptions.workerSrc = AppOptions.get("workerSrc");
|
2018-06-07 20:52:40 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
|
|
|
if (typeof SystemJS !== "object") {
|
|
|
|
throw new Error("SystemJS must be used to load fake worker.");
|
2019-12-20 02:11:56 +09:00
|
|
|
}
|
2020-01-02 20:00:16 +09:00
|
|
|
window.pdfjsWorker = await SystemJS.import("pdfjs/core/worker.js");
|
2019-12-20 02:11:56 +09:00
|
|
|
return undefined;
|
2018-06-07 20:52:40 +09:00
|
|
|
}
|
|
|
|
return loadScript(PDFWorker.getWorkerSrc());
|
2018-01-20 02:16:17 +09:00
|
|
|
}
|
|
|
|
|
2016-05-10 08:18:43 +09:00
|
|
|
function loadAndEnablePDFBug(enabledTabs) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
2020-04-14 19:28:14 +09:00
|
|
|
return loadScript(appConfig.debuggerScriptPath).then(function () {
|
2018-06-07 20:52:40 +09:00
|
|
|
PDFBug.enable(enabledTabs);
|
2020-01-29 05:00:33 +09:00
|
|
|
PDFBug.init({ OPS }, appConfig.mainContainer);
|
2016-05-10 08:18:43 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-04-04 02:20:53 +09:00
|
|
|
function webViewerInitialized() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
2017-06-29 19:14:26 +09:00
|
|
|
let file;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const queryString = document.location.search.substring(1);
|
|
|
|
const params = parseQueryString(queryString);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
file = "file" in params ? params.file : AppOptions.get("defaultUrl");
|
2016-10-15 00:57:53 +09:00
|
|
|
validateFileURL(file);
|
2020-01-08 21:57:31 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
file = window.location.href.split("#")[0];
|
|
|
|
} else if (PDFJSDev.test("CHROME")) {
|
|
|
|
file = AppOptions.get("defaultUrl");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2013-08-15 06:36:40 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const fileInput = document.createElement("input");
|
2016-10-15 00:57:53 +09:00
|
|
|
fileInput.id = appConfig.openFileInputName;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fileInput.className = "fileInput";
|
|
|
|
fileInput.setAttribute("type", "file");
|
2016-10-15 00:57:53 +09:00
|
|
|
fileInput.oncontextmenu = noContextMenuHandler;
|
|
|
|
document.body.appendChild(fileInput);
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!window.File ||
|
|
|
|
!window.FileReader ||
|
|
|
|
!window.FileList ||
|
|
|
|
!window.Blob
|
|
|
|
) {
|
|
|
|
appConfig.toolbar.openFile.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
|
|
|
fileInput.value = null;
|
|
|
|
}
|
2017-09-16 20:05:01 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
fileInput.addEventListener("change", function (evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const files = evt.target.files;
|
2017-09-16 20:05:01 +09:00
|
|
|
if (!files || files.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
2018-08-28 16:56:26 +09:00
|
|
|
source: this,
|
2017-09-16 20:05:01 +09:00
|
|
|
fileInput: evt.target,
|
|
|
|
});
|
|
|
|
});
|
2018-06-10 22:39:06 +09:00
|
|
|
|
2020-03-07 12:37:22 +09:00
|
|
|
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
2020-04-14 19:28:14 +09:00
|
|
|
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
2018-06-10 22:39:06 +09:00
|
|
|
evt.preventDefault();
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
evt.dataTransfer.dropEffect = "move";
|
2018-06-10 22:39:06 +09:00
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
2018-06-10 22:39:06 +09:00
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const files = evt.dataTransfer.files;
|
|
|
|
if (!files || files.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
2018-08-28 16:56:26 +09:00
|
|
|
source: this,
|
2018-06-10 22:39:06 +09:00
|
|
|
fileInput: evt.dataTransfer,
|
|
|
|
});
|
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.openFile.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
|
2012-01-25 08:13:50 +09:00
|
|
|
}
|
2016-04-22 01:39:11 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (
|
Ensure that the viewer telemetry reporting, and fallback code, runs in development mode and GENERIC builds
While only the `MOZCENTRAL` builds will actually do anything meaningful with the telemetry data, none of the code in question actually runs *at all* in e.g. development mode.[1]
This seems bad since it essentially means that this code is completely untested, despite being quite important for the built-in Firefox PDF viewer, and this thus ought to be fixed.
In this case, the explanation for the current state of the code should be "for historical reasons". Before the viewer was split into the current components and before the pre-processor was improved, back when all code resided in the `web/viewer.js` file, the telemetry reporting was done with *direct* `FirefoxCom` calls. However, with the dummy `DefaultExternalServices.reportTelemetry` method there's nothing actually preventing attempting to report telemetry in any type of build.
NOTE: By running this code in GENERIC builds as well, in addition to just locally, the *viewer* part of telemetry reporting becomes tested e.g. in preview builds too which should help with reviewing.
---
[1] When fixing bug 1606566, I had to edit the relevant `PDFJSDev` checks to be able to actually test the changes locally.
2020-01-20 19:37:54 +09:00
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("MOZCENTRAL || GENERIC")) &&
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.supportsDocumentFonts
|
|
|
|
) {
|
|
|
|
AppOptions.set("disableFontFace", true);
|
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get(
|
|
|
|
"web_fonts_disabled",
|
|
|
|
null,
|
|
|
|
"Web fonts are disabled: unable to use embedded PDF fonts."
|
|
|
|
)
|
|
|
|
.then(msg => {
|
|
|
|
console.warn(msg);
|
|
|
|
});
|
2015-04-26 08:49:37 +09:00
|
|
|
}
|
2012-05-01 05:29:05 +09:00
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
if (!PDFViewerApplication.supportsPrinting) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.print.classList.add("hidden");
|
|
|
|
appConfig.secondaryToolbar.printButton.classList.add("hidden");
|
2012-07-10 08:04:55 +09:00
|
|
|
}
|
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
if (!PDFViewerApplication.supportsFullscreen) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.presentationModeButton.classList.add("hidden");
|
|
|
|
appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
|
2012-07-31 00:12:49 +09:00
|
|
|
}
|
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
if (PDFViewerApplication.supportsIntegratedFind) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.viewFind.classList.add("hidden");
|
2012-10-06 05:59:13 +09:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.mainContainer.addEventListener(
|
|
|
|
"transitionend",
|
2020-04-14 19:28:14 +09:00
|
|
|
function (evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (evt.target === /* mainContainer */ this) {
|
|
|
|
PDFViewerApplication.eventBus.dispatch("resize", { source: this });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2012-09-07 00:33:07 +09:00
|
|
|
|
2018-07-31 00:41:39 +09:00
|
|
|
try {
|
2016-05-10 08:18:43 +09:00
|
|
|
webViewerOpenFileViaURL(file);
|
2018-07-31 00:41:39 +09:00
|
|
|
} catch (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get("loading_error", null, "An error occurred while loading the PDF.")
|
|
|
|
.then(msg => {
|
|
|
|
PDFViewerApplication.error(msg, reason);
|
|
|
|
});
|
2018-07-31 00:41:39 +09:00
|
|
|
}
|
2016-05-10 08:18:43 +09:00
|
|
|
}
|
2012-08-16 00:17:30 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
let webViewerOpenFileViaURL;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFileViaURL = function (file) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (file && file.lastIndexOf("file:", 0) === 0) {
|
2016-10-15 00:57:53 +09:00
|
|
|
// file:-scheme. Load the contents in the main thread because QtWebKit
|
|
|
|
// cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded
|
|
|
|
// very quickly, so there is no need to set up progress event listeners.
|
|
|
|
PDFViewerApplication.setTitleUsingUrl(file);
|
2019-01-28 19:00:09 +09:00
|
|
|
const xhr = new XMLHttpRequest();
|
2020-04-14 19:28:14 +09:00
|
|
|
xhr.onload = function () {
|
2016-10-15 00:57:53 +09:00
|
|
|
PDFViewerApplication.open(new Uint8Array(xhr.response));
|
|
|
|
};
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
xhr.open("GET", file);
|
|
|
|
xhr.responseType = "arraybuffer";
|
2019-01-28 19:00:09 +09:00
|
|
|
xhr.send();
|
2016-10-15 00:57:53 +09:00
|
|
|
return;
|
2014-07-30 08:28:41 +09:00
|
|
|
}
|
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
if (file) {
|
|
|
|
PDFViewerApplication.open(file);
|
|
|
|
}
|
|
|
|
};
|
2020-01-08 21:57:31 +09:00
|
|
|
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFileViaURL = function (file) {
|
2016-10-15 00:57:53 +09:00
|
|
|
PDFViewerApplication.setTitleUsingUrl(file);
|
|
|
|
PDFViewerApplication.initPassiveLoading();
|
|
|
|
};
|
|
|
|
} else {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFileViaURL = function (file) {
|
2016-10-15 00:57:53 +09:00
|
|
|
if (file) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: webViewerOpenFileViaURL");
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
|
|
|
};
|
2014-02-28 02:45:02 +09:00
|
|
|
}
|
|
|
|
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
function webViewerResetPermissions() {
|
|
|
|
const { appConfig } = PDFViewerApplication;
|
|
|
|
if (!appConfig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Currently only the "copy"-permission is supported.
|
|
|
|
appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
|
|
|
}
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerPageRendered(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const pageNumber = evt.pageNumber;
|
|
|
|
const pageIndex = pageNumber - 1;
|
|
|
|
const pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
2015-01-28 05:13:34 +09:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent errors in the edge-case where the PDF document is removed *before*
|
|
|
|
// the 'pagerendered' event handler is invoked.
|
|
|
|
if (!pageView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-22 01:54:23 +09:00
|
|
|
// Use the rendered page to set the corresponding thumbnail image.
|
|
|
|
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
pageIndex
|
|
|
|
);
|
2015-01-28 05:13:34 +09:00
|
|
|
thumbnailView.setImage(pageView);
|
|
|
|
}
|
2012-08-08 08:52:22 +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 Stats !== "undefined" && Stats.enabled && pageView.stats) {
|
2014-09-30 01:15:06 +09:00
|
|
|
Stats.add(pageNumber, pageView.stats);
|
|
|
|
}
|
|
|
|
|
2014-09-16 04:57:12 +09:00
|
|
|
if (pageView.error) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.l10n
|
|
|
|
.get(
|
|
|
|
"rendering_error",
|
|
|
|
null,
|
|
|
|
"An error occurred while rendering the page."
|
|
|
|
)
|
|
|
|
.then(msg => {
|
|
|
|
PDFViewerApplication.error(msg, pageView.error);
|
|
|
|
});
|
2014-09-16 04:57:12 +09:00
|
|
|
}
|
2012-08-08 08:52:22 +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 (
|
Ensure that the viewer telemetry reporting, and fallback code, runs in development mode and GENERIC builds
While only the `MOZCENTRAL` builds will actually do anything meaningful with the telemetry data, none of the code in question actually runs *at all* in e.g. development mode.[1]
This seems bad since it essentially means that this code is completely untested, despite being quite important for the built-in Firefox PDF viewer, and this thus ought to be fixed.
In this case, the explanation for the current state of the code should be "for historical reasons". Before the viewer was split into the current components and before the pre-processor was improved, back when all code resided in the `web/viewer.js` file, the telemetry reporting was done with *direct* `FirefoxCom` calls. However, with the dummy `DefaultExternalServices.reportTelemetry` method there's nothing actually preventing attempting to report telemetry in any type of build.
NOTE: By running this code in GENERIC builds as well, in addition to just locally, the *viewer* part of telemetry reporting becomes tested e.g. in preview builds too which should help with reviewing.
---
[1] When fixing bug 1606566, I had to edit the relevant `PDFJSDev` checks to be able to actually test the changes locally.
2020-01-20 19:37:54 +09:00
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
) {
|
2016-04-14 06:21:05 +09:00
|
|
|
PDFViewerApplication.externalServices.reportTelemetry({
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
type: "pageInfo",
|
2019-08-07 01:46:33 +09:00
|
|
|
timestamp: evt.timestamp,
|
2016-04-14 06:21:05 +09:00
|
|
|
});
|
2016-10-15 00:57:53 +09:00
|
|
|
// It is a good time to report stream and font types.
|
2020-04-14 19:28:14 +09:00
|
|
|
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
2016-10-15 00:57:53 +09:00
|
|
|
PDFViewerApplication.externalServices.reportTelemetry({
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
type: "documentStats",
|
2017-04-28 19:02:42 +09:00
|
|
|
stats,
|
2016-10-15 00:57:53 +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":
|
|
|
|
case "outline":
|
2016-02-22 01:54:23 +09:00
|
|
|
view = SidebarView.OUTLINE;
|
|
|
|
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 "attachments":
|
2016-02-22 01:54:23 +09:00
|
|
|
view = SidebarView.ATTACHMENTS;
|
2015-08-05 05:57:51 +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 "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) {
|
2015-04-28 00:25:32 +09:00
|
|
|
// Processing couple of named actions that might be useful.
|
|
|
|
// See also PDFLinkService.executeNamedAction
|
2019-12-27 08:22:32 +09:00
|
|
|
const action = evt.action;
|
2015-04-28 00:25:32 +09:00
|
|
|
switch (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;
|
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2015-04-28 00:25:32 +09:00
|
|
|
|
2020-01-08 19:56:10 +09:00
|
|
|
function webViewerPresentationModeChanged({ active, switchInProgress }) {
|
|
|
|
let state = PresentationModeState.NORMAL;
|
|
|
|
if (switchInProgress) {
|
|
|
|
state = PresentationModeState.CHANGING;
|
|
|
|
} else if (active) {
|
|
|
|
state = PresentationModeState.FULLSCREEN;
|
|
|
|
}
|
|
|
|
PDFViewerApplication.pdfViewer.presentationModeState = state;
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2012-08-08 08:52:22 +09:00
|
|
|
|
2017-04-22 20:42:41 +09:00
|
|
|
function webViewerSidebarViewChanged(evt) {
|
2016-03-12 21:07:43 +09:00
|
|
|
PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled =
|
|
|
|
PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const store = PDFViewerApplication.store;
|
2017-04-22 20:42:41 +09:00
|
|
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
2016-03-12 21:07:43 +09:00
|
|
|
// Only update the storage when the document has been loaded *and* rendered.
|
2020-04-14 19:28:14 +09:00
|
|
|
store.set("sidebarView", evt.view).catch(function () {});
|
2016-03-12 21:07:43 +09:00
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2016-03-12 21:07:43 +09:00
|
|
|
|
2017-04-22 20:42:41 +09:00
|
|
|
function webViewerUpdateViewarea(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const location = evt.location,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
store = PDFViewerApplication.store;
|
2017-04-22 20:42:41 +09:00
|
|
|
|
|
|
|
if (store && PDFViewerApplication.isInitialViewSet) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
store
|
|
|
|
.setMultiple({
|
|
|
|
page: location.pageNumber,
|
|
|
|
zoom: location.scale,
|
|
|
|
scrollLeft: location.left,
|
|
|
|
scrollTop: location.top,
|
|
|
|
rotation: location.rotation,
|
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.catch(function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* unable to write to storage */
|
|
|
|
});
|
2016-03-12 21:07:43 +09:00
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
location.pdfOpenParams
|
|
|
|
);
|
2016-04-22 01:39:11 +09:00
|
|
|
PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
2013-05-16 07:31:17 +09:00
|
|
|
|
2014-07-18 20:53:04 +09:00
|
|
|
// Show/hide the loading indicator in the page number input element.
|
2019-12-27 08:22:32 +09:00
|
|
|
const currentPage = PDFViewerApplication.pdfViewer.getPageView(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.page - 1
|
|
|
|
);
|
2019-12-27 08:22:32 +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;
|
Re-write `PDFHistory` from scratch
This patch completely re-implements `PDFHistory` to get rid of various bugs currently present, and to hopefully make maintenance slightly easier. Most of the interface is similar to the existing one, but it should be somewhat simplified.
The new implementation should be more robust against failure, compared to the old one. Previously, it was too easy to end up in a state which basically caused the browser history to lock-up, preventing the user from navigating back/forward. (In the new implementation, the browser history should not be updated rather than breaking if things go wrong.)
Given that the code has to deal with various edge-cases, it's still not as simple as I would have liked, but it should now be somewhat easier to deal with.
The main source of complication in the code is actually that we allow the user to change the hash of a already loaded document (we'll no longer try to navigate back-and-forth in this case, since the next commit contains a workaround).
In the new code, there's also *a lot* more comments (perhaps too many?) to attempt to explain the logic. This is something that the old implementation was serverly lacking, which is a one of the reasons why it was so difficult to maintain.
One particular thing to note is that the new code uses the `pagehide` event rather than `beforeunload`, since the latter seems to be a bad idea based on https://bugzilla.mozilla.org/show_bug.cgi?id=1336763.
2017-07-16 20:39:39 +09:00
|
|
|
} else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
|
2017-07-14 21:24:32 +09:00
|
|
|
PDFViewerApplication.pdfLinkService.setHash(hash);
|
2013-05-16 07:31:17 +09:00
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-07-29 02:48:05 +09:00
|
|
|
|
2020-03-17 21:26:35 +09:00
|
|
|
let webViewerFileInputChange, webViewerOpenFile;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerFileInputChange = function (evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
PDFViewerApplication.pdfViewer &&
|
|
|
|
PDFViewerApplication.pdfViewer.isInPresentationMode
|
|
|
|
) {
|
2018-06-11 17:48:36 +09:00
|
|
|
return; // Opening a new PDF file isn't supported in Presentation Mode.
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const file = evt.fileInput.files[0];
|
2014-01-28 04:11:02 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (URL.createObjectURL && !AppOptions.get("disableCreateObjectURL")) {
|
2018-06-17 20:44:35 +09:00
|
|
|
let url = URL.createObjectURL(file);
|
|
|
|
if (file.name) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
url = { url, originalUrl: file.name };
|
2018-06-17 20:44:35 +09:00
|
|
|
}
|
|
|
|
PDFViewerApplication.open(url);
|
2016-10-15 00:57:53 +09:00
|
|
|
} else {
|
2018-06-17 20:44:35 +09:00
|
|
|
PDFViewerApplication.setTitleUsingUrl(file.name);
|
2016-10-15 00:57:53 +09:00
|
|
|
// Read the local file into a Uint8Array.
|
2019-12-27 08:22:32 +09:00
|
|
|
const fileReader = new FileReader();
|
2020-03-13 20:55:00 +09:00
|
|
|
fileReader.onload = function webViewerChangeFileReaderOnload(event) {
|
|
|
|
const buffer = event.target.result;
|
2017-06-29 19:14:26 +09:00
|
|
|
PDFViewerApplication.open(new Uint8Array(buffer));
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
|
|
|
fileReader.readAsArrayBuffer(file);
|
|
|
|
}
|
2014-01-28 04:11:02 +09:00
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
// URL does not reflect proper document location - hiding some icons.
|
2019-12-27 08:22:32 +09:00
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
appConfig.toolbar.viewBookmark.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.viewBookmarkButton.setAttribute(
|
|
|
|
"hidden",
|
|
|
|
"true"
|
|
|
|
);
|
|
|
|
appConfig.toolbar.download.setAttribute("hidden", "true");
|
|
|
|
appConfig.secondaryToolbar.downloadButton.setAttribute("hidden", "true");
|
2016-10-15 00:57:53 +09:00
|
|
|
};
|
2020-03-17 21:26:35 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
webViewerOpenFile = function (evt) {
|
2020-03-17 21:26:35 +09:00
|
|
|
const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
|
|
|
document.getElementById(openFileInputName).click();
|
|
|
|
};
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-07-29 02:48:05 +09:00
|
|
|
|
2016-04-29 05:04:09 +09:00
|
|
|
function webViewerPresentationMode() {
|
|
|
|
PDFViewerApplication.requestPresentationMode();
|
|
|
|
}
|
|
|
|
function webViewerPrint() {
|
|
|
|
window.print();
|
|
|
|
}
|
|
|
|
function webViewerDownload() {
|
|
|
|
PDFViewerApplication.download();
|
|
|
|
}
|
|
|
|
function webViewerFirstPage() {
|
|
|
|
if (PDFViewerApplication.pdfDocument) {
|
|
|
|
PDFViewerApplication.page = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function webViewerLastPage() {
|
|
|
|
if (PDFViewerApplication.pdfDocument) {
|
|
|
|
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
function webViewerNextPage() {
|
|
|
|
PDFViewerApplication.page++;
|
|
|
|
}
|
|
|
|
function webViewerPreviousPage() {
|
|
|
|
PDFViewerApplication.page--;
|
|
|
|
}
|
|
|
|
function webViewerZoomIn() {
|
|
|
|
PDFViewerApplication.zoomIn();
|
|
|
|
}
|
|
|
|
function webViewerZoomOut() {
|
|
|
|
PDFViewerApplication.zoomOut();
|
|
|
|
}
|
2019-07-17 18:59:56 +09:00
|
|
|
function webViewerZoomReset() {
|
|
|
|
PDFViewerApplication.zoomReset();
|
2019-03-19 18:45:27 +09:00
|
|
|
}
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerPageNumberChanged(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfViewer = PDFViewerApplication.pdfViewer;
|
Attempt to tweak the error messages, in `BaseViewer`, for invalid pageNumbers/pageLabels (bug 1505824)
Rather than closing [bug 1505824](https://bugzilla.mozilla.org/show_bug.cgi?id=1505824) as WONTFIX (which is my preferred solution), given how *minor* this "problem" is, it's still possible to adjust the error messages a bit.
The main point here, which is relevant even if the changes in `BaseViewer` are ultimately rejected during review, is that we'll no longer attempt to call `BaseViewer.currentPageLabel` with an empty string from `webViewerPageNumberChanged` in `app.js`.
The other changes are:
- Stop printing an error in `BaseViewer._setCurrentPageNumber`, and have it return a boolean indicating if the page is within bounds.
- Have the `BaseViewer.{currentPageNumber, currentPageLabel}` setters print their own errors for invalid pages.
- Have the `BaseViewer.currentPageLabel` setter no longer depend, indirectly, on the `BaseViewer.currentPageNumber` setter.
- Improve a couple of other error messages.
2018-11-15 00:16:09 +09:00
|
|
|
// Note that for `<input type="number">` HTML elements, an empty string will
|
|
|
|
// be returned for non-number inputs; hence we simply do nothing in that case.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (evt.value !== "") {
|
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
|
|
|
pdfViewer.currentPageLabel = evt.value;
|
|
|
|
}
|
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);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 webViewerUpdateFindControlState({ state, previous, matchesCount }) {
|
2018-09-22 03:00:58 +09:00
|
|
|
if (PDFViewerApplication.supportsIntegratedFind) {
|
|
|
|
PDFViewerApplication.externalServices.updateFindControlState({
|
|
|
|
result: state,
|
|
|
|
findPrevious: previous,
|
|
|
|
matchesCount,
|
|
|
|
});
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
function webViewerPageChanging(evt) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const page = evt.pageNumber;
|
2016-02-22 01:54:23 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
|
2016-11-19 03:50:29 +09:00
|
|
|
PDFViewerApplication.secondaryToolbar.setPageNumber(page);
|
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) {
|
2016-06-27 19:32:28 +09:00
|
|
|
PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
2012-04-14 06:14:05 +09:00
|
|
|
}
|
2014-09-13 11:27:45 +09:00
|
|
|
|
2018-02-18 07:13:49 +09:00
|
|
|
// We need to update stats.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 Stats !== "undefined" && Stats.enabled) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
[api-major] Only create a `StatTimer` for pages when `enableStats == true` (issue 5215)
Unless the debugging tools (i.e. `PDFBug`) are enabled, or the `browsertest` is running, the `PDFPageProxy.stats` aren't actually used for anything.
Rather than initializing unnecessary `StatTimer` instances, we can simply re-use *one* dummy class (with static methods) for every page. Note that by using a dummy `StatTimer` in this way, rather than letting `PDFPageProxy.stats` be undefined, we don't need to guard *every* single stats collection callsite.
Since it wouldn't make much sense to attempt to use `PDFPageProxy.stats` when stat collection is disabled, it was instead changed to a "private" property (i.e. `PDFPageProxy._stats`) and a getter was added for accessing `PDFPageProxy.stats`. This getter will now return `null` when stat collection is disabled, making that case easy to handle.
For benchmarking purposes, the test-suite used to re-create the `StatTimer` after loading/rendering each page. However, modifying properties on various API code from the outside in this way seems very error-prone, and is an anti-pattern that we really should avoid at all cost. Hence the `PDFPageProxy.cleanup` method was modified to accept an optional parameter, which will take care of resetting `this.stats` when necessary, and `test/driver.js` was updated accordingly.
Finally, a tiny bit more validation was added on the viewer side, to ensure that all the code we're attempting to access is defined when handling `PDFPageProxy` stats.
2017-12-07 00:30:04 +09:00
|
|
|
if (pageView && pageView.stats) {
|
2014-09-30 01:15:06 +09:00
|
|
|
Stats.add(page, pageView.stats);
|
|
|
|
}
|
|
|
|
}
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
2011-09-03 10:16:52 +09:00
|
|
|
|
2018-12-12 21:46:47 +09:00
|
|
|
function webViewerVisibilityChange(evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (document.visibilityState === "visible") {
|
2018-12-12 21:46:47 +09:00
|
|
|
// Ignore mouse wheel zooming during tab switches (bug 1503412).
|
|
|
|
setZoomDisabledTimeout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let zoomDisabledTimeout = null;
|
|
|
|
function setZoomDisabledTimeout() {
|
|
|
|
if (zoomDisabledTimeout) {
|
|
|
|
clearTimeout(zoomDisabledTimeout);
|
|
|
|
}
|
2020-04-14 19:28:14 +09:00
|
|
|
zoomDisabledTimeout = setTimeout(function () {
|
2018-12-12 21:46:47 +09:00
|
|
|
zoomDisabledTimeout = null;
|
|
|
|
}, WHEEL_ZOOM_DISABLED_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2016-12-09 00:28:40 +09:00
|
|
|
function webViewerWheel(evt) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const {
|
|
|
|
pdfViewer,
|
|
|
|
supportedMouseWheelZoomModifierKeys,
|
|
|
|
} = PDFViewerApplication;
|
2019-07-24 00:36:45 +09:00
|
|
|
|
2016-12-09 00:28:40 +09:00
|
|
|
if (pdfViewer.isInPresentationMode) {
|
2016-09-28 05:27:42 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
(evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey) ||
|
|
|
|
(evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey)
|
|
|
|
) {
|
2015-02-01 00:46:23 +09:00
|
|
|
// Only zoom the pages, not the entire viewer.
|
2014-10-16 05:03:13 +09:00
|
|
|
evt.preventDefault();
|
2016-04-08 04:03:04 +09:00
|
|
|
// NOTE: this check must be placed *after* preventDefault.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (zoomDisabledTimeout || document.visibilityState === "hidden") {
|
2016-04-08 04:03:04 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-07-03 06:20:37 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const previousScale = pdfViewer.currentScale;
|
2015-07-03 06:20:37 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const delta = normalizeWheelEventDelta(evt);
|
2016-09-28 05:27:42 +09:00
|
|
|
|
2017-06-29 19:14:26 +09:00
|
|
|
const MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
|
2019-12-27 08:22:32 +09:00
|
|
|
const ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
|
2016-09-28 05:27:42 +09:00
|
|
|
if (ticks < 0) {
|
|
|
|
PDFViewerApplication.zoomOut(-ticks);
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
const isViewerInPresentationMode =
|
|
|
|
pdfViewer && pdfViewer.isInPresentationMode;
|
2015-01-29 21:37:49 +09:00
|
|
|
|
2012-04-12 07:47:11 +09:00
|
|
|
// First, handle the key bindings that are independent whether an input
|
|
|
|
// control is selected or not.
|
2013-03-12 01:04:43 +09:00
|
|
|
if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
|
|
|
|
// either CTRL or META key with optional SHIFT.
|
2012-04-12 07:47:11 +09:00
|
|
|
switch (evt.keyCode) {
|
2013-07-18 20:37:55 +09:00
|
|
|
case 70: // f
|
2014-09-22 20:41:17 +09:00
|
|
|
if (!PDFViewerApplication.supportsIntegratedFind) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 21:57:31 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
2016-10-15 00:57:53 +09:00
|
|
|
// CTRL or META without shift
|
|
|
|
if (cmd === 1 || cmd === 8) {
|
|
|
|
switch (evt.keyCode) {
|
|
|
|
case 83: // s
|
|
|
|
PDFViewerApplication.download();
|
|
|
|
handled = true;
|
|
|
|
break;
|
|
|
|
}
|
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.
|
2019-12-27 08:22:32 +09:00
|
|
|
const curElement = document.activeElement || document.querySelector(":focus");
|
|
|
|
const curElementTagName = curElement && curElement.tagName.toUpperCase();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
curElementTagName === "INPUT" ||
|
|
|
|
curElementTagName === "TEXTAREA" ||
|
|
|
|
curElementTagName === "SELECT" ||
|
|
|
|
(curElement && curElement.isContentEditable)
|
|
|
|
) {
|
2013-09-05 06:48:31 +09:00
|
|
|
// Make sure that the secondary toolbar is closed when Escape is pressed.
|
2019-12-26 04:03:46 +09:00
|
|
|
if (evt.keyCode !== /* Esc = */ 27) {
|
2013-09-05 06:48:31 +09:00
|
|
|
return;
|
|
|
|
}
|
2012-10-02 06:32:02 +09:00
|
|
|
}
|
2012-04-11 01:55:52 +09:00
|
|
|
|
2019-12-26 04:03:46 +09:00
|
|
|
// No control key pressed at all.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (cmd === 0) {
|
|
|
|
let turnPage = 0,
|
|
|
|
turnOnlyIfPageFit = false;
|
2012-04-11 01:55:52 +09:00
|
|
|
switch (evt.keyCode) {
|
2012-10-06 11:55:47 +09:00
|
|
|
case 38: // up arrow
|
|
|
|
case 33: // pg up
|
2018-05-15 12:10:32 +09:00
|
|
|
// vertical scrolling using arrow/pg keys
|
|
|
|
if (pdfViewer.isVerticalScrollbarEnabled) {
|
|
|
|
turnOnlyIfPageFit = true;
|
|
|
|
}
|
|
|
|
turnPage = -1;
|
|
|
|
break;
|
2012-10-06 11:55:47 +09:00
|
|
|
case 8: // backspace
|
2018-05-15 12:10:32 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
|
|
|
turnOnlyIfPageFit = true;
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = -1;
|
|
|
|
break;
|
2012-04-11 01:55:52 +09:00
|
|
|
case 37: // left arrow
|
2012-12-14 05:10:21 +09:00
|
|
|
// horizontal scrolling using arrow keys
|
2015-01-29 21:37:49 +09:00
|
|
|
if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2018-05-15 12:10:32 +09:00
|
|
|
turnOnlyIfPageFit = true;
|
2012-12-14 05:10:21 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* falls through */
|
2012-04-11 01:55:52 +09:00
|
|
|
case 75: // 'k'
|
|
|
|
case 80: // 'p'
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = -1;
|
2012-04-11 01:55:52 +09:00
|
|
|
break;
|
2013-02-11 00:14:17 +09:00
|
|
|
case 27: // esc key
|
2016-05-11 08:31:03 +09:00
|
|
|
if (PDFViewerApplication.secondaryToolbar.isOpen) {
|
|
|
|
PDFViewerApplication.secondaryToolbar.close();
|
2013-09-05 06:48:31 +09:00
|
|
|
handled = true;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!PDFViewerApplication.supportsIntegratedFind &&
|
|
|
|
PDFViewerApplication.findBar.opened
|
|
|
|
) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.findBar.close();
|
2013-02-11 00:14:17 +09:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
2012-10-06 11:55:47 +09:00
|
|
|
case 40: // down arrow
|
|
|
|
case 34: // pg down
|
2018-05-15 12:10:32 +09:00
|
|
|
// vertical scrolling using arrow/pg keys
|
|
|
|
if (pdfViewer.isVerticalScrollbarEnabled) {
|
|
|
|
turnOnlyIfPageFit = true;
|
|
|
|
}
|
|
|
|
turnPage = 1;
|
|
|
|
break;
|
|
|
|
case 13: // enter key
|
2012-10-06 11:55:47 +09:00
|
|
|
case 32: // spacebar
|
2018-05-15 12:10:32 +09:00
|
|
|
if (!isViewerInPresentationMode) {
|
|
|
|
turnOnlyIfPageFit = true;
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = 1;
|
|
|
|
break;
|
2012-04-11 01:55:52 +09:00
|
|
|
case 39: // right arrow
|
2012-12-14 05:10:21 +09:00
|
|
|
// horizontal scrolling using arrow keys
|
2015-01-29 21:37:49 +09:00
|
|
|
if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2018-05-15 12:10:32 +09:00
|
|
|
turnOnlyIfPageFit = true;
|
2012-12-14 05:10:21 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
/* falls through */
|
2012-04-11 01:55:52 +09:00
|
|
|
case 74: // 'j'
|
|
|
|
case 78: // 'n'
|
2018-05-15 12:10:32 +09:00
|
|
|
turnPage = 1;
|
2012-04-11 01:55:52 +09:00
|
|
|
break;
|
2012-07-31 00:12:49 +09:00
|
|
|
|
2012-10-06 11:55:47 +09:00
|
|
|
case 36: // home
|
2015-01-29 21:37:49 +09:00
|
|
|
if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.page = 1;
|
2012-10-06 11:55:47 +09:00
|
|
|
handled = true;
|
2015-07-23 19:25:19 +09:00
|
|
|
ensureViewerFocused = true;
|
2012-10-06 11:55:47 +09:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 35: // end
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
isViewerInPresentationMode ||
|
|
|
|
PDFViewerApplication.page < PDFViewerApplication.pagesCount
|
|
|
|
) {
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2012-07-31 00:12:49 +09:00
|
|
|
handled = true;
|
2015-07-23 19:25:19 +09:00
|
|
|
ensureViewerFocused = true;
|
2012-07-31 00:12:49 +09:00
|
|
|
}
|
|
|
|
break;
|
2012-09-08 08:05:14 +09:00
|
|
|
|
2016-09-07 20:30:26 +09:00
|
|
|
case 83: // 's'
|
|
|
|
PDFViewerApplication.pdfCursorTools.switchTool(CursorTool.SELECT);
|
|
|
|
break;
|
2013-10-03 05:09:43 +09:00
|
|
|
case 72: // 'h'
|
2016-09-07 20:30:26 +09:00
|
|
|
PDFViewerApplication.pdfCursorTools.switchTool(CursorTool.HAND);
|
2013-10-03 05:09:43 +09:00
|
|
|
break;
|
2016-09-07 20:30:26 +09:00
|
|
|
|
2012-09-08 08:05:14 +09:00
|
|
|
case 82: // 'r'
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.rotatePages(90);
|
2012-09-08 08:05:14 +09:00
|
|
|
break;
|
2018-12-16 15:29:29 +09:00
|
|
|
|
|
|
|
case 115: // F4
|
|
|
|
PDFViewerApplication.pdfSidebar.toggle();
|
|
|
|
break;
|
2012-09-08 08:05:14 +09:00
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
turnPage !== 0 &&
|
|
|
|
(!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")
|
|
|
|
) {
|
2018-05-15 12:10:32 +09:00
|
|
|
if (turnPage > 0) {
|
|
|
|
if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
|
|
|
PDFViewerApplication.page++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (PDFViewerApplication.page > 1) {
|
|
|
|
PDFViewerApplication.page--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handled = true;
|
|
|
|
}
|
2012-09-08 08:05:14 +09:00
|
|
|
}
|
|
|
|
|
2019-12-26 04:03:46 +09:00
|
|
|
// shift-key
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (cmd === 4) {
|
2012-09-08 08:05:14 +09:00
|
|
|
switch (evt.keyCode) {
|
2018-01-05 03:54:19 +09:00
|
|
|
case 13: // enter key
|
2013-06-27 05:25:47 +09:00
|
|
|
case 32: // spacebar
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!isViewerInPresentationMode &&
|
|
|
|
pdfViewer.currentScaleValue !== "page-fit"
|
|
|
|
) {
|
2013-06-27 05:25:47 +09:00
|
|
|
break;
|
|
|
|
}
|
2016-08-07 20:10:50 +09:00
|
|
|
if (PDFViewerApplication.page > 1) {
|
|
|
|
PDFViewerApplication.page--;
|
|
|
|
}
|
2013-06-27 05:25:47 +09:00
|
|
|
handled = true;
|
|
|
|
break;
|
|
|
|
|
2012-09-08 08:05:14 +09:00
|
|
|
case 82: // 'r'
|
2014-09-22 20:41:17 +09:00
|
|
|
PDFViewerApplication.rotatePages(-90);
|
2012-09-08 08:05:14 +09:00
|
|
|
break;
|
2012-04-11 01:55:52 +09:00
|
|
|
}
|
2011-09-03 10:16:52 +09:00
|
|
|
}
|
2011-12-19 04:42:06 +09:00
|
|
|
|
2015-01-29 21:37:49 +09:00
|
|
|
if (!handled && !isViewerInPresentationMode) {
|
2014-02-27 21:33:35 +09:00
|
|
|
// 33=Page Up 34=Page Down 35=End 36=Home
|
|
|
|
// 37=Left 38=Up 39=Right 40=Down
|
|
|
|
// 32=Spacebar
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
(evt.keyCode >= 33 && evt.keyCode <= 40) ||
|
|
|
|
(evt.keyCode === 32 && curElementTagName !== "BUTTON")
|
|
|
|
) {
|
2015-07-23 19:25:19 +09:00
|
|
|
ensureViewerFocused = true;
|
2014-02-27 21:33:35 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 19:25:19 +09:00
|
|
|
if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
|
|
|
|
// The page container is not focused, but a page navigation key has been
|
|
|
|
// pressed. Change the focus to the viewer container to make sure that
|
|
|
|
// navigation by keyboard works as expected.
|
|
|
|
pdfViewer.focus();
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:42:06 +09:00
|
|
|
if (handled) {
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
2016-12-09 00:28:40 +09:00
|
|
|
}
|
2012-07-31 00:12:49 +09:00
|
|
|
|
2019-04-03 20:48:18 +09:00
|
|
|
/**
|
|
|
|
* Converts API PageLayout values to the format used by `PDFViewer`.
|
|
|
|
* NOTE: This is supported to the extent that the viewer implements the
|
|
|
|
* necessary Scroll/Spread modes (since SinglePage, TwoPageLeft,
|
|
|
|
* and TwoPageRight all suggests using non-continuous scrolling).
|
|
|
|
* @param {string} mode - The API PageLayout value.
|
|
|
|
* @returns {number} A value from {SpreadMode}.
|
|
|
|
*/
|
|
|
|
function apiPageLayoutToSpreadMode(layout) {
|
|
|
|
switch (layout) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "SinglePage":
|
|
|
|
case "OneColumn":
|
2019-04-03 20:48:18 +09:00
|
|
|
return SpreadMode.NONE;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "TwoColumnLeft":
|
|
|
|
case "TwoPageLeft":
|
2019-04-03 20:48:18 +09:00
|
|
|
return SpreadMode.ODD;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "TwoColumnRight":
|
|
|
|
case "TwoPageRight":
|
2019-04-03 20:48:18 +09:00
|
|
|
return SpreadMode.EVEN;
|
|
|
|
}
|
|
|
|
return SpreadMode.NONE; // Default value.
|
|
|
|
}
|
|
|
|
|
2017-07-19 23:26:17 +09:00
|
|
|
/**
|
|
|
|
* Converts API PageMode values to the format used by `PDFSidebar`.
|
|
|
|
* NOTE: There's also a "FullScreen" parameter which is not possible to support,
|
|
|
|
* since the Fullscreen API used in browsers requires that entering
|
|
|
|
* fullscreen mode only occurs as a result of a user-initiated event.
|
|
|
|
* @param {string} mode - The API PageMode value.
|
|
|
|
* @returns {number} A value from {SidebarView}.
|
|
|
|
*/
|
|
|
|
function apiPageModeToSidebarView(mode) {
|
|
|
|
switch (mode) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseNone":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.NONE;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseThumbs":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.THUMBS;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseOutlines":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.OUTLINE;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseAttachments":
|
2017-07-19 23:26:17 +09:00
|
|
|
return SidebarView.ATTACHMENTS;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UseOC":
|
|
|
|
// Not implemented, since we don't support Optional Content Groups yet.
|
2017-07-19 23:26:17 +09:00
|
|
|
}
|
|
|
|
return SidebarView.NONE; // Default value.
|
|
|
|
}
|
|
|
|
|
2016-10-07 06:46:30 +09:00
|
|
|
/* Abstract factory for the print service. */
|
2019-12-27 08:22:32 +09:00
|
|
|
const PDFPrintServiceFactory = {
|
2016-10-07 06:46:30 +09:00
|
|
|
instance: {
|
|
|
|
supportsPrinting: false,
|
2017-04-28 19:02:42 +09:00
|
|
|
createPrintService() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Not implemented: createPrintService");
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
|
|
|
},
|
2016-10-07 06:46:30 +09:00
|
|
|
};
|
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
PDFViewerApplication,
|
|
|
|
DefaultExternalServices,
|
|
|
|
PDFPrintServiceFactory,
|
|
|
|
};
|