1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00
Commit graph

4355 commits

Author SHA1 Message Date
Jonas Jenwald
ecbd660609 Stop sending the unused options parameter to various download-methods in the viewer
The `options` handling, for the download-methods, was originally added in PR 16391 and became obsolete in PR 17771.

This fixes failures, in mozilla-central tests, which appeared after landing PR 18527.
2024-08-02 20:46:13 +02:00
calixteman
a372bf8f4d
Merge pull request #18541 from calixteman/use_ml_but_no_dialog
[Editor] Guess alt text even when showing the dialog is disabled
2024-08-02 18:02:53 +02:00
Tim van der Meij
7ac87dd6f8
Merge pull request #18544 from Snuffleupagus/app-bind-listeners
Improve the larger event listeners in the `web/app.js` file
2024-08-02 17:56:19 +02:00
Calixte Denizet
d2c519e57a Guess alt text even when showing the dialog is disabled 2024-08-02 17:40:10 +02:00
calixteman
c8ba7b02b0
Merge pull request #18546 from calixteman/load_model_switch_stamp
[Editor] Load the model when the user switch to the stamp editing mode
2024-08-02 17:21:26 +02:00
Calixte Denizet
a81b071d2d [Editor] Load the model when the user switch to the stamp editing mode 2024-08-02 17:14:09 +02:00
Jonas Jenwald
aae223f79b Replace onScrollModeChanged and onSpreadModeChanged with one function
Given that these event handlers are virtually identical, obviously with the exception of the name-parameter, let's reduce a little bit of code duplication.
2024-08-02 16:16:25 +02:00
Jonas Jenwald
22ec252193 Improve the larger event listeners in the web/app.js file
- Shorten the names of the event listeners.

 - Use `bind` to pass in the `PDFViewerApplication`-scope to the event handlers.
   This makes the event handler code (a lot) less verbose, and this change is possible now that we're removing event listeners with `AbortSignal`.

 - Move the GENERIC-only event listeners into the same pre-processor block.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `~4.3` kilo-bytes, which isn't a lot but still cannot hurt.
2024-08-02 16:16:25 +02:00
Tim van der Meij
b80e552760
Merge pull request #18527 from Snuffleupagus/app-inline-short-listeners
Inline single-line event handlers in the `web/app.js` file
2024-08-02 16:08:45 +02:00
Calixte Denizet
f32d19de18 Fix the color of the buttons in a dialog in HCM 2024-08-02 15:38:55 +02:00
calixteman
08821a3e5d
Merge pull request #18543 from calixteman/disable_create_alttext_button
[Editor] Avoid to have the create alt-text button without a click listener
2024-08-02 15:06:05 +02:00
Calixte Denizet
271bd4d079 [Editor] Avoid to have the create alt-text button without a click listener
The toggle button hasn't a click listener after we deleted and downloaded the model.
2024-08-02 11:05:58 +02:00
Calixte Denizet
974911f24f [Editor] Don't create the image settings dialog if new alt-text is disabled 2024-08-02 10:41:34 +02:00
calixteman
4422e6fb3b
Merge pull request #18538 from calixteman/fix_new_alt_text_l10n
[Editor] Fix l10n issues
2024-08-02 10:39:08 +02:00
Calixte Denizet
63d0fa5733 [Editor] Fix l10n issues
Remove the strings containing only a variable.
2024-08-02 10:36:18 +02:00
Calixte Denizet
1a8bcdb2ba [Editor] Use the color defined for the message bar foreground 2024-08-02 09:35:21 +02:00
Jonas Jenwald
89f3a26c2f Inline single-line event handlers in the web/app.js file
We have a fair number of (effectively) single-line event handlers in the  `web/app.js` file, which leads to unnecessarily verbose code. These can, without affecting readability too much, be replaced either by:
 - Using `bind` for the simplest cases.
 - Using arrow-functions for the remaining ones.

Note that this is possible since we started removing event listeners with `AbortSignal`, which means that we no longer need to keep a reference to the event handler functions to be able to remove them.

Given that the old event handler functions use fairly long function names, and the way that they access `PDFViewerApplication` (given their scope), they impact the overall code-size unnecessarily.
*Note:* This patch reduces the size of the `gulp mozcentral` output by `~3.7` kilo-bytes, which isn't a lot but still cannot hurt.
2024-08-01 22:02:55 +02:00
Calixte Denizet
32d09276f0 [Editor] Add a new dialog for alt-text settings (bug 1909604)
This patch adds a new entry in the secondary menu in order to open a dialog to let the user:
 - disables the alt-text generation thanks to a ML model;
 - deletes the alt-text model downloaded in Firefox;
 - disabled the new alt-text flow.
