Commit Graph

624 Commits

Author SHA1 Message Date
Jonas Jenwald
c4c8227d20 Re-factor updating of thumbnails in the PDFSidebar-class
This patch does two things:
 - Moves the updating of thumbnails into `web/app.js`, via a new `PDFSidebar` callback-function, to avoid having to include otherwise unnecessary parameters when initializing a `PDFSidebar`-instance.
 - Only attempt to generate thumbnail-images from pages that are *cached* in the viewer. Note that only pages that exist in the `PDFPageViewBuffer`-instance can be rendered, hence it's not actually meaningful to check every single page when updating the thumbnails.
   For large documents, with thousands of pages, this should be a tiny bit more efficient when e.g. opening the sidebar since we no longer need to check pages that we know have not been rendered.
2023-05-28 17:54:34 +02:00
Jonas Jenwald
0e604f8f42 Use local variables more in PDFViewerApplication._initializeViewerComponents 2023-05-28 15:33:23 +02:00
Jonas Jenwald
bc8523ac29 Introduce a "thumbnailrendered" event to simplify cleanup after thumbnail rendering (PR 12613 follow-up)
The way that the cleanup was implemented in PR 12613 has always bothered me slightly, since the `isPageCached`-method that I introduced there always felt quite out-of-place in the `IPDFLinkService`-implementations.
By introducing a new "thumbnailrendered" event, similar to the existing "pagerendered" one, we're able to move the cleanup handling into the `PDFViewer`-class instead.
2023-05-26 15:30:22 +02:00
Calixte Denizet
7f1e8d1920 [GeckoView] Add some telemetry for the toolbar buttons (bug 1829216) 2023-05-22 16:43:09 +02:00
Tim van der Meij
ac8032628b
Merge pull request #16424 from Snuffleupagus/core-optional-chaining
Introduce more optional chaining in the `src/core/` folder
2023-05-18 12:40:08 +02:00
calixteman
5f91d39f13
Merge pull request #16425 from calixteman/gv_nimbus
[GeckoView] Add a Nimbus experiment for the toolbar (bug 1833093)
2023-05-15 18:26:28 +02:00
Calixte Denizet
4ed512ab2c [GeckoView] Add a Nimbus experiment for the toolbar (bug 1833093) 2023-05-15 17:18:14 +02:00
Jonas Jenwald
1b4a7c5965 Introduce more optional chaining in the src/core/ folder
After PR 12563 we're now free to use optional chaining in the worker-thread as well. (This patch also fixes one previously "missed" case in the `web/` folder.)

For the MOZCENTRAL build-target this patch reduces the total bundle-size by `1.6` kilobytes.
2023-05-15 12:38:28 +02:00
Jonas Jenwald
8f3940fbf3 Move the sidebar-resizing handling into the PDFSidebar class
Originally the `PDFSidebarResizer` class was slightly larger, since the code used to contain e.g. feature testing for older (and no longer supported) browsers.
Given that there's some amount of overlap, when it comes to what DOM-elements and state that these classes need, it now seems reasonable to simply move the sidebar-resizing into the `PDFSidebar` class.

For the MOZCENTRAL build-target this patch reduces the size of the *built* `web/viewer.js` file by just over `1.1` kilobytes.
2023-05-12 10:00:12 +02:00
Calixte Denizet
a652dc85e4 [GeckoView] Add a button to download and open the file in an external app (bug 1829367) 2023-05-05 15:52:15 +02:00
Jonas Jenwald
317abd6d07 Change the createPromiseCapability helper function into a PromiseCapability class
This is not only slightly more compact, but it also simplifies the handling of the `settled` getter.
2023-04-29 13:43:24 +02:00
Jonas Jenwald
95bf9fc17f Remove SystemJS usage, in development mode, from the worker
Now that https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 has landed in Firefox, we're able to use worker-modules during development :-)

This removes the final piece of SystemJS usage from the PDF.js library, thus allowing a fair bit of clean-up, and we now use *only* native `import`/`export` statements everywhere in development mode.
2023-04-29 13:43:24 +02:00
Jonas Jenwald
804aa896a7 Stop using the PRODUCTION build-target in the JavaScript code
This *special* build-target is very old, and was introduced with the first pre-processor that only uses comments to enable/disable code.
When the new pre-processor was added `PRODUCTION` effectively became redundant, at least in JavaScript code, since `typeof PDFJSDev === "undefined"` checks now do the same thing.

