Commit Graph

3378 Commits

Author SHA1 Message Date
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
Jonas Jenwald
be2dfe45f9
Merge pull request #15035 from Snuffleupagus/prefer-modern-dom-apis-2
Use modern DOM methods a bit more (PR 15031 follow-up)
2022-06-17 19:37:43 +02:00
Calixte Denizet
e7dc1ef4f3 [Editor] - Add the ability to directly draw after selecting ink tool
- Right now, we must select the tool, then click to select a page and
  click to start drawing and it's a bit painful;
- so just create a new ink editor when we're hovering a page without one.
2022-06-16 19:53:07 +02:00
Jonas Jenwald
a19feac217 Reduce some duplication for AppOptions that use compatibilityParams
We can check for a relevant `compatibilityParams`-entry directly in `AppOptions.{get, getAll}` instead, which removes some unnecessary duplication.
2022-06-16 16:51:33 +02:00
Jonas Jenwald
df79b18a31 Only define the renderer-option in the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a little bit of unnecessary code in e.g. the Firefox PDF Viewer.
2022-06-16 16:11:47 +02:00
Jonas Jenwald
4902ad8923 Use modern DOM methods a bit more (PR 15031 follow-up)
Apparently the ESLint rule added in PR 15031 wasn't able to catch all cases that can be converted, which is probably not all that surprising given how some of these call-sites look.

 - Use `Element.prepend()` to insert nodes before all other ones in the element, rather than using `firstChild` with `insertBefore`-calls; see https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend

 - Fix one *incorrect* `insertBefore` call, in the AnnotationLayer-code.
   Initially the patch simply changed that to an `Element.before()`-call, however that broke one of the integration-tests. It turns out that the `index` may try to access a non-existent select-child, which triggers undefined behaviour; note the warning in https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore#parameters
2022-06-13 10:47:37 +02:00
Jonas Jenwald
4d39898823 Enable the unicorn/prefer-modern-dom-apis ESLint plugin rule
This rule will help enforce slightly shorter code, and according to MDN both `Element.replaceWith()` and `Element.before()` are available in all browsers that we currently support.

Please find additional information here:
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-modern-dom-apis.md
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/before
2022-06-12 20:05:05 +02:00
Jonas Jenwald
8129815538 Enable the unicorn/prefer-dom-node-append ESLint plugin rule
This rule will help enforce slightly shorter code, especially since you can insert multiple elements at once, and according to MDN `Element.append()` is available in all browsers that we currently support.

Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/append
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-append.md
2022-06-12 13:07:03 +02:00
Jonas Jenwald
1465471b10 Tweak the editorNone icon to circumvent the "duplicated files"-check
The update in https://bugzilla.mozilla.org/show_bug.cgi?id=1773794 failed, because the `editorNone` icon is identical to a pre-existing one. Given that all of the editor-icons are simply placeholders for now, we can just make a tiny change to the SVG-paths to prevent these kind of problems.
2022-06-11 11:17:08 +02:00
Jonas Jenwald
9ac4536693 Enable the unicorn/prefer-at ESLint plugin rule (PR 15008 follow-up)
Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-at.md
2022-06-09 21:21:19 +02:00
calixteman
61a65344a3
Merge pull request #14989 from calixteman/ink1
[editor] Add an Ink editor
2022-06-09 21:13:06 +02:00
Calixte Denizet
c161a86ba1 [editor] Add an Ink editor
- Approximate the drawn curve by a set of Bezier curves in using
  js code from https://github.com/soswow/fit-curves.
  The code has been slightly modified in order to make the linter
  happy.
2022-06-09 19:35:59 +02:00
Jonas Jenwald
7a89f4a789 Set the MIME type correctly when downloading fonts in debugger.js (PR 5366 follow-up)
Because of a capitalization error, the MIME type wasn't actually being set correctly. However, please note that downloading of font files still worked correctly which is probably why this has gone unnoticed since 2014.
2022-06-09 09:52:28 +02:00
calixteman
2fbf14ace8
Merge pull request #14978 from calixteman/editor2
[editor] Add support for saving a newly added FreeText
2022-06-08 15:51:03 +02:00
Calixte Denizet
7773b3f5be [edition] Add support for saving a newly added FreeText 2022-06-08 14:34:09 +02:00
Jonas Jenwald
7761d2bf95
Merge pull request #15001 from marco-c/canvas_presentational
Set "presentation" role for page canvases (issue 14437)
2022-06-07 20:03:38 +02:00
Marco Castelluccio
8c9678158e Set "presentation" role for page canvases (issue 14437) 2022-06-07 18:56:30 +02:00
Calixte Denizet
2dd0c861bf Outline fields which are required (bug 1724918)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1724918;

