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

4221 commits

Author SHA1 Message Date
Tim van der Meij
40f9371bf8
Merge pull request #17923 from nicolo-ribaudo/fix-text-selection
Fix flickering on text selection
2024-05-14 15:58:20 +02:00
Tim van der Meij
ac7b86d341
Merge pull request #18080 from calixteman/bug1895909
[Editor] Fix the CSS properties of the canvas when it's used in a stampEditor (bug 1895909)
2024-05-14 15:33:53 +02:00
Nicolò Ribaudo
6f2e4d0d94
Fix flickering on text selection
When seleciting on a touch screen device, whenever the finger moves to a
blank area (so over `div.textLayer` directly rather than on a `<span>`),
the selection jumps to include all the text between the beginning of the
.textLayer and the selection side that is not being moved.

The existing selection flickering fix when using the mouse cannot be
trivially re-used on mobile, because when modifying a selection on
a touchscreen device Firefox will not emit any pointer event (and
Chrome will emit them inconsistently). Instead, we have to listen to the
'selectionchange' event.

The fix is different in Firefox and Chrome:
- on Firefox, we have to make sure that, when modifying the selection,
  hovering on blank areas will hover on the .endOfContent element
  rather than on the .textLayer element. This is done by adjusting the
  z-indexes so that .endOfContent is above .textLayer.
- on Chrome, hovering on blank areas needs to trigger hovering on an
  element that is either immediately after (or immediately before,
  depending on which side of the selection the user is moving) the
  currently selected text. This is done by moving the .endOfContent
  element around between the correct `<span>`s in the text layer.

The new anti-flickering code is also used when selecting using a mouse:
the improvement in Firefox is only observable on multi-page selection,
while in Chrome it also affects selection within a single page.

After this commit, the `z-index`es inside .textLayer are as follows:
- .endOfContent has `z-index: 0`
- everything else has `z-index: 1`
  - except for .markedContent, which have `z-index: 0`
    and their contents have `z-index: 1`.

`.textLayer` has an explicit `z-index: 0` to introduce a new stacking context,
so that its contents are not drawn on top of `.annotationLayer`.
2024-05-14 14:31:12 +02:00
Jonas Jenwald
298d72133e
Merge pull request #18051 from Snuffleupagus/NodePackages
[api-minor] Re-factor how Node.js packages/polyfills are  loaded (issue 17245)
2024-05-14 11:43:57 +02:00
Tim van der Meij
0347e59b99
Merge pull request #18061 from Snuffleupagus/api-report-Stats
Slightly re-factor how the viewer initializes debug-only functionality
2024-05-13 19:38:59 +02:00
Calixte Denizet
093bdfd971 [Editor] Fix the CSS properties of the canvas when it's used in a stampEditor (bug 1895909)
And move the page canvas properties under canvasWrapper in order to avoid future regressions.
2024-05-13 16:58:19 +02:00
Jonas Jenwald
75a1955fd0
Revert "Fix rendering problem when zooming on Safari" 2024-05-13 16:14:38 +02:00
Jonas Jenwald
5fbc5ba16a Move the loadPDFBug function into PDFViewerApplication._parseHashParams
Given that this is a debug-only function we don't need to define it "globally" in the `web/app.js` file.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
ba8c620e4b Inline the loadFakeWorker function at its only call-site in web/app.js
Given that this is a debug-only, and fairly short, function we can just inline the code.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
4a8d742592 Move the reporting of page Stats into the API
This avoids having to add a couple of event listeners in the viewer, when debugging is enabled, and is consistent with the existing handling of `FontInspector` and `StepperManager` in the API.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
469738c1ce Remove event listeners with signal in web/pdf_viewer.js 2024-05-08 16:07:43 +02:00
Jonas Jenwald
9418ed19e7 [api-minor] Remove the, now unused, pdfjsLibPromise global
This global was only introduced to work-around problems caused by the GENERIC PDF.js build using top level await. Since that was removed in the previous commit, this global is now dead code.
2024-05-07 18:21:56 +02:00
Calixte Denizet
7742c3eb63 Avoid to aria-hide the structure tree (bug 1894849)
If one ancestor of the structure tree has the attribute aria-hidden
then it's invisible for screen readers.
2024-05-03 14:39:43 +02:00
Jonas Jenwald
2b69fb76ac [api-minor] Improve the FileSpec implementation
- Check that the `filename` is actually a string, before parsing it further.
 - Use proper "shadowing" in the `filename` getter.
 - Add a bit more validation of the data in `pickPlatformItem`.
 - Last, but not least, return both the original `filename` and the (path stripped) variant needed in the display-layer and viewer.
