Commit Graph

2281 Commits

Author SHA1 Message Date
Jonas Jenwald
1bdfdd07b8 Utilize async/await in PDFViewerApplication.load to reduce the number of Promises and temporary variables necessary when setting the initial document location 2018-09-03 09:52:36 +02:00
Jonas Jenwald
3eba7ea267 Refactor a number of methods in PDFViewerApplication to be async rather than manually returning Promises
*Ignoring whitespace changes is probably necessary, in order for the diff to be readable.*
2018-09-03 09:52:36 +02:00
Jonas Jenwald
a60963f882 Refactor the ViewHistory to utilize async methods rather than manually returning Promises 2018-09-03 09:52:36 +02:00
Jonas Jenwald
233b3274bf Refactor the Preferences classes to utilize async methods rather than manually returning Promises 2018-09-03 09:52:36 +02:00
Jonas Jenwald
64e70fc16f Refactor the OverlayManager to utilize async methods rather than manually returning Promises 2018-09-03 09:52:36 +02:00
Jonas Jenwald
b0fa02e845 Refactor the IL10n implementations to utilize async methods rather than manually returning Promises
This changes the methods signatures of `GenericL10n`, `MozL10n`, and `NullL10n`.
2018-09-03 09:52:36 +02:00
Jonas Jenwald
0b1f41c5b3 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-30 17:28:12 +02:00
Jonas Jenwald
7bc4bfcc8b Add 'documentinit'/'documentloaded' events to PDFViewerApplication.load
The new events follow the same naming pattern as the 'pagesinit'/'pagesloaded' events dispatched on `BaseViewer` instances, and the intention is to allow the eventual removal of 'documentload'.
2018-08-30 10:39:32 +02:00
Jonas Jenwald
486c843215 Add source parameters to all remaining EventBus.dispatch calls that are currently missing those
This is necessary for subsequent patches, and will help avoid unnecessary event re-dispatching in cases where the event source is `window`.
2018-08-30 10:39:32 +02:00
Jonas Jenwald
d7f6f4f051 Remove left-over this.enhanceTextSelection property from the BaseViewer constructor (PR 9479 follow-up) 2018-08-20 16:01:31 +02:00
Jonas Jenwald
0b32dfea86 Use ES6 features, rather than a temporary variable, when swapping padding values in BaseViewer._setScale 2018-08-20 14:18:16 +02:00
Jonas Jenwald
eef70c1eae Remove the deprecated ways, in BaseViewer, of setting the Scroll/Spread modes (PR 9858 follow-up)
Considering that a number of `[api-minor]` changes have landed since PR 9858, removing this code ought to be OK now (the less time these methods remain exposed, the better); implements https://github.com/mozilla/pdf.js/pull/9858#issuecomment-401730065.
2018-08-20 14:11:47 +02:00
Jonas Jenwald
50a47be190 [api-minor] Remove the obsolete createBlob helper function
At this point in time, all supported browsers have native support for `Blob`; please see https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#Browser_compatibility.
Furthermore, note how the helper function was throwing an error if `Blob` isn't available anyway.
2018-08-19 13:37:19 +02:00
Tim van der Meij
3521424576
Merge pull request #9920 from Snuffleupagus/getMetadata-linearization
[api-minor] Add an `IsLinearized` property to the `PDFDocument.documentInfo` getter, to allow accessing the linearization status through the API (via `PDFDocumentProxy.getMetadata`)
2018-07-29 20:23:22 +02:00
Jonas Jenwald
08b05b9fda Validate the Preferences when fetching them from storage
When updating Preferences using the `set` method, the input is carefully validated. However, no validation is (currently) done when a `BasePreferences` instance is created, which probably isn't that great. Hence this patch that simply ignores, to not unnecessarily break loading of the viewer itself, any invalid Preferences.
2018-07-28 14:32:24 +02:00
Jonas Jenwald
780cbadcd7 Stop re-loading the Preferences in PDFViewerApplication.open, and remove the BasePreferences.reload method
Given that the various Preferences are currently, and have been for quite some time, only used when initializing `PDFViewerApplication` re-loading them when a new PDF file is opened in the viewer is essentially a no-op.

