Commit Graph

11155 Commits

Author SHA1 Message Date
Jonas Jenwald
327f2eb588 Ensure that onProgress is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.

From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.

However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.

---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 13:51:12 +02:00
Tim van der Meij
ecbdc508f7
Merge pull request #10155 from kevin51jiang/build-button
Add Build Status Button
2018-10-14 14:51:37 +02:00
Kevin Jiang
c4ac6ad431
Add Build Status Button
Add build Status button so that it's easy to see if pdf.js passed tests or not.
2018-10-13 18:26:48 -04:00
Tim van der Meij
e41c50c3c5
Merge pull request #10152 from Snuffleupagus/classList-toggle
Add support for `classList.toggle` with the, optional, "force" parameter
2018-10-12 23:28:53 +02:00
Jonas Jenwald
ea4db64f41 Convert some occurrences, in the /web folder, of classList.{add, remove} to classList.toggle with the "force" parameter 2018-10-12 15:41:11 +02:00
Jonas Jenwald
4cde844ffe Add a DOMTokenList.toggle polyfill for the second, optional, "force" parameter
This is based on the polyfill available at https://developer.mozilla.org/en-US/docs/Web/API/Element/classList#Polyfill
2018-10-12 15:41:09 +02:00
Tim van der Meij
06c6503ba0
Merge pull request #10150 from Snuffleupagus/linkService-pagesCount
Add missing `pagesCount` getter to `IPDFLinkService` and `SimpleLinkService`
2018-10-11 22:37:34 +02:00
Jonas Jenwald
df8d9f45f9 Add missing pagesCount getter to IPDFLinkService and SimpleLinkService 2018-10-11 10:29:15 +02:00
Tim van der Meij
9e9426c354
Merge pull request #10143 from Snuffleupagus/getMainThreadWorkerMessageHandler-catch-errors
Ensure that `getMainThreadWorkerMessageHandler` won't accidentally break `getDocument` (PR 10139 follow-up)
2018-10-11 00:05:01 +02:00
Tim van der Meij
6f30cbb478
Merge pull request #10140 from Snuffleupagus/rm-pdfjsFilePath
Combine the `pdfjsFilePath` and fallback `workerSrc` handling in `src/display/api.js`
2018-10-10 00:18:38 +02:00
Jonas Jenwald
0e2c6047e4 Ensure that getMainThreadWorkerMessageHandler won't accidentally break getDocument (PR 10139 follow-up)
*This should have been part of PR 10139.*

In the event that a user has attempted to manually load the worker file on the main-thread, but somehow failed to do that correctly, there's a possibility that `getMainThreadWorkerMessageHandler` could throw. Considering how/where that helper function is being called, an error could still prevent `PDFDocumentLoadingTask` from completing (regardless if it's being resolved/rejected).
2018-10-09 15:44:31 +02:00
Jonas Jenwald
21c8dd4842 Combine the pdfjsFilePath and fallback workerSrc handling in src/display/api.js
With the way that the `getWorkerSrc()` helper function is implemented now, there's no longer a particularly strong reason for keeping the global `pdfjsFilePath` variable around.
With this patch the fallback `workerSrc` will thus, assuming is wasn't already set, be set to the "pdfjsFilePath" which simplifies the `getWorkerSrc()` function and reduces the amount of global state.

Finally, the global `workerSrc` variable was renamed to prevent shadowing.
2018-10-09 13:47:48 +02:00
Tim van der Meij
f45e46d7ad
Merge pull request #10133 from kevinleedrum/fix-content-length
Set returnValues.suggestedLength to Content-Length if integer
2018-10-09 00:05:57 +02:00
Kevin Lee Drum
4cf10ac79d set returnValues.suggestedLength to Content-Length if integer 2018-10-07 13:26:29 -04:00
Tim van der Meij
b2e7d0c89b
Merge pull request #10139 from Snuffleupagus/issue-10135
Ensure that the `PDFDocumentLoadingTask` is rejected when "setting up fake worker" failed (issue 10135)
2018-10-07 15:54:50 +02:00
Jonas Jenwald
755c6edc5e Ensure that the PDFDocumentLoadingTask is rejected when "setting up fake worker" failed (issue 10135)
This should, hopefully, cover all the possible ways[1] in which "fake workers" are loaded. Given the different code-paths, adding unit-tests might not be that simple.
Note that in order to make this work, the various `fakeWorkerFilesLoader` functions were converted to return `Promises`.

