Commit Graph

2371 Commits

Author SHA1 Message Date
Jonas Jenwald
4773bf6fcb Add support for updating the document hash, off by default, when the browser history is updated (issue 5753)
This is *really* the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.

I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:
 - It's already possible to easily obtain the current hash, by simply clicking on the `viewBookmark` button at any time.
 - Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see `PDFHistory._popState`). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
 - It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the `file://` protocol).
This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during `pushState`/`replaceState` calls.

---
[1] Using the `historyUpdateUrl` viewer preference.

[2] This depends, to a great extent, on browsers always firing `popstate` events *before* `hashchange` events, which may or may not actually be guaranteed.
2019-01-06 20:09:02 +01:00
Jonas Jenwald
d46715210a Accept non-matching document fingerprints, in PDFHistory, when the viewer is reloaded (issue 6847)
This should hopefully be sufficient to address issue 6847, and given the limited impact of the code changes I'm not completely sure if this would need to be controlled by a preference!?

Initially my intention was to try and provide some (slightly more detailed) implementation suggestions in the issue, but having looked briefly at doing that it would essentially have amounted to actually writing the code anyway. (Especially considering that the recent questions seemed to more-or-less ignore the information already provided in the first post.)

Finally, note that since `performance.navigation.type` is marked as deprecated, a slightly different approach was choosen instead.
2019-01-06 17:02:39 +01:00
Tim van der Meij
103f4616ac
Merge pull request #10334 from Snuffleupagus/OpenAction-dest
[api-minor] Add support for OpenAction destinations (issue 10332)
2018-12-23 20:49:50 +01:00
Jonas Jenwald
f0719ed565 [api-minor] Change the getViewport method, on PDFPageProxy, to take a parameter object rather than a bunch of (randomly) ordered parameters
If, as PR 10368 suggests, more parameters should be added to `getViewport` I think that it would be a mistake to not change the signature *first* to avoid needlessly unwieldy call-sites.

To not break any existing code and third-party use-cases, this is obviously implemented with a deprecation warning *and* with a working fallback[1] for the old method signature.

---
[1] This is limited to `GENERIC` builds, which should be sufficient.
2018-12-21 11:55:20 +01:00
Jonas Jenwald
a7e70a50f5 Add OpenAction destination support, off by default, to the viewer
Given that it's really not clear to me if this is actually desired functionality in the default viewer, and considering that it doesn't fit in *great* with the way that `PDFHistory` is initialized, this feature is currently off by default[1].

---
[1] It's controlled with the `disableOpenActionDestination` Preference/AppOption.
2018-12-19 11:45:17 +01:00
Thiago da Silva
811c8803b3 Fix small visual quirk in thumbnail viewer 2018-12-18 22:48:26 +01:00
Thiago da Silva
2abea7d7c2 Add keyboard shortcut to toggle sidebar 2018-12-16 13:00:15 -02:00
Brendan Dahl
826893e6f4 Use high DPI icons on semi-high DPI screens.
The icons looks really fuzzy on a machine with a device pixel ratio of
1.5. Using the 2x icons looks much better.
2018-12-14 16:27:38 -08:00
Jonas Jenwald
5d594885de Attempt to ignore mouse wheel zooming during tab switches (bug 1503412)
This patch re-factors, and extends, the already existing `zoomDisabledTimeout` used during mouse wheel zooming.
Unfortunately I haven't got the required hardware to actually test this patch, but there's a decent chance that it will fix, or at least reduce, the problems reported in https://bugzilla.mozilla.org/show_bug.cgi?id=1503412.
2018-12-12 13:46:47 +01:00
Jonas Jenwald
89e479dd6c Tweak the PDFHistory._tryPushCurrentPosition method to work better with the different Scroll/Spread viewer modes
Given that a larger number of pages may now be visible at once, and importantly that their layout may be non-vertical, one of the conditions should be tweaked to not accidentally miss cases where a page is still visible.

