Commit Graph

11334 Commits

Author SHA1 Message Date
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
Jonas Jenwald
05b021bcce Refactor the FontLoader into proper, build-specific, ES6 classes
Also changes `var` to `let`/`const` in code already touched in the patch, and makes use of template strings in a few spots.
2018-09-29 16:05:00 +02:00
Jonas Jenwald
45d6651976 Refactor unused Date.now() calls in FontLoader.queueLoadingCallback
The `started` timestamp is completely usused, and the `end` timestamp is currently[1] being used essentially like a boolean value.
Hence this code can be simplified to use an actual boolean value instead, which avoids potentially hundreds (or even thousands) of unnecessary `Date.now()` calls.

---
[1] Looking briefly at the history of this code, I cannot tell if the timestamps themselves were ever used for anything (except for tracking "boolean" state).
2018-09-29 15:57:04 +02:00
Jonas Jenwald
ad3e937816 Replace the Font.loading property with, the already existing, Font.missingFile property
The `Font.loading` property is only ever used *once* in the code, whereas `Font.missingFile` is more widely used. Furthermore the name `loading` feels, at least to me, slight less clear than `missingFile`. Finally, note that these two properties are the inverse of each other.
2018-09-29 15:57:04 +02:00
Jonas Jenwald
caf90ff6ee Convert FontFaceObject to an ES6 class
Also changes `var` to `let`/`const` in code already touched in the patch, and makes use of template strings in a few spots.
2018-09-29 15:57:04 +02:00
Tim van der Meij
b40fb3814a
Merge pull request #10111 from Snuffleupagus/rm-substr
Replace `String.prototype.substr()` occurrences with `String.prototype.substring()`
2018-09-29 15:50:41 +02:00
Jonas Jenwald
842e9206c0 Replace String.prototype.substr() occurrences with String.prototype.substring()
As outlined in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr, which refers to the ECMA-262 specification, using the `substr` function is advised against.

Hence this PR, which replaces all remaining `substr` occurrences with `substring` instead. Please refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr#Syntax respectively https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#Syntax for the differences between the two functions.

Note that in most cases in the code-base there's only one argument passed to `substr`, and those require no other changes except replacing "substr" with "substring". For the other cases, the `substr(start, length)` calls are changed to `substring(start, start + length)` instead.
2018-09-28 11:41:07 +02:00
Jonas Jenwald
f29b4d1116 Clear all find highlights when the findbar is closed (issue 7468)
Please note that this will require a `mozilla-central` follow-up patch, in order for this to work in the built-in Firefox PDF viewer as well.
2018-09-26 10:20:45 +02:00
Jonas Jenwald
1eaa3b8a08 Dispatch a 'pagecancelled' event, in PDFPageView.cancelRendering, when rendering is cancelled
Also, the patch updates `TextLayerBuilder` to use the new 'pagecancelled' event for (future) event removal purposes.
2018-09-23 22:34:39 +02:00
Tim van der Meij
54d6c2436c
Merge pull request #10095 from timvandermeij/updates
Update packages and translations
2018-09-21 15:40:26 +02:00
Tim van der Meij
3c9e25b839
Update translations 2018-09-21 15:26:10 +02:00
Tim van der Meij
2c710eda3e
Update packages 2018-09-21 15:16:30 +02:00
Tim van der Meij
ad6ab88fdf
Merge pull request #10090 from Snuffleupagus/pr-10019-followup
Ensure that all event properties are included, even if no (internal) listeners are registered, when re-dispatching events to the DOM (PR 10019 follow-up)
2018-09-21 14:43:55 +02:00
Jonas Jenwald
39776168a2 Add EventBus unit-tests to ensure that the (optional) argument handling works correctly 2018-09-21 14:31:35 +02:00
Jonas Jenwald
f317a2cb40 Ensure that the DOM event listeners are removed at the end of the relevant EventBus unit-tests, to prevent the tests from interfering with each other 2018-09-20 23:12:01 +02:00
Jonas Jenwald
250e55b0d9 Ensure that all event properties are included, even if no (internal) listeners are registered, when re-dispatching events to the DOM (PR 10019 follow-up) 2018-09-20 22:43:44 +02:00
Tim van der Meij
0e41eb1620
Merge pull request #10078 from timvandermeij/l10n-fix
Improve plural support for the matches counter
2018-09-16 15:25:30 +02:00
Tim van der Meij
f711dbc011
Improve plural support for the matches counter 2018-09-16 14:23:06 +02:00
Tim van der Meij
a85ee3616e
Merge pull request #10071 from Snuffleupagus/matchesCount-FirefoxCom-forward
Enable forwarding, in `FirefoxCom`, of the matchesCount to the browser findbar (bug 1062025)
2018-09-16 14:10:47 +02:00
Jonas Jenwald
06b9455263 Hard-code the MOZCENTRAL build to use the [other] plural forms of the matcheCount strings, to prevent errors for PDF files embedded in iframe/object tags
The built-in PDF Viewer (in Firefox) cannot use the browser findbar when PDF files are embedded in e.g. iframe/object tags, and the PDF.js findbar (i.e. `PDFFindBar`) will thus be used instead in those cases.
This is slightly problematic, since the `MOZCENTRAL` version of the viewer uses a special, slimmed down, version of the `l10n.js` file that doesn't (currently) support plural forms. To prevent the matchesCounter from breaking completely in this edge-case, temporarily hard-code the plural form to use the default `[other]` version of the locale strings.
2018-09-15 23:45:38 +02:00
Jonas Jenwald
be7fdf148c Further ensure that PDFFindController._requestMatchesCount won't return broken data (PR 10052 follow-up)
This prevents the findbar from intermittently displaying `0 of {number} matches`, which *could* theoretically happen for large and/or slow loading documents.
2018-09-15 23:45:38 +02:00
Jonas Jenwald
fafd8819bc Enable forwarding, in FirefoxCom, of the matchesCount to the browser findbar (bug 1062025)
This depends on https://bugzilla.mozilla.org/show_bug.cgi?id=1062025 landing in `mozilla-central` first, since https://searchfox.org/mozilla-central/rev/37663bb87004167184de6f2afa6b05875eb0528e/browser/extensions/pdfjs/content/PdfStreamConverter.jsm#719,740 would otherwise throw for the unknown event name.
2018-09-15 23:45:38 +02:00