- it applies for both Acroform and XFA.
2022-06-07 17:02:11 +02:00
calixteman
193a28431c
Merge pull request #14991 from Snuffleupagus/editor-XFA-disable
[editor] Disable the editor-buttons in XFA documents
2022-06-05 12:03:05 +02:00
Tim van der Meij
37f7995dde
Merge pull request #14984 from Snuffleupagus/dialog-polyfill-CSS
Bundle the `<dialog>` polyfill-CSS in the GENERIC `legacy/`-viewer (PR 14710 follow-up)
2022-06-05 11:18:18 +02:00
Jonas Jenwald
d34e7fff01 [editor] Disable the editor-buttons in XFA documents
Given the differences between XFA documents and "normal" PDF documents, we don't support editing of the former ones. Hence, when a XFA-document is opened, we temporarily disable the editor-buttons.
2022-06-05 10:00:08 +02:00
Jonas Jenwald
51bf928061 [editor] A couple of small FreeText-related fixes (PR 14976 follow-up)
- Ensure that the modified-warning won't be displayed, when navigating away from the viewer, if the user has added custom Annotations and then *removed all* of them.
 - Ensure that the *initial* editor-buttons state, i.e. the `toggled`-class, is correctly displayed in the toolbar when then viewer loads.
 - Tweak the CSS-classes for the editor-buttons, such that they use the correct focus/hover-rules (similar to the sidebar-buttons).
 - Remove a no longer accurate comment from the `BaseViewer.annotationEditorMode`-setter.
 - Address a couple of *smaller* outstanding review comments, including some re-formatting changes, from PR 14976.