This patch proposes that we remove `PRODUCTION` from the JavaScript code, since that simplifies the conditions and thus improves readability in many cases.
*Please note:* There's not, nor has there ever been, any gulp-task that set `PRODUCTION = false` during building.
2023-04-17 12:04:34 +02:00
Jonas Jenwald
0e19c3a120 [api-minor] Add support, in PDFFindController, for mixing phrase/word searches (issue 7442)
*Please note:* This patch only extends the `PDFFindController` implementation itself to support this functionality, however it's *purposely* not exposed in the default viewer.

This replaces the previous `phraseSearch`-parameter, and a `query`-string will now always be interpreted as a phrase-search.
To enable searching for individual words, the `query`-parameter must instead consist of an Array of strings. This way it's now also possible to combine phrase/word searches, with a `query`-parameter looking something like `["Lorem ipsum", "foo", "bar"]` which will search for the phrase "Lorem ipsum" *and* the words "foo" respectively "bar".
2023-04-15 13:32:37 +02:00
Calixte Denizet
7f0d45ce47 [GeckoView] Show the download button by default and add a pref to disable it (bug 1827963)
For the moment there is no real consensus on how we should download a pdf on Android.
Hence we keep this solution for the moment but behind a pref (which will be true on
nightly only).
2023-04-13 20:33:03 +02:00
Calixte Denizet
3b147205ba [GeckoView] Add a basic toolbar with a download button for GV (bug 1823164) 2023-04-07 11:54:16 +02:00
Jonas Jenwald
c2f1e65cc3 [api-minor] Remove SVG-rendering from the viewer (PR 15173 follow-up) 2023-04-02 15:23:45 +02:00
Jonas Jenwald
40a96a2524 [Firefox] Stop using a baseUrl in the PDFLinkService (PR 16153 follow-up)
With the changes in PR 16153 we're no longer setting a `<base href>` in the Firefox PDF Viewer, hence it shouldn't be necessary to keep setting a `baseUrl` in the `PDFLinkService`-class.
Given that the original document URL is now kept, the browser itself will handle relative URLs and we can thus slightly reduce the amount of string parsing required when handling various links in the viewer.
2023-03-30 11:51:25 +02:00
Calixte Denizet
e9474f1c84 [api-minor] Add an option to set the max canvas area 2023-03-08 10:37:06 +01:00
Jonas Jenwald
6985286300 Remove the unused eventBus option in PDFThumbnailViewer (PR 15215 follow-up)
This became unused with PR 15215, but I unfortunately forgot to remove it.
2023-02-12 18:38:31 +01:00
Jonas Jenwald
0e070c805e Slightly re-factor preferences/options initialization in the viewer
Given that the debugging hash-parameters will only be used when the `pdfBugEnabled` option is manually set[1], we can skip a *tiny* bit of asynchronicity for "regular" users.

---
[1] Note that it's enabled by default in the development viewer, i.e. in `gulp server` mode.
2023-02-10 15:45:39 +01:00
Jonas Jenwald
6c158da5a8 Limit AppOptions._hasUserOptions to only GENERIC builds
It's completely unused elsewhere, e.g. in the Firefox PDF Viewer.
2023-02-10 15:37:51 +01:00
Calixte Denizet
c92ba393c2 Fix pinch-to-zoom on mac for the Firefox builtin viewer
In the mac case we don't want to care about the scaleFactor threshold
because else if too big another move could start and then subsequent
events aren't considered as wheel events.
It isn't really ideal and at some point we'll need to find a way at
least for the Firefox case to get the real events instead of the fake
wheel ones.
2023-02-08 15:04:41 +01:00
Jonas Jenwald
72abcedf48
Merge pull request #16018 from Snuffleupagus/GeckoView-skip-pageLabels
[GeckoView] Skip fetching/parsing of pageLabels
2023-02-07 21:36:30 +01:00
Jonas Jenwald
00560ed830
Merge pull request #16009 from Snuffleupagus/GeckoView-viewer-bundle-size
[GeckoView] Reduce the size of the *built* viewer
2023-02-07 18:28:44 +01:00
Jonas Jenwald
a348162c5b [GeckoView] Skip fetching/parsing of pageLabels
Currently there's no toolbar in the GV-viewer, hence invoking the pageLabels functionality isn't meaningful and just leads to unnecessary parsing on both the main- and worker-threads. (And if a toolbar is added at some point, it's not clear to me if we'd want to support pageLabels in the GV-viewer anyway.)
2023-02-07 16:20:27 +01:00
Jonas Jenwald
8c4843f69a [GeckoView] Introduce a development mode constant to tell the viewers apart
Currently we have a couple of pre-processor checks, specifically for the GV-viewer, spread throughout the code. This works fine when *building* the viewer, however they're obviously ignored in development mode (i.e. `gulp server`).
This leads to a situation where the GV development viewer, i.e. http://localhost:8888/web/viewer-geckoview.html, behaves subtly different from its built version. This could easily lead to bugs, hence this patch introduces a development mode constant to hopefully improve things here.