Furthermore, with the only usage of `BasePreferences.reload` now gone, the value of that method seems questionable at best. In the event that the functionality is actually needed again, similar to the `ViewHistory`, it'd probably make more sense to simply replace `PDFViewerApplication.preferences` with a new `BasePreferences` instance instead (using e.g. `DefaultExternalServices.createPreferences`).
2018-07-28 13:50:16 +02:00
Jonas Jenwald
522040d130 Expose the Linearization status in the document properties dialog
This uses the same terminology, i.e. "Fast Web View", as is used by Adobe software.
2018-07-26 17:30:46 +02:00
Jonas Jenwald
34957ec8eb Add a BasePreferences.getAll method and use it to fetch all Preferences at once in PDFViewerApplication._readPreferences
Given that *all* Preferences are already fetched in `PDFViewerApplication._readPreferences`, the amount of boilerplate/duplication can be considerably reduced with the addition of a `BasePreferences.getAll` method.
2018-07-25 10:43:36 +02:00
Jonas Jenwald
c3433aea48 Remove a (now) unnecessary externalLinkTarget check in PDFViewerApplication._readPreferences
The only reason that this check ever existed in the first place, is that originally there was a global `PDFJS.openExternalLinkInNewWindow` option which was then subsumed by the (more generic) `PDFJS.externalLinkTarget` option. (The `externalLinkTarget` has since been moved into a `PDFLinkService` option, as part of PDF.js version `2.0`.)

Hence, during the period where both `PDFJS.openExternalLinkInNewWindow` and `PDFJS.externalLinkTarget` existed side-by-side, there was a need to allow the former one to override the latter one (for backward compatibility purposes). However, that's no longer the case, and this extra `externalLinkTarget` check can now be removed.
2018-07-25 10:43:36 +02:00
Jonas Jenwald
c6a0ae08f1 Ensure that the externalLinkTarget option is correctly set when the viewer is embedded (PR 9479 follow-up)
*This was a stupid error on my part; sorry about breaking this!*

With the current code, the value of the `externalLinkTarget` option is now (potentially) updated *after* the viewer components have been initialized. For the "viewer in iframe/object tag" case, the result is that the value of the `externalLinkTarget` option isn't adjusted as intended any more.
2018-07-25 10:43:36 +02:00
Jonas Jenwald
36b683ca55 Provide custom messages for the no-restricted-globals ESLint rule, and refactor the .eslintrc files (PR 9868 follow-up)
Without providing useful (custom) error messages for the `no-restricted-globals` rule, see https://eslint.org/docs/rules/no-restricted-globals, it's quite likely that the rule will be incorrectly disabled rather than the required globals being imported as intended.

To reduced duplication of the `no-restricted-globals` rule in multiple `.eslintrc` files, it's instead moved to the top-level `.eslintrc` file and disabled as needed on a folder/file basis outside of `/src` and `/web`.
2018-07-23 14:10:13 +02:00
Jonas Jenwald
647fa74793 Change waitOnEventOrTimeout, in web/ui_utils.js, to return a regular Promise and remove the createPromiseCapability import
*Another small piece of clean-up of code I've previously written; follow-up to PR 8775.*

Importing `createPromiseCapability`, and then using it in just *one* spot, seems unnecessary since the `waitOnEventOrTimeout` function may just as well return a regular `Promise` directly.
2018-07-16 13:48:33 +02:00
Jonas Jenwald
61186698c3 Replace the remaining occurences of instanceof Array with Array.isArray()
*Follow-up to PRs 8864 and 8813.*

As explained in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray, `instanceof Array` can have inconsistent behavior. To ensure that only `Array.isArray` is used, an ESLint plugin/rule is added to enforce this.
2018-07-09 13:17:41 +02:00
Jonas Jenwald
200e3d6bd8 Update the various ESLint packages to their latest versions 2018-07-09 12:52:55 +02:00
Tim van der Meij
31012570ea
Merge pull request #9868 from Snuffleupagus/url-polyfill
Stop exposing the `URL` polyfill in the global scope
2018-07-08 16:29:53 +02:00
Jonas Jenwald
d8c2bcc93a Temporarily disable the Spread mode buttons when horizontal scrolling is enabled
Given that the non-default Spread modes (currently) doesn't affect the page layout when horizontal scrolling is enabled, having the Spread buttons appear active when clicking them appears to do *nothing* is probably confusing rather than helpful to users.
2018-07-08 12:11:03 +02:00
Jonas Jenwald
36d6255866 Hide the Scroll/Spread mode buttons when the viewer is a PDFSinglePageViewer instance
If the current viewer is a `PDFSinglePageViewer` instance the Scroll/Spread modes are no-ops, hence displaying buttons that do *nothing* when clicked will probably do very little besides confuse users.
2018-07-08 12:08:48 +02:00
Jonas Jenwald
46e1d5daa4 Simplify resetting of the SecondaryToolbar Scroll/Spread mode buttons, and add a missing comment in PDFCursorTools
The names 'resetscrollmode'/'resetspreadmode' were probably *not* great choices, given that the only thing being reset are toolbar buttons and not the actual Scroll/Spread modes. Furthermore, there's really no need for two separate events here.

