Commit Graph

2072 Commits

Author SHA1 Message Date
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
Tim van der Meij
1c9af00bee Merge pull request #8775 from Snuffleupagus/rewrite-PDFHistory-2
Re-write `PDFHistory` from scratch
2017-09-03 20:38:59 +02:00
Yury Delendik
47c28643d6 Revert PDFPageView.pdfPage reset. 2017-08-31 16:49:01 -05:00
Jonas Jenwald
0ac1fba2f9 Prevent PDFHistory._tryPushCurrentPosition() from effectively becoming a no-op if the document hash contains an invalid/non-existent destination
By using the (heuristic) `POSITION_UPDATED_THRESHOLD` constant, we can ensure that the current document position will be added to the browser history when a sufficiently "large" number of `updateviewarea` events have been dispatched.
2017-08-30 19:45:13 +02:00
Jonas Jenwald
0d58bb5512 Temporarily add the current position to the browser history when the viewer is idle
This patch attempts to address an issue in the old `PDFHistory` implementation, where the current position wouldn't be correctly saved when the browser was closed.
In theory this *should* already be working, however as the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1153393 showed, it seems that both `pagehide` and `beforeunload` arrive to late to successfully update the history during closing.

Hence a timeout is used to *temporarily* add the current position to the browser history when the viewer is idle.
Note that we need to take care not to update the browser history too often, since that would render the viewer more or unusable. Furthermore, if the timeout is *too* long it may end up effectively disable this whole functionality.

The `UPDATE_VIEWAREA_TIMEOUT` constant is thus a heuristic value, which we may need to tweak taking the above into account.
2017-08-30 19:45:13 +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
388851e37b Add a isDestsEqual helper function, to allow comparing explicit destinations, in pdf_history.js 2017-08-30 19:45:13 +02:00
Jonas Jenwald
0c4985546a Add a waitOnEventOrTimeout helper function that allows waiting for an event or a timeout, whichever occurs first 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
028d7c0950 Ensure that PDFViewerApplication.error outputs proper messages in FIREFOX/MOZCENTRAL builds
*It appears that this accidentally broke with PR 8394.*

Currently, the following will be printed in the console:
```
An error occurred while loading the PDF.
[object Promise],[object Promise]
```

With this patch we'll again get proper output, e.g. something with this format:
```
An error occurred while loading the PDF.
PDF.js v? (build: ?)
Message: unknown encryption method
```
2017-08-28 13:49:40 +02:00
Jonas Jenwald
870a8f6c35 Remove the ability to pass a scale parameter in the (optional) args object parameter of PDFViewerApplication.open(file, args)
Since the very early days of the viewer, it's been possible to pass in a `scale` when opening a PDF file. However, most of the time it was/is actually being ignored, which limits its usefulness considerably.

In older versions of the viewer, if a document hash was present (i.e. `PDFViewerApplication.initialBookmark` being set) or if the document existed in the `ViewHistory`, the `scale` passed to `PDFViewerApplication.open` would thus always be ignored.
In addition to the above, in the current viewer there's even more cases where the `scale` parameter will be ignored: if a (valid) browser history entry exists on document load, or if the `defaultZoomValue` preference is set to a non-default value.
Hence the result is that in most situation, a `scale` passed to `PDFViewerApplication.open` will be completely ignored.

A much better, not to mention supported, way of setting the initial scale is by using the `defaultZoomLevel` preference. In comparision, this also has the advantage of being used in situations where the `scale` would be ignored.