Please note: This patch is based on code-inspection, and the only ill effect occurring without it would be a couple of (near) duplicate history entries in some *rare* edge-cases.
2018-12-07 15:06:58 +01:00
Jonas Jenwald
0dc995c7e0 In GENERIC builds, dispatch a "webviewerloaded" event (from the webViewerLoad function) before initializing the viewer
With the removal of the global `PDFJS` object, in PDF.js version `2.0`, the viewer options are no longer as easily accessible as they previously were (and issues have been filed about this).
In particular, since the viewer files aren't necessarily loaded *immediately*, this means that `PDFViewerApplication`/`PDFViewerApplicationOptions` aren't necessarily available directly. By dispatching an event once all viewer files are loaded but *before* the viewer initialization has run, setting `AppOptions` during load (in custom implementations of the default viewer) should hopefully become a little bit easier[1].

---
[1] In hindsight, this should probably have been implemented when the global `PDFJS` object was removed...
2018-11-30 10:04:30 +01:00
Jonas Jenwald
d9743e462d Replace the OVERRIDES list in PDFViewerApplication._readPreferences with a disablePreferences, in GENERIC builds, `AppOption instead
Rather than having a (somewhat) randomly choosen list of Preferences which `AppOptions` are allowed to override, it makes much more sense to simply add an AppOption to allow custom implementations to ignore Preferences altogether (it's also inline with the AppOption that allows the `ViewHistory` to be bypassed on load).
2018-11-29 11:46:40 +01:00
Wojciech Maj
9921f92a36 Enable eslint-plugin-import to prevent unresolved paths 2018-11-23 13:50:28 +01:00
Wojciech Maj
616135962a Fix badly formatted .eslintrc 2018-11-23 13:49:58 +01:00
PalmerAL
5f15dc2023 Use span instead of div in the text layer
This improves copy/pasting text content since it reduces the amount of unnecessary newlines.
2018-11-18 15:54:08 +01:00
Jonas Jenwald
9a47a86565 Attempt to tweak the error messages, in BaseViewer, for invalid pageNumbers/pageLabels (bug 1505824)
Rather than closing [bug 1505824](https://bugzilla.mozilla.org/show_bug.cgi?id=1505824) as WONTFIX (which is my preferred solution), given how *minor* this "problem" is, it's still possible to adjust the error messages a bit.

The main point here, which is relevant even if the changes in `BaseViewer` are ultimately rejected during review, is that we'll no longer attempt to call `BaseViewer.currentPageLabel` with an empty string from `webViewerPageNumberChanged` in `app.js`.

The other changes are:
 - Stop printing an error in `BaseViewer._setCurrentPageNumber`, and have it return a boolean indicating if the page is within bounds.
 - Have the `BaseViewer.{currentPageNumber, currentPageLabel}` setters print their own errors for invalid pages.
 - Have the `BaseViewer.currentPageLabel` setter no longer depend, indirectly, on the `BaseViewer.currentPageNumber` setter.
 - Improve a couple of other error messages.
2018-11-17 17:23:09 +01:00
Jonas Jenwald
9a677ce51a Avoid unnecessary PDFFindController.scrollMatchIntoView calls in TextLayerBuilder._renderMatches when highlightAll is set (PR 10201 follow-up)
When `highlightAll` is *not* set, there's only going to be a single match per page and unconditionally calling `PDFFindController.scrollMatchIntoView` doesn't really matter.
However, when `highlightAll` is set the current code may result in a large number of unnecessary `PDFFindController.scrollMatchIntoView` calls. Since `TextLayerBuilder._renderMatches` already checks if a particular match is the selected one, for highlighting purposes, it's simple enough to also skip scrolling completely for non-selected matches.
2018-11-14 15:42:15 +01:00
Tim van der Meij
4724ebbcf1
Merge pull request #10231 from Snuffleupagus/find-no-scroll-highlightAll
Stop scrolling the document when "Highlight All" is toggled in the findbar (issue 5561)
2018-11-10 20:37:47 +01:00
Tim van der Meij
5b1b5730a1
Merge pull request #10220 from Snuffleupagus/find-less-scrolling
Only scroll search results into view as a result of an actual find operation, and not when the user scrolls/zooms/rotates the document (bug 1237076, issue 6746)
2018-11-10 20:29:02 +01:00
Tim van der Meij
5706961452
Merge pull request #10223 from Snuffleupagus/find-reset-on-query-change
When the search query changes, regardless of the search command, always re-calculate matches (bug 1030622)
2018-11-10 20:10:22 +01:00
Jonas Jenwald
06609b5337 Prevent errors if PDFFindController.executeCommand is ever called without a state object
Most of the code in `PDFFindController` assumes that a valid `state` always exits, hence it cannot hurt to add a simple check to avoid errors being thrown.
2018-11-09 11:32:19 +01:00
Jonas Jenwald
8afb550218 When the search query changes, regardless of the search command, always re-calculate matches (bug 1030622)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1030622
2018-11-09 11:32:19 +01:00
Jonas Jenwald
de6b0fd12d Stop scrolling the document when "Highlight All" is toggled in the findbar (issue 5561)
This is consistent with the general, e.g. HTML, search functionality of the Firefox browser.
2018-11-09 11:31:59 +01:00
Jonas Jenwald
fd87f13521 Only scroll search results into view as a result of an actual find operation, and not when the user scrolls/zooms/rotates the document (bug 1237076, issue 6746)
Currently searching, and particularily highlighting of search results, may interfere with subsequent user-interactions such as scrolling/zooming/rotating which can result in a somewhat jarring UX where the document suddenly "jumps" to a previous position.
This is especially annoying in cases where the highlighted search result isn't even visible when a user initiated scrolling/zooming/rotating happens, and there exists a couple of bugs/issues about this behaviour.

It seems reasonable, as far as I'm concerned, to treat searching as one operation and any subsequent non-search user interactions with the viewer as separate and thus not scroll the current search result into view *unless* the user is actually doing another search.
This also seems consistent with general searching in e.g. Firefox and Adobe Reader:
 - Compare with "regular" searching of e.g. HTML files in Firefox, where the user scrolling and/or zooming the document will not force a currently highlighted search result to become re-scrolled into view.
 - Compare also with Adobe Reader, where the user scrolling, zooming, and/or rotating the document will not force the currently highlighted search result to become re-scrolled into view.

The question is then why search highlighting was implemented this way in PDF.js to begin with. It might be that this wasn't really intended behaviour, but more a consequence of the asynchronous nature of the API. Considering that most operations, such as fetching the page, rendering it and extracting its text-content are all asynchronous; searching and highlighting of matches thus becomes asynchronous too.
However, it should be possible to track when search results have been scrolled into view and highlighted, and thus prevent these wierd "jumps" when the user interacts with the document.

*Please note:* Unfortunately this required moving the scrolling of matches back into `PDFFindController`, since I simply couldn't see any other (reasonable) way of implementing the functionality without tracking the `_shouldScroll` property in only *one* spot.
However, given that the new `PDFFindController.scrollMatchIntoView` method follows a similar pattern as `BaseViewer.scrollPageIntoView` and `PDFThumbnailViewer.scrollThumbnailIntoView`, this is hopefully deemed OK.
2018-11-09 11:30:45 +01:00
Jonas Jenwald
e16e072cb3 Directly call _setCurrentPageNumber when updating the Scroll/Spread modes in BaseViewer
Given that the `_updateScrollMode`/`_updateSpreadMode` methods are "private", there's no particular reason to not just directly call `_setCurrentPageNumber`.
2018-11-09 10:16:40 +01:00
Jonas Jenwald
2e38b7d00b Update BaseViewer.scrollPageIntoView to always validate the pageNumber parameter
Note that when e.g. presentation mode is active, we fail[1] to ensure that the `pageNumber` parameter is actually an integer before calling `_setCurrentPageNumber` (that method expects the argument be an integer).
Also changes the method signature, of `scrollPageIntoView`, to use object destructuring instead.

---
[1] Most likely, this is actually *my* oversight :-)
2018-11-09 09:58:37 +01:00
Jonas Jenwald
6bb7492fae Simply export the various interface definitions, rather than disabling ESLint, in web/interfaces.js 2018-11-08 13:21:46 +01:00
Jonas Jenwald
d805d799ff For repeated 'findagain' operations, attempt to reset the search position if the user has e.g. scrolled in the document (issue 4141)
Currently we'll only attempt to start from the current page when a new search is done, however for 'findagain' operations we'll always continue from the last match position.
This could easily lead to confusing behaviour if the user has scrolled to a completely different part of the document. In an attempt to improve this somewhat, for repeated 'findagain' operations, we'll instead reset the position to the current page when it's *absolutely* certain that the user has scrolled.

Note that this required adding a new `BaseViewer` method, and exposing that through `PDFLinkService`, in order to check if a given page is visible.
In an attempt to avoid issues, in custom implementations of `PDFFindController`, the code checks for the existence of the `PDFLinkService.isPageVisible` method *before* using it.
2018-11-03 12:03:11 +01:00
Jonas Jenwald
d7941b4ce7 Add a helper method, in PDFFindController, to determine if matches need to be re-calculated when a new search operation occurs 2018-11-03 11:52:48 +01:00
Jonas Jenwald
af99d1dc08 Attempt to improve readability of PDFFindController.executeCommand by (slightly) refactoring the code responsible for calling PDFFindController._nextMatch
Unfortunately the `PDFFindController.executeCommand` method has now become a bit more complicated than one would like, but hopefully this small change will improve the structure somewhat (especially for subsequent patches).
2018-11-03 11:48:40 +01:00
Jonas Jenwald
4b9d0a67d2 Inline the 'scalechanging' event dispatching in BaseViewer._setScaleUpdatePages
With only *one* event now being dispatched when the scale changes, in combination with there only being two call-sites, it doesn't seem necessary to keep the helper method for dispatching the 'scalechanging' event.
2018-10-31 23:32:39 +01:00
Jonas Jenwald
e2e9657ed0 Remove the attachDOMEventsToEventBus functionality, since EventBus instances are able to re-dispatch events to the DOM (PR 10019, bug 1492849 follow-up)
This also removes the old 'pagechange'/'scalechange'/'documentload' events.
2018-10-31 23:32:39 +01:00
Jonas Jenwald
014b7a3147 Reduce the number of redundant updatetextlayermatches events dispatched when calculating matches in PDFFindController
Currently `PDFFindController._calculateMatch` is (indirectly) dispatching an `updatetextlayermatches` event for every *single* page of the document. For short documents, such as the `tracemonkey` file, this probably doesn't matter too much, but for documents with a couple of thousand pages it seems unfortunate.

It shouldn't be necessary, in general, to dispatch `updatetextlayermatches` events here, since that's already being taken care of in `PDFFindController._updateMatch` which is always called when a match has been found.
However, when `highlightAll` is set we still need to ensure that pages which finished rendered *before* searching begun are updated correctly.
2018-10-31 16:05:12 +01:00
Tim van der Meij
42b7bb4751
Merge pull request #10190 from Snuffleupagus/_getCurrentVisiblePage
Add a helper method for `_getVisiblePages`, in `BaseViewer`, for the case where only a single page is displayed in the viewer
2018-10-29 23:19:32 +01:00
Jonas Jenwald
96abb4bbe7 [Regression] Ensure that "Highlight All" is propagated to all pages for 'findagain' events where the findbar was previously closed (PR 10100 follow-up)
**STR:**
1. Open the default viewer, with the `tracemonkey` file.
2. Open the findbar, and search for "trace".
3. Enable the "Highlight All" option.
4. Close the findbar.
5. Re-open the findbar, and click on the "findNext" button.
6. Scroll down to the *second* page of the document.

**ER:**
Since "Highlight All" is active, all matches on the *second* page should be highlighted.

**AR:**
No matches are highlighted on the *second* page.
2018-10-29 19:50:29 +01:00
Jonas Jenwald
2a79bcbe45 Add a helper method for _getVisiblePages, in BaseViewer, for the case where only a single page is displayed in the viewer
This is relevant for e.g. `PDFSinglePageViewer`, and `PDFViewer` with Presentation Mode active.
By moving this code to a helper method in `BaseViewer`, it's thus possible to reduce the amount of duplicate code that currently needed in `PDFViewer` and `PDFSinglePageViewer`.
2018-10-28 14:59:31 +01:00
Tim van der Meij
991a574c60
Merge pull request #10184 from Snuffleupagus/findbarclose-abort
Ensure that matches are not scrolled into after the findbar has been closed (PR 10100 follow-up)
2018-10-28 14:01:03 +01:00
Tim van der Meij
04ce2afd4a
Merge pull request #10182 from Snuffleupagus/TextLayerBuilder-rm-findController-checks
Small clean-up of the search related methods in `TextLayerBuilder`
2018-10-28 13:45:01 +01:00
Jonas Jenwald
5dc12f9a6d Only normalize the search query once, in `PDFFindController, for every page being searched
For a short document, such as e.g. the `tracemonkey` file, this repeated normalization won't matter much, but for documents with a couple of thousand pages it seems completely unnecessary (and wasteful) to keep repeating the normalization whenever for every single page.
2018-10-27 11:44:24 +02:00
Jonas Jenwald
84ae4f9a5e Only normalize the text-content once, in PDFFindController, and not on every new search operation
Currently the text-content is normalized every time that a new search operation is started, which seems completely useless considering that the "raw" text-content is never used for anything.
For a short document, such as e.g. the `tracemonkey` file, this repeated normalization won't matter much, but for documents with a couple of thousand pages it seems completely unnecessary (and wasteful) to keep repeating the normalization whenever e.g. a new search operation starts.
2018-10-26 20:23:32 +02:00
Jonas Jenwald
12d8b52c49 Move the normalize helper function out of PDFFindController
In the event that multiple instances of `PDFFindController` ever exists simultaneously, they will all be able to share just one `normalize` function in this way. Furthermore, the regular expression is now created lazily rather than at class construction time.
2018-10-26 18:22:32 +02:00
Jonas Jenwald
64d75c32bf Ensure that matches are not scrolled into after the findbar has been closed (PR 10100 follow-up)
Despite all highlighted matches being removed in response to the 'findbarclose' event, there's a risk that a match could still be scrolled into view *after* the findbar has been closed[1].
Hence we need to ensure that long running searches, particularily those happening in large and/or slow loading documents[2], are ignored as well.