Finally, in a follow-up to PR 15842, also ignores the `pageMode`-state since there's no sidebar available.
2023-02-07 16:07:12 +01:00
Jonas Jenwald
0cf4fbd471 [GeckoView] Avoid unused outline, attachments, and layers fetching
Currently there's no UI for this functionality in the GV-viewer, however we still call the API methods. This potentially leads to a bunch of worker-thread parsing, for PDF documents with these features, despite the result being completely unused.
Given that mobile devices are usually more resource constrained than desktop/laptop computers, not to mentioned battery life, we can avoid doing work that'll just be ignored anyway.
2023-02-07 12:30:05 +01:00
Jonas Jenwald
a98e80c4ff [GeckoView] Reduce the size of the *built* viewer
Given that the GV-viewer isn't using most of the UI-related components of the default-viewer, we can avoid including them in the *built* viewer to save space.[1]
The least "invasive" way of implementing this, at least that I could come up with, is to leverage import maps with suitable stubs for the GV-viewer.

The one slightly annoying thing is that we now have larger import maps across multiple html-files, and you'll need to remember to update all of them when making future changes.

---
[1] With this patch, the built `viewer.js` size is 391 kB and `viewer-geckoview.js` is 285 kB.
2023-02-05 14:12:32 +01:00
Tim van der Meij
05d821e680
Merge pull request #16007 from Snuffleupagus/getDocument-params-init
Re-factor the parameter parsing/validation in `getDocument`
2023-02-05 13:16:59 +01:00
Jonas Jenwald
512aa50fdd Re-factor the parameter parsing/validation in getDocument
This is very old code, where we loop through the user-provided options and build an internal parameter object. To prevent errors we also need to ensure that the parameters are correct/valid, which is especially important for the ones that are sent to the worker-thread such that structured cloning won't fail.[1]

Over the years this has led to more and more code being added in `getDocument` to validate the user-provided options, and at this point *most* of them have at least basic validation. However the way that this is implemented feels slightly backwards, since we first build the internal parameter object and only *afterwards* validate those parameters.[2]

Hence this patch changes the `getDocument` function to instead check/validate the supported options upfront, and then *explicitly* build the internal parameter object with only the needed properties.

---
[1] Note the supported types at https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types

[2] The internal parameter object may also, because of the loop, end up with lots of unnecessary properties since anything that the user provides is being copied.
2023-02-05 11:52:25 +01:00
Jonas Jenwald
d9181236b2 [GENERIC viewer] Simplify the keyboard find-again state building
By using modern JavaScript features, we can ever so slightly reduce the amount of code needed here.
2023-02-04 23:16:04 +01:00
Jonas Jenwald
d6178a13d7 Reduce a tiny bit of duplication in the webViewerInitialized function 2023-02-04 23:16:04 +01:00
Jonas Jenwald
d930f267f6 Remove a couple of unnecessary PresentationMode-checks in webViewerKeyDown
Given that the `PDFViewerApplication.{zoomIn, zoomOut}` methods already contain PresentationMode-checks, this is just unnecessary duplication.
2023-02-04 23:15:56 +01:00
Jonas Jenwald
ea1ec7ffab Remove a couple of unnecessary pdfDocument checks in web/app.js
These functions invoke the `PDFViewer.currentPageNumber` setter, which already checks that a `pdfDocument` is currently active. Also, given that they're event handlers for the First/Last-page buttons (in the SecondaryToolbar) they can't be invoked before the viewer has been fully initalized.
2023-02-04 22:17:53 +01:00
Tim van der Meij
b75dafba87
Merge pull request #15987 from Snuffleupagus/onOpenWithTransport-params
Remove unused parameters from the `onOpenWithTransport` method in `PDFViewerApplication.initPassiveLoading`
2023-02-04 15:07:42 +01:00
Jonas Jenwald
94a235db93 [GeckoView] Don't initalize the cursor-tools, since they're unused
The reasons for making this change are:
 - There's no UI available to toggle the cursor-tools in the GeckoView-specific viewer.
 - The `HandTool`-implementation basically *simulates* touch scrolling, and is thus unlikely to be helpful/useful anyway.
 - PR 15831 already changed the relevant call-sites to handle `PDFViewerApplication.pdfCursorTools` being undefined.