All in all this leads to the current situation where we have code which is essentially dead, since no part of the viewer (by default) relies on it.
To clean up this code, and to avoid having to pass (basically) unused parameters around, I'd thus like to remove the ability to pass a `scale` to `PDFViewerApplication.open`.
2017-08-24 13:14:00 +02:00
Jonas Jenwald
c523948cc7 Remove handling of fallback arguments from PDFViewer.scrollPageIntoView
The method signature was improved in PR 7440, which has now been present in a number of releases (starting with `v1.6.210`).
Hence we should be able to remove this now, and just print an error message if the old format is used.
2017-08-22 12:08:34 +02:00
Jonas Jenwald
81b4761e6e Remove the migration code for old localStorage data in ViewHistory
This was added in PR 7793, which has now been present in a number of PDF.js releases (from version `v1.7.225`).
Hence we should be able to remove it now, considering that the migration code was only intended as a best effort solution to avoid wiping out all existing user data at once. Also, keep in mind that `ViewHistory` is already limited with regards to the number of documents it will simultaneous store data for.
2017-08-19 11:41:04 +02:00
Jonas Jenwald
9273350c6b Attempt to delay disabling of the attachment view until FileAttachment annotations of the *initial* page has been parsed
As discussed in PR 8673, we cannot solve the general issue (since that would require parsing every single page). However, we can mitigate the effect somewhat, by waiting for the FileAttachment annotations of the initially rendered page.
2017-08-17 14:30:03 +02:00
Jonas Jenwald
96fb0c0370 Call the reset() methods in the PDFAttachmentViewer and PDFOutlineViewer constructors
Rather than duplicating initialization code, we can just call `this.reset()` instead (which is also similar to other existing code, e.g. `PDFViewer`). This will also help ensure that the DOM is completely reset, before any outline items or attachments are displayed.
2017-08-17 13:04:24 +02:00
Jonas Jenwald
e49dfe4ed7 Don't load compatibility.js in the viewer while in non-PRODUCTION mode
At this point, the default viewer is already not usable in older browsers in `gulp server` mode, since we only run the code through Babel as part of the build step.
Hence there shouldn't be much point in manually loading `compatibility.js` in `viewer.html` the way that we've been doing, especially considering that it's already being loaded by `src/shared/util.js`.
2017-08-14 15:57:18 +02:00
Jonas Jenwald
cbc411a2c7 Convert DownloadManager to an ES6 class 2017-08-06 14:15:18 +02:00
Tim van der Meij
f83bd721fc Merge pull request #8752 from Snuffleupagus/es6-dom_events
ES6-ify the code in `web/dom_events.js`
2017-08-05 15:32:50 +02:00
Yury Delendik
d0e93721ae More robust getPage() error handling. 2017-08-04 17:03:33 -05:00
Jonas Jenwald
b2b1752005 ES6-ify the code in web/dom_events.js 2017-07-29 13:17:22 +02:00
Jonas Jenwald
fce31c3f83 Ensure that the loadingBar isn't displayed again when the entire file has already been fetched
This could only (potentially) happen when `disableAutoFetch` is used.
2017-07-29 11:36:45 +02:00
Jonas Jenwald
20d6286cce Add support for, the API property, PageMode in the viewer (issue 8657)
Note that the PageMode, as specified in the API, will only be honoured when either: the user hasn't set the `sidebarViewOnLoad` preference to a non-default value, or a non-default `sidebarView` entry doesn't exist in the view history, or the "pagemode" hash parameter is included in the URL.

Since this is new functionality, the patch also includes a preference (`disablePageMode`), to make it easy to opt-out of this functionality if the user/implementor so wishes.
2017-07-19 16:58:25 +02:00
Jonas Jenwald
f7c4ed4bc3 Refactor reading from the ViewHistory in PDFViewerApplication.load 2017-07-19 16:40:47 +02:00
Tim van der Meij
4a74cc418c Merge pull request #8653 from Rob--W/crx-migrate-pref-enableHandToolOnLoad-to-cursorToolOnLoad
Add UI for the cursorToolOnLoad pref in the Chrome extension + migration logic
2017-07-16 22:40:37 +02:00
Jonas Jenwald
e1536251d5 Convert PDFViewer to an ES6 class 2017-07-16 10:20:35 +02:00
Jonas Jenwald
49333ddd44 Move the hasEqualPageSizes getter from PDFViewerApplication and into PDFViewer instead
Since the method needs to access properties that are directly available inside of `PDFViewer`, it seems simpler to just have it live there.
2017-07-16 10:17:38 +02:00
Rob Wu
19549bb7d6 [CRX] Integrate cursorToolOnLoad pref + migration logic
Add UI for the cursorToolOnLoad pref in the UI of the Chrome extension.

Add logic to migrate the enableHandToolOnLoad pref to cursorToolOnLoad.
For past values in the mutable extension storage area:
1. If enableHandToolOnLoad=true, save cursorToolOnLoad=1.
2. Remove enableHandToolOnLoad.

For the managed extension storage, which is immutable since it is based
on administrative policies, use the following logic:
1. If enableHandToolOnLoad=true and cursorToolOnLoad=0 (default).
   set cursorToolOnLoad=0 and assume enableHandToolOnLoad=false.
2. As usual, managed preferences can (and will) be overridden by the user.

The first migration logic is in extensions/chromium/options/migration.js
and can be removed after a few months / less than many years.

The second migration logic is in web/chromecom.js, and should be kept
around for a long while (many years).

