Commit Graph

2117 Commits

Author SHA1 Message Date
Jonas Jenwald
ad0c1fb2c0 Use ES6 notation, and replace var with let, in web/pdf_viewer.component.js and web/pdfjs.js 2017-11-05 16:53:47 +01:00
Jonas Jenwald
730928a402 ES6-ify the code in web/chromecom.js
These changes consists mainly of replacing `var` with `let`.
2017-11-05 13:26:06 +01:00
Tim van der Meij
f87c16bcc4
Merge pull request #8993 from Snuffleupagus/sidebar-constant-position
Layout the sidebar in the same vertical position regardless of the viewer width (issue 4052, bug 850591)
2017-11-04 16:53:11 +01:00
Jonas Jenwald
f0c98a7ab0 [api-major] Stop bundling, and also remove, the web/compatibility.js file in pdfjs-dist
As suggested in PR 8102.
2017-10-31 22:32:43 +01:00
Brendan Dahl
b46443f0c1
Merge pull request #9077 from yurydelendik/v2
Version 2.0 merge
2017-10-31 14:24:20 -07:00
Jonas Jenwald
8f9d548874 Update ESLint and enable the lines-between-class-members rule
This rule will help aid readability in `class`es, please see https://eslint.org/docs/rules/lines-between-class-members.
2017-10-29 11:41:13 +01:00
Yury Delendik
b4e25fb2e8 Merge remote-tracking branch 'mozilla/version-2.0' into v2 2017-10-27 14:01:45 -05:00
Tim van der Meij
f6bebabbcb Merge pull request #9057 from Snuffleupagus/es6-print-code
Use `let`/`const` instead of `var` in the printing code
2017-10-22 21:00:34 +02:00
Jonas Jenwald
b0f524e65c Replace a few occurences of var with let in already ES6 converted web/ files 2017-10-22 16:23:38 +02:00
Jonas Jenwald
d14cb5eb27 Use let/const instead of var in the printing code 2017-10-22 16:13:14 +02:00
Tim van der Meij
17cc94db4e Merge pull request #9034 from Snuffleupagus/javascript-null
[api-major] Change `getJavaScript` to return `null`, rather than an empty Array, when no JavaScript exists
2017-10-17 21:58:45 +02:00
Jonas Jenwald
47448c27c3 Remove the enableHandToolOnLoad preference migration code in web/pdf_cursor_tools.js 2017-10-17 18:34:33 +02:00
Tim van der Meij
7d7edd9cc6
[api-major] Remove the PDFJS_NEXT option
Nothing uses this option anymore, so setting it is a no-op now. We can
safely remove it.

Use `SKIP_BABEL` (instead of `PDFJS_NEXT`) now if you want to skip Babel
translation for a build.
2017-10-16 23:16:51 +02:00
Jonas Jenwald
1cd1582cb9 [api-major] Change getJavaScript to return null, rather than an empty Array, when no JavaScript exists
Other API methods already return `null`, rather than empty Arrays/Objects, hence it makes sense to change `getJavaScript` to be consistent.
2017-10-15 22:17:14 +02:00
Jonas Jenwald
816ffa29aa Remove all warning/fallback code for obsolete method signatures in web/ files 2017-10-15 16:57:30 +02:00
Jonas Jenwald
7a0db8960d Layout the sidebar in the same vertical position regardless of the viewer width (issue 4052, bug 850591)
If we want to (eventually) make it possible to resize the sidebar, then having its width indirectly affect the toolbar is going to wreck havoc on the media queries used to show/hide buttons in the main toolbar (since many of them depend on the toolbar state, and thus its width).
Updating all of the media queries dynamically with JavaScript seems like a non-starter, given that it'd cause *very* messy code. It thus seem to me that we'd need to fix the position of the sidebar, to have any hope of (in the short term) addressing issue 2072.

Hence, I'm suggesting that the we always layout the sidebar in a consistent vertical position, and only animate the `viewerContainer` rather than the entire `mainContainer`.

Fixes 4052.
Fixes bug 850591.
2017-10-11 18:17:28 +02:00
Jonas Jenwald
33b1d1b20a Fix a PDFHistory regression with document hashes of the nameddest=... form
Unfortunately I've just found out that this isn't working entirely correct; my apologies for accidentally breaking this in PR 8775.