---
[1] Unfortunately there's lots of them, for various build targets and configurations.
2018-10-06 13:18:51 +02:00
Tim van der Meij
d4469da22b
Merge pull request #10138 from Snuffleupagus/toolbar-pageScaleValue
Ensure that `Toolbar.setPageScale` always sets the `pageScaleValue` property to a valid value
2018-10-05 22:41:59 +02:00
Tim van der Meij
3c6d0a8c44
Merge pull request #10136 from Snuffleupagus/toolbar-signature
Remove the unused `mainContainer` parameter from the `Toolbar` constructor
2018-10-05 22:38:38 +02:00
Jonas Jenwald
a4d4364f5d Ensure that Toolbar.setPageScale always sets the pageScaleValue property to a valid value
Rather than having every invocation of `Toolbar._updateUIState` compute a valid `pageScaleValue`, it seems easier to simply ensure that it happens when the value is actually updated.
2018-10-05 12:13:48 +02:00
Jonas Jenwald
5d421964e5 Remove the unused mainContainer parameter from the Toolbar constructor
Looking at the history of this code, this parameter has never been used.
I'm guessing that most likely the code in `web/toolbar.js` began life as a copy of `web/secondary_toolbar.js`, which would probably explain why that parameter exists.
2018-10-05 10:17:37 +02:00
Tim van der Meij
ff2df9c5b6
Merge pull request #10117 from leblanc-simon/ink-annotation-support
Add support of Ink annotation
2018-10-04 23:39:41 +02:00
Tim van der Meij
5da53ee98f
Merge pull request #10128 from Snuffleupagus/find-controller-enable
Make `PDFFindController` less confusing to use, by allowing searching to start when `setDocument` is called
2018-10-04 23:12:50 +02:00
Jonas Jenwald
2ed3591b22 Make PDFFindController less confusing to use, by allowing searching to start when setDocument is called
*This patch is based on something that I noticed while working on PR 10126.*

The recent re-factoring of `PDFFindController` brought many improvements, among those the fact that access to `BaseViewer` is no longer required. However, with these changes there's one thing which now strikes me as not particularly user-friendly[1]: The fact that in order for searching to actually work, `PDFFindController.setDocument` must be called *and* a 'pagesinit' event must be dispatched (from somewhere).

For all other viewer components, calling the `setDocument` method[2] is enough in order for the component to actually be usable.
The `PDFFindController` thus stands out quite a bit, and it also becomes difficult to work with in any sort of custom implementation. For example: Imagine someone trying to use `PDFFindController` separately from the viewer[3], which *should* now be relatively simple given the re-factoring, and thus having to (somehow) figure out that they'll also need to manually dispatch a 'pagesinit' event for searching to work.

Note that the above even affects the unit-tests, where an out-of-place 'pagesinit' event is being used.
To attempt to address these problems, I'm thus suggesting that *only* `setDocument` should be used to indicate that searching may start. For the default viewer and/or the viewer components, `BaseViewer.setDocument` will now call `PDFFindController.setDocument` when the document is ready, thus requiring no outside configuration anymore[4]. For custom implementation, and the unit-tests, it's now as simple as just calling `PDFFindController.setDocument` to allow searching to start.

---
[1] I should have caught this during review of PR 10099, but unfortunately it's sometimes not until you actually work with the code in question that things like these become clear.

[2] Assuming, obviously, that the viewer component in question actually implements such a method :-)

[3] There's even a very recent issue, filed by someone trying to do just that.