2023-02-03 18:20:36 +01:00
Jonas Jenwald
d906a383ca Remove a couple of manual loops in the PDFViewerApplication.open method
Some of the code in this method is *very* old, and we could thus modernize it a little bit by removing a couple of the loops used to build the `getDocument` argument.
2023-02-03 14:55:07 +01:00
Jonas Jenwald
cf8ee47589 Remove unused parameters from the onOpenWithTransport method in PDFViewerApplication.initPassiveLoading
The only parameter that we actually need here is the `PDFDataRangeTransport`-instance, since the others are not necessary.
 - The `url` parameter, as passed to the `getDocument` function in the API, is simply being ignored; see 2d87a2eb1c/src/display/api.js (L447-L458)
 - The `length` parameter, as passed to the `getDocument` function in the API, is always being overwritten; see 2d87a2eb1c/src/display/api.js (L519-L525)
2023-02-01 09:33:22 +01:00
Jonas Jenwald
5e88228767 Allow, optionally, using worker-modules during local development
Until PR 12563 is deemed safe to land, I'd still like to be able to use worker-modules in the viewer during local development.
Hence this patch which *temporarily* adds a new `workerModules` hash-parameter, only available in non-PRODUCTION mode, that allows using worker-modules in the development viewer.

To enable this functionality, simply use http://localhost:8888/web/viewer.html#workerModules=true
2023-01-31 12:09:44 +01:00
Jonas Jenwald
6129be7b68 Change the PDFViewerApplication.open method to only accept objects
If this method was added today, I really can't imagine that we'd support anything *except* objects. Unfortunately we cannot just remove this now, since the code has existed since "forever", however we can deprecate this and limit it to only the GENERIC build.

Furthermore, we can avoid a redundant `PDFViewerApplication.setTitleUsingUrl` call in the Firefox PDF Viewer since the title has already been set previously in that case.
2023-01-28 18:55:22 +01:00
Calixte Denizet
1cb482be6a Try to avoid to interpret wheel events as pinch-to-zoom ones (bug 1810800) 2023-01-24 20:12:12 +01:00
Jonas Jenwald
d7013bee54 Move the disableAutoFetch functionality into the ProgressBar-class
It seems nicer overall, since we're exporting the `ProgressBar` in the viewer-components, to move this functionality into the `ProgressBar`-class itself rather than handling it "manually" in the default-viewer.
2023-01-21 12:32:34 +01:00
Jonas Jenwald
eee65e4b6e Add a PDFViewerApplication helper method to center the position after wheel/pinch-zooming
This avoids having to repeat the same code twice, now that we support both wheel- and pinch-zooming.
2023-01-19 13:35:35 +01:00
calixteman
dafcf82365
Merge pull request #15909 from calixteman/pinch_trackpad
Add support for smooth pinch-to-zoom on a trackpad (bug 1659492)
2023-01-11 16:26:21 +01:00
Calixte Denizet
f5dcc69ea1 Add support for smooth pinch-to-zoom on a trackpad (bug 1659492)
- Scale factor is rounded to only scale by integer percent, hence the unused
  ticks are accumulated (like we already do for zoom with the mouse wheel).
- Use the same thing for the pinch-to-zoom on a touchscreen: it led to slightly
  refactor the code because it happened to ignore a not so small scale which
  led to a not so smooth zooming.
2023-01-11 15:14:33 +01:00
Calixte Denizet
8068dff9d1 Simplify PDFViewerApplication::supportsPrinting (follow-up of #15894) 2023-01-11 12:33:33 +01:00
Calixte Denizet
0c1cf2c237 Fix pinch-to-zoom on a macbook trackpad (bug 1809080) 2023-01-09 13:48:46 +01:00
Calixte Denizet
661f425934 [GV] Add an option in the find controller to update matches count only when the last page is reached (bug 1803188).
In GeckoView, on an event, a callback must be executed with the result of an action,
but the callback can be used only one time.
So for each FindInPage event, we must trigger only one matches count update.
2023-01-06 10:56:26 +01:00
Calixte Denizet
409c8b344f [GV] Remove print stuff because window.print isn't implemented (bug 1808668) 2023-01-05 13:02:29 +01:00