Commit Graph

4145 Commits

Author SHA1 Message Date
Calixte Denizet
334f0eb060 [Editor] Add a toolbar to selected editors with a button to delete it (bug 1863763) 2023-11-10 15:19:43 +01:00
Jonas Jenwald
823d375b8b Ensure that the viewer waits for the library to complete loading (issue 17228)
This should *hopefully* fix 17228, by tweaking the build scripts to give the GENERIC viewer something to await to avoid breaking third-party users of the standalone viewer components.
2023-11-10 13:22:49 +01:00
Jonas Jenwald
bf016743fc Remove the "Open file"-button from the main toolbar
This button is *only* used in the GENERIC viewer, and will currently be visible either in the main or secondary toolbars (depending on the viewer width).
To simplify upcoming changes, and to avoid then having to complicate the relevant CSS rules unnecessarily, let's place the "Open file"-button permanently in the secondary toolbar instead.

(Note that the GENERIC viewer also, since five years, supports drag-and-drop in order to open local files.)
2023-11-09 08:08:17 +01:00
Jonas Jenwald
50f52b43a5
Merge pull request #17222 from Snuffleupagus/rm-viewerCssTheme
Remove the `viewerCssTheme`-option, since it's partially broken
2023-11-04 17:40:03 +01:00
Tim van der Meij
87c83ab31c
Merge pull request #17220 from Snuffleupagus/pr-17176-followup
Also pause translation when expanding the current outline-item (PR 17176 follow-up)
2023-11-04 15:29:14 +01:00
Jonas Jenwald
d46578e959 Remove the viewerCssTheme-option, since it's partially broken
The `viewerCssTheme`-implementation has always been somewhat hacky, and now it's also *partially* broken ever since we've started using CSS nesting.
Trying to support nested media queries would thus require a lot more parsing of the CSS rules, which seems inefficient and thus generally undesirable.[1]

As discussed on Matrix, let's try to remove the `viewerCssTheme`-option and see if there's any (significant) fallout from this.

---
[1] If this option is brought back, it seems to me that it (in Firefox) should probably be set through the platform-code that handles theming.
2023-11-04 09:19:01 +01:00
Jonas Jenwald
bf7e8126df Also pause translation when expanding the current outline-item (PR 17176 follow-up)
Depending on the structure of the outline we could potentially need to expand a few levels, especially in long PDF documents, hence it cannot hurt to pause translation in that case as well.
2023-11-03 13:26:36 +01:00
Jonas Jenwald
84aaafcd3e Use a limit when splitting URL-strings in web/app.js
This should be a *tiny* bit more efficient, since it avoids parsing substrings that we don't care about.
2023-11-03 10:53:19 +01:00
Jonas Jenwald
e20dabb65b Simplify how the docBaseUrl-option is handled in PDFViewerApplication.open
Reduce the "special" handling a bit here, by setting the viewer-option such that it'll be automatically included in the API-parameters.
2023-11-03 10:52:31 +01:00
Jonas Jenwald
8bbfcd3bef Re-factor how the canvasMaxAreaInBytes-option is handled in PDFViewerApplication.open (PR 17208 follow-up)
With the changes in PR 17208, where browser-preferences are now handled as "regular" viewer-options, we can tweak the definition of `canvasMaxAreaInBytes` to slightly simplify things in the `PDFViewerApplication.open` method.
2023-11-03 10:52:27 +01:00
Jonas Jenwald
ce9cfa2d72 Skip the PREFERENCE-branch in AppOptions.getAll in official builds
Given that this branch is only necessary in development mode and *during* building, but is never actually used in the final viewer-bundles, we can utilize the pre-processor to ignore this code.
2023-10-31 20:13:13 +01:00
Jonas Jenwald
eebc230cf1 [Firefox] Fetch browser preferences/options together with the viewer preferences (bug 1862192)
Currently we *synchronously* fetch a number of browser preferences/options, from the platform code, during the viewer respectively PDF document initialization paths.
This seems unnecessary, and we can re-factor the code to instead include the relevant data when fetching the regular viewer preferences.
2023-10-31 15:32:01 +01:00
Jonas Jenwald
26fc69f241
Merge pull request #17192 from Snuffleupagus/textLayer-pause-l10n
Pause translation when appending the textLayer and structTreeLayer to the page
2023-10-29 09:31:09 +01:00
Jonas Jenwald
80612f3714
Merge pull request #17184 from Snuffleupagus/xfaLayer-append-print
Handle appending consistently in the xfaLayer regardless of rendering intent (PR 17177 follow-up)
2023-10-28 22:33:17 +02:00
Jonas Jenwald
3f0b3b15de
Merge pull request #17196 from Snuffleupagus/annotationLayer-css-nesting
Use CSS nesting in the annotationLayer
2023-10-27 19:50:10 +02:00
Jonas Jenwald
7d5b970eee Collect the forced-colors CSS rules for linkAnnotation in one spot 2023-10-27 19:29:33 +02:00
Jonas Jenwald
b779e418a5 Use CSS nesting in the annotationLayer 2023-10-27 18:46:47 +02:00
Jonas Jenwald
525be9afea Use CSS nesting in the textLayer 2023-10-27 17:38:01 +02:00
Jonas Jenwald
d293048c5d Pause translation when appending the textLayer and structTreeLayer to the page
Note that we must append the textLayer to the DOM *before* enabling the `highlighter` and `accessibilityManager`, to avoid breaking e.g. a pending searching operation.
The least invasive solution, that I was able to come up with, is to introduce a new `TextLayerBuilder` callback-function for this purpose.
2023-10-27 16:55:46 +02:00
Jonas Jenwald
097f214222 Handle appending consistently in the xfaLayer regardless of rendering intent (PR 17177 follow-up)
After PR 17177 the interface of `XfaLayerBuilder` is now inconsistent, since whether or not we directly append the xfaLayer to the DOM now depends on the rendering intent.
2023-10-26 12:05:33 +02:00
Jonas Jenwald
399f444c84 Pause translation when appending the xfaLayer to the page 2023-10-25 20:33:39 +02:00
Jonas Jenwald
6b265b3a15 Pause translation when appending the outline/attachment/layer trees to the sidebar
Also, pause translation when collapsing/expanding subtrees.
2023-10-25 17:38:02 +02:00
Jonas Jenwald
0fc899338c
Merge pull request #17006 from Snuffleupagus/rm-enableStampEditor-pref
Remove the `enableStampEditor` preference
2023-10-25 16:24:49 +02:00
calixteman
f27f2bb403
Merge pull request #17165 from calixteman/improve_removenullchars
Slightly improve the performance of removeNullCharacters
2023-10-25 15:01:32 +02:00
Jonas Jenwald
846bd86520 Fix error that's breaking the ConstL10n class (PR 17161 follow-up)
I forgot to include `web/l10n_utils.js` in PR 17161, which currently breaks `ConstL10n` since there's no longer a method called `setL10n`; sorry about that!
2023-10-25 12:11:57 +02:00
Calixte Denizet
651057c039 Slightly improve the performance of removeNullCharacters
Most of the strings shouldn't contain special chars (<= 0x1F) so we can
have a fast path which just checks if the string contains at least one such
a char.
2023-10-25 10:11:14 +02:00
Jonas Jenwald
bcb01e5e2b Tweak the matchCount l10n-args handling slightly (PR 17146 follow-up)
Given that providing unused parameters in the l10n-args shouldn't be a problem, let's simplify the relevant JavaScript code a tiny bit.
2023-10-24 13:17:02 +02:00
Jonas Jenwald
e2af77fd6c Add a unit-test to ensure that NullL10n won't diverge from the L10n-class
To prevent the *standalone* viewer-components from breaking, we need to ensure that the `NullL10n`-interface won't accidentally diverge from the actual `L10n`-implementations.
2023-10-24 13:13:14 +02:00
Jonas Jenwald
04696080f8 Update the "aria-label" of the page when a pageLabel exists
Looking at the `PDFThumbnailView.setPageLabel` method you'll see that we update e.g. the "aria-label" of the thumbnail-image for documents that contain (valid) pageLabels.
This isn't done in `PDFPageView`, which seems inconsistent, hence this patch.
2023-10-23 13:42:06 +02:00
Jonas Jenwald
17af706070 [api-minor] Use "data-l10n-id"/"data-l10n-args", rather than manually updating DOM-elements, to trigger translation (PR 17146 follow-up)
This patch changes almost all viewer-components[1] to use "data-l10n-id"/"data-l10n-args" for localization, which means that in many cases we no longer need to pass around the `L10n`-instance any more.