2024-08-01 21:34:50 +02:00
Tim van der Meij
d562e0525d
Merge pull request #18523 from Snuffleupagus/Toolbar-more-bindListeners
Move all event listeners into `Toolbar.prototype.#bindListeners`
2024-08-01 20:41:32 +02:00
Tim van der Meij
0269cf5b4d
Merge pull request #18518 from timvandermeij/viewer-toolbar-height
Introduce a CSS variable for the toolbar height (bug 1171799)
2024-08-01 20:06:43 +02:00
Jonas Jenwald
7c3aa9445c Move all event listeners into Toolbar.prototype.#bindListeners
Over time a couple of event listeners have been placed in the constructor, despite there being an existing helper method for that purpose. To improve the code organization, let's move these to the intended method instead.
2024-07-31 09:49:25 +02:00
Tim van der Meij
e3838c1c70
Introduce a CSS variable for the toolbar height (bug 1171799)
This refactoring lays the foundation for making the toolbar height
configurable in Firefox via the `browser.uidensity` preference. For
this to work correctly the toolbar height must be defined in a single
place that can easily be updated dynamically, hence this patch which
moves it to a CSS variable in such a way that the rest of the UI adapts
correctly if the value is changed.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-07-30 21:22:49 +02:00
Tim van der Meij
f1f58bbe67
Give all HTML button elements a type
The HTML button elements we use are all regular buttons that don't
submit form data to a server. According to
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#notes
those buttons should all have their type set to `button` explicitly, but
we only do that a handful of them. This commit fixes the issue by
consistently giving all our buttons the `button` type.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-07-30 18:49:18 +02:00
calixteman
8f45374881
Merge pull request #18492 from calixteman/new_stamp_dialog
[Editor] Implement the new alt text flow (bug 1909604)
2024-07-30 10:25:02 +02:00
Tim van der Meij
f430a6bfd4
Improve how the findbar's toggle button is referenced in the viewer code
The sidebar and secondary toolbar both have a reference to their toggle
buttons in their own sections in `getViewerConfiguration`, so it makes
sense for the findbar to do the same.

While we actually have a findbar-specific reference to the toggle
button, I noticed that we don't use it consistently because the toolbar
also has a reference to the exact same toggle button and we use both in
the code. This is probably for historical reasons: the docstring in the
toolbar file indicates that the `viewFind` element is an input to the
component, but that option is never actually used in the code itself.

This commit fixes the issue by removing the toolbar-specific reference,
since it's not actually used (anymore) in the toolbar code, so that we
consistently use the findbar-specific reference everywhere.
2024-07-29 19:55:32 +02:00
Calixte Denizet
ed22d934e5 Implement the new alt text flow (bug 1909604)
For the Firefox pdf viewer, we want to use AI to guess an alt-text when adding an image to a pdf.
For now the telemtry stuff is not implemented and will come soon.
In order to test it locally:
 - set enableAltText, enableFakeMLManager and enableUpdatedAddImage to true.
or in Firefox:
 - set browser.ml.enable, pdfjs.enableAltText and pdfjs.enableUpdatedAddImage to true.
2024-07-29 14:31:47 +02:00
Tim van der Meij
6f9fc70926
Merge pull request #18481 from nicolo-ribaudo/fix-selection-with-links
Disable link annotations during text selection
2024-07-28 12:08:38 +02:00
Jonas Jenwald
935d9047fc Initialize all user-options upfront in AppOptions
- Initialize all user-options upfront, to allow getting the options without having to check if they exist first. (This is easier to implement after PR 18475 landed.)

 - Move the user-options into a private field in `AppOptions`. (This code is old enough to pre-date general availability of that class feature.)

 - Move code/methods limited to GENERIC-builds into `AppOptions`.
2024-07-27 14:16:09 +02:00
Jonas Jenwald
58c7b5b635 Consistently dispatch events, if needed, when setting AppOptions
Currently we'll only dispatch events, for the options that support it, when updating preferences. Since this could potentially lead to inconsistent behaviour, let's avoid any future surprises by *always* dispatching events regardless of how the relevant option is being changed.

Obviously we should then also dispatch events in `AppOptions.set`, and to avoid adding even more duplicated code this method is changed into a wrapper for `AppOptions.setAll`.
While this is technically a tiny bit less efficient I don't think it matters in practice, since outside of development- and debug-mode `AppOptions.set` is barely used.
2024-07-27 10:10:38 +02:00
Tim van der Meij
cb737512de
Merge pull request #18486 from Snuffleupagus/AppOptions-replace-locale
Replace the GENERIC-only "locale" with "localeProperties" in AppOptions
2024-07-23 15:50:29 +02:00
Nicolò Ribaudo
64a0e59662
Disable link annotations during text selection
When selecting text, hovering over an element
causes all the text between (according the the dom
order) the current selection and that element to
be selected.

This means that when, while selecting, the cursor
moves over a link, all the text in the page gets
selected. Setting `user-select: none` on the link
annotations would improve the situation, but it
still makes it impossible to extend the selection
within a link without using Shift+arrows keys on
the keyboard.

This commit fixes the problem by setting
`pointer-events: none` on the `<section>`s in the
annotation layer while selecting some text. This
way, they are ignored for hit-testing and do not
affect selection.

It is still impossible to _start_ a selection
inside a link, as the link text is covered by the
link annotation.

