Commit Graph

3723 Commits

Author SHA1 Message Date
calixteman
d9f13558d6
Merge pull request #15770 from calixteman/set_dims
Set the dimensions of the various layers at their creation
2022-12-11 17:32:29 +01:00
Jonas Jenwald
828efd9d00 Change the XfaLayerBuilder.render method to be asynchronous
This is consistent with the `render` methods of the other layers, and reduces overall indentation in the method.
Furthermore, don't "swallow" errors since the `PDFPageView._renderXfaLayer` method is already able to deal with that.
2022-12-11 13:08:23 +01:00
Calixte Denizet
a989b5a879 Set the dimensions of the various layers at their creation
- Use a unique helper function in display/display_utils.js;
- Move those dimensions in css' side.
2022-12-10 14:35:06 +01:00
Jonas Jenwald
bed1a1baa1 [AnnotationEditorLayerBuilder] Inline the destroy code in the cancel method
It doesn't seem necessary to have a *separate* `destroy` method given that the `cancel` method always invokes it unconditionally.
In the `PDFPageView.reset` method we currently attempt to call `destroy` directly, however that'll never actually happen since either:
 - We're keeping the annotationEditorLayer, in which case we're just hiding the layer and nothing more (and the relevant branch is never entered).
 - We're removing the annotationEditorLayer, in which case the `PDFPageView.cancelRendering` method has already cancelled *and* nulled it (and there's thus nothing left to `destroy` here).

*Please note:* Hopefully I'm not overlooking something obvious here, since both reading through the code *and* also adding `console.log(this.annotationEditorLayer);` [before this line](9d4aadbf7a/web/pdf_page_view.js (L438)) suggests that it's indeed unnecessary.
2022-12-10 10:16:20 +01:00
Jonas Jenwald
527258c316 Ensure that the various layers always get the correct initial size (issue 15795) 2022-12-09 14:30:12 +01:00
Jonas Jenwald
47ac706972 Fix page-switching for landscape documents with SpreadModes and PresentationMode (PR 14877 follow-up)
In PR 14877 I forgot to update the horizontal padding, used when computing the scale of the pages, for the case where SpreadModes and PresentationMode are being used together.

Steps to reproduce:
 1. Open the viewer with the default `tracemonkey.pdf` document.
 1. Enable any SpreadMode.
 2. Rotate the document *once*, either clockwise or counterclockwise.
 3. Enter PresentationMode.
 4. Try swithching page, e.g. by clicking on the document.

Expected result:
 The visible pages change as you click.

Actual result:
 The visible pages are "stuck" in the current view.
2022-12-09 14:09:56 +01:00
Jonas Jenwald
d7d21f0d6e Change AnnotationEditorLayerBuilder.render to not access "private" API functionality
The `PDFPageProxy._pageIndex` property is a "private" one that shouldn't be accessed, since it could theoretically break tomorrow if we re-factor the relevant API code.

Also, try to clean-up and improve consistency in a couple of JSDoc comments.
2022-12-08 15:40:04 +01:00
Jonas Jenwald
6a5c1343f8 Stop trying to disable searching in PresentationMode
This change was made in PR 5552, however I cannot tell why we needed to disable searching in PresentationMode. Furthermore, with the changes in PR 13908 which effectively moved where this code is invoked, searching has now (accidentally) been working in PresentationMode in e.g. the Firefox PDF Viewer for well over a year.

So, let's just enable searching unconditionally in PresentationMode to simplify the code.
2022-12-08 15:33:57 +01:00
calixteman
fe3df4dcb4
Merge pull request #15782 from calixteman/15780
[api-minor][Editor] Don't use the editor parent which can be null.
2022-12-08 14:27:42 +01:00
Calixte Denizet
b93bf9f654 [Editor] Don't use the editor parent which can be null.
An annotation editor layer can be destroyed when it's invisible, hence some
annotations can have a null parent but when printing/saving or when changing
font size, color, ... of all added annotations (when selected with ctrl+a) we
still need to have some parent properties especially the page dimensions, global
scale factor and global rotation angle.
This patch aims to remove all the references to the parent in the editor instances
except in some cases where an editor should obviously have one.
It fixes #15780.
2022-12-08 14:06:06 +01:00
Jonas Jenwald
c639063050
Merge pull request #15776 from Snuffleupagus/rm-createDownloadManager-options
Remove the unused `DefaultExternalServices.createDownloadManager` options (PR 12191 follow-up)
2022-12-07 10:31:15 +01:00
Jonas Jenwald
cdd39ec69e
Merge pull request #15778 from Snuffleupagus/keep-structTree
Don't re-create the `structTreeLayer` on zooming and rotation
2022-12-06 10:02:20 +01:00
Jonas Jenwald
fe8fded23b [api-minor] Combine the textContent/textContentStream parameters
Rather than handling these parameters separately, which is a left-over from back when streaming of textContent was originally added, we can simply pass either data directly to the `TextLayer` and let it handle things accordingly.

Also, improves a few JSDoc comments and `typedef`-imports.
2022-12-04 21:22:14 +01:00
Jonas Jenwald
da0e6bc590 Don't re-create the structTreeLayer on zooming and rotation
Compared to the recent PR 15722 for the `textLayer` this one should be a (comparatively) much a smaller win overall, since most documents don't have any structTree-data and the required parsing should be cheaper. However, it seems to me that it cannot hurt to improve this nonetheless.

Note that by moving the `structTreeLayer` initialization we remove the need for the "textlayerrendered" event listener, which thus simplifies the code a little bit.

Also, removes the API-caching of the structTree-data since this was basically done to offset the lack of caching in the viewer.
2022-12-04 10:18:58 +01:00
Jonas Jenwald
cd72818438 Remove unused StructTreeLayerBuilder constructor parameter
Also change the "private" methods into properly private ones.
2022-12-03 22:58:37 +01:00
Jonas Jenwald
9369adb4bd Remove the unused DefaultExternalServices.createDownloadManager options (PR 12191 follow-up) 2022-12-03 12:52:36 +01:00
Calixte Denizet
973478e704 Remove execution permission on cursor-editorFreeText.svg 2022-12-02 09:52:03 +01:00
calixteman
6e4968225e
Merge pull request #15722 from calixteman/refactor_textlayer
[api-minor] Refactor the text layer code in order to avoid to recompute it on each draw
2022-12-01 18:56:02 +01:00
Calixte Denizet
eed9bf71c5 Refactor the text layer code in order to avoid to recompute it on each draw
The idea is just to resuse what we got on the first draw.
Now, we only update the scaleX of the different spans and the other values
are dependant of --scale-factor.
Move some properties in the CSS in order to avoid any updates in JS.
2022-12-01 18:42:43 +01:00
Jonas Jenwald
0cf4e6620d Prevent the debugger from breaking on unbalanced save/restore OPS (issue 15767) 2022-12-01 15:43:17 +01:00
Jonas Jenwald
7c25b1b455 [api-minor] Remove the TextLayer timeout parameter (PR 15742 follow-up)
The deprecation is included in the current release, i.e. version `3.1.81`, and given the edge-case nature of this option I really don't think that we need to keep it deprecated for multiple releases.
2022-11-29 19:57:38 +01:00
calixteman
a3ac8a6438
Merge pull request #15718 from calixteman/test_text_cursor
[Editor] Change the text annotation cursor for the high dpi screens.
2022-11-29 16:37:36 +01:00
Calixte Denizet
8689905a19 [Editor] Change the text annotation cursor for the high dpi screens. 2022-11-29 15:48:55 +01:00
Jonas Jenwald
0d648f531b Ignore PDF documents opened from "data:"-URLs when handling internal links (bug 1803050)
This patch has been successfully tested in a local, artifact, Firefox build.