One part of the code-base where the `L10n`-instance is still being used "directly" is the AnnotationEditors, however while it might be possible to convert (most of) that code as well that's not attempted in this patch.

---
[1] The one exception is the `PDFDocumentProperties` dialog, since the way it's currently implemented makes that less straightforward to fix without a lot of code changes.
2023-10-22 14:17:47 +02:00
Tim van der Meij
898cc2e399
Merge pull request #17151 from Snuffleupagus/Fluent-PDFDocumentProperties-fixes
A couple of `PDFDocumentProperties` tweaks (PR 17115 follow-up)
2023-10-22 12:33:34 +02:00
Jonas Jenwald
da186d1b89
Merge pull request #17146 from Snuffleupagus/NullL10n-refactor
[api-minor] Re-factor `NullL10n` and remove the hard-coded l10n strings (PR 17115 follow-up)
2023-10-21 17:53:30 +02:00
Jonas Jenwald
e20ef39f59 Use a ResizeObserver to update the layout of PDFFindBar
*Please note:* In the Firefox PDF Viewer this findbar is only used for PDF documents placed in e.g. `<iframe>` elements.

By registering a `ResizeObserver` when the `PDFFindBar` is open we slightly unify and simplify how the findbar layout (row vs column) is handled.
This will be especially helpful with upcoming changes, where we'll make use of "data-l10n-id"/"data-l10n-args" to trigger translation in the viewer.
2023-10-21 16:17:49 +02:00
Jonas Jenwald
7df082fce3 A couple of PDFDocumentProperties tweaks (PR 17115 follow-up)
- The old translation engine handled language code casing slightly differently, hence we need to tweak the non-metric locale check in `PDFDocumentProperties` to account for that.

 - Use only lowercase names for the pre-defined page names, to improve overall consistency.
2023-10-21 10:27:47 +02:00
Jonas Jenwald
f07675a6a8 [api-minor] Re-factor NullL10n and remove the hard-coded l10n strings (PR 17115 follow-up)
*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135).

After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes.
To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes:
 - Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones.

 - Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them.

 - Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer.

 - Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much.
   For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
