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

781 commits

Author SHA1 Message Date
Jonas Jenwald
ee7441d5bc Shorten the PDFViewerApplication._parseHashParams method
The way that the debugging hash-parameter parsing is implemented leads to a lot of boilerplate code in this method, since *most* of the cases are very similar.[1]
With just a few exceptions most of the options can be handled automatically, by defining an appropriate checker for each option.

---

[1] With the recent introduction of TESTING-only options the size of this method increased a fair bit.
2024-08-15 13:50:35 +02:00
Jonas Jenwald
9e0c6ef476 Handle the "switchannotationeditorparams" event in the editor-code (issue 18196)
The problem seems to be caused by the browser trying to "restore" editing input-elements, in the various toolbars, to their previous values when the tab is re-opened.

Hence the simplest solution appears to be to move the event handling into the editor-code, which is also less code overall, since the listener thus won't be registered early enough for the problem to appear.
2024-08-13 15:29:55 +02:00
Jonas Jenwald
17b24639b9
Merge pull request #18594 from Snuffleupagus/rm-enableHighlightEditor-pref
Remove the `enableHighlightEditor` preference
2024-08-13 08:14:09 +02:00
Jonas Jenwald
b9f5e78e15 Remove the enableHighlightEditor preference
This was enabled by default in Firefox 126, see [bug 1867513](https://bugzilla.mozilla.org/show_bug.cgi?id=1867513), so hopefully we should be able to remove the option/preference now.
2024-08-10 16:00:31 +02:00
Calixte Denizet
debcb2267e [Editor] Add a first test to test the new alt text flow 2024-08-10 14:59:35 +02:00
Jonas Jenwald
c0bf3d3c94 [Editor] Remove event listeners with AbortSignal.any()
There's a fair number of event listeners in the editor-code that we're currently removing "manually", by keeping references to their event handler functions.
This was necessary since we have a "global" `AbortController` that applies to all event listeners used in the editor-code, however it's now possible to combine multiple `AbortSignal`s; please see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static

Since this functionality is [fairly new](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static#browser_compatibility) the viewer will check that `AbortSignal.any()` is available before enabling the editing-functionality.
(It should hopefully be fairly straightforward, famous last words, for users to implement a polyfill to allow editing in older browsers.)

Finally, this patch also adds checks and test-only asserts to ensure that we don't add duplicate event listeners in various editor-code.
2024-08-09 11:24:34 +02:00
Calixte Denizet
1d51c3e711 Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
The user can change a setting in a tab and it must have an effect in the current viewer.
2024-08-07 23:21:38 +02:00
calixteman
6c005eabb3
Revert "[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)" 2024-08-07 23:11:31 +02:00
Calixte Denizet
92ade5495b [Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
The user can change a setting in a tab and it must have an effect in the current viewer.
2024-08-07 22:45:08 +02:00
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
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
974911f24f [Editor] Don't create the image settings dialog if new alt-text is disabled 2024-08-02 10:41:34 +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
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
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
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
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
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
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
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
Tim van der Meij
7a8aceef20
Merge pull request #18463 from Snuffleupagus/app-rm-downloadComplete
Re-factor the code to remove all uses of `PDFViewerApplication.downloadComplete`
2024-07-20 18:11:32 +02:00
Jonas Jenwald
482d6211aa Reduce a tiny bit of duplication in PDFViewerApplication.setTitleUsingUrl
Rather than repeating code, we can always fallback to the raw URL instead.
2024-07-20 10:19:45 +02:00
Jonas Jenwald
64a4f0dc7e Avoid downloading the document twice in PDFViewerApplication.download
The old implementation in `PDFViewerApplication.download` means that if the `getDocument`-call hasn't yet downloaded the *entire* PDF document it will be re-downloaded. This seems generally undesirable since:
 - In some (probably rare) cases a URL may not be valid an arbitrary number of times, which means that the download may fail.
 - It will lead to wasted resources, since we'll end up fetching the same PDF document *twice* in that case (once via the `getDocument`-call and once to allow the user to save it).

Hence this patch suggests that we change this very old code to instead always call the `PDFDocumentProxy.getData` method, since that'll trigger immediate downloading of the remaining document via the existing `getDocument`-call.

Finally, the patch removes the `PDFViewerApplication.downloadComplete` property since it's now unused.
2024-07-20 09:57:33 +02:00
Jonas Jenwald
006242489d Stop using downloadComplete in PDFViewerApplication.progress
This was only necessary to prevent (unlikely) visual glitches when `disableAutoFetch = true` is being used.
However, it turns out that we can move this functionality into the `ProgressBar` class instead by checking if the entire PDF document has loaded. This works since the API is always reporting 100% loading progress regardless of how the document was loaded; see [this code](ed83d7c5e1/src/display/api.js (L2735-L2740)).
2024-07-20 09:27:43 +02:00
Calixte Denizet
b71fa727e1 Load the image-to-text model when opening the pdf viewer in Firefox (bug 1908938) 2024-07-19 21:57:46 +02:00
Calixte Denizet
5946d20dc9 [Editor] Allow to change a preference from the editor UI manager
We want to be able to update a global pref (i.e. enableAltText) in using a toggle button in the new alt-text dialog.
2024-07-18 15:12:39 +02:00
Jonas Jenwald
99f34f4c2e Include additional data when fetching browser preferences in the PDF Viewer (bug 1908401)
To avoid having to request and await various browser data early during the PDF Viewer initialization, we can include that data in the existing preference fetching instead. With other planned changes to the PDF Viewer, the current situation would only become worse over time.

*Note:* Technically this data aren't preference-values, however we're already including other non-prefs in this list (e.g. `isInAutomation`) and doing it this way simplifies the overall implementation.
2024-07-17 16:57:55 +02:00
Calixte Denizet
dfccc8ffd9 [Editor] Add an option to use the new 'add an image' flow (bug 1907207)
UX team designed in a new flow we'll implement soon and we want to be able to
make an experiment to be able to compare current flow vs the new one.
2024-07-12 16:28:48 +02:00
Jonas Jenwald
6b47ddd4d5 Remove the remaining zoomDisabledTimeout usage (issue 17727)
With https://bugzilla.mozilla.org/show_bug.cgi?id=1882168 now marked as fixed by the landing of https://bugzilla.mozilla.org/show_bug.cgi?id=1902017 we should *hopefully* be able to remove this work-around.
2024-07-11 12:17:41 +02:00
Jonas Jenwald
d9f0ec0b87 Re-factor BasePreferences to essentially be a wrapper around AppOptions
In the MOZCENTRAL build the `BasePreferences` class is almost unused, since it's only being used to initialize and update the `AppOptions` which means that theoretically we could move the relevant code there.
However for the other build targets (e.g. GENERIC and CHROME) we still need to keep the `BasePreferences` class, although we can re-factor things to move the necessary validation inside of `AppOptions` and thus simplify the code and reduce duplication.

The patch also moves the event dispatching, for changed preference values, into `AppOptions` instead.
2024-07-09 22:49:59 +02:00
calixteman
db9115625b
Merge pull request #18398 from calixteman/bug1905923
[Editor] Change the enableML pref for enableAltText (bug 1905923)
2024-07-05 22:51:15 +02:00
Calixte Denizet
0fba6e570e [Editor] Change the enableML pref for enableAltText (bug 1905923)
We want to use this pref to make a Nimbus experiment in the next weeks.
2024-07-05 21:01:12 +02:00
Calixte Denizet
0910f17a58 Allow to change the toolbar height when changing the pref toolbar.density in Firefox (bug 1171799)
It's a first step to just dispatch the pref change to the toolbar.
The second one, to effectively use it, will come after PR #18385 is merged.
2024-07-05 18:59:29 +02:00
Calixte Denizet
74cbfbd09f [Editor] Remove the option enableStamp 2024-07-04 22:01:35 +02:00
Calixte Denizet
35474f8ef4 Add the possibility to dispatch some pdf.js events at the chrome level (bug 1904585) 2024-06-25 21:03:34 +02:00
Jonas Jenwald
6492587066 Try to shutdown Fluent "more" when closing the viewer during testing
Even with PR 18280 fixed, we still *occasionally* see l10n-related errors when closing the integration-tests on the bots.
2024-06-22 16:40:12 +02:00
bootleq
890c567eca Expose entireWord in updateFindControlState
Allow apps with supportsIntegratedFind to better monitor the find state.

A recognized use case is the Firefox findbar, its "not found" sound must
consider `entireWord` and only make noise when it is off.

See related implementation in
https://hg.mozilla.org/mozilla-central/rev/16b902cbcf26

This change can help if we have to move the implementation from cpp to jsm.
2024-06-21 13:12:59 +08:00
Jonas Jenwald
02c03154b3 Close PDFFindBar when closing the viewer during testing
By closing `PDFFindBar` we also disconnect the `ResizeObserver`, since we've seen at least one case where that's running during shutdown: http://54.193.163.58:8877/91c40554d1b07c0/output.txt
2024-06-20 11:51:21 +02:00
Jonas Jenwald
c771ac81cd Add a new helper, in the viewer, to close everything during testing
This has two advantages, as far as I'm concerned:
 - The tests don't need to manually invoke multiple functions to properly clean-up, which reduces the risk of missing something.
 - By collecting all the relevant clean-up in one method, rather than spreading it out, we get a much better overview of exactly what is being reset.
2024-06-19 13:48:08 +02:00
Tim van der Meij
4b5d5a557c
Merge pull request #18280 from calixteman/issue18279
Pause l10n (i.e. disconnect the mutation observer in fluent) when closing the viewer
2024-06-18 21:47:06 +02:00
Calixte Denizet
34389d4e47 Pause l10n (i.e. disconnect the mutation observer in fluent) when closing the viewer 2024-06-18 21:08:47 +02:00
Tim van der Meij
0d8828f93d
Merge pull request #18282 from Snuffleupagus/issue-18274
Don't save modified documents, when running tests, upon closing the viewer (issue 18274)
2024-06-18 20:55:27 +02:00