Commit Graph

41 Commits

Author SHA1 Message Date
Jonas Jenwald
a8de614a9f Also enable renderInteractiveForms by default in the viewer components (PR 12201 follow-up)
Given that `renderInteractiveForms` is now enabled by default in "full" viewer, it seems reasonable to enable it by default in the viewer components as well.
Especially considering that it's simple to disable, when creating the affected components, for anyone implementing their own viewer.
2020-08-22 14:24:04 +02:00
Jonas Jenwald
a6c1ef82ae Update BaseViewer.createAnnotationLayerBuilder, and PDFPageView, to accurately reflect IPDFAnnotationLayerFactory (PR 12147 follow-up) 2020-08-05 23:02:30 +02:00
Jonas Jenwald
346afd1e1c [api-minor] Fix the AnnotationStorage usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
*The [api-minor] label probably ought to have been added to the original PR, given the changes to the `createAnnotationLayerBuilder` signature (if nothing else).*

This patch fixes the following things:
 - Let the `AnnotationLayer.render` method create an `AnnotationStorage`-instance if none was provided, thus making the parameter *properly* optional. This not only fixes the reference tests, it also prevents issues when the viewer components are used.
 - Stop exporting `AnnotationStorage` in the official API, i.e. the `src/pdf.js` file, since it's no longer necessary given the change above. Generally speaking, unless absolutely necessary we probably shouldn't export unused things in the API.
 - Fix a number of JSDocs `typedef`s, in `src/display/` and `web/` code, to actually account for the new `annotationStorage` parameter.
 - Update `web/interfaces.js` to account for the changes in `createAnnotationLayerBuilder`.
 - Initialize the storage, in `AnnotationStorage`, using `Object.create(null)` rather than `{}` (which is the PDF.js default).
2020-07-31 16:32:46 +02:00
Jonas Jenwald
9a437a158f [api-minor] Deprecate getGlobalEventBus and update the "viewer components" examples accordingly
To avoid outright breaking third-party usages of the "viewer components" the `getGlobalEventBus` functionality is left intact, but a deprecation message is printed if the function is invoked.

The various examples are updated to *explicitly* initialize an `EventBus` instance, and provide that when initializing the relevant viewer components.
2020-02-27 14:44:48 +01:00
Jonas Jenwald
de36b2aaba Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).

Prettier is being used for a couple of reasons:

 - To be consistent with `mozilla-central`, where Prettier is already in use across the tree.

 - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.

Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.

*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.

(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-26 12:34:24 +01:00
Jonas Jenwald
d621899d50 Add a reset method to the PDFHistory implementation
This patch addresses a couple of smaller issues with the `PDFHistory` class:
 - Most, if not all, other viewer components can be reset in one way or another, and there's no good reason for the `PDFHistory` implementation to be different here.

 - Currently it's (technically) possible to keep adding entries to the browser history, via the `PDFHistory` instance, even after the document has been closed. That obviously makes no sense, and is caused by the lack of a `reset` method.

 - The internal `this._isPagesLoaded` property was never actually reset, which would lead to it being temporarily wrong when a new document was opened in the default viewer.
2019-12-13 10:38:39 +01:00
Jonas Jenwald
a965662184 Enable the getter-return, no-dupe-else-if, and no-setter-return ESLint rules
All of these rules can help catch errors during development. Please note that only `getter-return` required a few changes, which was limited to disabling the rule in a couple of spots; please find additional details about these rules at:
 - https://eslint.org/docs/rules/getter-return
 - https://eslint.org/docs/rules/no-dupe-else-if
 - https://eslint.org/docs/rules/no-setter-return
2019-11-23 11:40:30 +01:00
Tim van der Meij
8b4ae6f3eb
Consistently use @type for getter data types in JSDoc comments
Sometimes we also used `@return` or `@returns`, but `@type` is what
the JSDoc documentation recommends. This also improves the documentation
because before this commit the types were not shown and now they are.
2019-10-13 13:58:17 +02:00
Tim van der Meij
f4daafc077
Consistently use square brackets for optional parameters in JSDoc comments
Square brackets are recommended to indicate optional parameters. Using
them helps for automatically generating correct documentation.
2019-10-13 13:58:17 +02:00
Brendan Dahl
98e989116c Add a way to disable external links. 2019-08-21 11:20:41 -07:00
Jonas Jenwald
4773bf6fcb Add support for updating the document hash, off by default, when the browser history is updated (issue 5753)
This is *really* the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.

I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:
 - It's already possible to easily obtain the current hash, by simply clicking on the `viewBookmark` button at any time.
 - Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see `PDFHistory._popState`). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
 - It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the `file://` protocol).