*Please note:* The only thing that'll no longer work for PDF documents opened using "data:"-URLs is middle-clicking on internal/outline links, in order to open the destination in a new tab. This is however an extremely small loss of functionality, and as can be seen in the bug the alternative (i.e. doing nothing) is surely much worse.
2022-11-29 14:08:01 +01:00
Calixte Denizet
ea1995991b Don't add an extra space after a Katakana or a Hiragana at the eol when searching 2022-11-29 10:46:48 +01:00
Calixte Denizet
b9cb651c44 [api-minor] Remove all the useless telemetry stuff in the viewer (bug 1802468)
Add a deprecation notification for PDFDocumentLoadingTask.onUnsupportedFeature and PDFDocumentProxy.stats
which are likely useless.
The unsupported feature stuff have initially been added in (#4048) in order to be able to display a
warning bar and to help to have some numbers to know how a feature was used.
Those data are no more used in Firefox.
2022-11-28 20:55:15 +01:00
Jonas Jenwald
73760144e0
Merge pull request #15747 from Snuffleupagus/FileAttachment-icons
Add default icons for FileAttachment annotations (bug 1230933)
2022-11-26 17:59:52 +01:00
Jonas Jenwald
aa5b678f94 Add default icons for FileAttachment annotations (bug 1230933)
*Please note:* This "borrows" the icons from Thunderbird.

According to the PDF specification, see https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2096626, we should be providing default icons for FileAttachment annotations without appearances.
2022-11-26 11:24:59 +01:00
Jonas Jenwald
37c2408199 Ensure that the initial document position is always correct with non-default Scroll/Spread modes (issue 15695)
Please refer to the inline comment for additional details. The patch also improves internal consistency when `#scrollIntoView` is called directly.
2022-11-26 10:06:29 +01:00
Jonas Jenwald
9f5e1f4818
Revert "Remove the overflowing text special-case from scrollIntoView (issue 15714)" 2022-11-24 12:37:07 +01:00
Jonas Jenwald
73c268dc1c
Merge pull request #15730 from Snuffleupagus/issue-15729
Support FileAttachments with hash-signs in the filename (issue 15729)
2022-11-23 12:52:11 +01:00
calixteman
8cd2adf8a1
Merge pull request #15727 from calixteman/bug1801341
Unblock the load event when the pdf has a password (bug 1801341)
2022-11-23 12:09:12 +01:00
Calixte Denizet
38dd219d85 Unblock the load event when the pdf has a password (bug 1801341) 2022-11-23 11:17:58 +01:00
Jonas Jenwald
0ba242ea4a Support FileAttachments with hash-signs in the filename (issue 15729)
The reason for the issue is that we use the generic `getFilenameFromUrl` helper function, which was originally intended for regular URLs.
For the filenames we're dealing with in FileAttachments, we really only want to strip the path when one exists[1].

---
[1] See [bug 1230933](https://bugzilla.mozilla.org/show_bug.cgi?id=1230933) for an example of such a case.
2022-11-23 10:47:33 +01:00
Jonas Jenwald
0ff43b27bb Remove the overflowing text special-case from scrollIntoView (issue 15714)
With the changes made in PR 14564 this *should* no longer be necessary now, however we still need to keep the `scrollMatches` parameter to handle textLayers with markedContent correctly when searching.
2022-11-22 11:54:30 +01:00
Jonas Jenwald
176e8f0ddc Initialize the find-related DIACRITICS_EXCEPTION_STR constant lazily
Adding some logging with `console.{time, timeEnd}` around all the constant definitions at the top of the `web/pdf_find_controller.js` file, I noticed that computing `DIACRITICS_EXCEPTION_STR` took close to half the total time.
My first idea was just to try and make it slightly more efficient, by reducing the amount of iterations and intermediate allocations. However, with this constant only being used during "match diacritics" searches it thus seemed like a good candidate for lazy initialization.

*Please note:* Given that this is a micro optimization, I fully understand if the patch is rejected.
2022-11-15 12:46:16 +01:00
Calixte Denizet
2be64d63e1 Normalize fullwidth, halfwidth and circled chars when searching 2022-11-14 19:27:51 +01:00
Jonas Jenwald
e7a6e7393a Use private fields in a few more viewer classes
These properties were always intended to be *private*, so let's use modern JS features to actually enforce that.
2022-11-04 15:29:45 +01:00
Jonas Jenwald
547556b5b2 Prevent keyboard interaction with form elements in PresentationMode (issue 12232)
This uses the relatively new `HTMLElement.inert` property, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert for additional information. The only "problem" is that this isn't yet available in all Firefox channels, but until https://bugzilla.mozilla.org/show_bug.cgi?id=1764263 is fixed we're no worse off than before.
2022-10-30 21:57:55 +01:00
Jonas Jenwald
f0811a4a3c Prevent mouse interaction with form elements in PresentationMode (issue 12232) 2022-10-30 21:55:44 +01:00
Calixte Denizet
67778eac60 [Editor] Change the cursor icons 2022-10-29 12:05:09 +02:00
Calixte Denizet
0996398372 Fix font for the 'current view' entry in the secondary toolbar (bug 1797310) 2022-10-26 10:49:23 +02:00
Jonas Jenwald
03775917db Update the l10n-strings for the download-buttons (bug 1662416)
According to https://bugzilla.mozilla.org/show_bug.cgi?id=1662416#c8
2022-10-24 18:29:44 +02:00
Calixte Denizet
80dfd5404f Update icons (last and final update) 2022-10-21 12:31:34 +02:00
Jonas Jenwald
0983ebb257 Tweak the vertical position of the sidebar notification icon
Given that the new sidebar icon is slightly shorter than the old one, it cannot hurt to ever so slightly tweak the vertical position of the notification icon.

(While the patch also changes the CSS rule used for the horizontal position, this is a no-op and was done to improve consistency between the two values.)
2022-10-15 22:19:24 +02:00
Jonas Jenwald
4f5f362d60 Remove unnecessary size attribute from the pageNumber-input
This attribute is overridden by the explicit `width` that's specified in the CSS rules, hence we can remove one more small piece of very old code; see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#size
2022-10-08 12:34:13 +02:00
Jonas Jenwald
450be1ad3e Simplify the dropdownToolbarButton-select width computation
The way that we set the width of the `dropdownToolbarButton`-select is very old, and despite some improvements over the years this is still somewhat hacky.
In particular, note how we're assigning the select-element a larger width than its containing `dropdownToolbarButton`-element. This was done to prevent displaying *two* separate icons, i.e. the native and the PDF.js one, since it's the only way to handle this in older browsers (particularly Internet Explorer).

Given the currently supported browsers, there's however a better solution available: use `appearance: none;` to disable native styling of the select-element. [According to MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/appearance#browser_compatibility), this is supported in all reasonably modern browsers.
This way we're able to simplify both the CSS rules and the JS-code that's used to adjust the `dropdownToolbarButton` width in a localization aware way.
2022-10-07 18:19:10 +02:00
Calixte Denizet
24757e32d1 [XFA] Add some padding inline in selects
Because of https://bugzilla.mozilla.org/show_bug.cgi?id=1582545, the padding-inline is by default 0.
0 is not really enough because of the outline, so just set it to 2px (it was 4px before the patch)
in order to have something visually correct.
2022-10-07 15:11:58 +02:00
Jonas Jenwald
8629a55215
Merge pull request #15538 from Snuffleupagus/viewer-error-logging
Stop localizing error *details* in the viewer (PR 15533 follow-up)
2022-10-07 11:16:22 +02:00
Jonas Jenwald
1ea4c4b519 [api-minor] Make isOffscreenCanvasSupported configurable via the API (issue 14952)
This patch first of all makes `isOffscreenCanvasSupported` configurable, defaulting to `true` in browsers and `false` in Node.js environments, with a new `getDocument` parameter. While you normally want to use this, in order to improve performance, it should still be possible for users to control it (similar to e.g. `isEvalSupported`).

The specific problem, as reported in issue 14952, is that the SVG back-end doesn't support the new ImageMask data-format that's introduced in PR 14754. In particular:
 - When the SVG back-end is used in Node.js environments, this patch will "just work" without the user needing to make any code changes.
 - If the SVG back-end is used in browsers, this patch will require that `isOffscreenCanvasSupported: false` is added to the `getDocument`-call.
2022-10-07 00:10:46 +02:00
Jonas Jenwald
2f238a11c1 Stop localizing error *details* in the viewer (PR 15533 follow-up)
While it can't hurt to localize the main error-messages, also localizing the error *details* has always seemed somewhat unnecessary since those are only intended for debugging/development purposes. However, I can understand why that's done since the GENERIC viewer used to expose this information in the UI; via the `errorWrapper` UI that's removed in PR 15533.

At this point, when any errors are simply logged in the console, it no longer seems necessary to keep localizing the error *details* in the default viewer.
2022-10-06 13:09:39 +02:00
Jonas Jenwald
6bd5ef29ae Log the build number, in addition to the version, in the viewer
Given that the `build` number allows you to *directly* find the relevant commit, it cannot hurt to log that one as well.
2022-10-06 12:03:22 +02:00
Jonas Jenwald
ce66fefbff [api-minor] Add partial support for the "GoToE" action (issue 8844)
*Please note:* The referenced issue is the only mention that I can find, in either GitHub or Bugzilla, of "GoToE" actions.
Hence why I've purposely settled for a very simple, and partial, "GoToE" implementation to avoid complicating things initially.[1] In particular, this patch only supports "GoToE" actions that references the /EmbeddedFiles-dict in the PDF document.

See https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2048909

---
[1] Usually I always prefer having *real-world* test-cases to work with, whenever I'm implementing new features.
2022-10-06 10:33:07 +02:00
Jonas Jenwald
60f6272ed9 Use more for...of loops in the code-base
Most, if not all, of this code is old enough to predate the general availability of `for...of` iteration.
2022-10-03 13:08:38 +02:00
Jonas Jenwald
62c1a4e8c8 [Firefox viewer] Skip unused printing-string in DEFAULT_L10N_STRINGS
Given that the Firefox PDF Viewer uses the *browser* print UI, this fallback l10n-string isn't necessary in the MOZCENTRAL build.
2022-10-01 17:35:43 +02:00
Jonas Jenwald
75e06fddf1 [GENERIC viewer] Remove the errorWrapper UI
In the Firefox PDF Viewer this has never been used, with the error message simply printed in the web-console, and (somewhat) recently we've also updated the viewer code to avoid bundling the relevant code there. Furthermore, in the Firefox PDF Viewer we're not even display the *browser* fallback bar any more; see https://bugzilla.mozilla.org/show_bug.cgi?id=1705327.

Hence it seems slightly strange to keep this UI around in the GENERIC viewer, and this patch proposes that we simply remove it to simplify/unify the relevant code in the viewer. In particular this also allows us to remove a couple of l10n-strings, which have always been unused in the Firefox PDF Viewer.
2022-10-01 17:35:35 +02:00
Tim van der Meij
2c38a14a14
Merge pull request #15530 from Snuffleupagus/sidebar-toggleButton-l10n
Re-factor the `toggleButton` l10n in the `PDFSidebar` class
2022-10-01 13:10:32 +02:00
Jonas Jenwald
1ee096d229
Merge pull request #15515 from mozilla/revert-15418-pr-15319-followup
Revert "Don't listen for window resolution changes in old browsers (PR 15319 follow-up)"
2022-09-30 10:15:05 +02:00
Jonas Jenwald
bad00f825a Re-factor the toggleButton l10n in the PDFSidebar class
Rather than "manually" looking up the l10n-string and then updating the button, we can (and probably even should) just update the l10n-id and then trigger proper translation for the button DOM-element.
2022-09-30 09:59:58 +02:00
Jonas Jenwald
205ab95819 [Editing] Disable the HandTool during editing (bug 1792422)
This extends the approach used in PresentationMode to also cover the AnnotationEditor, and tries to handle the combination of both cases correctly.
In order to simplify the overall implementation we simply track the *first* seen "previous" cursorTool, and don't allow it to be reset as long as either PresentationMode or an AnnotationEditor is being used.
2022-09-29 10:44:06 +02:00
Jonas Jenwald
4c7a03c4cb
Revert "Don't listen for window resolution changes in old browsers (PR 15319 follow-up)" 2022-09-27 12:27:27 +02:00
Jonas Jenwald
b420f0165a Use stopImmediatePropagation without checking for its existence first
These checks were added years ago, but given the following compatibility data we should just be able to call the method directly: https://developer.mozilla.org/en-US/docs/Web/API/Event/stopImmediatePropagation#browser_compatibility
2022-09-24 15:02:12 +02:00
Tim van der Meij
907ef467ea
Merge pull request #15503 from Snuffleupagus/consistent-outline
Use a consistent `outline` for all UI buttons (PR 15438 follow-up)
2022-09-24 14:48:21 +02:00
Jonas Jenwald
5296fc991c Restore the old fonts in the errorWrapper (PR 15438 follow-up)
This only applies to the GENERIC viewer, hence we use the pre-processor to exclude it from the Firefox PDF Viewer.
2022-09-24 13:54:34 +02:00
Jonas Jenwald
616535b7a7 Use a consistent outline for all UI buttons (PR 15438 follow-up)
Currently the `viewBookmark`-button, which is actually a `href`-element, gets an inconsistent `outline`.
Similarly, the `dialog`-buttons also have an inconsistent `outline` after the changes in PR 15438.

Finally, simplifies a couple of `border` rules since setting a border-width when "none" is being used doesn't seem meaningful.
2022-09-24 13:42:27 +02:00
calixteman
9ded9dd4e5
Revert "Don't use window.print in the Firefox builtin viewer (bug 1774427)" 2022-09-22 16:58:49 +02:00
Jonas Jenwald
1558c0e85e Set a border-radius when hovering annotationLayer-inputs (PR 15438 follow-up)
The changes in PR 15438 added a `border-radius` when input-elements are focused, however there's no radius when the same elements are hovered. Having the radius change, and not just the `border-color`, when input goes from hovered to focused feels a bit inconsistent (at least to me).
2022-09-22 10:01:24 +02:00
Jonas Jenwald
2a1d536ec6 Restore the old fonts in the debugger (PR 15438 follow-up)
The changes in PR 15438 affected the debugger as well, which means that some of the panels/buttons look (in my opinion) a bit less nice than before.
2022-09-21 21:49:17 +02:00
Calixte Denizet
3b536f2701 [Editor] Make sure to have the annotation editor layer on top of the annotation one (bug 1791515)
Some z-index have been added in the annotation layer because the elements inside are re-ordered
in order to improve accessibility.
Hence we must add a "high" z-index on the annotation editor layer in order to avoid any bad
interaction between the different layers.
2022-09-20 10:58:35 +02:00
calixteman
e5fc7cf4bd
Merge pull request #15461 from calixteman/1790309
Use AccentColor as background for selected text in the text layer (bug 1790309)
2022-09-19 22:36:37 +02:00
Calixte Denizet
403aa5cfa0 [XFA] - Avoid an exception when zooming on a XFA 2022-09-19 21:31:52 +02:00
Calixte Denizet
68977ebc26 Use AccentColor as background for selected text in the text layer (bug 1790309)
and use the default color for the viewer in general.
2022-09-19 21:25:56 +02:00
Calixte Denizet
620f1ef1a9 Don't use window.print in the Firefox builtin viewer (bug 1774427)
Currently, it's impossible to print a pdf in a sandboxed iframe in using window.print.
2022-09-19 14:22:40 +02:00
calixteman
dc6c3eacbc
Merge pull request #15438 from calixteman/1726183
Improve CSS for HCM (bug 1726183)
2022-09-18 16:04:56 +02:00
Calixte Denizet
07cd7cb3dc Improve CSS for HCM (bug 1726183)
The default outline for a focused text input is not that bad but for any reason when changing
the background color, all the good default border/outline properties are lost (it's the same
behaviour in Edge).
So in order have something consistent in HCM/non-HCM, a 2px-border+1px-outline (on @MReschenberg
advices) is added when an input is focused with different colors depending on HCM.
While working on the above issue, I noticed few bugs I fixed when in HCM:
 - input, button and select have some default properties which have been created at a time where
   annotation layer didn't exist, hence this patch remove them and set those properties where
   they should live;
 - some elements (like the main toolbar) is using a box-shadow which is invisible in HCM, hence
   it's replaced by a border-bottom in HCM;
 - some separators are invisible in HCM, hence use GrayText color to render them correctly;
 - the options for the zoom selection were invisible in HCM with Desert (one of the Windows 11
   themes).
2022-09-18 16:03:24 +02:00
Tim van der Meij
67160f4cae
Merge pull request #15455 from Snuffleupagus/issue-15453
Don't update the Scroll/Spread-mode in the ViewHistory while PresentationMode is active (issue 15453)
2022-09-18 14:35:00 +02:00
Tim van der Meij
f7ab417757
Merge pull request #15432 from Snuffleupagus/validateFileURL-var
Some *small* viewer clean-up for non-GENERIC builds
2022-09-18 14:32:13 +02:00
Jonas Jenwald
2c02a2fc5c Don't update the Scroll/Spread-mode in the ViewHistory while PresentationMode is active (issue 15453)
By force-quitting the browser while the FullScreen API is active, we don't get a chance to exit PresentationMode *cleanly* and some of its state thus remains (via the `ViewHistory`).
To try and improve things here we can skip updating the Scroll/Spread-mode while PresentationMode is active, since they will be changed when entering PresentationMode, which seems to help and is really the best that we can do here (and what the issue describes is very much an edge-case anyway).
2022-09-18 11:42:01 +02:00
Jonas Jenwald
5e5aa9fb69
Merge pull request #15339 from Snuffleupagus/enable-editor
[api-major] Enable editing by default
2022-09-13 15:57:54 +02:00
Jonas Jenwald
3c6b3b55c7 Move the errorWrapper definition in the getViewerConfiguration function
Similar to how we handle e.g. the "Open File"-buttons in non-GENERIC builds, we can handle the `errorWrapper` definition in the same way.
2022-09-13 14:18:38 +02:00
Jonas Jenwald
0988915d06 Only define the validateFileURL variable in GENERIC builds
There's no point in having this variable defined (implicitly) as `undefined` in e.g. the Firefox PDF Viewer.
By defining it with `var` and using an ESLint ignore, rather than `let`, we can move it into the relevant pre-processor block instead. Note that since the entire viewer-code is placed, by Webpack, in a top-level closure this variable will thus not become globally accessible.
2022-09-13 14:18:23 +02:00
Jonas Jenwald
00aef590cf Disable the editing-indicator, in the document title, during printing (bug 1790552, PR 15351 follow-up) 2022-09-13 11:33:24 +02:00
Jonas Jenwald
3e8394ee33 [api-major] Enable editing by default
Note that this patch *at least* shouldn't land until both [bug 1784272](https://bugzilla.mozilla.org/show_bug.cgi?id=1784272) and [bug 1785248](https://bugzilla.mozilla.org/show_bug.cgi?id=1785248) are fixed.
2022-09-12 14:58:31 +02:00
calixteman
493bb65005
Merge pull request #15425 from Snuffleupagus/cursor-failed-fullscreen
Don't try to update the cursorTool when switching to PresentationMode failed
2022-09-12 14:51:55 +02:00
calixteman
2d1d64b214
Merge pull request #15416 from calixteman/buttons_telemetry
Add some telemetry to know how often the buttons in the secondary toolbar are used (bug 1789883)
2022-09-12 13:59:45 +02:00
Jonas Jenwald
71f8680d66 Don't try to update the cursorTool when switching to PresentationMode failed
Currently this may print an Error message in the console, and while nothing breaks (since no actual Error is thrown) we should probably avoid this.
2022-09-12 13:36:37 +02:00
Calixte Denizet
05e4aed787 Add some telemetry to know how often the buttons in the secondary toolbar are used (bug 1789883) 2022-09-12 12:37:48 +02:00
Tim van der Meij
f63d584cb1
Merge pull request #15414 from Snuffleupagus/mv-PDFViewer
Remove the abstract `BaseViewer`-class
2022-09-10 13:37:04 +02:00
Jonas Jenwald
4189a8567e Fix the visibility of a separator in the secondaryToolbar (PR 15391 follow-up)
After the changes in PR 15391 one separator may now become visible too soon when the viewer is narrow, applies e.g. to the MOZCENTRAL viewer, since the wrong CSS class is being used.
The reason that this happens is that only the GENERIC viewer includes the "openFile"-buttons, and we thus need the separator to also be conditionally defined.
2022-09-09 17:50:29 +02:00
Jonas Jenwald
c36205f10d Don't listen for window resolution changes in old browsers (PR 15319 follow-up)
This is a slightly speculative change, based on something that I happened to notice while browsing MDN, to hopefully prevent PDF.js from outright breaking in older browsers.
According to the following information on MDN, Safari didn't implement support for the necessary features until version 14:
 - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/change_event#browser_compatibility

Given the browsers that we currently support only older versions of Safari should be affected, hence it seems reasonable to simply disable the functionality rather than trying to polyfill it.
(It's interesting how it's very often Safari which is *much* slower than the other browsers at implementing new features.)
2022-09-09 10:39:35 +02:00
Jonas Jenwald
21fe5017bb Remove the abstract BaseViewer-class
After the changes in PR 14112 the `PDFViewer`-class is now "identical" to the `BaseViewer`-class and the `PDFSinglePageViewer`-class is just a very thin wrapper around the `BaseViewer`-class.
Hence we can rename these files, and also remove the abstract `BaseViewer`-class, which helps reduce some unnecessary "closures" in the *built* viewer.

*Please note:* These changes are made in two separate commits, to allow GitHub to preserve `blame` for the affected files.
2022-09-08 12:38:17 +02:00
Jonas Jenwald
6dc4c994b8 Remove the abstract BaseViewer-class
After the changes in PR 14112 the `PDFViewer`-class is now "identical" to the `BaseViewer`-class and the `PDFSinglePageViewer`-class is just a very thin wrapper around the `BaseViewer`-class.
Hence we can rename these files, and also remove the abstract `BaseViewer`-class, which helps reduce some unnecessary "closures" in the *built* viewer.

*Please note:* These changes are made in two separate commits, to allow GitHub to preserve `blame` for the affected files.
2022-09-08 12:38:17 +02:00
calixteman
b0a021d2cc
Merge pull request #15413 from calixteman/items_size
Set a display value for the secondary toolbar buttons
2022-09-08 12:35:08 +02:00
Calixte Denizet
f8ae49d20b Set a display value for the secondary toolbar buttons
and remove a useless property: visibleSmallView.
2022-09-08 12:19:21 +02:00
Calixte Denizet
e56c30eb59 Move 'presentation mode' and 'bookmarks' buttons in the secondary toolbar (bug 1789082) 2022-09-08 12:18:08 +02:00
calixteman
6852001b02
Merge pull request #15384 from calixteman/icons
Update some icons in the toolbar (bug 1739965)
2022-09-07 11:48:27 +02:00
Calixte Denizet
90c69876ca Update some icons in the toolbar (bug 1739965) 2022-09-07 10:45:03 +02:00
Jonas Jenwald
af6aacfc0e
Merge pull request #15398 from Snuffleupagus/more-optional-chaining
Use more optional chaining in the code-base
2022-09-06 20:31:03 +02:00
Jonas Jenwald
c70ceecff4 Remove the "tagged" telemetry-reporting
Given that this is no longer being recorded in Firefox, it shouldn't be necessary to keep the associated code in the default viewer.
2022-09-06 13:00:44 +02:00
Jonas Jenwald
38ee28b1d3 Use more optional chaining in the code-base
This patch updates a bunch of older code, that makes conditional function calls, to use optional chaining rather than `if`-blocks.

These mostly mechanical changes reduce the size of the `gulp mozcentral` build by a little over 1 kB.
2022-09-05 15:41:53 +02:00
calixteman
72375ed652
Merge pull request #15395 from calixteman/15340
Don't replace cr by a white space when the last char on the line is an ideographic char
2022-09-04 14:30:22 +02:00
Calixte Denizet
6c6f6fb2b8 Don't replace cr by a white space when the last char on the line is an ideographic char 2022-09-04 14:21:05 +02:00
Jonas Jenwald
21042371e6 Update npm packages 2022-09-04 10:16:40 +02:00
Tim van der Meij
50d72fc111
Merge pull request #15377 from Snuffleupagus/SetOCGState
[api-minor] Add basic support for the `SetOCGState` action (issue 15372)
2022-09-03 13:26:06 +02:00
Calixte Denizet
1b14b06e4c [Editor] Change the cursor when we switch to FreeText mode (bug 1787297) 2022-09-02 15:17:24 +02:00
Calixte Denizet
ec165abfa1 Update editing icons (bug 1785248) 2022-09-02 12:42:25 +02:00
Calixte Denizet
b8fa789022 [Editor] Update some strings (bug 1787299) 2022-09-01 18:02:17 +02:00
Jonas Jenwald
cc4baa2fe9 [api-minor] Add basic support for the SetOCGState action (issue 15372)
Note that this patch implements the `SetOCGState`-handling in `PDFLinkService`, rather than as a new method in `OptionalContentConfig`[1], since this action is nothing but a series of `setVisibility`-calls and that it seems quite uncommon in real-world PDF documents.

The new functionality also required some tweaks in the `PDFLayerViewer`, to ensure that the `layersView` in the sidebar is updated correctly when the optional-content visibility changes from "outside" of `PDFLayerViewer`.

---
[1] We can obviously move this code into `OptionalContentConfig` instead, if deemed necessary, but for an initial implementation I figured that doing it this way might be acceptable.
2022-09-01 17:34:24 +02:00
Jonas Jenwald
216b86a082 [api-minor] Support Named-actions in the outline (issue 15367)
Apparently this is implemented in e.g. Adobe Reader, and the specification does support it, however it cannot be commonly used in real-world PDF documents since it took over ten years for this feature to be requested.
2022-08-30 18:47:45 +02:00
Tim van der Meij
86370bd5c5
Merge pull request #15286 from Snuffleupagus/rm-deprecated
[api-major] Remove (most of) the remaining `deprecated` code
2022-08-28 19:21:45 +02:00
Jonas Jenwald
78f24e5535 [api-major] Remove (most of) the remaining deprecated code
There's three notable exceptions here:
 - The `saveDocument` one is converted into a permanent `warn`, since it still works when the `annotationStorage` is empty although it's (obviously) less efficient than `getData`.
 - The `fallbackWorkerSrc` functionality (for browsers), since just removing it would risk too much third-party breakage.
 - The SVG back-end, since a final decision is yet to be made. (It might be completely removed, or left as-is in an essentially "frozen" state.)
2022-08-28 15:05:00 +02:00
Jonas Jenwald
571ce13dd6 [api-major] Remove the enhanceTextSelection functionality (PR 15145 follow-up)
For the `gulp mozcentral` command, this reduces the size of the *built* `pdf.js` file by `> 10` kB.
2022-08-28 15:04:47 +02:00
Tim van der Meij
d62cce455f
Merge pull request #15349 from Snuffleupagus/bug-1787295
[editor] Remove the `editorNone` toolbar button (bug 1787295)
2022-08-27 14:04:06 +02:00
Tim van der Meij
c5b9e9aef8
Merge pull request #15351 from Snuffleupagus/bug-1785854
[api-minor][editor] Indicate, in the title, if the document has been edited (bug 1785854)
2022-08-27 13:52:07 +02:00
Tim van der Meij
4469453425
Merge pull request #15341 from Snuffleupagus/PasswordPrompt-cancel-button
Improve handling of the "Cancel"-button in the password dialog
2022-08-27 13:10:39 +02:00
Jonas Jenwald
d93d21fdfd Always focus the viewerContainer when entering PresentationMode (bug 1787456)
This fixes the regression in [bug 1787456](https://bugzilla.mozilla.org/show_bug.cgi?id=1787456), assuming that it should be handled on the PDF.js side.
2022-08-26 21:42:06 +02:00
Jonas Jenwald
f2b5210b36
Merge pull request #15347 from federicobond/fix-types
Update types in PDFPageViewOptions to properly declare optional parameters
2022-08-26 20:48:12 +02:00
Jonas Jenwald
19182d5f25 [editor] Remove the editorNone toolbar button (bug 1787295) 2022-08-26 09:25:05 +02:00
Jonas Jenwald
151dfc9a25 [api-minor][editor] Indicate, in the title, if the document has been edited (bug 1785854)
Note that this patch prepends the document title with "* ", rather than only "*" as suggested in the bug, since there's nothing that says that a PDF document cannot specify a title[1] beginning with an asterisk. To reduce possible confusion, having a space between the "editing marker" and the actual document title thus cannot hurt as far as I'm concerned.

In order to notify the viewer when all `AnnotationEditor`s have been removed, we utilize the existing `onAnnotationEditor`-callback to allow the document title to be updated as necessary.

Finally, this patch makes the following (slightly unrelated) changes:
 - Rename the `AnnotationStorage.removeKey` method to just `AnnotationStorage.remove` instead. This is consistent with e.g. the `has`-method and should suffice to explain what it does.
 - Remove the `AnnotationStorage.hasAnnotationEditors` getter, since the viewer now tracks the necessary state internally. This avoids unnecessarily having to iterate through the `AnnotationStorage`-instance when saving/printing the document.

---
[1] Using either an /Info dictionary or a /Metadata stream.
2022-08-26 00:20:58 +02:00
Jonas Jenwald
a4bfa7d18b [editor] Change the focus-outline to blue (bug 1787296) 2022-08-25 22:40:20 +02:00
Federico Bond
df912e9ab6 Update types in PDFPageViewOptions to properly declare optional parameters 2022-08-25 13:36:05 -03:00
Jonas Jenwald
de14b82af9 Improve handling of the "Cancel"-button in the password dialog
The password dialog can be cancelled in three different ways:
 - By clicking on its "Cancel"-button.
 - By pressing the Escape-key.
 - By force-opening another dialog, although this shouldn't happen in practice.

Here the "Cancel"-button case is slightly special since it'll trigger `PasswordPrompt.#cancel` *twice*, first directly via the click and secondly via the "close" event on the `dialog`-element.
While this shouldn't, as far as I know, cause any bugs it's nonetheless inconsistent with the other cases outlined above. To improve this we can simply attempt to *close* the password dialog instead, and then rely on the "close" event to run the `PasswordPrompt.#cancel` method.
2022-08-22 11:17:08 +02:00
Jonas Jenwald
89840649d9 Ensure that we don't try to re-open, or update the password-callback, when the password dialog is already open
Currently in `disableWorker=true` mode it's possible that opening of password-protected PDF documents outright fails, if an *incorrect* password is entered. Apparently the event ordering is subtly different in the non-Worker case, which causes the password-callback to be updated *before* the dialog has been fully closed.
To avoid that we'll utilize a `PromiseCapability` to keep track of the state of the password dialog, such that we can delay both re-opening and (importantly) updating of the password-callback until doing so is safe.

This patch *may* also fix issue 15330, but it's impossible for me to tell.
2022-08-19 20:10:37 +02:00
Jonas Jenwald
5e126032ff Correctly mimic the proper event-format in AnnotationElement._setDefaultPropertiesFromJS (bug 1785218)
*This is a follow-up to PR 14869.*

In the old code we're accidentally "swallowing" part of the event-details, which explains why the annotationLayer didn't render.
One thing that made debugging a lot harder was the lack of error messages, from the viewer, and a few `PDFPageView`-methods were updated to improve this situation.
2022-08-17 15:44:27 +02:00
Jonas Jenwald
f669e5dd34 Ignoring "resize" events during printing (issue 15324)
This is a quick work-around, to prevent the viewer from breaking as a result of https://bugzilla.mozilla.org/show_bug.cgi?id=774398
2022-08-16 13:51:35 +02:00
Jonas Jenwald
4919dae294 Refresh the viewer if the window resolution changes (bug 1784850)
*Please note:* This probably fixes bug 1784850, however I don't have the necessary hardware to reproduce the situation described in https://bugzilla.mozilla.org/show_bug.cgi?id=1784850#c0

Unfortunately it doesn't, as far as I can tell, appear possible to detect *all* resolution changes with a single media query. Instead we have to update it, and its listener, on every resolution change as outlined in [this MDN example](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes).
2022-08-15 16:56:57 +02:00
Jonas Jenwald
0024165f1f Move binarySearchFirstItem back to the web/-folder (PR 15237 follow-up)
This was moved into the `src/display/`-folder in PR 15110, for the initial editor-a11y patch. However, with the changes in PR 15237 we're again only using `binarySearchFirstItem` in the `web/`-folder and it thus seem reasonable to move it back there.
The primary reason for moving it back is that `binarySearchFirstItem` is currently exposed in the public API, and we always want to avoid that unless it's either PDF-related functionality or code that simply must be shared between the `src/`- and `web/`-folders. In this case, `binarySearchFirstItem` is a general helper function that doesn't really satisfy either of those alternatives.
2022-08-14 11:38:17 +02:00
Jonas Jenwald
6c4561f3d8 Don't add aria-owns attributes for non-existent elements (PR 15237 follow-up)
Currently when the `TextAccessibilityManager.enabled` method is called, we'll update `aria-owns` for any pre-existing elements. This obviously makes sense when e.g. zooming/rotating in the viewer, since the annotationLayer/annotationEditorLayer is kept in those cases.
However when the page is *fully* reset, e.g. as result of going out-of-view and thus being evicted from the cache, we still keep the `#textNodes`-Map around. This causes us to set the `aria-owns` attribute (in the textLayer) for an element that doesn't actually exist any more, which as far as I'm concerned seems incorrect. In this case the element will simply, as already implemented, be re-inserted when the annotationLayer/annotationEditorLayer renders again.
2022-08-13 21:52:38 +02:00
Tim van der Meij
b040d64a3c
Merge pull request #15300 from Snuffleupagus/viewer-export-constants
[GENERIC viewer] Export some viewer constants in the default viewer (issue 15294)
2022-08-13 15:25:29 +02:00
Calixte Denizet
f316300113 [Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375)
This patch doesn't structurally change the text layer: it just adds some aria-owns
attributes to some spans.
The aria-owns attribute expect to have an element id, hence it's why it adds back an
id on the element rendering an annotation, but this id is built in using crypto.randomUUID
to avoid any potential issues with the hash in the url.
The elements in the annotation layer are moved into the DOM in order to have them in the
same "order" as they visually are.
The overall goal is to help screen readers to present to the user the annotations as
they visually are and as they come in the text flow.
It is clearly not perfect, but it should improve readability for some people with visual
disabilities.
2022-08-12 14:35:26 +02:00
Jonas Jenwald
b8bb1d67d4 [GENERIC viewer] Export some viewer constants in the default viewer (issue 15294)
This exports the same constants as the viewer components, but in the default viewer. To avoid bloating the global-scope the constants are added to a new `PDFViewerApplicationConstants` object[1], which also allows us to skip this in builds where it's not actually needed (e.g. the Firefox *built-in* PDF Viewer).

*Please note:* I'm not completely sold on this idea, and thus wouldn't mind the patch being rejected, since we probably don't want to export every single viewer constant this way. (And it may seem a bit arbitrary, to users, why some constants are exported and others are not.)

---
[1] Somewhat similar to the existing `PDFViewerApplicationOptions` structure.
2022-08-11 16:22:12 +02:00
Jonas Jenwald
69462e5e14 Export additional constants in the viewer components
In addition to the existing `LinkTarget` constant, used by the `PDFLinkService`-constructor, this patch exports the following constants in the viewer components:
 - `ScrollMode` and `SpreadMode`, since the `BaseViewer` has getters/setters which work with those constants.
 - `RenderingStates`, since that one may be helpful when using `PDFPageView` directly.
2022-08-11 16:22:07 +02:00
Jonas Jenwald
047522a34a Move the reset-calls to occur last in the toolbar-constructors
By invoking the `reset` methods *last* in the `Toolbar`/`SecondaryToolbar`-constructors, we ensure that the "toolbarreset"/"secondarytoolbarreset"-events are actually handle when the viewer loads. Note that previously those events were dispatched *before* the relevant event-listeners had been attached.
With this small change we can avoid inconsistent initial toolbar-state, specifically in the case when the viewer is *reloaded* (since Firefox keeps the HTML-state on "soft" reloads).
2022-08-09 22:39:38 +02:00
Jonas Jenwald
2b0b8cd665 Add more private properties/methods in web/toolbar.js 2022-08-09 22:39:07 +02:00
Calixte Denizet
fbce8786d0 [Editing] Disable buttons until the first page is rendered 2022-08-09 20:35:35 +02:00
Tim van der Meij
0ebd1daf30
Merge pull request #15261 from Snuffleupagus/issue-15260
Don't include `images/toolbarButton-editorInk.svg` in the `gulp components` build (issue 15260)
2022-08-06 14:17:55 +02:00
calixteman
b985eaa98c
Merge pull request #15267 from calixteman/freetext_a11y
[Annotation] Add a div containing the text of a FreeText annotation (bug 1780375)
2022-08-04 11:49:29 +02:00
Calixte Denizet
31155740c3 [Annotation] Add a div containing the text of a FreeText annotation (bug 1780375)
An annotation doesn't have to be in the text flow, hence it's likely a bad idea
to insert its text in the text layer. But the text must be visible from a screen
reader point of view so it must somewhere in the DOM.
So with this patch, the text from a FreeText annotation is extracted and added in
a div in its HTML counterpart, and with the patch #15237 the text should be visible
and positioned relatively to the text flow.
2022-08-04 11:14:05 +02:00
calixteman
8bad06f158
Merge pull request #15268 from calixteman/bug1777693
Fix a typo in firefox print service (bug 1777693)
2022-08-03 18:02:18 +02:00
Calixte Denizet
6c9e538f56 Fix a typo in firefox print service (bug 1777693) 2022-08-03 17:25:01 +02:00
Calixte Denizet
94f57e5dd7 [Editor] Add some telemetry to know how often the editing features are used (bug 1782254) 2022-08-03 09:54:27 +02:00
Jonas Jenwald
44f77c9e82 Don't include images/toolbarButton-editorInk.svg in the gulp components build (issue 15260)
Given that this image is intended specifically for the default viewer, we simply use the CSS preprocessor to remove the image reference in the `gulp components` build.
Considering that the issue only affects a CSS file, I don't believe that replacing the *just released* PDF.js version is actually necessary here.
2022-08-02 10:26:46 +02:00
Jonas Jenwald
ad11cea33c [api-minor] Update the minimum supported Safari version
The Ink-editor uses `ResizeObserver`, which is supported in all reasonably modern browsers; see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#browser_compatibility

With the exception of Safari, `ResizeObserver` is thus available in all of the browsers that the PDF.js library currently support. Rather than trying to e.g. add a polyfill, let's just bump the compatibility (slightly) to Safari 13.1 instead; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_13
2022-07-31 17:40:26 +02:00
Jonas Jenwald
5b50a50559 Ignore too small page-canvases in PDFThumbnailView.setImage
It doesn't make sense to use a page-canvas that's *smaller* than the resulting thumbnail, since that causes the image to be upscaled which results in a blurry thumbnail. Note that this doesn't normally happen, unless a very small zoom-level is used in the viewer.
2022-07-31 13:59:56 +02:00
Tim van der Meij
b8aa9c6221
Merge pull request #15246 from Snuffleupagus/thumbnail-setImage-improvements
[api-minor] Improve `thumbnail` handling in documents that contain interactive forms
2022-07-31 11:42:55 +02:00
Jonas Jenwald
7543a91086 [Firefox] Remove a couple of webkit CSS rules related to editing
Thanks to the CSS preprocessor, we can get rid of a couple of unnecessary CSS rules in the Firefox PDF Viewer.
2022-07-30 20:07:44 +02:00
Jonas Jenwald
4a38949886 Remove unnecessary color CSS property
This property is first of all unused, and secondly it contained a static value which means that it'd not have worked correctly in light/dark themes.
2022-07-30 19:53:34 +02:00
Jonas Jenwald
0c31320c12 [api-minor] Improve thumbnail handling in documents that contain interactive forms
To improve performance of the sidebar we use the page-canvases to generate the thumbnails whenever possible, since that avoids unnecessary re-rendering when the sidebar is open. This works generally well, however there's an old problem in PDF documents that contain interactive forms (when those are enabled): Note how the thumbnails become partially (or fully) blank, since those Annotations are not included in the OperatorList.[1]

We obviously want to keep using the `PDFThumbnailView.setImage`-method for most documents, however we need a way to skip it only for those pages that contain interactive forms.
As it turns out it's unfortunately not all that simple to tell, after the fact, from looking only at the OperatorList that some Annotations were skipped. While it might have been possible to try and infer that in the viewer, it'd not have been pretty considering that at the time when rendering finishes the annotationLayer has not yet been built.
The overall simplest solution that I could come up with, was instead to include a *summary* of the interactive form-state when doing the final "flushing" of the OperatorList and expose that information in the API.

---
[1] Some examples from our test-suite: `annotation-tx2.pdf` where the thumbnail is completely blank, and `bug1737260.pdf` where the thumbnail is missing the "buttons" found on the page.
2022-07-30 16:53:32 +02:00
Tim van der Meij
c7b71a3376
Merge pull request #15215 from Snuffleupagus/optional-content-initial
[api-minor] Improve how we disable `PDFThumbnailView.setImage` for documents with Optional Content
2022-07-30 12:04:23 +02:00
Jonas Jenwald
2e059727a9 [api-minor] Change the various factories, in the viewer, to accept Objects
Currently all of these factories take a bunch of (randomly ordered) parameters, which first of all doesn't look that nice in the `PDFPageView`-class when some parameters are optional.
Furthermore, it also makes deprecation/removal of any existing parameter a *potentially* breaking change.
Finally, using an Object will provide a small amount of "documentation" at the call-site which isn't really the case with a bunch of "regular" parameters.

Note that all of the `viewer component` examples still work as-is with this patch, which is why I don't believe that we necessarily have to deprecate in the usual fashion.
2022-07-29 16:31:04 +02:00
Calixte Denizet
a85359b031 [Editor] Simplify the strings for the tools in the UI 2022-07-28 10:02:59 +02:00
Calixte Denizet
7831a100b3 [Editor] Add the possibility to change line opacity in Ink editor 2022-07-27 18:46:25 +02:00
Jonas Jenwald
37dc0e7d6e Limit the PDFPageView._isStandalone handling to the GENERIC viewer
This code is completely unnecessary in e.g. the Firefox PDF Viewer.
2022-07-24 17:29:37 +02:00
Jonas Jenwald
3446f15bf3 Improve how we disable PDFThumbnailView.setImage for documents with Optional Content (PR 12170 follow-up)
Rather than always disable `PDFThumbnailView.setImage` as soon as user has changed the visibility of the Optional Content, we can utilize the new method added in the previous patch to improve thumbnail performance. Note in particular how, in the old code, even *resetting* of the Optional Content to its default state wouldn't enable `PDFThumbnailView.setImage` again.

While slightly unrelated, this patch also removes the `PDFThumbnailViewer._optionalContentConfigPromise`-property since it's completely unused.
2022-07-24 17:29:37 +02:00
Calixte Denizet
7b25b39a17 [Editor] Replace mouse events by pointer ones (bug 1779015)
The goal is to be able to edit a pdf on a touchscreen.
2022-07-22 13:46:39 +02:00
Calixte Denizet
d6b9ca48a5 [Editor] Add the ability to make multiple selections (bug 1779582)
- several editors can be selected/unselected using ctrl+click;
- and then they can be copied, pasted, their properties can be changed.
2022-07-21 22:53:52 +02:00
Jonas Jenwald
f4e60ae986 Limit even more SVG-specific code to the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a bit more unnecessary code in e.g. the Firefox PDF Viewer.
2022-07-21 10:03:02 +02:00
Calixte Denizet
a7a5e98b7e [Editor] Add a z-index in order to draw them in the right order
The elements in the annotationEditor layer are rearranged to make them
more accessible, but we must draw them in the order they have been created,
hence this patch adds a z-index to the editors.
2022-07-20 15:47:43 +02:00
Calixte Denizet
e1f28d3504 [Editor] Move the keyboard manager at the container level
- This way, the keyboard callbacks are called even if the page has not
the focus, hence the user doesn't have to guess that they have to click
on the page which is a bit painful especially in Ink mode.
- Add two keyboard shortcuts to commit a Freetext editor (ctrl+enter and
escape).
2022-07-20 12:24:30 +02:00
Calixte Denizet
624b26e1de [Editor] Improve a11y for newly added element (#15109)
- In the annotationEditorLayer, reorder the editors in the DOM according
  the position of the elements on the screen;
- add an aria-owns attribute on the "nearest" element in the text layer
  which points to the added editor.
2022-07-19 18:52:17 +02:00
Jonas Jenwald
290aeaf755 Limit more SVG-specific code to the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a little bit more unnecessary code in e.g. the Firefox PDF Viewer.
2022-07-16 11:24:09 +02:00
Calixte Denizet
fe93742c8f Use default colors only in forced-colors mode (bug 1778068) 2022-07-07 19:36:03 +02:00
Calixte Denizet
edc9ad13bf [Editor] Change the cursor to a pen for the Ink editor 2022-07-07 18:23:59 +02:00
Jonas Jenwald
345bb18575 [editor] Use the fit-curve package (issue 15004)
Rather than including all of this external code in the PDF.js repository, we should be using the npm package instead.
Unfortunately this is slightly more complicated than you'd hope, since the `fit-curve` package (which is older) isn't directly compatible with modern JavaScript modules.
In particular, the following cases needed to be considered:
 - For the development viewer (i.e. `gulp server`) and the unit-tests, we thus need to build a fitCurve-bundle that can be directly `import`ed.
 - For the actual PDF.js build-targets, we can slightly reduce the sizes by depending on the "raw" `fit-curve` source-code.
 - For the Node.js unit-tests, the `fit-curve` package can be used as-is.
2022-07-07 10:43:43 +02:00
Calixte Denizet
ec0f9f6dcf [Editor] Dispatch an event when some global states are changing
- this way the context menu in Firefox can take into account what we
  have in the clipboard, if an editor is selected, ...
- when the user will click on a context menu item, an action will be
  triggered, hence this patch adds what is required to handle it;
- some tests will be added in the Firefox' patch.
2022-07-05 22:12:56 +02:00
Jonas Jenwald
552ee9decd Call AnnotationLayer.setDimensions as part of the render/update-methods (PR 15036 follow-up)
Rather than forcing the user to *manually* call `setDimensions`, which is also breaking any existing third-party code, it seems that we can simply let the `AnnotationLayer.{render, update}`-methods handle that internally.

As far as I can tell, based on testing manually in the viewer *and* running the browser-tests, everything still appears to work correctly with this patch.
2022-07-04 12:27:20 +02:00
Calixte Denizet
ae2cf7e1e7 [Editor] Update the id for a l10n string 2022-07-04 10:18:42 +02:00
Jonas Jenwald
03c6febc44
Merge pull request #15121 from Snuffleupagus/loadingBar-cleanup
[api-minor] Further modernize the `ProgressBar` class (PR 14918 follow-up)
2022-07-02 16:46:40 +02:00
Jonas Jenwald
845b7f06f9
Merge pull request #15123 from Snuffleupagus/editor-presentation-disable
[editor] Disable editing while PresentationMode is active
2022-07-02 16:39:38 +02:00
Jonas Jenwald
37b61f2228 [editor] Disable editing while PresentationMode is active 2022-07-01 16:52:17 +02:00
Jonas Jenwald
84ae9f9c58 [editor] Tweak @media CSS rules to account for the new toolbar buttons 2022-07-01 13:27:13 +02:00
Jonas Jenwald
d9ce17642f [api-minor] Further modernize the ProgressBar class (PR 14918 follow-up)
- Simplify how we look-up the DOM-element, which should also be a tiny bit more efficent.

 - Use private class-fields, rather than property-names prefixed with underscores.

 - Inline the `#updateBar` helper-method directly in the `percent`-setter, since having a separate method doesn't seem necessary in this case.

 - Set the `indeterminate`-class on the ProgressBar DOM-element, to simplify the code.

Finally, also (slightly) re-factors the `PDFViewerApplication.progress`-method to make it a bit smaller.
2022-07-01 10:31:25 +02:00
Calixte Denizet
9723c5d377 [Editor] Handle correctly colors when saving a document in HCM
- for example in Dusk theme (Windows 11), black appears to be white, so
  the user will draw something in white. But if they want to print or
  save the used color must be black.
- fix a bug with the color input which only accepts hex string colors;
- adjust outline color of the selected/hovered editors in HCM.
2022-06-30 09:56:34 +02:00
Calixte Denizet
a694e360a4 [Editor] Allow to select a freetext editor when in ink mode
- and when in ink mode, change the toolbar active button when
  a freetext edited.
2022-06-29 19:35:40 +02:00
Jonas Jenwald
63f2d0bb64 Fix the annotationEditorMode-compatibility for older browsers (PR 15113 follow-up) 2022-06-29 16:16:48 +02:00
calixteman
ce63663282
Merge pull request #15111 from calixteman/1776914
Add a visible page border in HCM (bug 1776914)
2022-06-29 14:43:56 +02:00
Calixte Denizet
3e751679ba Add a visible page border in HCM (bug 1776914) 2022-06-29 11:52:19 +02:00
Jonas Jenwald
44a75c2a0f [editor] Slightly shorten the en-US freetext_default_content placeholder text
Now that it's possible to change the font-size, this placeholder string feels a little bit long (especially for larger font-sizes).

Given that Editing is not enabled/released yet, I hope that it should be fine to update this without changing the l10n-id.
2022-06-29 11:40:54 +02:00
Jonas Jenwald
f3ba02bc00 [editor] Remove the unused name-property from the editorParamsToolbars DOM elements
As far as I can tell, this is completely unused and can thus be removed.
2022-06-29 11:40:54 +02:00
Jonas Jenwald
4a4c6b9851 [editor] Introduce a proper annotationEditorMode option/preference (PR 15075 follow-up)
This replaces the boolean `annotationEditorEnabled` option/preference with a "proper" `annotationEditorMode` one. This way it's not only possible for the user to control if Editing is enabled/disabled, but also which *specific* Editing-mode should become enabled upon PDF document load.

Given that Editing is not enabled/released yet, I cannot imagine that changing the name and type of the option/preference should be an issue.
2022-06-29 11:35:58 +02:00
Calixte Denizet
1a3ef2a0aa [editor] Add some UI elements in order to set font size & color, and ink thickness & color 2022-06-28 12:05:04 +02:00
calixteman
23fcdabb37
Merge pull request #15088 from calixteman/editor_rotation
Support rotating editor layer
2022-06-25 16:18:07 +02:00
Jonas Jenwald
9748d3eb85 Remove element ids from the layersView in the sidebar
Similar to other recent patches, see e.g. PR 15057, we don't want to add these kind of `id`s to DOM-elements since they shouldn't become "linkable" through the URL hash.

*Please note:* This patch can be tested, in the viewer, with e.g. `bug1737260.pdf` from the test-suite.
2022-06-24 20:15:46 +02:00
Calixte Denizet
0c420f5135 Support rotating editor layer
- As in the annotation layer, use percent instead of pixels as unit;
- handle the rotation of the editor layer in allowing editing when rotation
  angle is not zero;
- the different editors are rotated counterclockwise in order to be usable
  when the main page is itself rotated;
- add support for saving/printing rotated editors.
2022-06-24 20:02:32 +02:00
Jonas Jenwald
1cc7cecc7b [api-minor] Introduce a PrintAnnotationStorage with *frozen* serializable data
Given that printing is triggered *synchronously* in browsers, it's thus possible for scripting (in PDF documents) to modify the Annotation-data while printing is currently ongoing.
To work-around that we add a new printing-specific `AnnotationStorage`, where the serializable data is *frozen* upon initialization, which the viewer can thus create/utilize during printing.
2022-06-23 17:06:46 +02:00
Jonas Jenwald
d7c9a0a793 Fix (obvious) typo in typedef-import of IPDFXfaLayerFactory (PR 14373 follow-up)
This only affects the viewer-components TypeScript definitions, and not any actual code.
2022-06-22 11:06:11 +02:00
calixteman
8d466f5dac
Merge pull request #15060 from calixteman/annotation_rotation
Rotate annotations based on the MK::R value (bug 1675139)
2022-06-21 18:03:09 +02:00
Calixte Denizet
cdc58b7a52 Rotate annotations based on the MK::R value (bug 1675139)
- it aims to fix: https://bugzilla.mozilla.org/show_bug.cgi?id=1675139;
- An annotation can be rotated (counterclockwise);
- the rotation can be set in using JS.
2022-06-21 17:57:26 +02:00
Jonas Jenwald
35a6a508ee [editor] Support disabling of editing when pdfjs.enablePermissions is set (issue 15049)
For encrypted PDF documents without the required permissions set, this patch adds support for disabling of Annotation-editing. However, please note that it also requires that the `pdfjs.enablePermissions` preference is set to `true` (since PDF document permissions could be seen as user hostile).[1]

As I started looking at the issue, it soon became clear that *only* trying to fix the issue without slightly re-factor the surrounding code would be somewhat difficult.
The following is an overview of the changes in this patch; sorry about the size/scope of this!

 - Use a new `AnnotationEditorUIManager`-instance *for each* PDF document opened in the GENERIC viewer, to prevent user-added Annotations from "leaking" from one document into the next.

 - Re-factor the `BaseViewer.#initializePermissions`-method, to simplify handling of temporarily disabled modes (e.g. for both Annotation-rendering and Annotation-editing).

 - When editing is enabled, let the Editor-buttons be `disabled` until the document has loaded. This way we avoid the buttons becoming clickable temporarily, for PDF documents that use permissions.

 - Slightly re-factor how the Editor-buttons are shown/hidden in the viewer, and reset the toolbar-state when a new PDF document is opened.

 - Flip the order of the Editor-buttons and the pre-exising toolbarButtons in the "toolbarViewerRight"-div. (To help reduce the size, a little bit, for the PR that adds new Editor-toolbars.)

 - Enable editing by default in the development viewer, i.e. `gulp server`, since having to (repeatedly) do that manually becomes annoying after a while.

 - Finally, support disabling of editing when `pdfjs.enablePermissions` is set; fixes issue 15049.

---

[1] Either manually with `about:config`, or using e.g. a [Group Policy](https://github.com/mozilla/policy-templates).
2022-06-21 11:54:09 +02:00
Jonas Jenwald
8d154d7f6a
Merge pull request #15064 from calixteman/rescale_followup
Avoid having overflowing sections (#15036 follow-up)
2022-06-20 09:33:13 +02:00
Calixte Denizet
2ff65dd514 Popup trigger area must filled its parent (fix #15063) 2022-06-19 22:44:58 +02:00
Calixte Denizet
af47a0b7e0 Avoid having overflowing sections (#15036 follow-up) 2022-06-19 22:09:02 +02:00
Tim van der Meij
f516bb2174
Merge pull request #15058 from Snuffleupagus/rm-baseviewerinit-event
[api-minor] Remove the "baseviewerinit" event since it's unused (PR 14324 follow-up)
2022-06-19 13:21:39 +02:00
Jonas Jenwald
caaa78f7da [api-minor] Remove the "baseviewerinit" event since it's unused (PR 14324 follow-up)
Given that neither the viewer or the examples listen for this event, it seems unnecessary to keep dispatching it.
2022-06-19 09:57:05 +02:00
Calixte Denizet
e2db9bacef Get rid of CSS transform on each annotation in the annotation layer
- each annotation has its coordinates/dimensions expressed in percentage,
  hence it's correctly positioned whatever the scale factor is;
- the font sizes are expressed in percentage too and the main font size
  is scaled thanks a css var (--scale-factor);
- the rotation is now applied on the div annotationLayer;
- this patch improve the rendering of some strings where the glyph spacing
  was not correct (it's a Firefox bug);
- it helps to simplify the code and it should slightly improve the update of
  page (on zoom or rotation).
2022-06-18 17:54:59 +02:00
Jonas Jenwald
03757d82b7 Replace element ids with custom attributes for Widget-annotations (issue 15056)
We want to avoid adding regular `id`s to Annotation-elements, since that means that they become "linkable" through the URL hash in a way that's not supported/intended. This could end up clashing with "named destinations", and that could easily lead to bugs; see issue 11499 and PR 11503 for some context.

Rather than using `id`s, we'll instead use a *custom* `data-element-id` attribute such that it's still possible to access the Annotation-elements directly.
Unfortunately these changes required updating most of the integration-tests, and to reduce the amount of repeated code a couple of helper functions were added.
2022-06-18 16:43:05 +02:00
Tim van der Meij
3ca8d2c4f9
Merge pull request #15052 from Snuffleupagus/mv-defaultUrl-option
Simplify setting the `defaultUrl`-option in the CHROME viewer (PR 12470 follow-up)
2022-06-18 11:29:21 +02:00
Tim van der Meij
80af3a0d07
Merge pull request #15048 from Snuffleupagus/mv-renderer-option
Only define the `renderer`-option in the GENERIC viewer
2022-06-18 11:26:43 +02:00
Jonas Jenwald
77aa86e275 Stop defining the defaultUrl-option in the MOZCENTRAL viewer
This option is not used, nor has it ever been used, in the *built-in* Firefox PDF Viewer. Hence we can define it only for the environments where it makes sense instead.
2022-06-18 09:43:35 +02:00
Jonas Jenwald
abcc32ade0 Simplify setting the defaultUrl-option in the CHROME viewer (PR 12470 follow-up)
This should really have been done as part of PR 12470, since it's now possible to directly set the `defaultUrl`-option without having to fallback to `var`-usage.
2022-06-18 09:43:23 +02:00