2024-05-01 18:02:05 +02:00
Jonas Jenwald
16dbf5dcfd
Merge pull request #18031 from Snuffleupagus/issue-18030
[api-minor] Expose the /Desc-attribute of file attachments in the viewer (issue 18030)
2024-05-01 17:53:22 +02:00
Jonas Jenwald
bf4e36d1b5 [api-minor] Expose the /Desc-attribute of file attachments in the viewer (issue 18030)
In the viewer this will be displayed in the `title` of the hyperlink, which is probably the best we can do here given how the viewer is implemented.
2024-05-01 09:02:11 +02:00
Tim van der Meij
77e2182b8e
Merge pull request #18019 from Aditi-1400/safari-zoom-fix
Fix rendering problem when zooming on Safari
2024-04-30 14:50:46 +02:00
Jonas Jenwald
150964dd6d Remove unnecessary check from PDFLinkService.goToDestination (PR 17984 follow-up)
After the changes in PR 17984 this code can no longer be reached, since the destination is now validated on the worker-thread.
2024-04-29 18:54:09 +02:00
Jonas Jenwald
f6cd03955b [api-minor] Move the page reference/number caching into the API
Rather than having to handle this *manually* throughout the viewer, this functionality can instead be moved into the API which simplifies the code slightly.
2024-04-29 18:54:06 +02:00
Jonas Jenwald
fa69d9a3bc Inline the helper method in PDFLinkService.goToDestination
We no longer need the helper method to *potentially* call itself once data is available, and can instead take full advantage of async/await by inlining the code.
2024-04-29 18:52:12 +02:00
Aditi
04580168a2 Fix rendering problem when zooming on Safari 2024-04-29 17:32:06 +05:30
Jonas Jenwald
8c3d571939 Re-factor SimpleLinkService to extend PDFLinkService
Rather than having to maintain a dummy `IPDFLinkService` implementation, we can simply let it extend the primary `PDFLinkService` class instead.
Note how *some* methods already checked for an active PDF document, and those checks only needed to be used consistently throughout `PDFLinkService` in order for this to work.
2024-04-28 10:18:41 +02:00
Tim van der Meij
885dd72433
Merge pull request #17984 from Snuffleupagus/issue-17981
Validate explicit destinations on the worker-thread to prevent `DataCloneError` (issue 17981)
2024-04-24 16:25:02 +02:00
Jonas Jenwald
7206d0a237 Validate explicit destinations on the worker-thread to prevent DataCloneError (issue 17981)
*Note:* This borrows a helper function from the viewer, however the code cannot be directly shared since the worker-thread has access to various primitives.
2024-04-22 22:51:35 +02:00
Jonas Jenwald
32b885c5ef Remove event listeners with signal in web/annotation_layer_builder.js and web/text_highlighter.js 2024-04-21 09:41:21 +02:00
Jonas Jenwald
2831caef13 Remove event listeners with signal in web/pdf_scripting_manager.js 2024-04-20 12:00:58 +02:00
Jonas Jenwald
bf785f2180 Remove event listeners with signal in web/pdf_history.js 2024-04-20 12:00:58 +02:00
Jonas Jenwald
702ee7b1e1 Add signal-support in the EventBus, and utilize it in the viewer (PR 17964 follow-up)
This mimics the `signal` option that's available for `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal).
2024-04-20 12:00:58 +02:00
Jonas Jenwald
ff2e0c8afd Skip the scroll/scrollend workaround in the Firefox PDF Viewer (PR 17724 follow-up)
Given that [bug 1881974](https://bugzilla.mozilla.org/show_bug.cgi?id=1881974) has been fixed in Firefox 126, the workaround should no longer be necessary in the *built-in* Firefox PDF Viewer.
2024-04-18 18:41:21 +02:00
Jonas Jenwald
46a29ff41b Remove event listeners with signal in web/app.js
By using the `signal` option when invoking `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal), we're able to remove an arbitrary number of event listeners with (effectively) a single line of code.
Besides getting rid of a bunch of `removeEventListener`-calls, which means shorter code, we no longer need to manually keep track of event-handling functions.
2024-04-18 18:41:21 +02:00
Jonas Jenwald
0788c4d918 Remove event listeners with signal in web/pdf_presentation_mode.js
By using the `signal` option when invoking `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal), we're able to remove an arbitrary number of event listeners with (effectively) a single line of code.
Besides getting rid of a bunch of `removeEventListener`-calls, which means shorter code, we no longer need to manually keep track of event-handling functions.
2024-04-18 18:41:18 +02:00
Calixte Denizet
71ea8499f0 [Editor] Provide an element to render in the annotation layer after a freetext has been edited (bug 1890535) 2024-04-18 13:29:41 +02:00
Jonas Jenwald
a41bb40fbb [api-minor] Update the minimum supported Safari version to 16.4
This patch updates the minimum supported browsers as follows:
 - Safari 16.4, which was released on 2023-03-27; see https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes

