Commit Graph

3859 Commits

Author SHA1 Message Date
Tim van der Meij
42edc4d895
Merge pull request #16630 from Rob--W/crx-url-hash-init
Correct recognition of fragments at document load
2023-07-08 14:05:33 +02:00
Calixte Denizet
5c5f9af803 [Editor] Edit an existing FreeText annotation in double-clicking on it (bug 1787298) 2023-07-07 17:44:45 +02:00
Calixte Denizet
37bd78c707 [Editor] Add a basic stamp editor (bug 1790255)
For now it allows to add a stamp annotation with an image selected from the file system.
2023-07-06 11:27:50 +02:00
Rob Wu
1d07ef401e [CRX] Re-initialize initialBookmark after URL rewrite
`PDFViewerApplication` reads from `location.hash` to initialize
`initialBookmark`. But when extensions/chromium/pdfHandler.js prepares
the redirect URL, the reference fragment is encoded instead of bare.
`rewriteUrlClosure` in `chromecom.js` is responsible for decoding the
URL, but that currently runs too late.

To fix this, update `initialBookmark` after rewriting the URL.

This was not a problem in the past because `rewriteUrlClosure` in
`chromecom.js` executed before the initialization of `initialBookmark`.
2023-07-02 15:28:33 +02:00
Jonas Jenwald
58252a528d Inline the webViewerInitialized function in PDFViewerApplication.run
Given the size of this function respectively method, it seems reasonable to simply inline the `webViewerInitialized`-code here.
2023-07-02 11:43:28 +02:00
Jonas Jenwald
cae8fe4c7e Move the setTitleUsingUrl-call into PDFViewerApplication.initPassiveLoading
This seems overall nicer, rather than having to "manually" call this when initializing passive loading.
2023-07-02 11:43:16 +02:00
Tim van der Meij
8a954823b5
Merge pull request #16616 from Snuffleupagus/PDFCursorTools-tweaks
A couple of small tweaks of the `PDFCursorTools` class
2023-07-01 13:04:44 +02:00
Jonas Jenwald
be775143b2 [api-minor] Remove the CSS.supports checks for the pageColors-option in the GENERIC viewer
Given the browsers that we currently support it's probably not necessary to keep the checks for the color-values.
2023-06-30 18:37:16 +02:00
Jonas Jenwald
f373fcb356 Remove a couple of unused options from the GrabToPan constructor
These options are completely unused in the PDF.js viewer, and given that the last update of the `GrabToPan`-code from upstream was in 2016 it shouldn't hurt to remove them.
2023-06-29 13:16:10 +02:00
Jonas Jenwald
d329267926 Use Element.scrollTo unconditionally in the GrabToPan class
According to the MDN compatibility data this is available in all browsers that we currently support; please see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo#browser_compatibility
2023-06-28 12:43:36 +02:00
Jonas Jenwald
4f82dd3932 Create a GrabToPan-instance lazily in the PDFCursorTools class
Unless the user enables the "HandTool" we don't actually need to create a `GrabToPan`-instance.
2023-06-28 12:43:36 +02:00
Jonas Jenwald
789e318cf7 A couple of small tweaks of the PDFCursorTools class
- Introduce a few private fields for internal state.

 - Inline a small method at its only call-site.
2023-06-28 12:43:34 +02:00
Jonas Jenwald
a024cd0127 Re-factor how HCM highlight-filters are handled in the viewer components (PR 16593 follow-up)
This is something that I completely overlooked during review of PR 16593, since the idea is (obviously) that the viewer-components should be usable as-is without the user needing to manually pass in any *additional* parameters.