This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during `pushState`/`replaceState` calls.

---
[1] Using the `historyUpdateUrl` viewer preference.

[2] This depends, to a great extent, on browsers always firing `popstate` events *before* `hashchange` events, which may or may not actually be guaranteed.
2019-01-06 20:09:02 +01:00
Jonas Jenwald
a7e70a50f5 Add OpenAction destination support, off by default, to the viewer
Given that it's really not clear to me if this is actually desired functionality in the default viewer, and considering that it doesn't fit in *great* with the way that `PDFHistory` is initialized, this feature is currently off by default[1].

---
[1] It's controlled with the `disableOpenActionDestination` Preference/AppOption.
2018-12-19 11:45:17 +01:00
Jonas Jenwald
6bb7492fae Simply export the various interface definitions, rather than disabling ESLint, in web/interfaces.js 2018-11-08 13:21:46 +01:00
Jonas Jenwald
d805d799ff For repeated 'findagain' operations, attempt to reset the search position if the user has e.g. scrolled in the document (issue 4141)
Currently we'll only attempt to start from the current page when a new search is done, however for 'findagain' operations we'll always continue from the last match position.
This could easily lead to confusing behaviour if the user has scrolled to a completely different part of the document. In an attempt to improve this somewhat, for repeated 'findagain' operations, we'll instead reset the position to the current page when it's *absolutely* certain that the user has scrolled.

Note that this required adding a new `BaseViewer` method, and exposing that through `PDFLinkService`, in order to check if a given page is visible.
In an attempt to avoid issues, in custom implementations of `PDFFindController`, the code checks for the existence of the `PDFLinkService.isPageVisible` method *before* using it.
2018-11-03 12:03:11 +01:00
Jonas Jenwald
df8d9f45f9 Add missing pagesCount getter to IPDFLinkService and SimpleLinkService 2018-10-11 10:29:15 +02:00
Jonas Jenwald
d60ce998f1 Attempt to simplify the fileattachmentannotation event dispatching
This attempts to reduced the level of indirection, and the amount of code, when dispatching `fileattachmentannotation` events, by removing the `PDFLinkService.onFileAttachmentAnnotation` method and just accessing `PDFLinkService.eventBus` directly in the `FileAttachmentAnnotationElement` constructor.
Given that other properties, such as `externalLinkTarget`/`externalLinkRel`, are already being accessed directly this pattern seems fine here as well.
2018-10-01 15:09:08 +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
513412c92e Add a new getLanguage method to the various IL10n implementations 2018-03-25 18:49:46 +02:00
Jonas Jenwald
c45c394364 Move the imageResourcesPath option to a BaseViewer/PDFPageView/AnnotationLayerBuilder option
This removes the `PDFJS.imageResourcesPath` dependency from the viewer components and the test-suite, but please note that as a *temporary* solution the default viewer still uses it.
2018-02-13 14:28:38 +01:00
Jonas Jenwald
e135c03123 Store the rotation in the PDFHistory 2017-09-09 11:27:05 +02:00
Jonas Jenwald
133d06e9a4 Re-write PDFHistory from scratch
This patch completely re-implements `PDFHistory` to get rid of various bugs currently present, and to hopefully make maintenance slightly easier. Most of the interface is similar to the existing one, but it should be somewhat simplified.

The new implementation should be more robust against failure, compared to the old one. Previously, it was too easy to end up in a state which basically caused the browser history to lock-up, preventing the user from navigating back/forward. (In the new implementation, the browser history should not be updated rather than breaking if things go wrong.)