Nowadays we usually we try, where feasible and possible, to support browsers/environments that are about two years old. The reasons for limiting support to a slightly more recent Safari version include:
 - Safari has always been slower, compared to other browsers, at implementing e.g. new JavaScript features.
 - Trying to provide support for Safari is often difficult, and over the years we have seen *a lot* of bugs that are specific to Safari.
 - Safari is, and has been for many years, only listed as "mostly" supported in the FAQ.
 - This allows us to remove feature-testing, only relevant to Safari, from the main code-base.

By limiting support to only "recent" browsers we reduce the risk of holding back improvements of the built-in Firefox PDF Viewer, and also (significantly) reduce the maintenance/support burden for the PDF.js core contributors.

*Please note:* As always, the minimum supported browser version assumes that a `legacy`-build of the PDF.js library is being used; see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
2024-04-15 12:44:37 +02:00
Tim van der Meij
e08de772ff
Merge pull request #17879 from ex37/master
Improve type definitions for the viewer
2024-04-14 16:35:02 +02:00
Eduard Ghazanchyan
da43a53a68 Improve type definitions for the viewer
This commit improves compatibility of the viewer code with TypeScript by including missing type imports/definitions and correcting existing ones
2024-04-12 17:12:04 +04:00
Tim van der Meij
e005e6ecdd
Merge pull request #17933 from Snuffleupagus/pr-17464-followup
Fix resetting of cursor-tools when closing the document (PR 17464 follow-up)
2024-04-12 13:32:52 +02:00
Jonas Jenwald
60832fee27 Fix resetting of cursor-tools when closing the document (PR 17464 follow-up)
With the removal of the "secondarytoolbarreset" event in PR 17464 resetting of cursor-tools state accidentally broke.
2024-04-12 13:16:44 +02:00
Tim van der Meij
a45aec6393
Convert the history code to use proper private methods
This allows us to get rid of the `@private` JSDoc comments, which were
used to convey intent back when proper private methods could not be used
yet in JavaScript. This improves code readability/maintenance and enables
better usage validation by tooling such as ESlint.
2024-04-11 15:17:30 +02:00
Jonas Jenwald
f3b03e5c4b
Merge pull request #17917 from Snuffleupagus/showAll-rtl
Fix the RTL-rule for the `editorHighlightShowAll` button, such that it works outside of the Firefox PDF Viewer
2024-04-10 12:55:30 +02:00
Jonas Jenwald
3596a03279 Fix the RTL-rule for the editorHighlightShowAll button, such that it works outside of the Firefox PDF Viewer
These CSS rules were imported straight from mozilla-central, and contains a property that causes the RTL-rule to be skipped everywhere else (even when using the development viewer in Firefox).
2024-04-10 11:35:04 +02:00
Jonas Jenwald
8a1511cdd5 Tweak the fill-value of the Stamp-icon to work better in non-Firefox browsers
Currently this icon is invisible in e.g. Google Chrome, so update the `fill`-value to be more inline with the other editor-icons.
2024-04-10 11:14:41 +02:00
calixteman
77ee914bd6
Merge pull request #17882 from calixteman/bug1889122
Use the string value of the field when calling the Format callback (bug 1889122)
2024-04-10 09:40:54 +02:00
Calixte Denizet
b643c0fcfb Use the string value of the field when calling the Format callback (bug 1889122) 2024-04-09 22:52:11 +02:00
Tim van der Meij
862c27ee67
Convert the thumbnail view(er) code to use proper private methods
This allows us to get rid of the `@private` JSDoc comments, which were
used to convey intent back when proper private methods could not be used
yet in JavaScript. This improves code readability/maintenance and enables
better usage validation by tooling such as ESlint.
2024-04-05 14:44:48 +02:00
Tim van der Meij
2e5282928f
Merge pull request #17854 from Snuffleupagus/rm-PromiseCapability
[api-minor] Replace the `PromiseCapability` with  `Promise.withResolvers()`
2024-04-02 15:21:43 +02:00
Tim van der Meij
10312105a4
Merge pull request #17861 from Snuffleupagus/compatibilityParams-init
Limit all `compatibilityParams` handling to the GENERIC viewer
2024-04-02 14:47:37 +02:00
calixteman
26466b50bc
Merge pull request #17855 from calixteman/bug1888657
Avoid useless CSS animation when nothing is done (bug 1888657)
2024-04-01 19:01:14 +02:00
Calixte Denizet
d3a613dd5b Avoid useless CSS animation when nothing is done (bug 1888657) 2024-04-01 17:32:38 +02:00
Jonas Jenwald
0fdea4b05c Remove the addWindowResolutionChange listener unconditionally (PR 17767 follow-up)
Given that `PDFViewerApplication.unbindWindowEvents` can be invoked in mozilla-central tests, we should ensure that the listener is always removed.
2024-04-01 16:00:25 +02:00
Jonas Jenwald
e4d0e84802 [api-minor] Replace the PromiseCapability with Promise.withResolvers()
This replaces our custom `PromiseCapability`-class with the new native `Promise.withResolvers()` functionality, which does *almost* the same thing[1]; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers

The only difference is that `PromiseCapability` also had a `settled`-getter, which was however not widely used and the call-sites can either be removed or re-factored to avoid it. In particular:
 - In `src/display/api.js` we can tweak the `PDFObjects`-class to use a "special" initial data-value and just compare against that, in order to replace the `settled`-state.
 - In `web/app.js` we change the only case to manually track the `settled`-state, which should hopefully be OK given how this is being used.
 - In `web/pdf_outline_viewer.js` we can remove the `settled`-checks, since the code should work just fine without it. The only thing that could potentially happen is that we try to `resolve` a Promise multiple times, which is however *not* a problem since the value of a Promise cannot be changed once fulfilled or rejected.
 - In `web/pdf_viewer.js` we can remove the `settled`-checks, since the code should work fine without them:
     - For the `_onePageRenderedCapability` case the `settled`-check is used in a `EventBus`-listener which is *removed* on its first (valid) invocation.
     - For the `_pagesCapability` case the `settled`-check is used in a print-related helper that works just fine with "only" the other checks.
 - In `test/unit/api_spec.js` we can change the few relevant cases to manually track the `settled`-state, since this is both simple and *test-only* code.

---
[1] In browsers/environments that lack native support, note [the compatibility data](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers#browser_compatibility), it'll be polyfilled via the `core-js` library (but only in `legacy` builds).
2024-04-01 11:42:37 +02:00