[4] Short of providing a `PDFFindController` instance when creating a `BaseViewer` instance, of course.
2018-10-04 10:28:50 +02:00
Tim van der Meij
8411a7da28
Merge pull request #10126 from Snuffleupagus/find-fixes
[Regression] Restore the ability to start searching before a document has loaded, and ignore searches for previously opened documents (PR 10099 follow-up)
2018-10-04 00:09:26 +02:00
Jonas Jenwald
6be4921eaf Make the clearing of find highlights, when closing the findbar, asynchronous
Since searching itself is an asynchronous operation, removal of highlights needs to be asynchronous too since otherwise there's a risk that the events happen in the wrong order and find highlights thus remain visible.

Also, this patch will now ensure that only 'findbarclose' events for the *current* document is handled since other ones doesn't really matter. Note in particular that when no document is loaded text-layers are, obviously, not present and subsequently it's unnecessary to attempt to hide non-existent find highlights.
2018-10-03 10:47:14 +02:00
Jonas Jenwald
236871c68b [Regression] Restore the ability to start searching before a document has loaded, and ignore searches for previously opened documents (PR 10099 follow-up)
For many years it's been possible to enter a search term into the findbar(s) before the document has finised loading, such that searching starts immediately once it has loaded.
PR 10099 accidentally broke that, which I unfortunately missed during reviewing.

Since searching is asynchronous you cannot directly check in `executeCommand` if the document is loaded/current, but need to wait until searching is actually enabled first.

Furthermore this patch also ensures that the `_findTimeout` is always correctly cleared given that it adds further asynchronous behaviour to searching, since you obviously only want to deal with searches relevant to the current document.
2018-10-03 10:47:07 +02:00
Simon Leblanc
b5806735d8 Add support of Ink annotation 2018-10-03 00:28:49 +02:00
Tim van der Meij
1cfb723dd4
Merge pull request #10123 from Snuffleupagus/viewer-component-signatures
Attempt to simplify the `PDFFindBar` and `PDFSidebar` constructors
2018-10-02 23:30:26 +02:00
Tim van der Meij
138324502c
Merge pull request #10119 from Snuffleupagus/rm-onFileAttachmentAnnotation
Attempt to simplify the `fileattachmentannotation` event dispatching
2018-10-02 23:25:22 +02:00
Jonas Jenwald
8eda8c27f8 Attempt to simplify the signature of the PDFSidebar constructor, by moving the eventBus parameter from the options object and removing the PDFOutlineViewer dependency
This is similar to the format used by a number of other viewer components, and should simplify the `PDFSidebar` initialization slightly.
Furthermore, by using the `eventBus` it's no longer necessary for `PDFSidebar` to have a direct dependency on `PDFOutlineViewer`.

There's still room for improvement here, but this patch is at least a start (since it's not clear to me how best to handle the viewers).
2018-10-02 13:14:11 +02:00
Jonas Jenwald
3f3ddaf541 Attempt to simplify the signature of the PDFFindBar constructor, by moving the eventBus parameter from the options object
This is similar to the format used by a number of other viewer components, and should simplify the `PDFFindBar` initialization slightly.
2018-10-02 12:57:07 +02:00
Brendan Dahl
25446dbd8d
Merge pull request #9982 from Snuffleupagus/mozcentral-FontLoadingAPI
Use the Font Loading API in `MOZCENTRAL` builds, and `GENERIC` builds for Firefox version 63 and above (issue 9945, bug 1088663)
2018-10-01 13:44:47 -07: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
Tim van der Meij
ec10cae5b6
Merge pull request #10099 from timvandermeij/find-controller
[api-major] Rework the find controller for unit testing
2018-09-30 18:36:13 +02:00
Tim van der Meij
1b402996cf
Implement a basic unit test for the find controller
This commit shows that we can now unit test the find controller and
that executing regular queries works. Note that this is only a first
step and not a complete suite of unit tests for all possible options
of the find controller.

