Commit Graph

607 Commits

Author SHA1 Message Date
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
Jonas Jenwald
66a3aa28fd Reduce duplication in the accumulateWheelTicks/accumulateTouchTicks methods (PR 15886 follow-up)
It just occurred to me that we can reduce some duplication by having the, virtually identical, `accumulateWheelTicks`/`accumulateTouchTicks` methods use a common helper instead that takes advantage of [bracket notation](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics#bracket_notation).
2023-01-04 18:19:39 +01:00
Calixte Denizet
d6b7a1f034 [api-minor] Add the pinch-to-zoom feature (bug 1677933) 2023-01-04 16:00:46 +01:00
Jonas Jenwald
88432a0e3f Improve name consistency in the viewer (PR 15812 follow-up)
This tweaks a few name that originated in PR 15812, to improve overall consistency:
 - Use the `drawingDelay` parameter-name in all methods that accept a delay.
 - Use the `postponeDrawing` variable-name in all relevant methods.
2022-12-28 13:26:01 +01:00
Jonas Jenwald
4224984525 Only display the pageNumber-loadingIcon when rendering is currently running
*This makes the same kind of changes as in the previous patch, but for the pageNumber-loadingIcon in the main toolbar.*

To display the pageNumber-loadingIcon when rendering starts, if the page is the most visible one, we'll utilize the existing "pagerender" event.
To toggle the pageNumber-loadingIcon as the user moves through the document we'll now instead utilize the "pagechanging" event, which should actually be slightly more efficient overall[1]. Note how we'd, in the old code, only consider the most visible page anyway when toggling the pageNumber-loadingIcon.

---
[1] Even in a PDF document as relatively short/simple as `tracemonkey.pdf`, scrolling through the entire document can easily trigger the "updateviewarea" event more than a thousand times.
2022-12-27 13:28:39 +01:00
Calixte Denizet
663007a5c7 Only redraw after zooming is finished (bug 1661253)
Right now, the visible pages are redrawn for each scale change.
Consequently, zooming with mouse wheel or in pinching can be pretty janky
(even on a desktop machine but with a hdpi screen).
So the main idea in this patch is to draw the visible pages only once zooming
is finished.
2022-12-26 18:13:17 +01:00
calixteman
1ab711e2ac
Merge pull request #15830 from calixteman/dont_compute_rect
Avoid to compute the client rect of the viewer
2022-12-17 12:34:40 +01:00
Calixte Denizet
c550953c6d Avoid to compute the client rect of the viewer
The container position and dimensions should be almost constant, hence
it's pretty useless to query them on each rescale.
Finally it avoids to trigger some reflows.
2022-12-16 20:55:29 +01:00
Jonas Jenwald
0289038961 [GeckoView] Ignore the pageLayout, from the PDF document, to prevent issues
First of all, given the screen-sizes of most mobile phones using Spread modes is unlikely to be useful.
Secondly, and more importantly, since there's (currently) no UI available for the user to override a PDF document-specified Spread mode this would result in a bad UX otherwise.

Also, removes an outdated comment from the `apiPageLayoutToViewerModes` helper function.
2022-12-16 12:09:56 +01:00
Jonas Jenwald
4bd66a2150 Protect a few additional DOM element accesses in the viewer (PR 15831 follow-up)
A couple of cases that I missed during review, for code-paths that don't run by default in the viewer.
2022-12-15 18:48:10 +01:00
Calixte Denizet
f19572c4cc [GV] Add a viewer for GeckoView 2022-12-15 13:39:48 +01:00
Jonas Jenwald
9369adb4bd Remove the unused DefaultExternalServices.createDownloadManager options (PR 12191 follow-up) 2022-12-03 12:52:36 +01:00
Calixte Denizet
eed9bf71c5 Refactor the text layer code in order to avoid to recompute it on each draw
The idea is just to resuse what we got on the first draw.
Now, we only update the scaleX of the different spans and the other values
are dependant of --scale-factor.
Move some properties in the CSS in order to avoid any updates in JS.
2022-12-01 18:42:43 +01:00
Jonas Jenwald
0d648f531b Ignore PDF documents opened from "data:"-URLs when handling internal links (bug 1803050)
This patch has been successfully tested in a local, artifact, Firefox build.

*Please note:* The only thing that'll no longer work for PDF documents opened using "data:"-URLs is middle-clicking on internal/outline links, in order to open the destination in a new tab. This is however an extremely small loss of functionality, and as can be seen in the bug the alternative (i.e. doing nothing) is surely much worse.
2022-11-29 14:08:01 +01:00
Calixte Denizet
b9cb651c44 [api-minor] Remove all the useless telemetry stuff in the viewer (bug 1802468)
Add a deprecation notification for PDFDocumentLoadingTask.onUnsupportedFeature and PDFDocumentProxy.stats
which are likely useless.
The unsupported feature stuff have initially been added in (#4048) in order to be able to display a
warning bar and to help to have some numbers to know how a feature was used.
Those data are no more used in Firefox.
2022-11-28 20:55:15 +01:00
Calixte Denizet
38dd219d85 Unblock the load event when the pdf has a password (bug 1801341) 2022-11-23 11:17:58 +01:00
Jonas Jenwald
2f238a11c1 Stop localizing error *details* in the viewer (PR 15533 follow-up)
While it can't hurt to localize the main error-messages, also localizing the error *details* has always seemed somewhat unnecessary since those are only intended for debugging/development purposes. However, I can understand why that's done since the GENERIC viewer used to expose this information in the UI; via the `errorWrapper` UI that's removed in PR 15533.

At this point, when any errors are simply logged in the console, it no longer seems necessary to keep localizing the error *details* in the default viewer.
2022-10-06 13:09:39 +02:00
Jonas Jenwald
6bd5ef29ae Log the build number, in addition to the version, in the viewer
Given that the `build` number allows you to *directly* find the relevant commit, it cannot hurt to log that one as well.
2022-10-06 12:03:22 +02:00