The patch also adds a comment that ought to have been included in PR 9040, to prevent future refactoring/removing of what may appear to be an unnecessary `Promise.resolve` call.
2018-07-08 10:55:56 +02:00
Jonas Jenwald
a9ce4e8417 Stop exposing the URL polyfill in the global scope
This moves/exposes the `URL` polyfill similarily to the existing `ReadableStream` polyfill, rather than exposing it globally, to avoid interfering with any "outside" code.
Both the `URL` and `ReadableStream` polyfills are now exposed on the `pdfjsLib` object, such that they are accessible to the viewer components.
Furthermore, the `no-restricted-globals` ESLint rule is also enabled to prevent accidental usage of the native `URL`/`ReadableStream` implementations directly in the `src/` and `web/` folders; see also https://eslint.org/docs/rules/no-restricted-globals

Addresses the remaining TODO in https://github.com/mozilla/pdf.js/projects/6
2018-07-04 09:16:28 +02:00
Jonas Jenwald
39a1fce59b Refactor PDFFindController to use the 'pagesinit' event, dispatched on the eventBus, to resolve the _firstPagePromise
Rather than having to manually call a method on `PDFFindController` instances from `BaseViewer.setDocument`, thus essentially having to resolve the private `_firstPagePromise` from the "outside", this can be done easily with the 'pagesinit' event dispatched on the `eventBus` instead.
Please note this particular `PDFFindController` code pre-dates the `eventBus` by almost three years, which should explain why the code looks the way it does.
2018-07-01 16:25:51 +02:00
Jonas Jenwald
ff26d419dd Ensure that Scroll/Spread mode buttons are correctly reset, when the document is closed
Since the Scroll/Spread modes are now document specific, as all other properties such as page/scale/rotation, ensure that the toolbar is always correctly reset.
2018-06-30 14:54:33 +02:00
Jonas Jenwald
bb193dc501 For consistency with other viewer state, remove and deprecate setting Scroll/Spread modes in the BaseViewer constructor
Since other viewer state, such as the current page/scale/rotation[1], are not available as `BaseViewer` constructor options, this makes the Scroll/Spread modes stand out quite a bit. Hence it probably makes sense to remove/deprecate this, to avoid inconsistent and possibly confusing state in this code.

---

[1] These properties are *purposely* not available in the constructor, since attempting to set them before a document is loaded has number of issues; please refer to https://github.com/mozilla/pdf.js/pull/8539#issuecomment-309706629 for additional details.
2018-06-30 12:36:57 +02:00
Jonas Jenwald
8b85ae4181 Re-factor updating of Scroll/Spread modes, and place all the code in BaseViewer with overrides (as necessary) in the extending classes
This structure probably makes somewhat more sense, given that `PDFSinglePageViewer` is somewhat of a special case.
2018-06-30 12:36:56 +02:00
Jonas Jenwald
a7ac27e385 Replace setScrollMode/setSpreadMode methods with getters/setters
Since all the other viewer methods use the getter/setter pattern, e.g. for setting page/scale/rotation, the way that the Scroll/Spread modes are set thus stands out. For consistency, this really ought to use the same pattern as the rest of the `BaseViewer`. (To avoid breaking third-party implementations, the old methods are kept around as aliases.)
2018-06-30 12:36:54 +02:00
Jonas Jenwald
9515f579c6 Change the scrollMode/spreadMode to "private" properties on BaseViewer instances 2018-06-30 12:19:02 +02:00
Jonas Jenwald
a9a93bd923 Allow the scrollModeOnLoad/spreadModeOnLoad Preferences to override ViewHistory settings
Note how the other "...OnLoad" preferences will allow a *non-default* value to always override a history entry. To improve overall consistency for the viewer options, and to reduce possibly confusing behaviour, this patch changes the `scrollModeOnLoad`/`spreadModeOnLoad` preferences to behave as all the other ones.
2018-06-30 12:19:02 +02:00
Jonas Jenwald
baf9c98bc7 Add scrollModeOnLoad/spreadModeOnLoad default values to AppOptions
For some reason, these weren't added to `AppOptions` despite actually being set and read from `web/app.js`. Not adding them creates inconsistencies, since all other options *are* present in `web/app_options.js`.
2018-06-30 12:19:02 +02:00
Jonas Jenwald
e522b2d87e Remove the unused PDFViewerApplication.documentFingerprint property
This property isn't accessed anywhere in the `web/app.js` file, and is also not being reset in `PDFViewerApplication.close`. Hence it seems that it can simply be removed, especially since the fingerprint is already synchronously available through `PDFViewerApplication.pdfDocument.fingerprint` (provided that a document is loaded).
2018-06-30 12:19:02 +02:00
Jonas Jenwald
3c622ef048 Replace the cloneObj helper function, in the viewer, with native Object.assign (PR 9795 follow-up) 2018-06-27 20:39:39 +02:00
Jonas Jenwald
95a4fa25b9 Don't wait arbitrary long for all pages to be resolved before attempting to re-apply the initial position on load (PR 6318 follow-up)
With the current code, the location in the viewer could change *well* after the user has started to interact with the viewer (for very large and/or slow loading documents). Attempt to reduce the likelyhood of that happening, by adding an upper bound to the time spent waiting before attempting to re-apply the initial position.
2018-06-26 14:19:59 +02:00
Jonas Jenwald
3691f9cc78 Simplify the handling of the defaultZoomValue preference in PDFViewerApplication.load 2018-06-26 14:13:44 +02:00
Jonas Jenwald
5bbbbf152e Stop storing/using the 'exists' property of ViewHistory database entries
Rather than using a "special" property to check if a `ViewHistory` database entry existed on load, it seems that you could just as well check for the existence of one of the actually needed properties instead (here 'page' is used).

