Commit Graph

11125 Commits

Author SHA1 Message Date
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
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
Tim van der Meij
ed32f6a082
Merge pull request #10066 from timvandermeij/find-controller
Refactor the find controller
2018-09-15 20:38:08 +02:00
Tim van der Meij
d0b5aa0869
Merge pull request #10070 from Snuffleupagus/matchesCount-plural
Attempt to support plural forms in the matches counter of the findbar (issue 10067)
2018-09-13 22:42:13 +02:00
Brendan Dahl
ae7dcae27e Fix abbreviation. 2018-09-13 13:10:38 -07:00
Tim van der Meij
67e1e39f99
Move scrolling the selected match into view from the find controller to the text layer builder
The find controller should only coordinate finding a string in the
document and should not be responsible for presenting the matches to the
user. The text layer builder already contains the logic to render the
matches in the viewer, so it should also take care of scrolling the
selected match into view.
2018-09-13 22:06:01 +02:00
Tim van der Meij
ede414554e
Change let to const where possible in the find controller
Doing so clearly indicates which variables are read-only and may not be
mutated, which helps readability and prevents subtle issues.
2018-09-13 22:06:00 +02:00
Tim van der Meij
38c9f5fc24
Mark all private members as such in the find controller
Moreover, use getters for all members that are only being read.
2018-09-13 22:05:41 +02:00
Jonas Jenwald
6c4157acd9 Attempt to support plural forms in the matches counter of the findbar (issue 10067)
Based on a quick look at https://github.com/fabi1cazenave/webL10n/#pluralization, it seems that supporting plural forms shouldn't be as difficult as I first thought it might be.
2018-09-13 13:50:51 +02:00
Brendan Dahl
6adeabbb66 Add Glyph & Cog's XPDF copyright/license information. 2018-09-12 13:59:56 -07:00
Tim van der Meij
29683d40a5
Merge pull request #10063 from Snuffleupagus/JPEG-isSourcePDF-assert
Slightly improve the `isSourcePDF` parameter handling in `JpegImage` (PR 10031 follow-up)
2018-09-12 14:56:42 +02:00