To support this we can very easily expose the current `FilterFactory`-instance on the `PDFPageProxy`-class[1], and if needed initialize the highlight-filters when initializing the page (again limited to the viewer-components).
2023-06-26 23:37:39 +02:00
calixteman
c4a61a7692
Merge pull request #16593 from calixteman/popup_hcm
Improve highlightments and popups in HCM (bug 1830850)
2023-06-26 16:34:17 +02:00
Jonas Jenwald
80b4708fa3 [GeckoView] Remove the enableFloatingToolbar preference
Note that we'll now display the toolbar unconditionally in GeckoView.
2023-06-26 15:17:03 +02:00
Calixte Denizet
c519cc821b Improve highlightments and popups in HCM (bug 1830850)
- Modify the text and background colors in popup to fit a11y requirements
- Add a backdrop filter on clickable areas in using a svg filter mapping
  canvas colors to Highlight and HighlightText ones.
2023-06-26 14:45:03 +02:00
Jonas Jenwald
5f5db4b160 Run the PDF.js-viewer API unit-test in Node.js environments (PR 16592 follow-up)
It occurred to me that we can actually run this unit-test in Node.js environments by making use of the preprocessor to stub out the browser globals there.
2023-06-26 09:37:34 +02:00
Tim van der Meij
fa95bbce12
Merge pull request #16569 from Snuffleupagus/PDFScriptingManager-private
[api-minor] Re-factor the `PDFScriptingManager` class to use private fields/methods
2023-06-24 19:50:17 +02:00
Tim van der Meij
436699b0db
Merge pull request #16592 from Snuffleupagus/rm-viewer-component-default-factory
[api-minor] Remove the default-factories from the viewer components (PR 15811 follow-up)
2023-06-24 19:39:37 +02:00
Jonas Jenwald
7667f55e45 [Firefox] Simplify FirefoxPreferences._readFromStorage (PR 16583 follow-up)
Now that https://bugzilla.mozilla.org/show_bug.cgi?id=1840064 has landed in mozilla-central we can implement the final piece of clean-up for the `FirefoxPreferences._readFromStorage` method.
2023-06-24 18:37:43 +02:00
Jonas Jenwald
e153e3a741 Expose FindState in the viewer-components (issue 16589) 2023-06-24 13:23:02 +02:00
Jonas Jenwald
f596490a1b Add a unit-test to check that the *official* PDF.js-viewer API exposes the expected functionality
Until now we've not actually had *any* tests that ensure that the *official* PDF.js-viewer API exposes the intended functionality, which means that things can easily break accidentally.

*Please note:* This unit-test cannot (easily) be run in Node.js-environments, since the `external/webL10n/l10n.js` file contains various browser-specific functionality.
2023-06-23 12:22:54 +02:00
Jonas Jenwald
c5e4a22ee0 [api-minor] Remove the default-factories from the viewer components (PR 15811 follow-up)
The changes in PR 15811 have now been included in no less than six official releases, hence it should hopefully be OK to remove this now.
2023-06-23 11:54:30 +02:00
Jonas Jenwald
547b8276e6 [api-minor] Re-factor the PDFScriptingManager class to use private fields/methods
- Change (most) fields/methods into private ones, since that's now supported.
 - Tweak the constructor-parameters, and simplify the sandbox initialization w.r.t. the viewer components.
 - Remove some unused function/method parameters.
 - Slightly simplify the "updatefromsandbox"-handler by using local variables and inverting some conditions.
2023-06-22 08:09:58 +02:00
Jonas Jenwald
cca299eeb9 [GeckoView] Ignore Scroll/Spread-modes in the PDFViewer setters
Rather than sprinkling pre-processor statements throughout the viewer-code, simply "disable" the relevant `PDFViewer` setters instead.

