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

19512 commits

Author SHA1 Message Date
Jonas Jenwald
17b24639b9
Merge pull request #18594 from Snuffleupagus/rm-enableHighlightEditor-pref
Remove the `enableHighlightEditor` preference
2024-08-13 08:14:09 +02:00
Tim van der Meij
9fd23d8082
Generalize the CSS rules for labeled toolbar buttons
This commit fixes a regression from #18596 where the "Add image" button
styles broke because it's a labeled toolbar button but the labeled
toolbar button CSS rules were only scoped to the secondary toolbar.
However, nowadays labeled toolbar buttons are also used in e.g. the
editor parameters toolbar, and this highlighted that we didn't clearly
encode the concept of labeled toolbar buttons in the CSS so far.

This patch extracts the CSS rules for labeled toolbar buttons that were
previously limited to the secondary toolbar into a dedicated generic
class that can be applied on top of any unlabeled toolbar button to
convert it to a labeled toolbar button, regardless of its position in
the DOM. This also makes the distinction clearer in the HTML, and the
new CSS scope for the toolbar buttons lays the foundation for combining
the other toolbar buttons rules in there later on.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:27:33 +02:00
Tim van der Meij
68bda90777
Improve grouping of the secondary toolbar button CSS rules
Using the `:is(a)` selector we can move the previously separate rules
into the main `.toolbarButton` override rules.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:08:29 +02:00
Tim van der Meij
2a982e71ed
Merge the duplicate .editorParamsToolbar CSS blocks
Now that we have dedicated CSS scopes for the findbar and the secondary
toolbar we have ended up with two CSS blocks with identical selectors,
so now we can combine them for simplicity and to remove some rules in
the first block that were always overridden by the second block.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:04:36 +02:00
Tim van der Meij
d0fbfe10c5
Merge pull request #18598 from Snuffleupagus/base-class-init-TESTING-check
Limit base-class initialization checks to development and TESTING modes
2024-08-12 19:06:21 +02:00
Tim van der Meij
9103cf00c0
Merge pull request #18597 from timvandermeij/css-secondary-toolbar-part-3
Group and scope the secondary toolbar rules using CSS nesting
2024-08-12 19:03:04 +02:00
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
5193adf1fd
Group and scope the secondary toolbar 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 remaining secondary toolbar rules 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.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-11 18:27:04 +02:00
Tim van der Meij
aa2337f934
Merge pull request #18596 from timvandermeij/css-secondary-toolbar-part-2
Remove the `secondaryToolbarButton` CSS class
2024-08-11 18:25:29 +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
efe00cf68c
Merge pull request #18595 from timvandermeij/css-secondary-toolbar-part-1
Group and scope the secondary toolbar button container/icon rules using CSS nesting
2024-08-11 16:14:59 +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
Tim van der Meij
4367fc1bc0
Merge pull request #18581 from calixteman/new_alt_text_test_1
[Editor] Add a first test to test the new alt text flow
2024-08-10 18:14:12 +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
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
calixteman
b6b99a7b75
Merge pull request #18588 from mozilla/revert-18580-alt_text_pass_buffer
Revert "[Editor] Pass a buffer instead of a typed array when passing image data to the model"
2024-08-09 17:53:16 +02:00
calixteman
31727ccb4d
Revert "[Editor] Pass a buffer instead of a typed array when passing image data to the model" 2024-08-09 17:49:47 +02:00
Tim van der Meij
daabc7abea
Merge pull request #18587 from Snuffleupagus/PDFViewer-check-AbortSignal-any
Check that `AbortSignal.any()` is supported in `PDFViewer` too (PR 18586 follow-up)
2024-08-09 17:35:25 +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
4569e88778
Merge pull request #18568 from timvandermeij/css-findbar
Group and scope the findbar rules using CSS nesting
2024-08-08 20:27:14 +02:00
Tim van der Meij
fb049b0a05
Merge pull request #18583 from timvandermeij/eslint-plugin-mozilla
Remove the `eslint-plugin-mozilla` dependency
2024-08-08 20:26:52 +02:00
Tim van der Meij
be93d530de
Remove the eslint-plugin-mozilla dependency
We only used two rules from the plugin which can both easily be replaced
nowadays:

- `mozilla/avoid-removeChild` is equal to the already active
  `unicorn/prefer-dom-node-remove` rule; please see [1] and [2].
- `mozilla/import-globals` is mostly obsolete nowadays ever since we
  removed the Firefox extension code from this repository and we
  eliminated most globals usage. The three remaining occurrences can be
  replaced with explicit `/* globals */` comments that we already use
  elsewhere, which overall is also more consistent.

[1] https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/rules/avoid-removeChild.html
[2] https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-remove.md
2024-08-08 19:51:20 +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
Tim van der Meij
cd3d188f99
Merge pull request #18571 from timvandermeij/linting
Enable the `unicorn/{prefer-includes,throw-new-error}` linting rules
2024-08-08 19:18:26 +02:00
Tim van der Meij
318433b2d8
Enable the unicorn/throw-new-error linting rule
For more information refer to
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/throw-new-error.md.

This didn't require any changes because we already do this correctly,
but it ensures that new code remains consistent and explicit.
2024-08-08 19:03:07 +02:00
Tim van der Meij
ad95df2214
Enable the unicorn/prefer-includes linting rule
For more information refer to
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-includes.md.

Fortunately this only required one change because we already use
`.includes()` everywhere else. Note that that is mostly due to the
`mozilla/use-includes-instead-of-indexOf` rule which we replace with
this new rule now because it's more complete.
2024-08-08 19:01:35 +02:00
calixteman
40aa593b1f
Merge pull request #18580 from calixteman/alt_text_pass_buffer
[Editor] Pass a buffer instead of a typed array when passing image data to the model
2024-08-08 14:48:27 +02:00
Calixte Denizet
d2e8e742eb [Editor] Pass a buffer instead of a typed array when passing image data to the model 2024-08-08 14:43:36 +02:00
calixteman
999403f5ef
Merge pull request #18579 from calixteman/cancel_ai_requests_2
Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
2024-08-07 23:26:37 +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
e099840100
Merge pull request #18578 from mozilla/revert-18573-cancel_ai_requests
Revert "[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)"
2024-08-07 23:14:11 +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
calixteman
5709b1300d
Merge pull request #18575 from calixteman/ai_disclaimer_icon_position
[Editor] Move the AI icon on the top of its parent div
2024-08-07 19:22:29 +02:00
calixteman
3cad8d1c27
Merge pull request #18574 from calixteman/add_window_uimanager_test
[Editor] Add the uiManager to the window object when testing
2024-08-07 19:17:24 +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
e037c5711d [Editor] Add the uiManager to the window object when testing 2024-08-07 18:06:14 +02:00