2013-06-19 01:05:55 +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-06-28 19:34:12 +09:00
|
|
|
const CSS_UNITS = 96.0 / 72.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
|
|
|
const DEFAULT_SCALE_VALUE = "auto";
|
2017-06-28 19:34:12 +09:00
|
|
|
const DEFAULT_SCALE = 1.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
|
|
|
const MIN_SCALE = 0.1;
|
2017-06-28 19:34:12 +09:00
|
|
|
const MAX_SCALE = 10.0;
|
|
|
|
const UNKNOWN_SCALE = 0;
|
|
|
|
const MAX_AUTO_SCALE = 1.25;
|
|
|
|
const SCROLLBAR_PADDING = 40;
|
|
|
|
const VERTICAL_PADDING = 5;
|
|
|
|
|
2017-08-01 21:11:28 +09:00
|
|
|
const PresentationModeState = {
|
|
|
|
UNKNOWN: 0,
|
|
|
|
NORMAL: 1,
|
|
|
|
CHANGING: 2,
|
|
|
|
FULLSCREEN: 3,
|
|
|
|
};
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
const RendererType = {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
CANVAS: "canvas",
|
|
|
|
SVG: "svg",
|
2016-11-19 04:03:49 +09:00
|
|
|
};
|
|
|
|
|
2018-02-13 23:01:55 +09:00
|
|
|
const TextLayerMode = {
|
|
|
|
DISABLE: 0,
|
|
|
|
ENABLE: 1,
|
|
|
|
ENABLE_ENHANCE: 2,
|
|
|
|
};
|
|
|
|
|
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 ScrollMode = {
|
|
|
|
UNKNOWN: -1,
|
|
|
|
VERTICAL: 0, // Default value.
|
|
|
|
HORIZONTAL: 1,
|
|
|
|
WRAPPED: 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
const SpreadMode = {
|
|
|
|
UNKNOWN: -1,
|
|
|
|
NONE: 0, // Default value.
|
|
|
|
ODD: 1,
|
|
|
|
EVEN: 2,
|
|
|
|
};
|
|
|
|
|
2019-12-27 00:13:49 +09:00
|
|
|
// Used by `PDFViewerApplication`, and by the API unit-tests.
|
|
|
|
const AutoPrintRegExp = /\bprint\s*\(/;
|
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
// Replaces {{arguments}} with their values.
|
|
|
|
function formatL10nValue(text, args) {
|
|
|
|
if (!args) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, 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
|
|
|
return name in args ? args[name] : "{{" + name + "}}";
|
2017-05-04 10:05:53 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-02 06:20:41 +09:00
|
|
|
* No-op implementation of the localization service.
|
2017-05-04 10:05:53 +09:00
|
|
|
* @implements {IL10n}
|
|
|
|
*/
|
2019-12-23 02:16:32 +09:00
|
|
|
const NullL10n = {
|
2018-07-30 23:28:39 +09:00
|
|
|
async getLanguage() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 "en-us";
|
2018-03-20 21:42:45 +09:00
|
|
|
},
|
|
|
|
|
2018-07-30 23:28:39 +09:00
|
|
|
async 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
|
|
|
return "ltr";
|
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
|
|
|
},
|
|
|
|
|
2018-07-30 23:28:39 +09:00
|
|
|
async get(property, args, fallback) {
|
|
|
|
return formatL10nValue(fallback, args);
|
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
|
|
|
async translate(element) {},
|
2017-05-04 10:05:53 +09:00
|
|
|
};
|
2016-04-02 00:29:44 +09:00
|
|
|
|
2013-06-19 01:05:55 +09:00
|
|
|
/**
|
|
|
|
* Returns scale factor for the canvas. It makes sense for the HiDPI displays.
|
2019-10-13 01:14:29 +09:00
|
|
|
* @returns {Object} The object with horizontal (sx) and vertical (sy)
|
|
|
|
* scales. The scaled property is set to false if scaling is
|
|
|
|
* not required, true otherwise.
|
2013-06-19 01:05:55 +09:00
|
|
|
*/
|
2013-09-21 04:11:14 +09:00
|
|
|
function getOutputScale(ctx) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const devicePixelRatio = window.devicePixelRatio || 1;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const backingStoreRatio =
|
|
|
|
ctx.webkitBackingStorePixelRatio ||
|
|
|
|
ctx.mozBackingStorePixelRatio ||
|
|
|
|
ctx.msBackingStorePixelRatio ||
|
|
|
|
ctx.oBackingStorePixelRatio ||
|
|
|
|
ctx.backingStorePixelRatio ||
|
|
|
|
1;
|
2019-12-23 02:16:32 +09:00
|
|
|
const pixelRatio = devicePixelRatio / backingStoreRatio;
|
2013-06-19 01:05:55 +09:00
|
|
|
return {
|
|
|
|
sx: pixelRatio,
|
|
|
|
sy: pixelRatio,
|
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
|
|
|
scaled: pixelRatio !== 1,
|
2013-06-19 01:05:55 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-13 03:14:13 +09:00
|
|
|
/**
|
|
|
|
* Scrolls specified element into view of its parent.
|
2015-10-13 19:47:07 +09:00
|
|
|
* @param {Object} element - The element to be visible.
|
|
|
|
* @param {Object} spot - An object with optional top and left properties,
|
|
|
|
* specifying the offset from the top left edge.
|
|
|
|
* @param {boolean} skipOverflowHiddenElements - Ignore elements that have
|
|
|
|
* the CSS rule `overflow: hidden;` set. The default is false.
|
2013-07-13 03:14:13 +09:00
|
|
|
*/
|
2017-06-28 19:34:12 +09:00
|
|
|
function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
|
2013-07-13 03:14:13 +09:00
|
|
|
// Assuming offsetParent is available (it's not available when viewer is in
|
|
|
|
// hidden iframe or object). We have to scroll: if the offsetParent is not set
|
2016-11-19 03:50:29 +09:00
|
|
|
// producing the error. See also animationStarted.
|
2017-06-28 19:34:12 +09:00
|
|
|
let parent = element.offsetParent;
|
2013-07-13 03:14:13 +09:00
|
|
|
if (!parent) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
console.error("offsetParent is not set -- cannot scroll");
|
2013-07-13 03:14:13 +09:00
|
|
|
return;
|
|
|
|
}
|
2017-06-28 19:34:12 +09:00
|
|
|
let offsetY = element.offsetTop + element.clientTop;
|
|
|
|
let offsetX = element.offsetLeft + element.clientLeft;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
while (
|
|
|
|
(parent.clientHeight === parent.scrollHeight &&
|
|
|
|
parent.clientWidth === parent.scrollWidth) ||
|
|
|
|
(skipOverflowHiddenElements &&
|
|
|
|
getComputedStyle(parent).overflow === "hidden")
|
|
|
|
) {
|
2013-11-25 23:54:47 +09:00
|
|
|
if (parent.dataset._scaleY) {
|
|
|
|
offsetY /= parent.dataset._scaleY;
|
2013-12-04 03:53:20 +09:00
|
|
|
offsetX /= parent.dataset._scaleX;
|
2013-11-25 23:54:47 +09:00
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
offsetY += parent.offsetTop;
|
2013-12-04 03:53:20 +09:00
|
|
|
offsetX += parent.offsetLeft;
|
2013-07-13 03:14:13 +09:00
|
|
|
parent = parent.offsetParent;
|
2013-12-04 03:53:20 +09:00
|
|
|
if (!parent) {
|
2013-07-13 03:14:13 +09:00
|
|
|
return; // no need to scroll
|
2013-12-04 03:53:20 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (spot) {
|
|
|
|
if (spot.top !== undefined) {
|
|
|
|
offsetY += spot.top;
|
|
|
|
}
|
|
|
|
if (spot.left !== undefined) {
|
|
|
|
offsetX += spot.left;
|
|
|
|
parent.scrollLeft = offsetX;
|
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
}
|
|
|
|
parent.scrollTop = offsetY;
|
|
|
|
}
|
|
|
|
|
2014-09-13 03:39:23 +09:00
|
|
|
/**
|
|
|
|
* Helper function to start monitoring the scroll event and converting them into
|
|
|
|
* PDF.js friendly one: with scroll debounce and scroll direction.
|
|
|
|
*/
|
|
|
|
function watchScroll(viewAreaElement, callback) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const debounceScroll = function(evt) {
|
2014-09-13 03:39:23 +09:00
|
|
|
if (rAF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// schedule an invocation of scroll for next animation frame.
|
|
|
|
rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
|
|
|
|
rAF = null;
|
|
|
|
|
2019-12-23 02:16:32 +09:00
|
|
|
const currentX = viewAreaElement.scrollLeft;
|
|
|
|
const lastX = state.lastX;
|
2018-05-15 12:10:32 +09:00
|
|
|
if (currentX !== lastX) {
|
|
|
|
state.right = currentX > lastX;
|
|
|
|
}
|
|
|
|
state.lastX = currentX;
|
2019-12-23 02:16:32 +09:00
|
|
|
const currentY = viewAreaElement.scrollTop;
|
|
|
|
const lastY = state.lastY;
|
2014-12-27 01:43:13 +09:00
|
|
|
if (currentY !== lastY) {
|
|
|
|
state.down = currentY > lastY;
|
2014-09-13 03:39:23 +09:00
|
|
|
}
|
|
|
|
state.lastY = currentY;
|
|
|
|
callback(state);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-12-23 02:16:32 +09:00
|
|
|
const state = {
|
2018-05-15 12:10:32 +09:00
|
|
|
right: true,
|
2014-09-13 03:39:23 +09:00
|
|
|
down: true,
|
2018-05-15 12:10:32 +09:00
|
|
|
lastX: viewAreaElement.scrollLeft,
|
2014-09-13 03:39:23 +09:00
|
|
|
lastY: viewAreaElement.scrollTop,
|
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
|
|
|
_eventHandler: debounceScroll,
|
2014-09-13 03:39:23 +09:00
|
|
|
};
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
let rAF = 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
|
|
|
viewAreaElement.addEventListener("scroll", debounceScroll, true);
|
2014-09-13 03:39:23 +09:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
/**
|
|
|
|
* Helper function to parse query string (e.g. ?param1=value&parm2=...).
|
|
|
|
*/
|
|
|
|
function parseQueryString(query) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 parts = query.split("&");
|
2019-12-23 02:16:32 +09:00
|
|
|
const params = Object.create(null);
|
2017-06-28 19:34:12 +09:00
|
|
|
for (let i = 0, ii = parts.length; i < ii; ++i) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 param = parts[i].split("=");
|
2019-12-23 02:16:32 +09:00
|
|
|
const key = param[0].toLowerCase();
|
|
|
|
const value = param.length > 1 ? param[1] : null;
|
2015-04-28 00:25:32 +09:00
|
|
|
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2014-12-27 01:43:13 +09:00
|
|
|
/**
|
|
|
|
* Use binary search to find the index of the first item in a given array which
|
|
|
|
* passes a given condition. The items are expected to be sorted in the sense
|
|
|
|
* that if the condition is true for one item in the array, then it is also true
|
|
|
|
* for all following items.
|
|
|
|
*
|
2019-10-12 22:54:17 +09:00
|
|
|
* @returns {number} Index of the first array element to pass the test,
|
2014-12-27 01:43:13 +09:00
|
|
|
* or |items.length| if no such element exists.
|
|
|
|
*/
|
|
|
|
function binarySearchFirstItem(items, condition) {
|
2017-06-28 19:34:12 +09:00
|
|
|
let minIndex = 0;
|
|
|
|
let maxIndex = items.length - 1;
|
2014-12-27 01:43:13 +09:00
|
|
|
|
|
|
|
if (items.length === 0 || !condition(items[maxIndex])) {
|
|
|
|
return items.length;
|
|
|
|
}
|
|
|
|
if (condition(items[minIndex])) {
|
|
|
|
return minIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (minIndex < maxIndex) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const currentIndex = (minIndex + maxIndex) >> 1;
|
|
|
|
const currentItem = items[currentIndex];
|
2014-12-27 01:43:13 +09:00
|
|
|
if (condition(currentItem)) {
|
|
|
|
maxIndex = currentIndex;
|
|
|
|
} else {
|
|
|
|
minIndex = currentIndex + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return minIndex; /* === maxIndex */
|
|
|
|
}
|
|
|
|
|
2015-10-29 07:27:42 +09:00
|
|
|
/**
|
|
|
|
* Approximates float number as a fraction using Farey sequence (max order
|
|
|
|
* of 8).
|
|
|
|
* @param {number} x - Positive float number.
|
|
|
|
* @returns {Array} Estimated fraction: the first array item is a numerator,
|
|
|
|
* the second one is a denominator.
|
|
|
|
*/
|
|
|
|
function approximateFraction(x) {
|
|
|
|
// Fast paths for int numbers or their inversions.
|
|
|
|
if (Math.floor(x) === x) {
|
|
|
|
return [x, 1];
|
|
|
|
}
|
2019-12-23 02:16:32 +09:00
|
|
|
const xinv = 1 / x;
|
|
|
|
const limit = 8;
|
2015-10-29 07:27:42 +09:00
|
|
|
if (xinv > limit) {
|
|
|
|
return [1, limit];
|
2016-12-10 22:28:27 +09:00
|
|
|
} else if (Math.floor(xinv) === xinv) {
|
2015-10-29 07:27:42 +09:00
|
|
|
return [1, xinv];
|
|
|
|
}
|
|
|
|
|
2019-12-23 02:16:32 +09:00
|
|
|
const x_ = x > 1 ? xinv : x;
|
2015-10-29 07:27:42 +09:00
|
|
|
// a/b and c/d are neighbours in Farey sequence.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 a = 0,
|
|
|
|
b = 1,
|
|
|
|
c = 1,
|
|
|
|
d = 1;
|
2015-10-29 07:27:42 +09:00
|
|
|
// Limiting search to order 8.
|
|
|
|
while (true) {
|
|
|
|
// Generating next term in sequence (order of q).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 p = a + c,
|
|
|
|
q = b + d;
|
2015-10-29 07:27:42 +09:00
|
|
|
if (q > limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (x_ <= p / q) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
c = p;
|
|
|
|
d = q;
|
2015-10-29 07:27:42 +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
|
|
|
a = p;
|
|
|
|
b = q;
|
2015-10-29 07:27:42 +09:00
|
|
|
}
|
|
|
|
}
|
2017-06-28 19:34:12 +09:00
|
|
|
let result;
|
2015-10-29 07:27:42 +09:00
|
|
|
// Select closest of the neighbours to x.
|
|
|
|
if (x_ - a / b < c / d - x_) {
|
2016-12-16 21:05:33 +09:00
|
|
|
result = x_ === x ? [a, b] : [b, a];
|
2015-10-29 07:27:42 +09:00
|
|
|
} else {
|
2016-12-16 21:05:33 +09:00
|
|
|
result = x_ === x ? [c, d] : [d, c];
|
2015-10-29 07:27:42 +09:00
|
|
|
}
|
2016-12-16 21:05:33 +09:00
|
|
|
return result;
|
2015-10-29 07:27:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function roundToDivide(x, div) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const r = x % div;
|
2015-10-29 07:27:42 +09:00
|
|
|
return r === 0 ? x : Math.round(x - r + div);
|
|
|
|
}
|
|
|
|
|
2018-03-20 01:27:04 +09:00
|
|
|
/**
|
|
|
|
* Gets the size of the specified page, converted from PDF units to inches.
|
|
|
|
* @param {Object} An Object containing the properties: {Array} `view`,
|
|
|
|
* {number} `userUnit`, and {number} `rotate`.
|
2019-10-13 01:14:29 +09:00
|
|
|
* @returns {Object} An Object containing the properties: {number} `width`
|
2018-03-20 01:27:04 +09:00
|
|
|
* and {number} `height`, given in inches.
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 getPageSizeInches({ view, userUnit, rotate }) {
|
2018-03-20 01:27:04 +09:00
|
|
|
const [x1, y1, x2, y2] = view;
|
|
|
|
// We need to take the page rotation into account as well.
|
|
|
|
const changeOrientation = rotate % 180 !== 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
|
|
|
const width = ((x2 - x1) / 72) * userUnit;
|
|
|
|
const height = ((y2 - y1) / 72) * userUnit;
|
2018-03-20 01:27:04 +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
|
|
|
width: changeOrientation ? height : width,
|
|
|
|
height: changeOrientation ? width : height,
|
2018-03-20 01:27:04 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
/**
|
|
|
|
* Helper function for getVisibleElements.
|
|
|
|
*
|
|
|
|
* @param {number} index - initial guess at the first visible element
|
|
|
|
* @param {Array} views - array of pages, into which `index` is an index
|
|
|
|
* @param {number} top - the top of the scroll pane
|
|
|
|
* @returns {number} less than or equal to `index` that is definitely at or
|
|
|
|
* before the first visible element in `views`, but not by too much. (Usually,
|
|
|
|
* this will be the first element in the first partially visible row in
|
|
|
|
* `views`, although sometimes it goes back one row further.)
|
|
|
|
*/
|
|
|
|
function backtrackBeforeAllVisibleElements(index, views, top) {
|
|
|
|
// binarySearchFirstItem's assumption is that the input is ordered, with only
|
2018-05-15 12:10:32 +09:00
|
|
|
// one index where the conditions flips from false to true: [false ...,
|
|
|
|
// true...]. With vertical scrolling and spreads, it is possible to have
|
|
|
|
// [false ..., true, false, true ...]. With wrapped scrolling we can have a
|
|
|
|
// similar sequence, with many more mixed true and false in the middle.
|
2018-05-15 12:10:32 +09:00
|
|
|
//
|
|
|
|
// So there is no guarantee that the binary search yields the index of the
|
|
|
|
// first visible element. It could have been any of the other visible elements
|
|
|
|
// that were preceded by a hidden element.
|
|
|
|
|
|
|
|
// Of course, if either this element or the previous (hidden) element is also
|
|
|
|
// the first element, there's nothing to worry about.
|
|
|
|
if (index < 2) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// That aside, the possible cases are represented below.
|
|
|
|
//
|
|
|
|
// **** = fully hidden
|
|
|
|
// A*B* = mix of partially visible and/or hidden pages
|
|
|
|
// CDEF = fully visible
|
|
|
|
//
|
|
|
|
// (1) Binary search could have returned A, in which case we can stop.
|
|
|
|
// (2) Binary search could also have returned B, in which case we need to
|
|
|
|
// check the whole row.
|
|
|
|
// (3) Binary search could also have returned C, in which case we need to
|
|
|
|
// check the whole previous row.
|
|
|
|
//
|
|
|
|
// There's one other possibility:
|
|
|
|
//
|
|
|
|
// **** = fully hidden
|
|
|
|
// ABCD = mix of fully and/or partially visible pages
|
|
|
|
//
|
|
|
|
// (4) Binary search could only have returned A.
|
|
|
|
|
|
|
|
// Initially assume that we need to find the beginning of the current row
|
|
|
|
// (case 1, 2, or 4), which means finding a page that is above the current
|
|
|
|
// page's top. If the found page is partially visible, we're definitely not in
|
|
|
|
// case 3, and this assumption is correct.
|
|
|
|
let elt = views[index].div;
|
|
|
|
let pageTop = elt.offsetTop + elt.clientTop;
|
|
|
|
|
|
|
|
if (pageTop >= top) {
|
|
|
|
// The found page is fully visible, so we're actually either in case 3 or 4,
|
|
|
|
// and unfortunately we can't tell the difference between them without
|
|
|
|
// scanning the entire previous row, so we just conservatively assume that
|
|
|
|
// we do need to backtrack to that row. In both cases, the previous page is
|
|
|
|
// in the previous row, so use its top instead.
|
|
|
|
elt = views[index - 1].div;
|
|
|
|
pageTop = elt.offsetTop + elt.clientTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we backtrack to the first page that still has its bottom below
|
|
|
|
// `pageTop`, which is the top of a page in the first visible row (unless
|
|
|
|
// we're in case 4, in which case it's the row before that).
|
|
|
|
// `index` is found by binary search, so the page at `index - 1` is
|
|
|
|
// invisible and we can start looking for potentially visible pages from
|
|
|
|
// `index - 2`. (However, if this loop terminates on its first iteration,
|
|
|
|
// which is the case when pages are stacked vertically, `index` should remain
|
|
|
|
// unchanged, so we use a distinct loop variable.)
|
|
|
|
for (let i = index - 2; i >= 0; --i) {
|
|
|
|
elt = views[i].div;
|
|
|
|
if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
|
|
|
|
// We have reached the previous row, so stop now.
|
|
|
|
// This loop is expected to terminate relatively quickly because the
|
|
|
|
// number of pages per row is expected to be small.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2014-09-13 03:39:23 +09:00
|
|
|
/**
|
|
|
|
* Generic helper to find out what elements are visible within a scroll pane.
|
2018-05-15 12:10:32 +09:00
|
|
|
*
|
|
|
|
* Well, pretty generic. There are some assumptions placed on the elements
|
|
|
|
* referenced by `views`:
|
|
|
|
* - If `horizontal`, no left of any earlier element is to the right of the
|
|
|
|
* left of any later element.
|
|
|
|
* - Otherwise, `views` can be split into contiguous rows where, within a row,
|
|
|
|
* no top of any element is below the bottom of any other element, and
|
|
|
|
* between rows, no bottom of any element in an earlier row is below the
|
|
|
|
* top of any element in a later row.
|
|
|
|
*
|
|
|
|
* (Here, top, left, etc. all refer to the padding edge of the element in
|
|
|
|
* question. For pages, that ends up being equivalent to the bounding box of the
|
|
|
|
* rendering canvas. Earlier and later refer to index in `views`, not page
|
|
|
|
* layout.)
|
|
|
|
*
|
|
|
|
* @param scrollEl {HTMLElement} - a container that can possibly scroll
|
|
|
|
* @param views {Array} - objects with a `div` property that contains an
|
|
|
|
* HTMLElement, which should all be descendents of `scrollEl` satisfying the
|
|
|
|
* above layout assumptions
|
|
|
|
* @param sortByVisibility {boolean} - if true, the returned elements are sorted
|
|
|
|
* in descending order of the percent of their padding box that is visible
|
|
|
|
* @param horizontal {boolean} - if true, the elements are assumed to be laid
|
|
|
|
* out horizontally instead of vertically
|
|
|
|
* @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
|
2014-09-13 03:39: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
|
|
|
function getVisibleElements(
|
|
|
|
scrollEl,
|
|
|
|
views,
|
|
|
|
sortByVisibility = false,
|
|
|
|
horizontal = false
|
|
|
|
) {
|
|
|
|
const top = scrollEl.scrollTop,
|
|
|
|
bottom = top + scrollEl.clientHeight;
|
|
|
|
const left = scrollEl.scrollLeft,
|
|
|
|
right = left + scrollEl.clientWidth;
|
2014-09-13 03:39:23 +09:00
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
// Throughout this "generic" function, comments will assume we're working with
|
|
|
|
// PDF document pages, which is the most important and complex case. In this
|
|
|
|
// case, the visible elements we're actually interested is the page canvas,
|
|
|
|
// which is contained in a wrapper which adds no padding/border/margin, which
|
|
|
|
// is itself contained in `view.div` which adds no padding (but does add a
|
|
|
|
// border). So, as specified in this function's doc comment, this function
|
|
|
|
// does all of its work on the padding edge of the provided views, starting at
|
|
|
|
// offsetLeft/Top (which includes margin) and adding clientLeft/Top (which is
|
|
|
|
// the border). Adding clientWidth/Height gets us the bottom-right corner of
|
|
|
|
// the padding edge.
|
|
|
|
function isElementBottomAfterViewTop(view) {
|
2019-01-11 21:18:36 +09:00
|
|
|
const element = view.div;
|
|
|
|
const elementBottom =
|
2014-12-27 01:43:13 +09:00
|
|
|
element.offsetTop + element.clientTop + element.clientHeight;
|
|
|
|
return elementBottom > top;
|
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
function isElementRightAfterViewLeft(view) {
|
2019-01-11 21:18:36 +09:00
|
|
|
const element = view.div;
|
|
|
|
const elementRight =
|
2018-05-15 12:10:32 +09:00
|
|
|
element.offsetLeft + element.clientLeft + element.clientWidth;
|
|
|
|
return elementRight > left;
|
|
|
|
}
|
2014-12-27 01:43: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
|
|
|
const visible = [],
|
|
|
|
numViews = views.length;
|
|
|
|
let firstVisibleElementInd =
|
|
|
|
numViews === 0
|
|
|
|
? 0
|
|
|
|
: binarySearchFirstItem(
|
|
|
|
views,
|
|
|
|
horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop
|
|
|
|
);
|
2018-05-15 12:10:32 +09:00
|
|
|
|
Prevent `TypeError: views[index] is undefined` being throw in `getVisibleElements` when the viewer, or all pages, are hidden
Previously a couple of different attempts at fixing this problem has been rejected, given how *crucial* this code is for the correct function of the viewer, since no one has thus far provided any evidence that the problem actually affects the default viewer[1] nor an example using the viewer components directly (without another library on top).
The fact that none of the prior patches contained even a *simple* unit-test probably contributed to the unwillingness of a reviewer to sign off on the suggested changes.
However, it turns out that it's possible to create a reduced test-case, using the default viewer, that demonstrates the error[2]. Since this utilizes a hidden `<iframe>`, please note that this error will thus affect Firefox as well.
Note that while errors are thrown when the hidden `<iframe>` loads, the default viewer doesn't break completely since rendering does start working once the `<iframe>` becomes visible (although the errors do break the initial Toolbar state).
Before making any changes here, I carefully read through not just the immediately relevant code but also the rendering code in the viewer (given it's dependence on `getVisibleElements`). After concluding that the changes should be safe in general, the default viewer was tested without any issues found. (The above being much easier with significant prior experience of working with the viewer code.)
Finally the patch also adds new unit-tests, one of which explicitly triggers the relevant code-path and will thus fail with the current `master` branch.
This patch also makes `PDFViewerApplication` slightly more robust against errors during document opening, to ensure that viewer/document initialization always completes as expected.
Please keep in mind that even though this patch prevents an error in `getVisibleElements`, it's still not possible to set the initial position/zoom level/sidebar view etc. when the viewer is hidden since rendering and scrolling is completely dependent[3] on being able to actually access the DOM elements.
---
[1] And hence the PDF Viewer that's built-in to Firefox.
[2] Copy the HTML code below and save it as `iframe.html`, and place the file in the `web/` folder. Then start the server, with `gulp server`, and navigate to http://localhost:8888/web/iframe.html
```html
<!DOCTYPE html>
<html>
<head>
<title>Iframe test</title>
<script>
window.onload = function() {
const button = document.getElementById('button1');
const frame = document.getElementById('frame1');
button.addEventListener('click', function(evt) {
frame.hidden = !frame.hidden;
});
};
</script>
</head>
<body>
<button id="button1">Toggle iframe</button>
<br>
<iframe id="frame1" width="800" height="600" src="http://localhost:8888/web/viewer.html" hidden="true"></iframe>
</body>
</html>
```
[3] This is an old, pre-exisiting, issue that's not relevant to this patch as such (and it's already being tracked elsewhere).
2019-01-12 02:25:10 +09:00
|
|
|
// Please note the return value of the `binarySearchFirstItem` function when
|
|
|
|
// no valid element is found (hence the `firstVisibleElementInd` check below).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (
|
|
|
|
firstVisibleElementInd > 0 &&
|
|
|
|
firstVisibleElementInd < numViews &&
|
|
|
|
!horizontal
|
|
|
|
) {
|
2018-05-15 12:10:32 +09:00
|
|
|
// In wrapped scrolling (or vertical scrolling with spreads), with some page
|
|
|
|
// sizes, isElementBottomAfterViewTop doesn't satisfy the binary search
|
|
|
|
// condition: there can be pages with bottoms above the view top between
|
|
|
|
// pages with bottoms below. This function detects and corrects that error;
|
|
|
|
// see it for more comments.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstVisibleElementInd = backtrackBeforeAllVisibleElements(
|
|
|
|
firstVisibleElementInd,
|
|
|
|
views,
|
|
|
|
top
|
|
|
|
);
|
2018-05-15 12:10:32 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// lastEdge acts as a cutoff for us to stop looping, because we know all
|
|
|
|
// subsequent pages will be hidden.
|
|
|
|
//
|
2018-05-15 12:10:32 +09:00
|
|
|
// When using wrapped scrolling or vertical scrolling with spreads, we can't
|
|
|
|
// simply stop the first time we reach a page below the bottom of the view;
|
|
|
|
// the tops of subsequent pages on the same row could still be visible. In
|
|
|
|
// horizontal scrolling, we don't have that issue, so we can stop as soon as
|
|
|
|
// we pass `right`, without needing the code below that handles the -1 case.
|
2018-05-15 12:10:32 +09:00
|
|
|
let lastEdge = horizontal ? right : -1;
|
2014-12-27 01:43:13 +09:00
|
|
|
|
2019-01-11 21:18:36 +09:00
|
|
|
for (let i = firstVisibleElementInd; i < numViews; i++) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 view = views[i],
|
|
|
|
element = view.div;
|
2019-01-11 21:18:36 +09:00
|
|
|
const currentWidth = element.offsetLeft + element.clientLeft;
|
|
|
|
const currentHeight = element.offsetTop + element.clientTop;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 viewWidth = element.clientWidth,
|
|
|
|
viewHeight = element.clientHeight;
|
2019-01-11 21:18:36 +09:00
|
|
|
const viewRight = currentWidth + viewWidth;
|
|
|
|
const viewBottom = currentHeight + viewHeight;
|
2018-05-15 12:10:32 +09:00
|
|
|
|
|
|
|
if (lastEdge === -1) {
|
|
|
|
// As commented above, this is only needed in non-horizontal cases.
|
|
|
|
// Setting lastEdge to the bottom of the first page that is partially
|
|
|
|
// visible ensures that the next page fully below lastEdge is on the
|
|
|
|
// next row, which has to be fully hidden along with all subsequent rows.
|
|
|
|
if (viewBottom >= bottom) {
|
|
|
|
lastEdge = viewBottom;
|
|
|
|
}
|
|
|
|
} else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
|
2014-09-13 03:39:23 +09:00
|
|
|
break;
|
|
|
|
}
|
2014-12-27 01:43: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
|
|
|
if (
|
|
|
|
viewBottom <= top ||
|
|
|
|
currentHeight >= bottom ||
|
|
|
|
viewRight <= left ||
|
|
|
|
currentWidth >= right
|
|
|
|
) {
|
2014-09-13 03:39:23 +09:00
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
const hiddenHeight =
|
|
|
|
Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
|
|
|
|
const hiddenWidth =
|
|
|
|
Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
|
|
|
|
const percent =
|
|
|
|
(((viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) * 100) /
|
|
|
|
viewHeight /
|
|
|
|
viewWidth) |
|
|
|
|
0;
|
2014-12-27 01:43:13 +09:00
|
|
|
visible.push({
|
|
|
|
id: view.id,
|
|
|
|
x: currentWidth,
|
|
|
|
y: currentHeight,
|
2017-04-28 19:02:42 +09:00
|
|
|
view,
|
2019-01-11 21:18:36 +09:00
|
|
|
percent,
|
2014-12-27 01:43:13 +09:00
|
|
|
});
|
2014-09-13 03:39: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
|
|
|
const first = visible[0],
|
|
|
|
last = visible[visible.length - 1];
|
2014-09-13 03:39:23 +09:00
|
|
|
|
|
|
|
if (sortByVisibility) {
|
|
|
|
visible.sort(function(a, b) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const pc = a.percent - b.percent;
|
2014-09-13 03:39:23 +09:00
|
|
|
if (Math.abs(pc) > 0.001) {
|
|
|
|
return -pc;
|
|
|
|
}
|
|
|
|
return a.id - b.id; // ensure stability
|
|
|
|
});
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 { first, last, views: visible };
|
2014-09-13 03:39:23 +09:00
|
|
|
}
|
|
|
|
|
2013-07-31 06:36:45 +09:00
|
|
|
/**
|
|
|
|
* Event handler to suppress context menu.
|
|
|
|
*/
|
2017-06-28 19:34:12 +09:00
|
|
|
function noContextMenuHandler(evt) {
|
|
|
|
evt.preventDefault();
|
2013-07-31 06:36:45 +09:00
|
|
|
}
|
|
|
|
|
2017-04-16 03:37:06 +09:00
|
|
|
function isDataSchema(url) {
|
2019-12-23 02:16:32 +09:00
|
|
|
let i = 0;
|
|
|
|
const ii = url.length;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
while (i < ii && url[i].trim() === "") {
|
2017-04-16 03:37:06 +09:00
|
|
|
i++;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 url.substring(i, i + 5).toLowerCase() === "data:";
|
2017-04-16 03:37:06 +09:00
|
|
|
}
|
|
|
|
|
2013-07-13 03:14:13 +09:00
|
|
|
/**
|
|
|
|
* Returns the filename or guessed filename from the url (see issue 3455).
|
2017-04-16 03:37:06 +09:00
|
|
|
* @param {string} url - The original PDF location.
|
|
|
|
* @param {string} defaultFilename - The value returned if the filename is
|
|
|
|
* unknown, or the protocol is unsupported.
|
|
|
|
* @returns {string} Guessed PDF filename.
|
2013-07-13 03:14: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
|
|
|
function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
|
|
|
|
if (typeof url !== "string") {
|
2018-09-30 19:22:50 +09:00
|
|
|
return defaultFilename;
|
|
|
|
}
|
2017-04-16 03:37:06 +09:00
|
|
|
if (isDataSchema(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
|
|
|
console.warn(
|
|
|
|
"getPDFFileNameFromURL: " +
|
|
|
|
'ignoring "data:" URL for performance reasons.'
|
|
|
|
);
|
2017-04-16 03:37:06 +09:00
|
|
|
return defaultFilename;
|
2017-02-06 08:46:12 +09:00
|
|
|
}
|
2017-06-28 19:34:12 +09:00
|
|
|
const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
|
2017-02-04 08:56:15 +09:00
|
|
|
// SCHEME HOST 1.PATH 2.QUERY 3.REF
|
2013-07-13 03:14:13 +09:00
|
|
|
// Pattern to get last matching NAME.pdf
|
2017-06-28 19:34:12 +09:00
|
|
|
const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
|
2019-12-23 02:16:32 +09:00
|
|
|
const splitURI = reURI.exec(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
|
|
|
let suggestedFilename =
|
|
|
|
reFilename.exec(splitURI[1]) ||
|
|
|
|
reFilename.exec(splitURI[2]) ||
|
|
|
|
reFilename.exec(splitURI[3]);
|
2013-07-13 03:14:13 +09:00
|
|
|
if (suggestedFilename) {
|
|
|
|
suggestedFilename = suggestedFilename[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
|
|
|
if (suggestedFilename.includes("%")) {
|
2013-07-13 03:14:13 +09:00
|
|
|
// URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
|
|
|
|
try {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
suggestedFilename = reFilename.exec(
|
|
|
|
decodeURIComponent(suggestedFilename)
|
|
|
|
)[0];
|
|
|
|
} catch (ex) {
|
|
|
|
// Possible (extremely rare) errors:
|
2013-07-13 03:14:13 +09:00
|
|
|
// URIError "Malformed URI", e.g. for "%AA.pdf"
|
|
|
|
// TypeError "null has no properties", e.g. for "%2F.pdf"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-06 08:46:12 +09:00
|
|
|
return suggestedFilename || defaultFilename;
|
2013-07-13 03:14:13 +09:00
|
|
|
}
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2016-09-28 05:27:42 +09:00
|
|
|
function normalizeWheelEventDelta(evt) {
|
2017-06-28 19:34:12 +09:00
|
|
|
let delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
|
2019-12-23 02:16:32 +09:00
|
|
|
const angle = Math.atan2(evt.deltaY, evt.deltaX);
|
2016-09-28 05:27:42 +09:00
|
|
|
if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
|
|
|
|
// All that is left-up oriented has to change the sign.
|
|
|
|
delta = -delta;
|
|
|
|
}
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
|
|
|
|
const MOUSE_DOM_DELTA_LINE_MODE = 1;
|
|
|
|
const MOUSE_PIXELS_PER_LINE = 30;
|
|
|
|
const MOUSE_LINES_PER_PAGE = 30;
|
2016-09-28 05:27:42 +09:00
|
|
|
|
|
|
|
// Converts delta to per-page units
|
|
|
|
if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
|
|
|
|
delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
|
|
|
|
} else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
|
|
|
|
delta /= MOUSE_LINES_PER_PAGE;
|
|
|
|
}
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
2017-08-19 21:23:40 +09:00
|
|
|
function isValidRotation(angle) {
|
|
|
|
return Number.isInteger(angle) && angle % 90 === 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
function isValidScrollMode(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
|
|
|
return (
|
|
|
|
Number.isInteger(mode) &&
|
|
|
|
Object.values(ScrollMode).includes(mode) &&
|
|
|
|
mode !== ScrollMode.UNKNOWN
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function isValidSpreadMode(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
|
|
|
return (
|
|
|
|
Number.isInteger(mode) &&
|
|
|
|
Object.values(SpreadMode).includes(mode) &&
|
|
|
|
mode !== SpreadMode.UNKNOWN
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
2018-03-20 21:25:13 +09:00
|
|
|
function isPortraitOrientation(size) {
|
|
|
|
return size.width <= size.height;
|
|
|
|
}
|
|
|
|
|
2017-08-12 23:06:20 +09:00
|
|
|
const WaitOnType = {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
EVENT: "event",
|
|
|
|
TIMEOUT: "timeout",
|
2017-08-12 23:06:20 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} WaitOnEventOrTimeoutParameters
|
|
|
|
* @property {Object} target - The event target, can for example be:
|
|
|
|
* `window`, `document`, a DOM element, or an {EventBus} instance.
|
|
|
|
* @property {string} name - The name of the event.
|
|
|
|
* @property {number} delay - The delay, in milliseconds, after which the
|
|
|
|
* timeout occurs (if the event wasn't already dispatched).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows waiting for an event or a timeout, whichever occurs first.
|
|
|
|
* Can be used to ensure that an action always occurs, even when an event
|
|
|
|
* arrives late or not at all.
|
|
|
|
*
|
|
|
|
* @param {WaitOnEventOrTimeoutParameters}
|
|
|
|
* @returns {Promise} A promise that is resolved with a {WaitOnType} value.
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 waitOnEventOrTimeout({ target, name, delay = 0 }) {
|
2018-07-16 20:40:51 +09:00
|
|
|
return new Promise(function(resolve, reject) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 target !== "object" ||
|
|
|
|
!(name && typeof name === "string") ||
|
|
|
|
!(Number.isInteger(delay) && delay >= 0)
|
|
|
|
) {
|
|
|
|
throw new Error("waitOnEventOrTimeout - invalid parameters.");
|
2017-08-12 23:06:20 +09:00
|
|
|
}
|
|
|
|
|
2018-07-16 20:40:51 +09:00
|
|
|
function handler(type) {
|
|
|
|
if (target instanceof EventBus) {
|
|
|
|
target.off(name, eventHandler);
|
|
|
|
} else {
|
|
|
|
target.removeEventListener(name, eventHandler);
|
|
|
|
}
|
2017-08-12 23:06:20 +09:00
|
|
|
|
2018-07-16 20:40:51 +09:00
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
}
|
|
|
|
resolve(type);
|
|
|
|
}
|
2017-08-12 23:06:20 +09:00
|
|
|
|
2018-07-16 20:40:51 +09:00
|
|
|
const eventHandler = handler.bind(null, WaitOnType.EVENT);
|
|
|
|
if (target instanceof EventBus) {
|
|
|
|
target.on(name, eventHandler);
|
|
|
|
} else {
|
|
|
|
target.addEventListener(name, eventHandler);
|
|
|
|
}
|
2017-08-12 23:06:20 +09:00
|
|
|
|
2018-07-16 20:40:51 +09:00
|
|
|
const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
|
2019-12-23 02:16:32 +09:00
|
|
|
const timeout = setTimeout(timeoutHandler, delay);
|
2018-07-16 20:40:51 +09:00
|
|
|
});
|
2017-08-12 23:06:20 +09:00
|
|
|
}
|
|
|
|
|
2016-11-19 03:50:29 +09:00
|
|
|
/**
|
|
|
|
* Promise that is resolved when DOM window becomes visible.
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 animationStarted = new Promise(function(resolve) {
|
|
|
|
if (
|
|
|
|
typeof PDFJSDev !== "undefined" &&
|
2020-01-08 23:33:11 +09:00
|
|
|
PDFJSDev.test("LIB && TESTING") &&
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
typeof window === "undefined"
|
|
|
|
) {
|
2018-06-01 19:52:06 +09:00
|
|
|
// Prevent "ReferenceError: window is not defined" errors when running the
|
|
|
|
// unit-tests in Node.js/Travis.
|
|
|
|
setTimeout(resolve, 20);
|
|
|
|
return;
|
|
|
|
}
|
2016-11-19 03:50:29 +09:00
|
|
|
window.requestAnimationFrame(resolve);
|
|
|
|
});
|
|
|
|
|
2016-04-26 07:57:15 +09:00
|
|
|
/**
|
|
|
|
* Simple event bus for an application. Listeners are attached using the
|
|
|
|
* `on` and `off` methods. To raise an event, the `dispatch` method shall be
|
|
|
|
* used.
|
|
|
|
*/
|
2017-06-28 19:34:12 +09:00
|
|
|
class 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
|
|
|
constructor({ dispatchToDOM = false } = {}) {
|
2016-04-26 07:57:15 +09:00
|
|
|
this._listeners = Object.create(null);
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
this._dispatchToDOM = dispatchToDOM === true;
|
2016-04-26 07:57:15 +09:00
|
|
|
}
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
on(eventName, listener) {
|
|
|
|
let eventListeners = this._listeners[eventName];
|
|
|
|
if (!eventListeners) {
|
|
|
|
eventListeners = [];
|
|
|
|
this._listeners[eventName] = eventListeners;
|
|
|
|
}
|
|
|
|
eventListeners.push(listener);
|
|
|
|
}
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
off(eventName, listener) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const eventListeners = this._listeners[eventName];
|
2017-06-28 19:34:12 +09:00
|
|
|
let i;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
|
2017-06-28 19:34:12 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
eventListeners.splice(i, 1);
|
2013-06-19 01:05:55 +09:00
|
|
|
}
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
dispatch(eventName) {
|
2019-12-23 02:16:32 +09:00
|
|
|
const eventListeners = this._listeners[eventName];
|
2017-06-28 19:34:12 +09:00
|
|
|
if (!eventListeners || eventListeners.length === 0) {
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
if (this._dispatchToDOM) {
|
2018-09-21 05:43:44 +09:00
|
|
|
const args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
this._dispatchDOMEvent(eventName, args);
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
}
|
2017-06-28 19:34:12 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Passing all arguments after the eventName to the listeners.
|
2018-09-21 05:43:44 +09:00
|
|
|
const args = Array.prototype.slice.call(arguments, 1);
|
2017-06-28 19:34:12 +09:00
|
|
|
// Making copy of the listeners array in case if it will be modified
|
|
|
|
// during dispatch.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
eventListeners.slice(0).forEach(function(listener) {
|
2017-06-28 19:34:12 +09:00
|
|
|
listener.apply(null, args);
|
|
|
|
});
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
if (this._dispatchToDOM) {
|
|
|
|
this._dispatchDOMEvent(eventName, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_dispatchDOMEvent(eventName, args = null) {
|
|
|
|
const details = Object.create(null);
|
|
|
|
if (args && args.length > 0) {
|
|
|
|
const obj = args[0];
|
2019-12-23 02:16:32 +09:00
|
|
|
for (const key in obj) {
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
const value = obj[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 === "source") {
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
if (value === window || value === document) {
|
|
|
|
return; // No need to re-dispatch (already) global events.
|
|
|
|
}
|
|
|
|
continue; // Ignore the `source` property.
|
|
|
|
}
|
|
|
|
details[key] = value;
|
|
|
|
}
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 event = document.createEvent("CustomEvent");
|
Add general support for re-dispatching events, on `EventBus` instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM.
Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events.
The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer.
Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality.
*Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied.
---
[1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
2018-08-28 17:26:18 +09:00
|
|
|
event.initCustomEvent(eventName, true, true, details);
|
|
|
|
document.dispatchEvent(event);
|
2017-06-28 19:34:12 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 03:51:50 +09:00
|
|
|
let globalEventBus = null;
|
|
|
|
function getGlobalEventBus(dispatchToDOM = false) {
|
|
|
|
if (!globalEventBus) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
globalEventBus = new EventBus({ dispatchToDOM });
|
2018-09-21 03:51:50 +09:00
|
|
|
}
|
|
|
|
return globalEventBus;
|
|
|
|
}
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
function clamp(v, min, max) {
|
|
|
|
return Math.min(Math.max(v, min), max);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProgressBar {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
constructor(id, { height, width, units } = {}) {
|
2014-08-17 08:06:03 +09:00
|
|
|
this.visible = true;
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2013-07-19 01:28:59 +09:00
|
|
|
// Fetch the sub-elements for later.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.div = document.querySelector(id + " .progress");
|
2013-07-19 01:28:59 +09:00
|
|
|
// Get the loading bar element, so it can be resized to fit the viewer.
|
|
|
|
this.bar = this.div.parentNode;
|
|
|
|
|
|
|
|
// Get options, with sensible defaults.
|
2017-06-28 19:34:12 +09:00
|
|
|
this.height = height || 100;
|
|
|
|
this.width = width || 100;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.units = units || "%";
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2013-07-19 01:28:59 +09:00
|
|
|
// Initialize heights.
|
2013-06-19 01:05:55 +09:00
|
|
|
this.div.style.height = this.height + this.units;
|
|
|
|
this.percent = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
_updateBar() {
|
|
|
|
if (this._indeterminate) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.div.classList.add("indeterminate");
|
2017-06-28 19:34:12 +09:00
|
|
|
this.div.style.width = this.width + this.units;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-19 01:05: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
|
|
|
this.div.classList.remove("indeterminate");
|
|
|
|
const progressSize = (this.width * this._percent) / 100;
|
2017-06-28 19:34:12 +09:00
|
|
|
this.div.style.width = progressSize + this.units;
|
|
|
|
}
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
get percent() {
|
|
|
|
return this._percent;
|
|
|
|
}
|
2013-07-19 01:28:59 +09:00
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
set percent(val) {
|
|
|
|
this._indeterminate = isNaN(val);
|
|
|
|
this._percent = clamp(val, 0, 100);
|
|
|
|
this._updateBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
setWidth(viewer) {
|
|
|
|
if (!viewer) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-23 02:16:32 +09:00
|
|
|
const container = viewer.parentNode;
|
|
|
|
const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
|
2017-06-28 19:34:12 +09:00
|
|
|
if (scrollbarWidth > 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
|
|
|
this.bar.setAttribute(
|
|
|
|
"style",
|
|
|
|
"width: calc(100% - " + scrollbarWidth + "px);"
|
|
|
|
);
|
2017-06-28 19:34:12 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
if (!this.visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.visible = 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.bar.classList.add("hidden");
|
|
|
|
document.body.classList.remove("loadingInProgress");
|
2017-06-28 19:34:12 +09:00
|
|
|
}
|
2013-06-19 01:05:55 +09:00
|
|
|
|
2017-06-28 19:34:12 +09:00
|
|
|
show() {
|
|
|
|
if (this.visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.visible = 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
|
|
|
document.body.classList.add("loadingInProgress");
|
|
|
|
this.bar.classList.remove("hidden");
|
2017-06-28 19:34:12 +09:00
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
/**
|
|
|
|
* Moves all elements of an array that satisfy condition to the end of the
|
|
|
|
* array, preserving the order of the rest.
|
|
|
|
*/
|
|
|
|
function moveToEndOfArray(arr, condition) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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 moved = [],
|
|
|
|
len = arr.length;
|
2018-05-15 12:10:32 +09:00
|
|
|
let write = 0;
|
|
|
|
for (let read = 0; read < len; ++read) {
|
|
|
|
if (condition(arr[read])) {
|
|
|
|
moved.push(arr[read]);
|
|
|
|
} else {
|
|
|
|
arr[write] = arr[read];
|
|
|
|
++write;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let read = 0; write < len; ++read, ++write) {
|
|
|
|
arr[write] = moved[read];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
2019-12-27 00:13:49 +09:00
|
|
|
AutoPrintRegExp,
|
2017-03-28 08:07:27 +09:00
|
|
|
CSS_UNITS,
|
|
|
|
DEFAULT_SCALE_VALUE,
|
|
|
|
DEFAULT_SCALE,
|
|
|
|
MIN_SCALE,
|
|
|
|
MAX_SCALE,
|
|
|
|
UNKNOWN_SCALE,
|
|
|
|
MAX_AUTO_SCALE,
|
|
|
|
SCROLLBAR_PADDING,
|
|
|
|
VERTICAL_PADDING,
|
2017-08-19 21:23:40 +09:00
|
|
|
isValidRotation,
|
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
|
|
|
isValidScrollMode,
|
|
|
|
isValidSpreadMode,
|
2018-03-20 21:25:13 +09:00
|
|
|
isPortraitOrientation,
|
2017-08-01 21:11:28 +09:00
|
|
|
PresentationModeState,
|
2017-03-28 08:07:27 +09:00
|
|
|
RendererType,
|
2018-02-13 23:01:55 +09:00
|
|
|
TextLayerMode,
|
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
|
|
|
ScrollMode,
|
|
|
|
SpreadMode,
|
2017-05-04 10:05:53 +09:00
|
|
|
NullL10n,
|
2017-03-28 08:07:27 +09:00
|
|
|
EventBus,
|
2018-09-21 03:51:50 +09:00
|
|
|
getGlobalEventBus,
|
2019-10-03 19:03:45 +09:00
|
|
|
clamp,
|
2017-03-28 08:07:27 +09:00
|
|
|
ProgressBar,
|
|
|
|
getPDFFileNameFromURL,
|
|
|
|
noContextMenuHandler,
|
|
|
|
parseQueryString,
|
2018-05-15 12:10:32 +09:00
|
|
|
backtrackBeforeAllVisibleElements, // only exported for testing
|
2017-03-28 08:07:27 +09:00
|
|
|
getVisibleElements,
|
|
|
|
roundToDivide,
|
2018-03-20 01:27:04 +09:00
|
|
|
getPageSizeInches,
|
2017-03-28 08:07:27 +09:00
|
|
|
approximateFraction,
|
|
|
|
getOutputScale,
|
|
|
|
scrollIntoView,
|
|
|
|
watchScroll,
|
|
|
|
binarySearchFirstItem,
|
|
|
|
normalizeWheelEventDelta,
|
|
|
|
animationStarted,
|
2017-08-12 23:06:20 +09:00
|
|
|
WaitOnType,
|
|
|
|
waitOnEventOrTimeout,
|
2018-05-15 12:10:32 +09:00
|
|
|
moveToEndOfArray,
|
2017-03-28 08:07:27 +09:00
|
|
|
};
|