2023-10-20 21:49:33 +02:00
Jonas Jenwald
5c14c559dd Initialize the L10n-instance as soon as possible in Firefox (PR 17115 follow-up)
Given that there's now a bit more asynchronicity in the l10n-initialization in the Firefox PDF Viewer, after PR 17115, try to limit the impact of that by moving it to occur a tiny bit earlier in the default viewer initialization.
2023-10-19 18:40:52 +02:00
Calixte Denizet
a0b9c937ae [L10n] Don't try to connect the root element when it has already been done
In Firefox debug builds, there is an assertion to check that we don't connect
a subelement of an already connected root. Thanks to this assertion, we can see
that the root has already been added to Fluent, hence we don't need to do it
a second time.
We don't need to await anymore on the translation in order to update the
toolbar: it'll be done by Fluent, so we can safely remove the "localized"
event and avoid to wait for it.
2023-10-19 18:19:05 +02:00
Jonas Jenwald
e820688510 Remove the enableStampEditor preference 2023-10-19 15:45:07 +02:00
Jonas Jenwald
d6cfbd2839
Merge pull request #17130 from Snuffleupagus/AppOption-move-init
Try to make the `Preferences`/`AppOptions` initialization slightly more efficient
2023-10-19 15:12:30 +02:00
Jonas Jenwald
5ddc949159 Try to make the Preferences/AppOptions initialization slightly more efficient
*Please note:* This patch contains a couple of micro-optimizations, hence I understand if it's deemed unnecessary.

Move the `AppOptions` initialization into the `Preferences` constructor, since that allows us to remove a couple of function calls, a bit of asynchronicity and one loop that's currently happening in the early stages of the default viewer initialization.

Finally, move the `Preferences` initialization to occur a *tiny* bit earlier since that cannot hurt given that the entire viewer initialization depends on it being available.
2023-10-19 14:44:55 +02:00
Jonas Jenwald
69ad0d9861 Only bundle NullL10n in GENERIC builds (bug 1859818) 2023-10-19 13:51:00 +02:00
Jonas Jenwald
482b789edf Use a CSS-only solution to set the dropdownToolbarButton width (issue 17137)
Note that CSS-features such as e.g. `flex` didn't exist, or had poor cross-browser support, back when the JavaScript-based solution was initially implemented.
2023-10-19 13:44:02 +02:00
calixteman
5d8be99782
Merge pull request #17115 from calixteman/mv_to_fluent
[api-minor] Move to Fluent for the localization (bug 1858715)
2023-10-19 13:40:50 +02:00
Calixte Denizet
66982a2a11 [api-minor] Move to Fluent for the localization (bug 1858715)
- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
  and then we rely on document.l10n which is a DOMLocalization object.
2023-10-19 11:20:41 +02:00
Jonas Jenwald
674052d3fc Re-factor the blob-URL caching in DownloadManager.openOrDownloadData
Cache blob-URLs on the actual data, rather than DOM elements, to reduce potential duplicates (note the updated unit-test).
2023-10-17 10:18:34 +02:00
Jonas Jenwald
d5acbbccd3 Update the ESLint globals list (PR 17055 follow-up)
Given that we only use standard `import`/`export` statements now, after recent PRs, the "exports" global is unused.
Instead we add "__non_webpack_import__" to the `globals` to avoid having to sprinkle disable statements throughout the code.

Finally, the way that `globals` are defined has changed in ESLint and we should thus explicitly specify them as "readonly"; please find additional details at https://eslint.org/docs/latest/use/configure/language-options#specifying-globals
2023-10-15 11:38:10 +02:00
Jonas Jenwald
5e986cb514 Use native import maps in development mode
This patch seem to work fine locally now, and `mozregression` points to it being fixed in bug https://bugzilla.mozilla.org/show_bug.cgi?id=1803984 which landed in Firefox 116.

By using the native `import maps` functionality, we can remove a development dependency. Please find the specification at https://wicg.github.io/import-maps/
2023-10-13 20:35:34 +02:00
Calixte Denizet
7851c0da8d [Debugger] Add some info about substitution font
When pdfBug is true, the substitution font is used in the text layer in order
to be able to know what is the font really used thanks to the devtools.
And to be sure that fonts are loaded, the font cache isn't cleaned up when
the debugger is active.
2023-10-09 12:06:33 +02:00
Jonas Jenwald
6ac3da0d1f Rename web/debugger.js since it's actually a JavaScript module (PR 17055 follow-up)
It's been loaded as a JavaScript module for a long time, and given that the file is bundled as-is (without building) it seems reasonable to just change the file extension now.
2023-10-08 13:16:42 +02:00
Tim van der Meij
bab4c7f617
Merge pull request #17055 from Snuffleupagus/output-modules
[api-major] Output JavaScript modules in the builds (issue 10317)
2023-10-07 15:02:59 +02:00
Tim van der Meij
89d8c639fa
Merge pull request #17077 from Snuffleupagus/css-rm-unneeded-alpha
Remove unnecessary alpha-value from CSS `rgb` colors
2023-10-07 12:33:48 +02:00
Jonas Jenwald
927e50f5d4 [api-major] Output JavaScript modules in the builds (issue 10317)
At this point in time all browsers, and also Node.js, support standard `import`/`export` statements and we can now finally consider outputting modern JavaScript modules in the builds.[1]

In order for this to work we can *only* use proper `import`/`export` statements throughout the main code-base, and (as expected) our Node.js support made this much more complicated since both the official builds and the GitHub Actions-based tests must keep working.[2]
One remaining issue is that the `pdf.scripting.js` file cannot be built as a JavaScript module, since doing so breaks PDF scripting.

Note that my initial goal was to try and split these changes into a couple of commits, however that unfortunately didn't really work since it turned out to be difficult for smaller patches to work correctly and pass (all) tests that way.[3]
This is a classic case of every change requiring a couple of other changes, with each of those changes requiring further changes in turn and the size/scope quickly increasing as a result.

