Commit Graph

548 Commits

Author SHA1 Message Date
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
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
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
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
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
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
e56c30eb59 Move 'presentation mode' and 'bookmarks' buttons in the secondary toolbar (bug 1789082) 2022-09-08 12:18:08 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Tim van der Meij
7111a172df
Merge pull request #14885 from Snuffleupagus/mozcentral-rm-unbindEvents
Stop bundling `PDFViewerApplication.{unbindEvents, unbindWindowEvents}` in MOZCENTRAL builds
2022-05-08 13:35:22 +02:00
Jonas Jenwald
39251c5789 Re-order the names of the new pageColors options/preferences (PR 14874 follow-up)
Given that the new API-option is an Object named `pageColors`, with `background`/`foreground` keys, it occurred to me that it'd be slightly more consistent if the options/preferences names fully reflected that.
2022-05-08 11:15:04 +02:00
Jonas Jenwald
80910f44e5 Stop bundling the openFile-buttons in the CHROME build
This is, for all intents and purposes, equivalent to PR 14833 and slightly reduces the size of the `gulp chromium` output.
2022-05-07 22:45:56 +02:00
Jonas Jenwald
ed8b172d12 Stop bundling PDFViewerApplication.{unbindEvents, unbindWindowEvents} in MOZCENTRAL builds
These methods are completely unused in the Firefox PDF Viewer, and were only added to supplement the `PDFViewerApplication.{bindEvents, bindWindowEvents}`-methods since third-party implementations may apparently need to remove event listeners (see PR 8525).
However, in the MOZCENTRAL build that's just dead code and this patch reduces the size of the *built* `web/viewer.js`-file by `~3.5` kB.
2022-05-07 15:51:32 +02:00
Jonas Jenwald
9817230ef8 Introduce a --viewer-container-height CSS variable to simplify the code
This new CSS variable will allow us to simplify a couple of different viewer components, since we no longer need to use JavaScript-based hacks and can directly set the CSS rules instead. In particular:

 - The `BaseViewer`-handling, used as part of the code that will center pages *vertically* in PresentationMode, can be simplified.
   By using CSS to control the height of the "dummy"-page we avoid unnecessarily invalidating the scale-value, which can reduce *some* unneeded re-rendering while PresentationMode is active.

 - The `SecondaryToolbar.#setMaxHeight`-method, and its associated parameters, are no longer necessary and can be completely removed.