The need for this migration logic arises from the change by:
https://github.com/mozilla/pdf.js/pull/7635
2017-07-15 01:50:15 +02:00
Jonas Jenwald
8ba8072937 Convert PDFLinkService to an ES6 class 2017-07-14 16:30:25 +02:00
Tim van der Meij
d95022328c Merge pull request #8618 from Snuffleupagus/webViewerResize-rm-hack
Remove the scale-not-initialized hack from `webViewerResize` (in app.js)
2017-07-14 14:14:12 +02:00
Tim van der Meij
3e472f1798 Merge pull request #8634 from nish17/master
Update inconsistent names
2017-07-14 13:53:36 +02:00
Tim van der Meij
d7367f102e Merge pull request #8609 from Snuffleupagus/findbar-more-adjustWidth
Ensure that `PDFFindBar._adjustWidth` is called in all situations where the width of the findbar might have changed
2017-07-14 13:34:17 +02:00
Christian Myksvoll
95093a5276 Check for undefined url (#8640)
* Check for undefined

new URL(file, window.location.href) throws the following error in IE11 + iPad Safari:
Unable to get property 'replace' of undefined or null reference

* Adapting previous change to pdf.js code standards

Added curly braces

* Moved check for undefined above try/catch
2017-07-13 13:48:04 -07:00
Yury Delendik
52460687ca Fixes pdf.js library source detection. 2017-07-13 14:57:39 -05:00
Nimesh Solanki
e004b3cfab update inconsistent names 2017-07-11 00:57:39 +05:30
Rob Wu
742ed3d1c9 Remove __pdfjsdev_webpack__, use webpack options
`__pdfjsdev_webpack__` was used to skip evaluating part of an AST,
in order to not mangle some `require` symbols.
This commit removes `__pdfjsdev_webpack__`, and:

- Uses `__non_webpack_require__` when one wants the output to
  contain `require` instead of `__webpack_require__`.
- Adds options to the webpack config to prevent "polyfills" for
  some Node.js-specific APIs to be added.
- Use `// eslint-disable-next-line no-undef` instead of `/* globals ... */`
  for variables that are not meant to be used globally.
2017-07-09 16:35:48 +02:00
Jonas Jenwald
c253ee9ab8 Ensure that the document is rendered on load, no matter what happens, by always calling PDFViewer.update *after* the initial position has been set 2017-07-06 13:50:02 +02:00
Jonas Jenwald
8391aacb89 Remove the scale-not-initialized hack from webViewerResize (in app.js)
Since we no longer, after PR 8555, allow changing the scale until the document is loaded, that hack is no longer necessary. Furthermore, no part of that event handling function needs to run unless a document is loaded.

The reason that this hack was initially added, is that previously the `ViewHistory` might be updated *before* `PDFViewerApplication.setInitialView` had run (in some cases leading to incorrect inital document scale). Since that is no longer possible, this is now dead code.
2017-07-06 13:13:22 +02:00
Jonas Jenwald
12f1b747b1 Merge pull request #8555 from Snuffleupagus/viewer-components-pdfDocument-checks
Don't allow setting various properties, such as `currentPageNumber`/`currentScale`/`currentScaleValue`/`pagesRotation`, before `{PDFViewer, PDFThumbnailViewer}.setDocument` has been called
2017-07-06 06:30:13 +02:00
Jonas Jenwald
9c95614bb6 Ensure that PDFFindBar._adjustWidth is called in all situations where the width of the findbar might have changed
After PR 8394, where the l10n service was converted to be asynchronous, we're no longer calling `_adjustWidth` after updating the `findMsg` label. Hence it's currently possible that the width of the findbar won't be correct. The solution is simple though, just call `_adjustWidth` after the `findMsg` label has been (asynchronously) updated.

Another existing issue, which was an oversight in PR 8132, is that `PDFFindBar.updateResultsCount` may be called directly from `PDFFindController`. In that case, we're not calling `_adjustWidth` at all, which means that the findbar may also not have the correct width.
The simple solution here is to always call `_adjustWidth` at the end of `updateResultsCount` (which is why we no longer need the `_adjustWidth` call at the end of `updateUIState`).
2017-07-05 11:34:14 +02:00
Jonas Jenwald
cb0009dab4 Actually reset the findResultsCount label, in addition to hiding it, when no matches are found
Currently we're *only* hiding the label, but not actually resetting it until a new match is found.
Obviously it's being hidden, but it seems that it really ought to be completely reset as well (since e.g. `PDFFindBar.reset` won't technically reset *all* state otherwise).
2017-07-05 11:19:29 +02:00
Jonas Jenwald
614e8cf295 Change var to let, and use object destructuring, in a couple of previously class converted web/*.js files
Note that these files were among the first to be converted to ES6 classes, so it probably makes sense to do another pass to bring them inline with the most recent ES6 conversions.
2017-07-03 11:22:49 +02:00
Jonas Jenwald
d64ac95a91 ES6-ify the code in web/app.js and web/viewer.js
The changes consist mostly of changing `var` to `let`/`const`, and using shorthand method signatures.
2017-06-30 10:10:01 +02:00
Tim van der Meij
19f56ec5c1
Convert the text layer builder to ES6 syntax 2017-06-29 23:41:25 +02:00
Jonas Jenwald
f6369fc87c ES6-ify the code in web/ui_utils.js
These changes consists mainly of replacing `var` with `let`/`const`, adding a couple of default parameters to function signatures, and finally converting `EventBus`/`ProgressBar` to proper classes.
2017-06-28 12:35:12 +02:00
Jonas Jenwald
d4b93bec96 Remove the selectScaleOption helper function, in Toolbar._updateUIState, and simply inline its code instead
After PR 8510, we now always lookup the localized `page_scale_percent` string to prevent any possible ordering issues. Since the scaleSelect dropdown is updated asynchronous, there's really no point in having a helper function any more, hence this code can rather be placed inline in `Toolbar._updateUIState`.
2017-06-26 13:06:24 +02:00