One possible "issue" with these changes is that we'll now only output JavaScript modules in the builds, which could perhaps be a problem with older tools. However it unfortunately seems far too complicated/time-consuming for us to attempt to support both the old and modern module formats, hence the alternative would be to do "nothing" here and just keep our "old" builds.[4]

---
[1] The final blocker was module support in workers in Firefox, which was implemented in Firefox 114; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility

[2] It's probably possible to further improve/simplify especially the Node.js-specific code, but it does appear to work as-is.

[3] Having partially "broken" patches, that fail tests, as part of the commit history is *really not* a good idea in general.

[4] Outputting JavaScript modules was first requested almost five years ago, see issue 10317, and nowadays there *should* be much better support for JavaScript modules in various tools.
2023-10-07 09:31:08 +02:00
Jonas Jenwald
8158628a90 [api-minor] Stop building a minified default viewer
The minified default viewer has never been distributed in either official releases or through pdfjs-dist, which means that it's most likely unused, and it's has never been tested nor actively maintained.
2023-10-06 12:12:30 +02:00
calixteman
905ad1fe68
Merge pull request #16761 from calixteman/editor_add_new_with_keyboard
[Editor] Add the possibility to create a new editor in using the keyboard (bug 1853424)
2023-10-06 11:44:07 +02:00
Jonas Jenwald
4ebddcb092 Remove unnecessary alpha-value from CSS rgb colors
Setting the alpha-value explicitly to `1` in `rgb` colors is unnecessary, since that's the default value, and this way we ever so slightly reduce the size of our CSS files.
Unfortunately I've not found a Stylelint rule to enforce this automatically, and the patch was generated using search and replace.
2023-10-06 09:50:03 +02:00
Calixte Denizet
ea5eafa265 [Editor] Add the possibility to create a new editor in using the keyboard (bug 1853424)
When an editing button is disabled, focused and the user press Enter (or space), an
editor is automatically added at the center of the current page.
Next creations can be done in using the same keys within the focused page.
2023-10-05 22:49:15 +02:00
calixteman
2453b79fa8
Merge pull request #17074 from calixteman/issue17071
Make the toolbar buttons usable with keyboard when Page Fit is used
2023-10-05 20:28:56 +02:00
Calixte Denizet
3263fd0307 Make the toolbar buttons usable with keyboard when Page Fit is used 2023-10-05 18:33:03 +02:00
Jonas Jenwald
4277205d78 Enable some Stylelint color-related rules to slightly reduce file sizes
- Use a consistent format for all alpha-values (this rule didn't require any code changes); see https://stylelint.io/user-guide/rules/alpha-value-notation
 - Use modern and slightly shorter color notation, since [according to MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb#browser_compatibility) that should be supported "everywhere" nowadays; see https://stylelint.io/user-guide/rules/color-function-notation/
 - Use "short" hexadecimal colors whenever possible; see https://stylelint.io/user-guide/rules/color-hex-length/
 - Help avoid adding broken hexadecimal colors (this rule didn't require any code changes); see https://stylelint.io/user-guide/rules/color-no-invalid-hex/
2023-10-05 17:51:21 +02:00
calixteman
40d6b0e1bf
Merge pull request #17062 from calixteman/resize_keyboard
[Editor] Support resizing editors with the keyboard (bug 1854340)
2023-10-04 13:55:04 +02:00
Calixte Denizet
05ca3fd99b [Editor] Support resizing editors with the keyboard (bug 1854340) 2023-10-04 12:57:37 +02:00
Jonas Jenwald
bf9c33e60f Add support for "GoToE" actions with destinations (issue 17056)
This shouldn't be very common in practice, since "GoToE" actions themselves seem quite uncommon; see PR 15537.
2023-10-04 11:14:23 +02:00
Jonas Jenwald
426209c6e6
Merge pull request #16699 from Snuffleupagus/rm-svg
[api-major] Remove the SVG back-end (PR 15173 follow-up)
2023-10-03 15:13:14 +02:00
Jonas Jenwald
0edc490e1b
Merge pull request #16774 from Snuffleupagus/rm-deprecated-options
[api-major] Remove various deprecated functionality and options
2023-10-03 15:12:39 +02:00
Calixte Denizet
eebd251552 [Editor] Don't show the alt-text button when the alt-text dialog is visible
This way, the button doens't cover the image.
2023-10-02 20:34:30 +02:00
Jonas Jenwald
3ced0dec1b [api-major] Remove the SVG back-end (PR 15173 follow-up)
This has been deprecated since version `2.15.349`, which is a year ago.
Removing this will also simplify some upcoming changes, specifically outputting of JavaScript modules in the builds.
2023-10-01 23:14:29 +02:00
Jonas Jenwald
9624505f0f Use a standard export statement in the web/pdfjs.js file
This removes the only remaining old and non-standard handling of exports in the `web/`-folder, since some initial attempts at outputting JavaScript modules in the builds have identified this file as a potential problem.
While this uses a hard-coded list, for overall simplicity, I don't believe that that's a big problem since:
 - Generating this file automatically would require a bunch more parsing *every single time* that the library is built.
 - The official API-surface doesn't change often enough for this to really impede development in any significant way.
 - The added unit-test helps ensure that this list cannot accidentally become outdated.
2023-09-30 12:10:02 +02:00
Jonas Jenwald
52862893f5
Merge pull request #17026 from Snuffleupagus/layerProperties-Object
Convert `layerProperties` to an Object (PR 15811 follow-up)
2023-09-28 18:44:32 +02:00
calixteman
b6d75e736a
Merge pull request #17038 from ayushmourya/master
Make downloadManager optional in JSDoc types
2023-09-28 17:23:33 +02:00
Jonas Jenwald
03ce3b2d54 Convert layerProperties to an Object (PR 15811 follow-up)
Given that this is accessed multiple times per page in the viewer, that leads to a number of (strictly speaking unneeded) function calls and allocated Objects for each invocation. By converting `layerProperties` to a, lazily initialized, Object we can avoid this.
2023-09-28 17:20:23 +02:00
Calixte Denizet
4f6fa35a28 [Editor] Disable pointer events in the parent layer while an editor is resized 2023-09-28 15:09:50 +02:00
Jonas Jenwald
00c8fbe7e0
Merge pull request #17040 from Snuffleupagus/rm-save-disabled-CSS
[Editor] Remove unused CSS rules for the altText "Save"-button (PR 17015 follow-up)
2023-09-27 16:29:16 +02:00
Calixte Denizet
bdb8410ad4 [Editor] Disabled the alt-text button when the editor is being resized 2023-09-27 15:13:17 +02:00
Jonas Jenwald
880abd910e [Editor] Remove unused CSS rules for the altText "Save"-button (PR 17015 follow-up)
When PR 17015 removed the `disabled` handling for the "Save"-button it left a bunch of now unused CSS rules behind, which seems like a simply oversight.
Rather than shipping "dead" CSS rules, let's remove those until such a time that they're actually needed.
2023-09-27 14:58:22 +02:00
ayush
87a1baf29f docs: Make downloadManager optional in JSDoc 2023-09-27 12:47:50 +05:30
Calixte Denizet
71376f089c [Editor] Remove the class fooEditing from the layer when destroying it
and simplify the way to handle the different types of editors.
2023-09-25 18:56:11 +02:00
Jonas Jenwald
fc898e1b38 [Editor] Add padding to the altText-button to account for different locales
*For many non-English locales the translated strings will be longer, which is easy to forget about during development/review.*

Note how for some locales (e.g. Swedish) the altText-button end up looking horizontally "cramped", hence it seems reasonable to add a bit of inline padding to improve this.
2023-09-24 16:13:16 +02:00
Calixte Denizet
57caa4601c [Editor] The ::before containter containing the border of a selected editor mustn't catch mouse events (bug 1854818) 2023-09-23 23:53:19 +02:00
Jonas Jenwald
f87ec67ab1 [api-major] Remove various deprecated functionality and options 2023-09-23 17:44:09 +02:00
Jonas Jenwald
1df31c0284 Use one noContextMenu function in both the src/- and web/-folders
Currently we duplicate this event handler function in multiple places, which seems unnecessary.
2023-09-23 15:37:13 +02:00
Calixte Denizet
88f3ed7745 [Editor] Disable context menu on alt-text button and in the associated dialog
but keep it for the text area.
Disable pointerdown on the alt-text button to disable dragging the editor
when the button is clicked (especially when slightly moving the mouse
between the down and the up).
2023-09-22 23:27:55 +02:00
Jonas Jenwald
9e0e67918f [Editor] Report telemetry when closing the altText dialog with Esc (PR 16987 follow-up)
The dialog element handles closing with <kbd>Esc</kbd> automatically, however we're not reporting telemetry in that case.
In order to fix that the easiest solution, as far as I'm concerned, seem to be moving the telemetry reporting into the dialog-close handler since it's always invoked.
2023-09-22 22:20:49 +02:00
Jonas Jenwald
8c5da23f67 Don't reset this.#currentEditor when destroying the dialog
This patch addresses an edge-case that'll probably never happen, but it nonetheless seems like something that we want to fix.

Note how we're using the `#currentEditor`-field to prevent opening the dialog when it's already active, and it being reset once the dialog has been closed.
By also resetting the `#currentEditor`-field during destruction, instead of waiting until the dialog has actually closed (assuming it's currently open), there's a *tiny* window of time[1] during which we could theoretically allow to (incorrectly) re-open the dialog and thus getting out-of-sync state in the viewer-component.

---
[1] Since the "close" event, on a dialog-element, is dispatched asynchronously by the browser.
2023-09-22 21:53:26 +02:00
Calixte Denizet
d5936d9a15 [Editor] Let the Save button always enabled in the alt-text dialog 2023-09-22 20:46:29 +02:00
calixteman
f66613c8e4
Merge pull request #17005 from calixteman/alt_text_tweak_save_flow
[Editor] Tweak the save flow in the alt-text dialog
2023-09-22 17:45:49 +02:00
Jonas Jenwald
43c7e88fa9 Don't bother trying to unregister the "reporttelemetry" event listener
Note that both event-unbind methods are unused in MOZCENTRAL builds; see https://searchfox.org/mozilla-central/rev/48b6992e03fa66f77ac9688ba61c95d31a451bc1/toolkit/components/pdfjs/content/web/viewer.js#1864-1869
2023-09-22 17:24:32 +02:00
Calixte Denizet
050093c9f5 [Editor] Tweak the save flow in the alt-text dialog
When the user edit an existing alt-text and remove it, we want to be able
to save this state and consequently remove the done state from the
alt-text button.
Remove the button from its parent when the editor is removed: it should
help to save few Kb of memory.
2023-09-22 17:10:20 +02:00
calixteman
3f859f76e6
Merge pull request #17010 from calixteman/alt_text_mask_1
[Editor] Darken the toolbar when the alt-text dialog is opened
2023-09-22 13:34:57 +02:00
Calixte Denizet
0237e2eb2b [Editor] Darken the toolbar when the alt-text dialog is opened
It aims to fix the issue spotted in:
https://github.com/mozilla/pdf.js/pull/17002#issuecomment-1730962273
2023-09-22 13:11:37 +02:00
Jonas Jenwald
ee5b8bcf9e [Editor] Make the altText dialog labels part of telemetry (PR 16987 follow-up)
Radio-buttons can also be toggled by clicking on their associated `label`-elements, and not only the `input`-elements itself, however it seems that "pointerdown" event listeners don't cover that case.
Hence it's possible that telemetry could miss certain cases of a mouse being used, and the easiest solution seem to be to instead use "click" event listeners and just ignore keyboard-based events.
2023-09-22 12:26:03 +02:00
calixteman
2fc8ab3477
Merge pull request #17002 from calixteman/alt_text_mask
[Editor] Avoid to darken the current editor when opening the alt-text dialog
2023-09-22 12:17:21 +02:00
Calixte Denizet
6545551e76 [Editor] Avoid to darken the current editor when opening the alt-text dialog 2023-09-21 20:44:53 +02:00
Jonas Jenwald
9b21f17b03 Prevent wheel/touch zooming in the viewer when a dialog is open 2023-09-21 20:08:08 +02:00
Jonas Jenwald
5711d0f95d [GeckoView] Exclude annotation_editor_layer_builder.css in the build (issue 16994)
Given the limitations of the old pre-processor that's used for CSS/HTML files, this unfortunately isn't as "easy" to implement as it is for JavaScript code.
Since this is the first case where we've wanted to do conditional CSS imports, rather than trying to completely re-write the pre-processor, this patch settles for handling it explicitly in the `expandCssImports` function.
2023-09-21 15:51:33 +02:00
calixteman
a7894a4d7b
Merge pull request #16993 from Snuffleupagus/gv-no-AltTextManager
[GeckoView] Avoid bundling the `AltTextManager` class, since it's unused
2023-09-21 14:19:51 +02:00
Calixte Denizet
61c77c7d8b Make one of the m-c linters happy 2023-09-21 14:09:48 +02:00
Jonas Jenwald
80e691d2ad Enable the Stylelint declaration-block-no-duplicate-properties rule (issue 16995)
Please refer to https://stylelint.io/user-guide/rules/declaration-block-no-duplicate-properties
2023-09-21 13:42:05 +02:00
Jonas Jenwald
e2b7896826 [GeckoView] Avoid bundling the AltTextManager class, since it's unused 2023-09-21 12:51:34 +02:00
calixteman
561aea530b
Merge pull request #16991 from Snuffleupagus/alt_text_edit-boolean
Ensure that all "alt_text_*" save-telemetry values are boolean (PR 16987 follow-up)
2023-09-21 11:04:06 +02:00
calixteman
237b8ce4a8
Merge pull request #16988 from calixteman/alt_text_dialog_others
[Editor] Tweak few values after review from UX
2023-09-21 11:03:19 +02:00
calixteman
67ddabcbc2
Merge pull request #16990 from calixteman/alt_text_aria_label
[Editor] Add an aria-label to the alt-text button depending on its state
2023-09-21 10:56:25 +02:00
Calixte Denizet
b5d18006a7 [Editor] Tweak few values after review from UX 2023-09-21 10:52:58 +02:00
Jonas Jenwald
5660cdfe68 Ensure that all "alt_text_*" save-telemetry values are boolean (PR 16987 follow-up)
Looking at the save-telemetry values they're all boolean *except* for "alt_text_edit" in one instance, since `this.#previousAltText` may be an empty string (looking at the `editAltText` method) and this value may thus become an empty string as well.
2023-09-21 08:36:41 +02:00
Calixte Denizet
c90ea2314e [Editor] Add an aria-label to the alt-text button depending on its state 2023-09-20 21:56:16 +02:00
Jonas Jenwald
fe60db27b1 Use the new "reporttelemetry" event in more viewer components
By utilizing the recently added "reporttelemetry" event, we can avoid having to manually pass in `externalServices` to a number of viewer components.
2023-09-20 20:18:10 +02:00
Calixte Denizet
7d0bf376d0 [Editor] Change the colors for the disabled Save button in alt text dialoag in HCM 2023-09-20 18:58:31 +02:00
calixteman
67646387c8
Merge pull request #16986 from calixteman/alt_text_contents
[Editor] Change some strings in the alt-text dialog
2023-09-20 18:52:37 +02:00
Calixte Denizet
9a677d0d4d [Editor] Change some strings in the alt-text dialog 2023-09-20 18:44:56 +02:00
Calixte Denizet
0a278ef0bc [Editor] Add more telemetry for the 'add image' feature (bug 1853960) 2023-09-20 17:23:23 +02:00
calixteman
b80e0d881d
Merge pull request #16984 from Snuffleupagus/altText-close
Don't try to close the `altText` dialog if it's not open (PR 16977 follow-up)
2023-09-20 11:14:28 +02:00
Calixte Denizet
7952a36384 [Editor] Add a tooltip showing the alt text when hovering the alt-text button (bug 1844952) 2023-09-20 10:50:28 +02:00
Jonas Jenwald
21c55b56bf Don't try to close the altText dialog if it's not open (PR 16977 follow-up)
When closing a document in the viewer, e.g. by running `PDFViewerApplication.close()` in the console, the `AltTextManager.#finish` method currently throws *unless* the `altText` dialog is actually open.
Similar to e.g. the PasswordPrompt, we should thus only attempt to close the `altText` dialog when it's open.
2023-09-20 07:59:46 +02:00
Calixte Denizet
c162b004ce [Editor] Remove copy/paste listener when alt text dialog is displayed 2023-09-19 22:41:47 +02:00
Calixte Denizet
c12049db07 [Editor] Allow the user to add and save an alt-text for images (bug 1844952) 2023-09-19 21:46:48 +02:00
calixteman
daae6589b6
Merge pull request #16979 from calixteman/alt_text_change_str1
[Editor] Update alt text dialog description
2023-09-19 10:36:50 +02:00
Calixte Denizet
f7870c04ae [Editor] Make the border of the resizers slightly rounded
It's a part of the UX specifications. There's a drawing issue in Firefox
(see bug https://bugzilla.mozilla.org/1853288) but setting the
background-clip property to content-box seems to be a good workaround.
2023-09-19 09:57:00 +02:00
Calixte Denizet
0df9d1d934 [Editor] Update alt text dialog description 2023-09-19 09:27:43 +02:00
Calixte Denizet
df0da86b64 [Editor] Add a dialog box in order to get alt-text data (bug 1844952)
Implement the specifications provided by UX for light, dark and HCM modes.
2023-09-18 21:42:52 +02:00
Calixte Denizet
60ccce5cb1 [Editor] Use the same height as in the svg for icons for the alt-text button 2023-09-18 19:07:36 +02:00
calixteman
c8727d9c70
Merge pull request #16974 from calixteman/fix_css_linter_issue
Fix a CSS linter issue in removing a useless comma
2023-09-18 19:01:33 +02:00
Calixte Denizet
9b6e37c2cd Fix a CSS linter issue in removing a useless comma 2023-09-18 18:45:14 +02:00
Calixte Denizet
9dbe95c63c [Editor] Avoid to have some transparency in the icon used in the 'Alt text' button 2023-09-18 18:25:03 +02:00
Calixte Denizet
a216836fd5 [Editor] Add a button to trigger a dialog for adding an alt text (bug 1844952) 2023-09-18 15:07:09 +02:00
Jonas Jenwald
2d79be941e Convert PDFBug, in web/debugger.js, to a class with static methods
This gets rid of one more closure from the code-base.
2023-09-17 08:06:43 +02:00
Jonas Jenwald
c9cd934f8a Stop hard-coding the panel width in web/debugger.js
Thanks to CSS variables we can avoid hard-coding the panel width in the JavaScript code.
2023-09-17 08:06:33 +02:00
Jonas Jenwald
22cd0c6ff8 Remove the closure from the Stepper class in web/debugger.js 2023-09-17 08:06:26 +02:00
Calixte Denizet
38f60a7eff [Editor] Change the colors of the outline and the resizers for selected editors in HCM 2023-09-15 10:29:49 +02:00
Calixte Denizet
01f9f385d7 [Editor] Change the style of the bounding box and the resizers (bug 1852897) 2023-09-14 09:45:41 +02:00
Calixte Denizet
c6f7e722c9 [Editor] Add the parent tag id (if any) to the serialized editors (bug 1845087)
The tag id will be useful in order to update the StructTree when saving
the pdf.
2023-09-07 18:22:33 +02:00
Calixte Denizet
a00b542f2f Unconditionally render non-form annotations in the annotation layer (bug 1851498)
The goal is to always have something which is focusable to let the user select
it with the keyboard.
It fixes the mentioned bug because, the annotation layer will now have a container
to attach the canvas for annotations having their own canvas.
2023-09-05 10:41:01 +02:00
Rob Wu
28bda9f68b Drop redundant styles from .grab-to-pan-grab:active
`.grab-to-pan-grab:active` is `#viewerContainer` when the mouse is
pressed down.  It is supposed to have a `cursor: grabbing` appearance
immediately on mousedown,

`.grab-to-pan-grabbing` is the overlay that is supposed to cover
everything, and also has the `cursor: grabbing` appearance. The "cover
everything" result is achieved through `position:fixed`, `inset:0`, etc.

The block with these CSS properties for "cover everything" is currently
shared by `.grab-to-pan-grab:active` and `.grab-to-pan-grabbing`, but
only "cursor" need to be shared. The original JS and CSS code at
https://github.com/Rob--W/grab-to-pan.js shows that these were supposed
to be associated with the overlay only.

The PR that added this to PDF.js also shows that the "cover everything"
CSS properties were supposed to be limited to the overlay only:
https://github.com/mozilla/pdf.js/pull/4209#discussion-diff-9285917

But the final version of the PR mistakenly merged them together.
This patch rectifies that mistake.
2023-09-03 19:45:18 +02:00
Jonas Jenwald
c5ee72bb95 Stop using removeNullCharacters in the addLinkAttributes helper function
Using `removeNullCharacters` on the URL should be completely redundant, given the kind of data that we're passing to the `addLinkAttributes` helper function. Note that whenever we're handling a URL, originating in the worker-thread, in the viewer that helper function is always being used.

Furthermore, on the worker-thread all URLs are parsed with the `createValidAbsoluteUrl` helper function, which uses `new URL()` to ensure that a valid URL is obtained. Note that the `URL` constructor will either throw, or in some cases just ignore them, when encountering `\u0000`-characters during parsing.

Hence it should be *impossible* for a valid URL to contain `\u0000`-characters and we can thus simplify the viewer-code a tiny bit. The use of `removeNullCharacters` is most likely a left-over from back when `new URL()` wasn't generally available in browsers.
2023-08-31 20:10:50 +02:00
Jonas Jenwald
9190445a21
Merge pull request #16891 from Snuffleupagus/structElement-removeNullCharacters
Ignore null-chars when using structTree-data in the viewer
2023-08-31 18:09:04 +02:00
Jonas Jenwald
b159cc9e4b
Merge pull request #16888 from stof/fix_jsdoc_types
Fix JSDoc types
2023-08-31 16:36:09 +02:00
Jonas Jenwald
284f32f50b Ignore null-chars when using structTree-data in the viewer
Testing the `tagged_stamp.pdf` document locally in the viewer, I noticed that e.g. the /Alt entry for the StampAnnotation contains "Secondary text for stamp\u0000".
Elsewhere in the viewer we're skipping null-chars and it's easy enough to do that in the `StructTreeLayerBuilder` class as well. (Note that we generally let the API itself return the data as-is.)
2023-08-31 16:29:10 +02:00
Christophe Coevoet
f84f2646f4 Fix JSDoc types
This fixes invalid type references (either due to invalid paths for the
import or missing imports) in the JS doc, as well as some missing or
invalid parameter names for @param annotations.
2023-08-31 13:09:52 +02:00
Calixte Denizet
d185db2b70 Add tagged annotations in the structure tree (bug 1850797) 2023-08-31 12:35:32 +02:00
Jonas Jenwald
de52c98ddf Add the "aria-controls" attribute to the StampEditor toolbar-button
Given that the other Editor toolbar-buttons use this attribute, it seems that the StampEditor should as well.
2023-08-22 10:05:21 +02:00
Jonas Jenwald
4d19db0b19 Re-format the code to account for prettier and globals updates
The `prettier` update slightly changed the formatting of some await-expressions; please see https://github.com/prettier/prettier/blob/main/CHANGELOG.md#302

The `globals` update removed the need for some eslint-disable statements; please see https://github.com/sindresorhus/globals/releases/tag/v13.21.0
2023-08-19 09:30:34 +02:00
Calixte Denizet
d527fb3ff2 [Editor] Remove the stamp editor displayed when the image was loading (bug 1848313)
Make the annotation editor layer unclickable while the image is loading and
change the cursor to 'wait'.
2023-08-11 16:46:23 +02:00
Calixte Denizet
659fbc5020 [Editor] Add a button to explicitly add an image (bug 1848108)
The main stamp button will be used to just enter in a add/edit image mode:
 - the user can add a new image in using the new button.
 - the user can edit an image in resizing, moving it.
In image mode, when the user clicks outside on the page but not on an editor,
then all the selected editors will be unselected.
2023-08-11 15:05:46 +02:00
Jonas Jenwald
caebe335b2 Re-factor PDFViewerApplication._initializeAutoPrint slightly (PR 16779 follow-up)
After the `src/core/`-changes in PR 16779 the `PDFDocumentProxy.getJSActions` method should no longer be able to return *empty* entries, which means that we can simplify the "JavaScript support is not enabled"-warning in the viewer.
Furthermore, improve the auto-printing hack used when scripting is disabled.
2023-08-10 21:36:08 +02:00
Calixte Denizet
402e3fed95 [Editor] Add the possibility to move all the selected editors with the mouse (bug 1847894) 2023-08-10 14:45:36 +02:00
Calixte Denizet
149f18b766 [Editor] Move the parameter elements for FreeText and Ink annotations at the right place (follow-up of #16802) 2023-08-09 13:35:45 +02:00
calixteman
e914870c14
Merge pull request #16793 from calixteman/editor_resize_rotated
[Editor] Fix the resizing of an editor when it's rotated (bug 1847268)
2023-08-08 18:24:20 +02:00
Calixte Denizet
aa71619c2d [Editor] Fix the resizing of an editor when it's rotated (bug 1847268)
There are 2 rotation we've to deal with: the viewer one and the editor one.
The previous implementation was a bit complex and having to deal with these
rotation would have potentially increase it.
So this patch aims to simplify the implementation and deal with all the possible
cases.
The main idea is to transform the mouse deltas according to the rotations and then
apply the resizing in the page coordinates system.
2023-08-08 12:54:12 +02:00
Calixte Denizet
35d1f5485e [Editor] Move the stamp button on the right of the pen one (bug 1847707) 2023-08-08 11:35:51 +02:00
Jonas Jenwald
8bd45cb260 [Editor] Change the resize cursors to bidirectional variants
When resizing an editor we're currently using unidirectional cursors, please refer to https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
Given that editors can (generally) be resized to become either smaller or larger, it seems overall more appropriate to use bidirectional cursors to make this clearer to the user.

Note that as mentioned in the MDN article some environments, which seems to apply to e.g. Windows 11, doesn't differentiate between the two cursor formats and simply use bidirectional ones unconditionally.

One additional benefit of these changes is that the relevant CSS rules become slightly more compact.
2023-08-06 22:09:15 +02:00
Calixte Denizet
b59b1a81a9 [Editor] Refactor dragging and dropping an editor (bugs 1802895, 1844618)
It'll help to have a full control on what's happening when moving an editor.
2023-08-03 14:47:16 +02:00
Jonas Jenwald
e6728f94f4
Merge pull request #16779 from Snuffleupagus/deprecate-getJavaScript
[api-minor] Deprecate the `PDFDocumentProxy.getJavaScript` method
2023-08-01 20:58:36 +02:00