---
[1] The match is hidden, as expected, but the document could still scroll unexpectedly.
[2] Large documents loaded with `disableAutoFetch = true` and `disableStream = true` set are particularily susceptible to this issue.
2018-10-26 12:43:12 +02:00
Jonas Jenwald
27b21f2558 Add a _updateAllPages helper method to PDFFindController in order to reduce the amount of event dispatching
Given that dispatching the 'updatetextlayermatches' event with `pageIndex = -1` set is now used to target the textLayers of *all* pages, there's no need to send individual events to every single page during `_nextMatch`. Since there can be an arbitrary number of pages in a document, this small/simple optimization seems too easy to ignore.
2018-10-26 11:50:44 +02:00
Jonas Jenwald
d73a71fb90 Small clean-up of the search related methods in TextLayerBuilder
This patch does four things:
 - Change the search related methods in `TextLayerBuilder` to be "private", since there're only called from within the class itself now.
 - Use `const` for local variables not intended to change in the search related methods in `TextLayerBuilder`.
 - Finally, removes most `this.findController` checks since they are redundant. Note how both `this._convertMatches` and `this._renderMatches` are *only* ever called, from `this._updateMatches`, when `this.findController` is actually defined. Hence there's really no need to repeat those checks all over the place, especially with all the relevant methods now being marked as "private".
 - Always initialize the `this._pageMatchesLength` property with an empty array, to simplify the code in `TextLayerBuilder`.
2018-10-25 21:38:25 +02:00
Jonas Jenwald
5bb7f4b615 Convert PDFDataRangeTransport to an ES6 class 2018-10-20 17:15:27 +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
df8d9f45f9 Add missing pagesCount getter to IPDFLinkService and SimpleLinkService 2018-10-11 10:29:15 +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
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