Commit Graph

11273 Commits

Author SHA1 Message Date
Tim van der Meij
e3e7ccc3e2
Merge pull request #10255 from Snuffleupagus/renderMatches-less-scrollMatchIntoView
Avoid unnecessary `PDFFindController.scrollMatchIntoView` calls in `TextLayerBuilder._renderMatches` when `highlightAll` is set (PR 10201 follow-up)
2018-11-16 23:04:00 +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
960213cb69
Merge pull request #10244 from dardinier/fix-webpack-example
Fix webpack example
2018-11-12 23:31:09 +01:00
Alexis Dardinier
2011345315 Update versions in webpack example
Fix package.json after review
2018-11-12 11:15:17 +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
Tim van der Meij
b9c03cd667
Merge pull request #10245 from Snuffleupagus/scrollPageIntoView
Update `BaseViewer.scrollPageIntoView` to always validate the `pageNumber` parameter
2018-11-09 23:02:17 +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
Tim van der Meij
2194aef03e
Merge pull request #10238 from Snuffleupagus/interfaces
Move the `interface` definitions out of `src/core/worker.js` and into their own file
2018-11-08 23:28:46 +01:00
Tim van der Meij
0dfedacc6d
Merge pull request #10233 from Snuffleupagus/PDFObjects-class
[api-minor] Convert `PDFObjects`, in `src/display/api.js`, to an ES6 class
2018-11-08 23:22:48 +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
4829f567c1 Move the interface definitions out of src/core/worker.js and into their own file
These interfaces are already used in different files, in both the `src/core/` and `src/display/` folders, and having them reside in their own file seems a lot clearer and is also similar to the existing viewer interfaces.

As part of moving the `interface` definitions, they're also converted to ES6 classes.
2018-11-08 13:21:37 +01:00
Jonas Jenwald
60da2d882b [api-minor] Refactor/simplify the PDFObject class
First of all, note how there's currently *two* methods for checking if a certain object exists, which seems completely unwarranted.
Furthermore, the rarely used `getData` method was removed and its only callsite changed to use a combination of `PDFObjects.{has, get}` instead.
Finally, the methods were rearranged slightly, to bring the most important ones (for an API user) to the top of the class.
2018-11-08 10:13:39 +01:00
Jonas Jenwald
d32321d84f Convert PDFObjects, in src/display/api.js, to an ES6 class
Also changes all occurrences of `var` to `const`, and marks internal properties/methods as "private".
2018-11-08 10:11:40 +01:00
Tim van der Meij
3e342554d1
Merge pull request #10228 from morille/patch-2
Don't detect nw.js as node.js
2018-11-07 23:51:01 +01:00
Tim van der Meij
744a693554
Merge pull request #10219 from Snuffleupagus/ps-parser-class
Convert `src/core/ps_parser.js` to use ES6 classes
2018-11-07 23:15:01 +01:00
Romain Petit
13b0ca6b2a Don't detect nw.js as node.js
nw.js is chrome plus nodejs.
It will succeed everywhere chrome succeeds, but fail in many cases where nodejs succeeds (see issue 9071).
So it's safer to consider it as a browser context rather than a nodejs context.

Make travis happy again

CS

Readability + Explanation

The relevant portion of the NW.js documentation:
http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context

Added full link to relevant doc.
2018-11-07 11:14:22 +01:00
Jonas Jenwald
a963d139dc Convert src/core/ps_parser.js to use ES6 classes
Besides being a fairly small and self-contained file, this code also shows a possible way of defining static constants on classes.
2018-11-03 17:43:06 +01:00
Tim van der Meij
45758dd2d5
Merge pull request #10217 from Snuffleupagus/findagain-position-reset
For repeated 'findagain' operations, attempt to reset the search position if the user has e.g. scrolled in the document (issue 4141)
2018-11-03 16:05:41 +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
Tim van der Meij
ec76aa531e
Merge pull request #10202 from Snuffleupagus/issue-10200
Attempt to clean-up/restore pending rendering operations on `RenderTask.cancel` (issue 10200)
2018-11-02 23:11:47 +01:00
Tim van der Meij
f6bc93402e
Merge pull request #10096 from Snuffleupagus/rm-attachDOMEventsToEventBus
Remove the `attachDOMEventsToEventBus` functionality, since `EventBus` instances are able to re-dispatch events to the DOM (PR 10019, bug 1492849 follow-up)
2018-11-01 23:27:26 +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
Tim van der Meij
7053b5a146
Merge pull request #10203 from Snuffleupagus/canvasInRendering-WeakSet
Change `canvasInRendering` to a `WeakSet` instead of a `WeakMap`
2018-10-31 22:59:20 +01:00
Tim van der Meij
bb5f261c58
Merge pull request #10201 from Snuffleupagus/find-less-updatePage
Reduce the number of redundant `updatetextlayermatches` events dispatched when calculating matches in `PDFFindController`
2018-10-31 22:29:40 +01:00
Jonas Jenwald
f23dba1c10 Change canvasInRendering to a WeakSet instead of a WeakMap
Note how nowhere in the code `canvasInRendering.get()` is ever called, and that this structure is really only used to store references to `<canvas>` DOM elements.
The reason for this being a `WeakMap` is probably because at the time we weren't using `core-js` polyfills yet, and since there already existed a manually implemented `WeakMap` polyfill it was probably simpler to use that.
2018-10-31 18:15:23 +01:00
Jonas Jenwald
f77b463339 Attempt to clean-up/restore pending rendering operations on RenderTask.cancel (issue 10200)
Please note that, given the lack of a runnable example, I'm not totally sure if this first of all is enough to *completely* address the issue as filed and second of all if we actually want this new behaviour.
2018-10-31 16:22:17 +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
Tim van der Meij
74b5d0b022
Merge pull request #10196 from Snuffleupagus/findbarclose-findagain-highlightAll
[Regression] Ensure that "Highlight All" is propagated to all pages for 'findagain' events where the findbar was previously closed (PR 10100 follow-up)
2018-10-29 23:12:37 +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
Tim van der Meij
a77ac5fa23
Merge pull request #10185 from Snuffleupagus/find-less-normalization
Reduce the number of redundant text normalization operations in `PDFFindController`
2018-10-28 13:31:15 +01:00
Tim van der Meij
ed4ac1bc67
Merge pull request #10162 from janpe2/svg-normalize-bbox
Normalize BBox of form XObjects in SVG back-end
2018-10-28 13:18:48 +01:00
Tim van der Meij
c76c9878be
Merge pull request #10188 from timvandermeij/download-button
Hide the beta version button on the website if there is only a stable version
2018-10-27 21:01:13 +02:00
Tim van der Meij
2b5bc6bcec
Hide the beta version button on the website if there is only a stable version 2018-10-27 20:57:01 +02:00
Tim van der Meij
31bff2d950
Merge pull request #10187 from timvandermeij/bump
Bump versions in `pdfjs.config`
2018-10-27 17:02:11 +02:00
Tim van der Meij
7c6c56214f
Bump versions in pdfjs.config 2018-10-27 16:55:23 +02: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