This way we can avoid storing what, more of less, amounts to useless state, which will help reduce the size of the `ViewHistory` database. Given that we don't directly, nor need to, validate the `ViewHistory` data but rely on other parts of the code-base to do so, the existance of an 'exists' property doesn't in and of itself really add much utility.

Finally, to simplify the implementation the 'exists' property won't be actively removed from the `ViewHistory` data. Instead we'll simply stop adding 'exists' when writing `ViewHistory` data, and rely on the existing pruning of old entries to eventually remove any remnants of 'exists' from storage.
2018-06-26 14:12:21 +02:00
Jonas Jenwald
253aae15fc Ensure that all entries above the current cacheSize is removed when initializing a ViewHistory instance
Note how, in the current code, only *one* old history entry would ever be removed. That would mean that if e.g. the `cacheSize` is reduced, it would potentially require loading of multiple files before the database would be correctly pruned.

Furthermore, in the case where the database was empty on load there's no need to attempt to shrink it, since trying to reduce the size of an *empty* array won't do much :-)
2018-06-26 14:07:52 +02:00
Tim van der Meij
e8b5088370
Merge pull request #9832 from Snuffleupagus/scrollMode-fixes
Fix a number of regressions/inefficiencies introduced by adding Scroll/Spread modes to the viewer (PR 9208 follow-up)
2018-06-23 21:09:55 +02:00
Jonas Jenwald
c8384061cf Ensure that the locale viewer option is never defined in the (various) extension builds (PR 9493 follow-up) 2018-06-23 13:33:40 +02:00
Jonas Jenwald
bfbe2b411c Simplify the _setScale call when changing Scroll modes
Since the current page will be explicitly scrolled into view *directly* afterwards anyway (compare with e.g. the `pagesRotation` code), trying to maintain the current position when re-applying the zoom level during changing of Scroll modes is redundant.
2018-06-23 11:47:53 +02:00
Jonas Jenwald
d3cb5e7117 Don't attempt to modify the DOM and/or trigger rendering when changing Scroll/Spread modes without a PDF document being loaded 2018-06-23 10:30:22 +02:00
Jonas Jenwald
05f682cd4b [Regression] Ensure that pre-rendering of the next/previous page works correctly in Presentation Mode, when horizontal scrolling was enabled
Note how in `BaseViewer.forceRendering` the Scroll mode is used to determine how pre-rendering will work. Currently this is broken in Presentation Mode, if horizontal scrolling was enabled prior to entering fullscreen.

Furthermore, there's a few additional cases where the `this.scrollMode === ScrollMode.HORIZONTAL` check is pointless either in Presentation Mode or when a `PDFSinglePageViewer` instance is used.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
6a086fa0b9 Refactor setScrollMode/setSpreadMode, in the viewer classes, such that they are no-ops in PDFSinglePageViewer instances
Since the Scroll/Spread modes doesn't make (any) sense in `PDFSinglePageViewer` instances, the general structure of these methods can be improved to reflect that.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
8bd1244298 Move _updateScrollModeClasses from BaseViewer to PDFViewer
Given that this method is a no-op in `PDFSinglePageViewer`, similar to `_regroupSpreads`, let's improve the general code structure by simply moving the method.
2018-06-23 10:16:04 +02:00