2022-06-04 21:48:11 +02:00
Calixte Denizet
be1aa11986 [edition] Add a FreeText editor (#14970)
- add a basic UI to edit some text in a pdf;
- an editor can be moved, suppressed, cut, copied, pasted, selected;
- add an undo/redo manager.
2022-06-04 18:20:11 +02:00
Jonas Jenwald
bb8f5ec20b Bundle the <dialog> polyfill-CSS in the GENERIC legacy/-viewer (PR 14710 follow-up)
In PR 14710 we only included the JavaScript-part of the polyfill, however we probably need to include the CSS as well to reduce the risk of problems in older browsers.

With the recent CSS-related improvements in the `preprocess`-function we could probably have included this conditionally in the `viewer.css` file. However, considering that the `<dialog>` polyfill-code is only invoked when actually needed it seemed most appropriate/correct to lazy-load the polyfill-CSS as well.
2022-06-04 18:11:35 +02:00
Tim van der Meij
a0eca3e34f
Merge pull request #14962 from Snuffleupagus/sidebar-more-visibleView
Improve the `PDFSidebar` implementation
2022-05-29 13:43:54 +02:00
Tim van der Meij
a43a30bb7b
Merge pull request #14964 from Snuffleupagus/onOpenWithData-contentDispositionFilename
Ensure that the `contentDispositionFilename` is always respected, when setting the document title (PR 13014 follow-up)
2022-05-29 13:26:23 +02:00
Calixte Denizet
9d82106d20 Set the text fields font size based on their height
- right now we're using the font size from the pdf itself but we use an other font
  in the annotation layer. So this size doesn't really make sense and leads to bad
  rendering (see pdf in #14928);
- use a sans-serif font for the fields containing text (fix issue #14736);
- remove useless padding in text-based fields (fix issue #14301);
- text fields allow/disallow scrolling bars (see bit 24 in Ff entry), so use this
  value to hide/show scrollbars in annotation layer.
2022-05-28 18:00:39 +02:00
calixteman
5b3fdee5f5
Merge pull request #14965 from calixteman/1771477
Support Hangul syllables when searching some text (bug 1771477)
2022-05-28 17:52:27 +02:00
Calixte Denizet
c7afce4210 Support Hangul syllables when searching some text (bug 1771477)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1771477;
- hangul contains some syllables which are decomposed when using NFD, hence
  the text must be correctly shifted in case it contains some of them.
2022-05-28 16:50:03 +02:00
Jonas Jenwald
d80035b716
Merge pull request #14959 from Snuffleupagus/pageColors-thumbnails
Support custom `pageColors` in the thumbnails (PR 14874)
2022-05-28 15:46:06 +02:00
Jonas Jenwald
0599ce77ff Ensure that the contentDispositionFilename is always respected, when setting the document title (PR 13014 follow-up)
Currently, when range-requests and/or streaming are not supported or for documents opened from `data`-URLs, we'll manually set the `contentDispositionFilename` (assuming it exists and is valid) from the `onOpenWithData`-callback in `PDFViewerApplication.initPassiveLoading`.
However, because of a small oversight in `PDFViewerApplication._initializeMetadata`, this *cached* `contentDispositionFilename` would be ignored and we'd only attempt to use the one returned by `PDFDocumentProxy.getMetadata` in the API (which in the cases outlined above will always be empty).

Also, to ensure that the document properties dialog always displays the *correct* fileName we'll now lookup it using the same exact method as in the viewer itself (via a new callback-function).
2022-05-28 12:39:49 +02:00
Jonas Jenwald
c0e7a454a1 Convert the PDFSidebar class to use private methods 2022-05-27 11:36:01 +02:00
Jonas Jenwald
d289da76a7 Re-factor the PDFSidebar.{setInitialView, switchView} methods (PR 10502 follow-up)
This removes the internal `_switchView`-method, since looking at all of this again it feels simpler to instead track the initial event dispatching.
2022-05-27 11:33:01 +02:00
Jonas Jenwald
13fda7caeb Remove the view-specific getters in the PDFSidebar class
With the exception of `isThumbnailViewVisible`, these getters are completely unused. Generally speaking, using the `visibleView`-getter directly works just as well and seems (at least to me) to be overall preferable considering how our classes are usually implemented.
2022-05-26 14:27:51 +02:00
Jonas Jenwald
9871761949 Support custom pageColors in the thumbnails (PR 14874)
Currently, when non-standard `pageColors` are specified, the thumbnails will look inconsistent depending on how they're created.
The thumbnails that are created by downsizing the *page* canvases will obviously use the `pageColors` as intended, however the thumbnails which are rendered *directly* will always use the default colors.
2022-05-26 10:07:27 +02:00
Jonas Jenwald
ca244d9bca Introduce a viewer constant for document.documentElement.style
Over time, as we've been introducing JavaScript code to modify CSS variables, we've been adding shorthand properties to various classes to reduce unnecessary repetition when accessing the document-styles.
Rather than repeating this in multiple places, it seems overall simpler to just introduce a constant and re-use that throughout the viewer instead.
2022-05-25 09:55:54 +02:00
Jonas Jenwald
8fcdad022b
Merge pull request #14948 from Pldi23/drag&drop_not_work_from_mail
Set 'dropEffect' based on 'effectAllowed' for drag-and-drop in the viewer (issue 14942)
2022-05-22 15:34:15 +02:00
Dmitry_Platonov
55da67e9aa Set 'dropEffect' based on 'effectAllowed' for drag-and-drop in the viewer (issue 14942). See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed 2022-05-22 14:57:55 +02:00
Jonas Jenwald
8a349801dc [Firefox viewer] Stop using FirefoxCom.requestAsync in the DownloadManager
After the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1757771, that simplified the MOZCENTRAL downloading code, the `ChromeActions.download`-method will no longer invoke the `sendResponse`-callback.
Hence it should no longer be necessary for the `DownloadManager`, in the MOZCENTRAL viewer, to use `FirefoxCom.requestAsync` since no response is ever provided.[1] For the allocated BlobURLs, they should (hopefully) be released when navigating away from the viewer.

---
[1] Note that that was *already* the case, for one of the previous code-paths in the `ChromeActions.download`-method.
2022-05-15 18:18:37 +02:00
Jonas Jenwald
4f1cd6a9c2 Remove the sourceEventType from the viewer (bug 1757771 follow-up)
After the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1757771, that simplified the MOZCENTRAL downloading code, the `sourceEventType` is now completely unused and should thus be removed (in my opinion).

Furthermore, with these changes, we also no longer need a *separate* internal "save"-event and can instead just use the older "download"-event everywhere.
2022-05-15 18:18:37 +02:00
Calixte Denizet
e94b9d1d7f Use a CSS transform to update the progress bar instead of changing the width (bug 1768481)
- it isn't a fix for bug 1768481 but just a tiny improvement to refresh the progress bar on the compositor thread.
2022-05-15 17:30:37 +02:00
Jonas Jenwald
1f3da032b4 [api-minor] Modernize and simplify the ProgressBar class
The original `ProgressBar`-functionality is very old, and could thus do with some general clean-up.
In particular, while it currently accepts various options those have never really been used in either the default viewer or in any examples. The sort of "styling" that these options provided are *much better*, not to mention simpler, done directly with CSS rules.

As part of these changes, the "progress" is now updated using CSS variables rather than by directly modifying the `style` of DOM elements. This should hopefully simplify future changes to this code, see e.g. PR 14898.

Finally, this also fixes a couple of other small things in the "mobile viewer" example.
2022-05-14 13:49:10 +02:00
Jonas Jenwald
efe3cb2982 Remove unnecessary clean-up in Toolbar.#adjustScaleWidth
While zeroing the temporary `canvas` makes sense, manually clearing the canvas and its context doesn't really accomplish anything since those are tied to the scope of the method.
2022-05-13 17:20:35 +02:00
Jonas Jenwald
3dd8b9cccf Ensure that setting the width of the zoom dropdown works correctly (PR 14028 follow-up)
We need to wait for UI rendering to start *before* getting the CSS variable values, since otherwise the values will be `NaN`.
This is only an issue if the viewer is completely hidden during loading, e.g. in a `display: none` iframe-element.
2022-05-13 17:10:42 +02:00
Jonas Jenwald
af5789125f Try to remove the mozOpaque canvas-property (PR 6551 follow-up)
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/mozOpaque, the `mozOpaque` canvas-property is not only non-standard (obviously) but it's also been deprecated.
Instead it's recommended to use `alpha = false` when getting the canvas-context, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#contextattributes, which all of our affected code is already doing.
2022-05-09 13:03:08 +02:00
Tim van der Meij
72943ae630
Merge pull request #14886 from Snuffleupagus/preprocessCSS-refactor
Use the regular `preprocess`-function for the CSS files as well
2022-05-08 13:53:14 +02:00