Compare e.g. this link: http://mirrors.ctan.org/info/lshort/english/lshort.pdf#page.157, with this one: http://mirrors.ctan.org/info/lshort/english/lshort.pdf#nameddest=page.157.

Notice how in the *second* case, the history stops working correctly.

*The various edge-case regressions in the new `PDFHistory` code is reminding my why I put off the rewrite for so long :-(*
2017-10-09 21:58:54 +02:00
Jonas Jenwald
b5a044b931 Only warn about unsupported JavaScript, in the viewer, when non-empty actions exist (issue 5767)
Some PDF files contain JavaScript actions that consist of nothing more that one, or possibly several, empty string(s). At least to me, printing a warning/showing the fallback seems completely unnecessary in that case.

Furthermore, this patch also makes use of an early `return`, so that we no longer will attempt to check for printing instructions when no JavaScript is present in the PDF file.

*Note:* It would perhaps make sense to change the API/core code, such that we ignore empty entries there instead. However, that would probably be considered a breaking changing with respect to backwards compatibility, hence this simple viewer only solution.

Fixes 5767.
2017-10-08 14:29:12 +02:00
Jonas Jenwald
ee5862bd81 Prevent the annotationLayer from, in some cases, becoming duplicated on the first page when the document loads
I don't know if this is a regression, but I noticed earlier today that depending on the initial scale *and* sidebar state, the `annotationLayer` of the first rendered page may end up duplicated; please see screen-shot below.

[screen-shot]

I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling `PDFPageView.draw()` will always, provided an `AnnotationLayerFactory` instance exists, call `AnnotationLayerBuilder.render()`. Hence the events described above will result in *two* such calls, where the actual annotation rendering/updating happens asynchronously.

For reasons that I don't (at all) understand, when multiple `pdfPage.getAnnotations()` promises are handled back-to-back (in `AnnotationLayerBuilder.render()`), the `this.div` property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.

Obviously it'd be good to find out why it breaks, since it *really* shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring `getAnnotations()` calls for `AnnotationLayerBuilder` instances that we're destroying (in `PDFPageView.reset()`).
2017-10-07 11:34:53 +02:00
Jonas Jenwald
e772124339 Fix a regression that (effectively) makes PDFHistory.forward a no-op
*It appears that this accidentally broken in PR 8775.*

Note that `PDFHistory.forward` is only used with certain named actions, and these aren't that commonly used, which ought to explain why this error managed to sneak in.

Steps to reproduce the issue (and verify the fix):
 1. Navigate to e.g. http://mirrors.ctan.org/info/lshort/english/lshort.pdf
 2. Click on a couple of links, or outline items, such that the history is populated with a few entries.
 3. In the console, execute `PDFViewerApplication.pdfHistory.back()` one or more times, thus navigating back to a previous viewer position.
 4. In the console, execute `PDFViewerApplication.pdfHistory.forward() one or more times.

At the last step above, no (forward) navigation happens with the current `master`; now compare with this patch.
2017-10-05 13:56:40 +02:00
Jonas Jenwald
04d4faefc4 Remove the this._currentUid property from PDFHistory, since it's no longer needed
Commit 938dffb06b, in PR 8885, removed the only actual usage of `this._currentUid` and it can thus be removed.
2017-10-05 13:38:25 +02:00
Jonas Jenwald
43134d5b33 Only handle RenderingCancelledException in the viewer code, when rendering is cancelled 2017-10-04 18:13:46 +02:00
Tim van der Meij
f3987bba23 Merge pull request #8724 from Snuffleupagus/PDFSinglePageViewer
Implement a `PDFSinglePageViewer` class (issue 8188)
2017-09-24 19:41:37 +02:00
Tim van der Meij
8ccad276b2
Implement support for polygon annotations 2017-09-23 16:52:47 +02:00
Tim van der Meij
99b17a494d
Implement support for polyline annotations 2017-09-23 16:37:23 +02:00
Jonas Jenwald
23daafd728 Implement a PDFSinglePageViewer class (issue 8188)
The new `PDFSinglePageViewer` class extends the previously created abstract `BaseViewer` class.

There's *a lot* of existing functionality in `PDFViewer` that depends on all the pages being loaded and synchronously available, once the `setDocument` method has been called.
Given that initializing `PDFPageView` instances requires passing a DOM element to which the page is attached, the simplest solution I could come up with is to append all pages to a (hidden) document fragment and just swap them (one at a time) into the viewer when page switching occurs.
2017-09-23 16:28:04 +02:00
Jonas Jenwald
5fa9cca8dd Refactor PDFViewer to extend an abstract BaseViewer class
This patch introduces an abstract `BaseViewer` class, that the existing `PDFViewer` then extends. *Please note:* This lays the necessary foundation for the next patch.
2017-09-23 16:28:04 +02:00
Jonas Jenwald
d7198d3e17 Rename web/pdf_viewer.js to web/base_viewer.js
Please note that the only reason for this change is to try and improve reviewability of later patches, by keeping the diffs more manageable.
2017-09-23 16:28:04 +02:00
Jonas Jenwald
6c3856c841 Ignore 'change' events that didn't originate in the viewer (issue 8915)
Rather that registering a 'change' event listener on the `window`, which will thus (unnecessarily) fire in *a number* of other situations such as e.g. when the user changes the pageNumber or the current search term, we could/should just register it directly on the dynamically created `fileInput` DOM element instead.
I can see no really compelling reason why we actually need to listen for `file` changes on the `window` itself, and this way we're also able to keep the `fileInput` related code confined to one part of the code which should aid readability.
Furthermore, in custom deployments, there's less risk that we're going to interfere with "outside" code this way.

Finally, preprocessor guards were added to the `webViewerOpenFile` function, since that code doesn't make sense in e.g. the extension builds.
2017-09-17 11:34:21 +02:00
Tim van der Meij
400e4aae0e
Implement support for stamp annotations 2017-09-16 16:37:50 +02:00
Jonas Jenwald
1ebbdc253a Use the SimpleLinkService when running "annotations" reference tests
Rather than (basically) duplicating the `SimpleLinkService` in `test/driver.js`, with potential test failuires if you forget to update the test mock, it seems much nicer to just re-use the viewer component.

Note that `SimpleLinkService` is already bundled into the `build/components/pdf_viewer.js` file. Hence we only need to expose it similar to the other viewer components in that file, and make sure that the `gulp components` command runs as part of the test-setup.
2017-09-12 15:24:46 +02:00
Jonas Jenwald
2916ed080d Merge pull request #8893 from timvandermeij/annotations-css-dedup
Combine the common styles and overrides for the annotation layer reference tests
2017-09-12 13:22:59 +02:00
Tim van der Meij
23cbe294d5
Combine the common styles and overrides for the annotation layer
reference tests

This patch allows us to use the common styles as used by the viewer as a
baseline for the annotation layer reference tests. They are extended
with a small set of overrides to ensure that all elements are visible
during the test.

The overrides file now only contains the absolutely necessary rules to
make all elements visible and is therefore no longer an almost verbatim
copy of the common styles.
2017-09-10 18:18:56 +02:00
Tim van der Meij
3a84d582d3 Merge pull request #8891 from Snuffleupagus/es6-firefoxcom
ES6-ify the code in `web/firefoxcom.js`
2017-09-10 16:10:58 +02:00
Jonas Jenwald
1d78935f3e Replace var with let in web/genericcom and web/genericl10n 2017-09-10 13:09:26 +02:00
Jonas Jenwald
aaff3385ee ES6-ify the code in web/firefoxcom.js
These changes consists mainly of replacing `var` with `let`/`const`, and finally converting the `DownloadManager` to a proper class.
2017-09-10 12:51:33 +02:00
Tim van der Meij
320779e6ed Merge pull request #8691 from timvandermeij/square-circle-annotations
Implement support for square and circle annotations
2017-09-09 22:56:54 +02:00
Tim van der Meij
44c116ac49
Implement support for circle annotations 2017-09-09 21:36:27 +02:00
Tim van der Meij
cace2e9047
Implement support for square annotations 2017-09-09 21:36:27 +02:00
Tim van der Meij
437e9cb056 Merge pull request #8865 from Snuffleupagus/hide-unsupported-LinkAnnotation
Hide unsupported `LinkAnnotation`s (issue 3897)
2017-09-09 19:07:43 +02:00
Tim van der Meij
e6d05be41a Merge pull request #8868 from Snuffleupagus/save-rotation
Store the rotation in the `ViewHistory`/`PDFHistory` (issue 5927)
2017-09-09 16:33:28 +02:00
Jonas Jenwald
30b7a0f093 Replace value === (value | 0) checks with Number.isInteger(value) in the web/ folder
Rather than doing what (at first) may seem like a fairly obscure comparison, using `Number.isInteger` will clearly indicate the intent of the code.
2017-09-09 14:12:52 +02:00
Jonas Jenwald
e135c03123 Store the rotation in the PDFHistory 2017-09-09 11:27:05 +02:00
Jonas Jenwald
44d5138d0f Store the rotation in the ViewHistory (issue 5927) 2017-09-09 11:27:05 +02:00
Jonas Jenwald
5565a6f8bf Slightly refactor the pages rotation handling code in the viewer
This changes both `PDFViewer` and `PDFThumbnailViewer` to return early in the `pagesRotation` setters if the rotation doesn't change.
It also fixes an existing issue, in `PDFViewer`, that would cause errors if the rotation changes *before* the scale has been set to a non-default value.

Finally, in preparation for subsequent patches, it also refactors the rotation code in `web/app.js` to update the thumbnails and trigger rendering with the new `rotationchanging` event.
2017-09-09 11:27:05 +02:00
Tim van der Meij
c8b5ba277a Merge pull request #8885 from Snuffleupagus/PDFHistory-followup
Address a couple of edge-cases in the new `PDFHistory` implementation (PR 8775 follow-up)
2017-09-08 23:10:45 +02:00
Jonas Jenwald
938dffb06b Reduce the value of UPDATE_VIEWAREA_TIMEOUT and simplify the 'popstate' event handler to avoid subtle bugs
When testing the new `PDFHistory` implementation in practice, I felt that the current value of `UPDATE_VIEWAREA_TIMEOUT` is too large to be truly useful.
The purpose of the timeout is to attempt to address (the PDF.js part of) https://bugzilla.mozilla.org/show_bug.cgi?id=1153393, and it's currently fairly easy for the user e.g. close the browser before the timeout had a change to finish.

Obviously, the timeout is a best-effort solution, but with the current value of `UPDATE_VIEWAREA_TIMEOUT` it's not as useful as one would want.
Please note that lowering it shouldn't be a problem, since it still prevents the browser history from updating at *every* 'updateviewarea' event or during (quick) scrolling, which is all that's really needed to not impact the UX negatively.

---

Furthermore, with this lower timeout, we can also simplify the part of the 'popstate' event handler that attempted to update the browser history with the current position before moving back. In most cases, the current position will now already exist in the history, and this *greatly* decreases the complexity of this code path.

The main impetus for this change though, is that I unfortunately found that given the asynchronous nature of updating the browser history, there is some *edge* cases where that code could cause history corruption.
In practice, the user could thus get "stuck" at a particular history entry and not be able to move back. I haven't got any reliable STR for this, since it's so difficult to trigger, but it involved navigating around in a document such that a number of destinations are added to the browser history and then changing the rotation before going back/forward in the history.

Rather that attempting to patch this code, and making it even more difficult to understand than it already is or adding more asynchronous behaviour, by far the easiest solution is to remove it and simply rely on the (lowered) `UPDATE_VIEWAREA_TIMEOUT` instead.
2017-09-07 21:02:25 +02:00
Jonas Jenwald
b7c4d788ed Prevent a temporary position from being added to the history while a destination is scrolled into view
Since e.g. zooming can occur when navigating to a new destionation, ensure that a resulting 'updateviewarea' event doesn't trigger adding of a *temporary* position to the browser history at a bad time.
2017-09-07 16:25:01 +02:00
Jonas Jenwald
077195d8ce Ensure that the PDFHistory._updateViewareaTimeout is always reset when the history is updated 2017-09-07 11:37:23 +02:00
Tim van der Meij
2a77f8b041
Provide checked styles for button widget annotations
Fixes #8875.
2017-09-07 00:25:45 +02:00