While writing this unit test, I found two smaller issues that I
addressed directly. The first one is that in the previous find
controller refactoring I forgot to rename some occurrences of a now
private member variable. Fortunately this did not cause any bugs since
we did have a public getter and the fetched value may be changed by
reference, but it's nevertheless good to fix. The second issue is that
some entries in the `test/unit/clitests.json` file were not correct,
resulting in these tests not being executed on e.g., Travis CI.
2018-09-30 18:32:34 +02:00
Tim van der Meij
f79fb88864
Remove the find controller setter in web/base_viewer.js
With `PDFFindController` instances no longer (directly) depending on
`BaseViewer` instances, we can pass a single `findController` when
initializing a viewer, similar to other components.
2018-09-30 16:59:58 +02:00
Tim van der Meij
38ff79186a
Replace callbacks for updating the UI with dispatching events on the event bus
This makes it more similar to how other components update the viewer UI
and avoids the need to have extra member variables and checks.
2018-09-30 16:59:57 +02:00
Tim van der Meij
e0c811f2ed
Use the link service for getting and setting page information
This removes the dependency on a `PDFViewer` instance from the find
controller, which makes it more similar to other components and makes it
easier to unit test with a mock link service.

Finally, we remove the search capabilities from the SVG example since it
doesn't work there because there is no separate text layer.
2018-09-30 16:59:46 +02:00
Tim van der Meij
e293c12afc
Implement the setDocument method for the find controller
Now it follows the same pattern as e.g., the document properties
component, which allows us to have one instance of the find controller
and set a new document to search upon switching documents.

Moreover, this allows us to get rid of the dependency on `pdfViewer` in
order to fetch the text content for a page. This is working towards
getting rid of the `pdfViewer` dependency upon initializing the
component entirely in future commits.

Finally, we make the `reset` method private since it's not supposed to
be used from the outside anymore now that `setDocument` takes care of
this, similar to other components.
2018-09-30 16:57:40 +02:00
Tim van der Meij
b14c1fbc28
Use the updatetextlayermatches event for highlighting matches on a page
This makes use of the event bus instead of requiring the PDF viewer
instance to get the page view for a page and calling `updateMatches` on
it.
2018-09-30 16:57:18 +02:00
Tim van der Meij
7aca53b1a4
Remove the find bar's dependency on the find controller
Pull request #10100 removed the last usage of the find controller from
the find bar, so we can drop the dependency now.
2018-09-30 16:55:30 +02:00
Tim van der Meij
ba172c7d03
Merge pull request #10116 from timvandermeij/updates
Update packages and translations
2018-09-30 15:54:50 +02:00
Tim van der Meij
a17aa16ba0
Update translations 2018-09-30 15:50:12 +02:00
Tim van der Meij
b187480b3f
Update packages 2018-09-30 15:45:10 +02:00
Tim van der Meij
d0620ec894
Merge pull request #10100 from Snuffleupagus/findbarclose
Clear all find highlights when the findbar is closed (issue 7468)
2018-09-30 15:35:00 +02:00
Tim van der Meij
8d4c79c99c
Merge pull request #10114 from Snuffleupagus/setDocument-optional-url
Update `{PDFLinkService, PDFDocumentProperties}.setDocument` to make the "url" parameter optional
2018-09-30 13:29:08 +02:00
Jonas Jenwald
1c814e208e Prevent getPDFFileNameFromURL from breaking if the url parameter is not a string 2018-09-30 12:28:59 +02:00
Jonas Jenwald
6da78bcc3f Update {PDFLinkService, PDFDocumentProperties}.setDocument to make the "url" parameter optional
This way the resetting of `PDFLinkService`/`PDFDocumentProperties` instances, as is done in `PDFViewerApplication.close`, only requires passing in *one* `null` argument instead of two.
2018-09-30 12:28:56 +02:00
Jonas Jenwald
d6f4d2ff33 Add a Symbol polyfill, using core-js, to allow using for...of loops
https://github.com/zloirock/core-js#ecmascript-symbol
2018-09-29 16:05:00 +02:00
Jonas Jenwald
435ec6a0d5 Use the Font Loading API in MOZCENTRAL builds, and GENERIC builds for Firefox version 63 and above (issue 9945) 2018-09-29 16:05:00 +02:00