Given that the code has to deal with various edge-cases, it's still not as simple as I would have liked, but it should now be somewhat easier to deal with.
The main source of complication in the code is actually that we allow the user to change the hash of a already loaded document (we'll no longer try to navigate back-and-forth in this case, since the next commit contains a workaround).

In the new code, there's also *a lot* more comments (perhaps too many?) to attempt to explain the logic. This is something that the old implementation was serverly lacking, which is a one of the reasons why it was so difficult to maintain.

One particular thing to note is that the new code uses the `pagehide` event rather than `beforeunload`, since the latter seems to be a bad idea based on https://bugzilla.mozilla.org/show_bug.cgi?id=1336763.
2017-08-30 19:45:13 +02:00
Jonas Jenwald
28ce3b6185 Rip out the current implementation of PDFHistory
The current implementation of `PDFHistory` contains a number of smaller bugs, which are *very* difficult to address without breaking other parts of its code.
Possibly the main issue with the current implementation, is that I wrote it quite some time ago, and at the time my understanding of the various edge-cases the code has to deal with was quite limited.
Currently `PDFHistory` may, despite most of those cases being fixed, in certain edge-cases lock-up the browser history, essentially preventing the user from navigating back/forward.

Hence rather than trying to iterate on `PDFHistory` to make it better, the only viable approach is unfortunately rip it out in its entirety and re-write it from scratch.
2017-08-30 19:45:13 +02:00
Jonas Jenwald
8ba8072937 Convert PDFLinkService to an ES6 class 2017-07-14 16:30:25 +02:00
Yury Delendik
5438ce9b98 Wraps mozL10n to async calls; splits firefox and generic l10n libs. 2017-05-31 09:22:25 -05:00
Tim van der Meij
8d9596480c
Convert the interfaces to ES6 syntax 2017-05-07 22:01:49 +02:00
Jonas Jenwald
2a0207ccaf Enable the object-shorthand ESLint rule in web
Please see http://eslint.org/docs/rules/object-shorthand.

For the most part, these changes are of the search-and-replace kind, and the previously enabled `no-undef` rule should complement the tests in helping ensure that no stupid errors crept into to the patch.
2017-04-29 20:29:04 +02:00
Tim van der Meij
3554a93c2b
Convert the annotation layer builder to ES6 syntax 2017-04-27 16:23:29 +02:00
Tim van der Meij
2da2c45889 Interactive forms: remove global PDFJS usage 2016-09-19 00:12:42 +02:00
Tim van der Meij
7c961b6b7a Minor code style improvements after #7539 2016-09-01 18:07:12 +02:00
Jeremy Press
6faa84abdb Continuing fairexpand #6663
1. Expanding divs to improve text selection. (Yury)
2. Adding enhanceTextSelection as an option.
3. Moving feature functionality from text_layer_builder.js to text_layer.js.
4. Added expandTextDivs method to only load expanded divs on first click, and only show on subsequent clicks
2016-08-31 09:54:52 -07:00
Jonas Jenwald
3079dd937f Remove a superfluous "s" in AnnotationsLayerBuilder from files in web/
This patch makes the naming consistent with the `TextLayerBuilder`, and also the new `AnnotationLayer`, and should thus help reduce possible confusion when working with the code.
Please note that the files were renamed using `git mv`, in order to preserve blame.
2015-12-18 19:55:54 +01:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Yury Delendik
5cff06e52a Refactors PDFHistory.
# Conflicts:
#	extensions/b2g/viewer.js
#	web/pdf_history.js
#	web/pdf_viewer.component.js
#	web/viewer.js
2015-05-16 11:20:36 -05:00
Yury Delendik
0ef6212b64 Refactors PDFLinkService.
# Conflicts:
#	web/viewer.js
2015-05-16 11:20:36 -05:00
Yury Delendik
2565e627a3 Refactors draw method in PDFPageView; makes optional some PDFPageViewOptions options 2014-12-20 23:41:34 -06:00
Yury Delendik
2ac7ac4678 Removes lastScrollSource and isViewerInPresentationMode from TextLayerBuilderOptions 2014-12-20 11:14:13 -06:00
Yury Delendik
9f384bbb41 Creates AnnotationsLayerBuilder. 2014-12-19 13:07:28 -06:00
Yury Delendik
7663942ee5 Creates IPDFTextLayerFactory interface 2014-12-17 15:21:54 -06:00
Yury Delendik
b16a406f3a Packages PDFViewer as a UI component. 2014-09-30 12:41:53 -05:00
Yury Delendik
44779f14b0 Renames and refactors PDFView to PDFViewerApplication. 2014-09-28 10:39:56 -05:00
Yury Delendik
a89bba35b2 Adds types definitions (jsdoc) for the PDFViewer code. 2014-09-28 10:39:56 -05:00