Note that in order for things to work correctly in general, the new `--viewer-container-height` CSS variable must potentially be updated on any window-based "resize"-event (even when there's no zooming). While this is currently only done in the default viewer, that shouldn't be an issue since neither PresentationMode nor Toolbar-functionality is included in the "viewer components".
2022-05-06 13:45:39 +02:00
Calixte Denizet
c8afd6ce8c [api-minor] Improve pdf reading in high contrast mode
- Use Canvas & CanvasText color when they don't have their default value
  as background and foreground colors.
- The colors used to draw (stroke/fill) in a pdf are replaced by the bg/fg
  ones according to their luminance.
2022-05-05 16:34:51 +02:00
Jonas Jenwald
9268924a15 Only define the webViewerFileInputChange/webViewerOpenFile variables in GENERIC builds
There's no point in having these variables defined (implicitly) as `undefined` in e.g. the Firefox PDF Viewer.
By defining them with `var` and using ESList ignores, rather than `let`, we can move them into the relevant pre-processor block instead. Note that since the entire viewer-code is placed, by Webpack, in a top-level closure these variables will thus *not* become globally accessible.
2022-04-29 18:07:56 +02:00
Jonas Jenwald
7cce41c26d Inline the webViewerOpenFileViaURL function in webViewerInitialized
Given that `webViewerOpenFileViaURL` only has a single call-site, and also isn't a particularly large/complex function, it doesn't seem necessary for this to be a separate function and hence it's simply inlined instead.

Also, changes the "no valid build-target was set"-case to throw unconditionally since the only way that it could ever be hit is if there are bugs in the `gulpfile`-code.
2022-04-29 18:07:52 +02:00
Jonas Jenwald
b04c373362 Stop bundling the openFile-buttons in the MOZCENTRAL build
Note how both of the openFile-buttons are always hidden during viewer initialization in the MOZCENTRAL build, i.e. the *built-in* Firefox PDF Viewer. Despite that we still include HTML, CSS, and JavaScript code for these buttons in the build.

This patch *reduces* the size of the `gulp mozcentral` output by `1679` bytes, which isn't a lot but still cannot hurt.
2022-04-25 11:35:17 +02:00
Jonas Jenwald
7023bac8d3 Move the PDFBug-related CSS from viewer.css and into its own file
Given that none of these CSS rules are used at all, unless debugging is enabled, it seems completely unnecessary to load them *unconditionally* for all users.[1]

Note that if *both* the `textLayer` and `pdfBug` debugging hash-parameters are specified simultaneously, we'll now load the `PDFBug`-file *twice* (since the code is simpler that way). However, given first of all that none of this is enabled by default and secondly that using those parameters together isn't helpful[2], potentially loading that file twice is hopefully not an issue.

For the `gulp mozcentral` target, the size of the *built* `viewer.css` file is reduced `> 3%` with this patch.

---
[1] For the Firefox built-in PDF Viewer, in order to even be able to access the `PDFBug` functionality, you need to first of all set `pdfjs.pdfBugEnabled = true` manually in `about:config`. Secondly, you then also need to append the `pdfBug=...` hash-parameter to the URL when *initially* loading the document.

[2] Note how the `textLayer`-settings are already, since essentially forever, overriding the highlighting-features of the "FontInspector"-tab.
2022-04-16 14:16:39 +02:00
Jonas Jenwald
07ac5c337f [GENERIC viewer] Remove some, now unnecessary, checks used with fileInput
According to the MDN compatibility data, see below, all of these features have been supported for years and years in all browsers. Looking closely at the data, the most likely reason for adding these checks in the first place was for IE 9 compatibility (since we originally "supported" that browser).

 - https://developer.mozilla.org/en-US/docs/Web/API/File#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/FileReader#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/FileList#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/Blob#browser_compatibility
2022-04-10 12:50:35 +02:00
Jonas Jenwald
5390d2b377 [GENERIC viewer] Re-factor the fileInput initialization
*This is yet another installment in a never-ending series of patches that attempt to simplify and improve old code.*

The `fileInput`-element is used to support the "Open file"-button in the `GENERIC` viewer, however this is very old code.
Rather than creating the element dynamically in JavaScript, we can simply define it conditionally in the HTML code thanks to the pre-processor. Furthermore, the `fileInput`-element currently has a number of unnecessary CSS rules, since the element is *purposely* never made visibly.

Note that with these changes, the `fileInput`-element will now *always* have `display: none;` set. This shouldn't matter, since we can still trigger the `click`-event of the element just fine (via JavaScript) and this patch has been successfully tested in both Mozilla Firefox and Google Chrome.
2022-04-09 21:21:18 +02:00
Jonas Jenwald
bb25b6dec5 Use a bit more optional chaining in the viewer 2022-04-07 16:20:41 +02:00
Jonas Jenwald
8fa73dbfab Convert web/debugger.js to a *basic* module
The various functionality in `web/debugger.js` is currently *indirectly* added to the global scope, since that's how `var` works when it's used outside of any functions/closures.
Given how this functionality is being accessed/used, not just in the viewer but also in the API and textLayer, simply converting the entire file to a module isn't trivial[1]. However, we can at least export the `PDFBug`-part properly and then `import` that dynamically in the viewer.
Also, to improve the code a little bit, we're now *explicitly* exporting the necessary functionality globally.

According to MDN, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility, all the browsers that we now support have dynamic `imports` implementations.

---
[1] We could probably pass around references to the necessary functionality, but given how this is being used I'm just not sure it's worth the effort. Also, adding *official* support for these viewer-specific debugging tools in the API feels both unnecessary and unfortunate.
2022-04-03 14:30:26 +02:00
Jonas Jenwald
6d2863f80a Simplify the fallback-logic in the default viewer
After [bug 1705327](https://bugzilla.mozilla.org/show_bug.cgi?id=1705327) the `ChromeActions.fallback`-method is now just a stub[1], since the fallback bar was removed.
Hence there's no good reason, as far as I can tell, to keep this code in the viewer itself when it's completely unused.

---
[1] See https://searchfox.org/mozilla-central/rev/292d17c13daa61016fd082e2337297091d53a015/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#575-581
2022-03-02 13:30:45 +01:00
Jonas Jenwald
9d773c1499 Only support the standard, unprefixed, Fullscreen API in the default viewer
At this point in time, after recent rounds of clean-up, the `webkit`-prefixed Fullscreen API is the only remaining *browser-specific* compatibility hack in the `web/`-folder JavaScript code.

The standard, and thus unprefixed, Fullscreen API has been supported for *over three years* in both Mozilla Firefox and Google Chrome. [According to MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API#browser_compatibility), the unprefixed Fullscreen API has been available since:
 - Mozilla Firefox 64, released on 2018-12-11; see https://wiki.mozilla.org/Release_Management/Calendar#Past_branch_dates
 - Google Chrome 71, released on 2018-12-04; see https://en.wikipedia.org/wiki/Google_Chrome_version_history

Hence *only* Safari now requires using a prefixed Fullscreen API, and it's thus (significantly) lagging behind other browsers in this regard.
Considering that the default viewer is written *specifically* to be the UI for the Firefox PDF Viewer, and that we ask users to not just use it as-is[1], I think that we should only support the standard Fullscreen API now.
Furthermore, note also that the FAQ already lists Safari as "Mostly" supported; see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support

---
[1] Note e.g. http://mozilla.github.io/pdf.js/getting_started/#introduction
> The viewer is built on the display layer and is the UI for PDF viewer in Firefox and the other browser extensions within the project. It can be a good starting point for building your own viewer. *However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.*
2022-02-25 16:06:28 +01:00