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

4379 commits

Author SHA1 Message Date
Jonas Jenwald
aebb8534f3 Limit base-class initialization checks to development and TESTING modes
We have a number of base-classes that are only intended to be extended, but never to be used directly. To help enforce this during development these base-class constructors will check for direct usage, however that code is obviously not needed in the actual builds.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `~2.7` kilo-bytes, which isn't a lot but still cannot hurt.
2024-08-12 12:26:35 +02:00
Tim van der Meij
2a22424c95
Remove the secondaryToolbarButton CSS class
Secondary toolbar buttons are toolbar buttons with some extra rules,
mainly to make them wider and have visible labels. However, this
similarity is currently not clearly reflected in the implementation
because the secondary toolbar buttons use a different CSS class,
`secondaryToolbarButton`, compared to the other toolbar buttons that
use the `toolbarButton` CSS class. This also causes some duplication
in the rules and requires extra care to keep the common bits for the
`secondaryToolbarButton` class in sync with the `toolbarButton` class.

Fortunately, now that we have a dedicated CSS scope for the secondary
toolbar, we can simplify this by giving all secondary toolbar buttons
the `toolbarButton` class and explicitly listing the required overrides
in the `#secondaryToolbar` scope instead. Doing so removes most of the
special-casing for secondary toolbar buttons while explicitly listing
the differences in a single place for a better overview. It also lays
the foundation for making all toolbar buttons respect the
`browser.uidensity` Firefox preference later by reducing differences.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-11 17:48:25 +02:00
Tim van der Meij
97b761dfbf
Group and scope the secondary toolbar button container/icon rules using CSS nesting
The secondary toolbar CSS rules predate the general availability of CSS
nesting, which makes them more difficult to understand and change
safely. The primary issues are that the rules are spread over the
`viewer.css` file, they share blocks with other elements and the scope
of the rules is sometimes bigger than necessary.

This refactoring groups all CSS rules for the secondary toolbar button
container/icons together, scoped to the top-level `#secondaryToolbar`
element, for improved overview and isolation. Note that this patch only
intends to move the existing rules around and not change any behavior.
Moreover, this patch does not move the rules for the secondary toolbar
itself and the secondary toolbar buttons; those will be part of a
follow-up patch and will be easier once this is in place first.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-11 13:52:23 +02:00
calixteman
e44e4db529
Merge pull request #18589 from calixteman/new_alt_text_telemetry
[Editor] Add the telemetry for the new alt text (bug 1912500)
2024-08-10 18:49:41 +02:00
Calixte Denizet
00305184b5 [Editor] Add the telemetry for the new alt text (bug 1912500) 2024-08-10 18:29:03 +02:00
Tim van der Meij
6e4b347e1b
Merge pull request #18593 from Snuffleupagus/PDFSidebar-AbortController
Remove the sidebar resizing event listeners with an `AbortController`
2024-08-10 18:28:38 +02:00
Tim van der Meij
ec48602379
Merge pull request #18592 from Snuffleupagus/firefoxcom-AbortSignal-any
[Firefox] Remove the "loadaiengineprogress" listener with `AbortSignal.any()`
2024-08-10 18:21:18 +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
be685a293c Remove the sidebar resizing event listeners with an AbortController 2024-08-10 12:24:59 +02:00
Jonas Jenwald
7619171265 Stop sidebar resizing on "blur" events
Because of an old oversight (by me) we don't stop sidebar resizing when the browser window loses focus, which seems generally wrong and can also lead to duplicate mouse-related event listeners being registered.
2024-08-10 12:24:54 +02:00
Jonas Jenwald
984debaa9f Use a few local variables in PDFSidebar.#addEventListeners
This, ever so slightly, shortens the code for a couple of repeatedly accessed class fields.
2024-08-10 12:06:45 +02:00
Jonas Jenwald
723c76929c [Firefox] Remove the "loadaiengineprogress" listener with AbortSignal.any() 2024-08-10 11:16:42 +02:00
Jonas Jenwald
da9cfe7781 Check that AbortSignal.any() is supported in PDFViewer too (PR 18586 follow-up)
Without this patch the viewer may break on load, since the check added in PR 18586 only applies to the toolbar.
2024-08-09 16:48:44 +02:00
Jonas Jenwald
b7198d316f
Merge pull request #18586 from Snuffleupagus/editor-AbortSignal-any
[Editor] Remove event listeners with `AbortSignal.any()`
2024-08-09 16:20:49 +02:00
calixteman
36dc666d04
Merge pull request #18584 from calixteman/preview_background
[Editor] Change the background color of the image preview in the new alt text dialog
2024-08-09 12:36:15 +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
bad214fc71 [Editor] Change the background color of the image preview in the new alt text dialog 2024-08-08 21:13:58 +02:00
Tim van der Meij
1fcdcedee1
Group and scope the findbar rules using CSS nesting
The findbar CSS rules predate the general availability of CSS nesting,
which makes them more difficult to understand and change safely. The
primary issues are that the findbar rules are spread all over the
`viewer.css` file, they share blocks with non-findbar elements and the
scope of the rules is sometimes bigger than necessary.

This refactoring groups all findbar-related CSS rules together, scoped
to the top-level `#findbar` element, for improved overview and
isolation. Note that this patch only intends to move the existing rules
around and not change any behavior yet, but it does lay the foundation
for e.g. making the findbar respect the `browser.uidensity` preference
in Firefox in follow-up work.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-08 19:19:32 +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
calixteman
fef2853263
Merge pull request #18573 from calixteman/cancel_ai_requests
[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
2024-08-07 23:11:04 +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
Calixte Denizet
f487ed3004 [Editor] Move the AI icon on the top of its parent div
And fix the line-height for all the dialog (which is "normal" in the specs).
Because of the wrong line-height, the icon was slightly misplaced.
2024-08-07 18:50:59 +02:00
Calixte Denizet
fc602c65c0 [Editor] Update the disclaimer string in the new alt-text dialog (bug 1911738)
And tweak the css in order to take into account that disclaimer can be on two (or more lines).
2024-08-06 10:17:18 +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
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