Fixes #18266
2024-07-23 10:42:34 +02:00
calixteman
33493301b3
Merge pull request #18484 from calixteman/bug1909310
Add a pref to know if the alt-text must be automatically generated (bug 1909310)
2024-07-23 10:02:03 +02:00
Jonas Jenwald
7ebfad6d92 Replace the GENERIC-only "locale" with "localeProperties" in AppOptions
Since "localeProperties" is needed in Firefox, let's remove a tiny bit of option duplication by using it in the GENERIC builds as well.
For convenience, the old debug-only "locale" hash-parameter is kept intact.
2024-07-23 09:51:32 +02:00
Calixte Denizet
042183b89b Add a pref to know if the alt-text must be automatically generated (bug 1909310) 2024-07-22 23:10:25 +02:00
Jonas Jenwald
b3ea789286 Add better support for AppOptions with multiple types (PR 18465 follow-up)
For options with varying types, see `useSystemFonts`, we're not sufficiently validating the type when setting a new value. This means that for an option that uses `OptionKind.UNDEF_ALLOWED` we'd allow *any* value, which is obviously not the intention.

Hence we instead introduce a new and *optional* `type`-field that allows specifying exactly which types are valid when multiple ones are supported.

*Note:* This obviously didn't occur to me until after PR 18465 landed, sorry about that!
2024-07-22 17:58:21 +02:00
Jonas Jenwald
12e083f60d Re-factor how the "docBaseUrl" API-option is set in the viewer
This option is old enough that it predates e.g. the introduction of AppOptions, so it probably cannot hurt to re-factor this a little bit now.

 - In development-mode we can just set this directly in AppOptions.

 - In the extension-builds we still need to set it dynamically, however by moving this code we get the benefit of being able to avoid storing a data-URL in that case; note how [the API ignores those anyway](98e772727e/src/display/api.js (L256-L262)).
2024-07-21 22:07:52 +02:00
Tim van der Meij
98e772727e
Merge pull request #18475 from Snuffleupagus/rm-AppOptions-remove
Remove the unused `AppOptions.remove` method
2024-07-21 21:28:52 +02:00
calixteman
998bc07375
Merge pull request #18472 from calixteman/bug1908939
Add the possibility to delete a model (bug 1908939)
2024-07-21 20:53:08 +02:00
Jonas Jenwald
d9ff29a46b Remove the unused AppOptions.remove method
This method has *never* been used anywhere in the code-base, so I really don't know why I added it originally.
2024-07-21 19:26:15 +02:00
Tim van der Meij
0c34efbef9
Merge pull request #18465 from Snuffleupagus/issue-18210
Disable system fonts on Android (issue 18210)
2024-07-21 17:53:49 +02:00
Calixte Denizet
b759470ed5 Add the possibility to delete a model (bug 1908939) 2024-07-21 17:09:41 +02:00
Calixte Denizet
5860c7bcc9 Add a pref containing the url for the sumo page about alt text (bug 1909097) 2024-07-21 16:55:26 +02:00
Jonas Jenwald
80d6bf6319 Disable system fonts on Android (issue 18210)
To avoid introducing any inline "hacks" in the viewer-code this meant adding `useSystemFonts` to the AppOptions, which thus required some new functionality since the default value should be `undefined` given how the option is handled in the API; note [this code](ed83d7c5e1/src/display/api.js (L298-L301)).

Finally, also moves the definition of the development-mode `window.isGECKOVIEW` property to the HTML file such that it's guaranteed to be set regardless of how and when it's accessed.
2024-07-21 15:28:16 +02:00
Jonas Jenwald
45ce3a057f Use shorter local variable names in a few AppOptions methods
Besides being slightly shorter, this should help reduce the risk of confusion given the very similar global Object/Map names.
2024-07-21 15:27:43 +02:00
Tim van der Meij
ebb3d27125
Merge pull request #18469 from Snuffleupagus/AppOptions-Maps
Introduce some `Map`-usage in the AppOptions
2024-07-21 14:47:29 +02:00
Jonas Jenwald
f8aa15aae9 Move the Preferences initialization as early as possible
Given that the entire default viewer initialization depends on the preferences being available, try to do this as early as possible.
2024-07-21 13:42:31 +02:00
Jonas Jenwald
26989fdf24 Add basic validation of the AppOptions BROWSER-kind 2024-07-21 09:32:36 +02:00
Jonas Jenwald
7bd920691f Change the userOptions, used with AppOptions, to a Map
This is needed for upcoming changes, and simplifies both checking if an entry exists and iteration of the entries.
2024-07-21 09:27:23 +02:00
Jonas Jenwald
57ee035573 Change the compatibilityParams, used with AppOptions, to a Map
This is needed for upcoming changes, and simplifies both checking if an entry exists and iteration of the entries.
2024-07-21 09:27:05 +02:00
Tim van der Meij
e92a6a14ff
Merge pull request #18450 from Snuffleupagus/AppOptions-set-validation
Add more validation when setting `AppOptions` (PR 18413 follow-up)
2024-07-20 19:11:54 +02:00