Also, given that the GeckoView-specific viewer doesn't have a sidebar we don't actually need to explicitly ignore a `pageMode` during loading.
2023-06-22 08:09:58 +02:00
Jonas Jenwald
fe1c36a0ed Move the fixupLangCode helper function into the web/genericl10n.js file
This helper function was added almost two years ago, in PR 13696, and it still has only a single call-site. Furthermore, with the changes made in PR 16572 it also cannot hurt to reduce the size of the `web/l10n_utils.js` file slightly.
2023-06-21 21:42:53 +02:00
Jonas Jenwald
5c0872d1b0 [Firefox] Avoid unnecessary string-parsing when reading preferences
Note how the [`ChromeActions.getPreferences` method](https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#497-530) returns the preferences as a string, which we then have to convert back into an Object in the viewer.
Back when that code was originally written it wasn't possible to send Objects from the platform-code, however that's no longer the case and we should be able to (eventually) remove this unnecessary string-parsing now.

*Please note that in order to prevent breakage we'll need to land these changes in stages:*
 - Land this patch in mozilla-central, as part of regular the PDF.js updates.
 - Change the return type in the `ChromeActions.getPreferences` method, in a mozilla-central patch.
 - Remove the string-handling from the `FirefoxPreferences._readFromStorage` method.
2023-06-21 20:14:46 +02:00
Jonas Jenwald
1f9d1f3696 [Firefox] Disable the ability to change preferences directly from the viewer
Please note that we've never had any functionality in the viewer itself that *set* preferences, and we've thus only ever read them.
For the GENERIC viewer it obviously makes sense for the user to be able to modify preferences, e.g. via the console, but that doesn't really apply to the *built-in* Firefox PDF Viewer since preferences are already accessible via `about:config` there. Hence it does seems somewhat strange to expose, a limited part of, the Firefox preference system in this way when we're not even using it.

Note that the unused preference setting-code also include a fair amount of *additional* validation on the platform-side, such as limiting any possible preference changes to the `pdfjs.`-branch and also an explicit white-list of preference names[1], to make sure that this is safe; please see:
 - https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#458-495
 - https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/modules/AsyncPrefs.sys.mjs#21-48

Assuming that this patch lands, I'll follow-up with a mozilla-central patch to remove the code mentioned above.

---
[1] This hard-coded list contains preferences that no longer exist, and also at least one (fairly obvious) typo.
2023-06-21 20:14:16 +02:00
Jonas Jenwald
7f53fb82a5 Remove the OverlayManager.unregister method since it's completely unused
This method was added only for consistency with the `register`-method, however it's never actually been used. To avoid including dead code in the builds, let's just remove the `unregister`-method for now.

*Please note:* If this method ever becomes useful, it'll be trivial to revert this commit.
2023-06-21 13:13:53 +02:00
Jonas Jenwald
19880fcf9a [api-minor] Move the l10n-translation into the AnnotationLayer
With the changes in PR 16552 we can now move general translation into the `AnnotationLayer` itself, which should improve things ever so slightly in third-party implementations where the default viewer isn't used.
2023-06-20 20:28:35 +02:00
Jonas Jenwald
197e806c86 [api-minor] Ensure that the AnnotationLayer gets a default l10n-instance in GENERIC builds (PR 16552 follow-up)
*This is something that I completely overlooked during review of PR 16552, despite leaving a l10n-related comment.*

The new l10n-handling of PopupAnnotations assume that the `AnnotationLayer` is always initialized with a l10n-instance, which might not actually be the case in third-party implementations where the default viewer isn't used.
To work-around that we'll now bundle, and fallback on, the existing `NullL10n`-implementation in GENERIC builds of the PDF.js library. This will only result in a slight file-size increase for the *built* `pdf.js` file, again limited to GENERIC builds, since the `web/l10n_utils.js` file has no dependencies.

Also, tweaks a couple of TESTING pre-processor checks to *only* include that code when running the reference tests.
2023-06-20 20:28:29 +02:00
Calixte Denizet
d1e172458f [api-minor] Make the popup independent of their associated annotations
- it'll help to be able to move popups on screen to let the user read the text
- popups won't inherit some properties from their parent:
  - the popup can be misrendered if for example the parent has a clip-path property.
- add an outline to the popup when the parent is focused.
- hide a popup when it's clicked.
2023-06-20 15:30:39 +02:00
Calixte Denizet
dd21139405 Disable events on canvas in the annotation layer 2023-06-15 21:10:40 +02:00
Jonas Jenwald
fee850737b Enable the unicorn/prefer-optional-catch-binding ESLint plugin rule
According to MDN this format is available in all browsers/environments that we currently support, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#browser_compatibility

Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-optional-catch-binding.md
2023-06-12 11:46:11 +02:00
Calixte Denizet
9f861c39f4 [Editor] Connect then annotation layer and the editor one 2023-06-05 14:05:52 +02:00
Tim van der Meij
bb5d38acc1
Merge pull request #16495 from Snuffleupagus/PDFRenderingQueue-components
Limit some `PDFRenderingQueue`-related code to the GENERIC viewer
2023-06-03 12:33:18 +02:00
Calixte Denizet
4351708ae6 [api-minor] Make the AnnotationLayer an object in order to use it in the AnnotationEditorLayer
It'll be useful to make the Freetext and Ink annotations editable.
2023-06-02 22:44:14 +02:00
Jonas Jenwald
a60bb5f936 Don't use partially rendered pages to generate thumbnails when drawingDelay is used (PR 15812 follow-up)
While it's slightly difficult to trigger in practice, unless the `defaultZoomDelay`-value is increased, it's currently possible to generate thumbnails from *partially* rendered pages when doing *temporary* CSS-only zooming.
2023-06-01 19:01:57 +02:00
Jonas Jenwald
af8df207bb Don't dispatch "pagerendered"-events on the *temporary* CSS-only zooming done when drawingDelay is used (PR 15812 follow-up)
We shouldn't dispatch a "pagerendered"-event when doing *temporary* CSS-only zooming, but simply wait until the actual rendering is done.
While I don't believe that this regression has caused any actual bugs, dispatching *duplicate* events is nonetheless inconsistent and should be fixed.
2023-06-01 19:01:50 +02:00
Jonas Jenwald
e8c727742c Limit some PDFRenderingQueue-related code to the GENERIC viewer
Given that this functionality is only relevant in third-party use-cases, for example the viewer-components, we can avoid needlessly including it in e.g. the MOZCENTRAL build.
2023-05-30 21:24:19 +02:00
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
Jonas Jenwald
d0bf505312 Re-factor the isPageVisible-handling in the find-controller (PR 10217 follow-up)
The way that this was implemented in PR 10217 has always bothered me slightly, since the `isPageVisible`-method that I introduced there always felt quite out-of-place in the `IPDFLinkService`-implementations.
Hence this is instead replaced by a callback-function in `PDFFindController`, to handle the page-visibility checks. Note that since the `PDFViewer`-constructor always sets this callback-function, e.g. the viewer-component examples still work as-is.
2023-05-26 13:59:39 +02:00
Jonas Jenwald
76ca395c32 [GeckoView] Remove the Toolbar-stub since the viewer has an actual toolbar now 2023-05-24 12:31:27 +02:00
Calixte Denizet
d2b4ed3cea [Editor] Improve curve smoothing for Ink tool (bug 1789443)
- Remove the dependency on fit-curve;
- Improve the way to draw the current line in using a Path2D and
  in clearing only the last part of the curve instead of clearing
  all the canvas;
- Smooth the curve when drawing to avoid to have some changes after
  the drawing ends;
- Make the smoothing a bit less agressive.
2023-05-23 17:15:21 +02:00
Calixte Denizet
7f1e8d1920 [GeckoView] Add some telemetry for the toolbar buttons (bug 1829216) 2023-05-22 16:43:09 +02:00
Jonas Jenwald
14fd59c4d0 Stop trying to sort the attachments in the sidebar
Looking at the behaviour in Adobe Reader it doesn't appear that attachments are sorted alphabetically, hence it doesn't seem necessary for us to do so either in the viewer.
An additional benefit of *not* sorting the attachments is that any "actual" attachments are now always placed at the top of the list in the sidebar, and if any `FileAttachment`-annotations exist in the document they will now be appended at the end.
2023-05-21 09:54:24 +02:00
Jonas Jenwald
e8030752f3 Introduce even more modern JavaScript features in the code-base
After PR 12563 we're now free to use e.g. logical OR assignment, nullish coalescing, and optional chaining in the entire code-base.
2023-05-18 18:55:41 +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