Commit Graph

3366 Commits

Author SHA1 Message Date
calixteman
cfac6fa511
Merge pull request #14874 from calixteman/colors
[api-minor] Improve pdf reading in high contrast mode
2022-05-05 21:48:19 +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
4fffab4ad3 Add (basic) support for Spread modes in PresentationMode (issue 14749)
After recent changes, adding *basic* Spread mode support in PresentationMode has now become reasonably straightforward.

However, documents with *varying* page sizes are non-trivial to handle and would require re-writing (or at least re-factoring) a bunch of the zooming-code.
Hence this PR *purposely* only allow Spread modes to be used, in PresentationMode, for documents where all pages have exactly the same size. While this obviously isn't a fully complete solution, it will however cover the vast majority of all documents and should hopefully be deemed good enough for now.
2022-05-05 11:53:09 +02:00
Jonas Jenwald
54410d5e41 Simplify the signature of BaseViewer._scrollIntoView and make the method private
In PR 14112 usage of this *internal* method was reduced, and it thus can't hurt to clean-up things a little bit more.
Note in particular that we can simplify the call-sites by directly passing in the already available `PDFPageView`-instance, since the `id`-property those contain can replace the previous `pageNumber`-parameter[1].

Given that the method name has always been prefixed with an underscore it was thus never intended to be "public", hence we can now enforce that with modern ECMAScript features.

---
[1] There's already a bunch of other spots, throughout the viewer-code, where we assume that the `PDFPageView.id`-property contains proper page *numbers* (and not e.g. indices); note how we initialize the `PDFPageView`-instances in the `BaseViewer.setDocument`-method.
2022-05-05 11:27:00 +02:00
Jonas Jenwald
aad4c6538f Re-factor the PresentationMode handling in BaseViewer.#ensurePageViewVisible
Given that we're (ab)using spread-modes in order to ensure that pages are centered *vertically* in PresentationMode, this re-factoring simplifies the code slightly.
Furthermore, in the event that we *possibly* want to try and support spread-modes in PresentationMode[1] this re-factoring will also prevent future duplication.

---
[1] Note that I'm not particularly keen on doing that, since documents with varying page sizes will be annoying to handle.
2022-05-03 13:25:34 +02:00
Tim van der Meij
75ac897284
Merge pull request #14857 from Snuffleupagus/rm-webViewerOpenFileViaURL
Inline the `webViewerOpenFileViaURL` function in  `webViewerInitialized`
2022-04-30 12:21:25 +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
1e24fe97f2 Remove unnecessary CSS classes when specifying button icons
Currently we're using *both* ids and classes when specifying the button icons, which seems completely unnecessary and only serves to bloat the CSS code.
In general you always need to be careful about CSS specificity, but in these cases that should not actually be a problem.

Also, while not a button, this patch makes a similar simplification for the `pageNumber`-input.
2022-04-29 09:40:03 +02:00
Jonas Jenwald
4f69d66ab2 Remove redundant class names from the button DOM-elements
Note how in the `viewer.html` file we're specifying class names for most buttons, despite that not really being necessary. First of all, in many cases those class names are *identical* to the element-ids. Secondly, looking through the CSS rules they are only ever used when specifying button icons.
All-in-all, we should be able to simplify the HTML-code and use the element-ids in the CSS rules instead. Obviously ids have a higher CSS specificity than classes, but given how the old classes were being used that shouldn't be a problem here.

Also, the patch generalizes the styling for buttons (e.g. `viewBookmark`) that are *actually* link-elements.

Finally, while slightly unrelated, this patch also removes a little bit of duplication when specifying the border for `toolbarField`s.
2022-04-29 09:36:35 +02:00
Tim van der Meij
b72a448327
Merge pull request #14835 from Snuffleupagus/CSS-cleanup-separators
Clean-up some CSS rules for the various toolbar separators
2022-04-27 14:32:23 +02:00
Jonas Jenwald
3c10c66cd3 Remove unused CSS rules for toolbar buttons with textButton-classes
Searching through all of the files in the `web/`-folder has no *other* hits for the "textButton" string. Hence it's clear that there are no DOM elements actually using this class, and it's thus dead code.
2022-04-25 14:55:32 +02:00
Jonas Jenwald
f9262d29fc Clean-up some CSS rules for the various toolbar separators
This re-factors the various toolbar separators to *explicitly* specify both their dimensions and margins. Also, for the `horizontalToolbarSeparator`-class we can just set the `background-color` rather than using `border-top`.

Note that the `splitToolbarButtonSeparator`-class currently sets a number of unnecessary CSS rules, since as mentioned by the Firefox Devtools both the `display`- and `z-index`-properties are being ignored because `float` is used.

Finally, there's also no need to set a `z-index` for some of the `:hover`-rules. It's possible that this *was* necessary before the re-design, since the buttons had borders then.
2022-04-25 14:53:12 +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
925a7bc58a Remove unnecessary print CSS rules
These rules became unnecessary with PR 7697, over five years ago, since printing is now done from a `printContainer`-element rather than "directly" using the viewer.

Note how the *entire* `outerContainer`, which contains all of the DOM elements that were being manually hidden, is now being hidden during printing. Furthermore, note also how the print-canvases/images and their containers are using custom CSS-classes[1] rather than re-using the ones from the viewer.

---
[1] See the `printedPage` respectively `xfaPrintedPage` classes.
2022-04-23 14:32:00 +02:00
Tim van der Meij
18dd2866f7
Merge pull request #14827 from Snuffleupagus/toolbar-margin
Simplify setting of spacing at the left/right edges of the toolbar(s)
2022-04-23 13:11:16 +02:00
Jonas Jenwald
7e57469683 Use more for...of loops in the viewer
Note that the arrays that we're looping over here are by definition *dense*, hence there's no point in checking if each element actually exists first.
2022-04-23 12:48:54 +02:00
Jonas Jenwald
33ed743c48 Simplify setting of spacing at the left/right edges of the toolbar(s)
Rather than modifying the leading/trailing `margin` on the actual toolbar buttons, to achieve appropriate spacing at the left/right edges of the toolbar(s), it seems much more appropriate (and simpler) to just specify an explicit `padding` for the relevant toolbar containers.

Also, for toolbar buttons placed in `splitToolbarButton`-classes we can reduce some complexity around setting the `margin` (since it should always be zero now).

With these changes, we're thus able to get rid of a couple more `!important`-rules.
2022-04-22 18:15:28 +02:00
Jonas Jenwald
0f7e3213a1 Some more, small, CSS clean-up
- Remove a redundant `margin-top` rule for the `.dropdownToolbarButton`. After the (somewhat) recent UI-refresh all buttons now use `margin: 2px 1px;`, which renders the override unnecessary (and getting rid of an `!important`-rule can't hurt).

 - Combine two `.toggled::before` rules, since they're identical.
2022-04-21 15:41:30 +02:00
Tim van der Meij
452a98b0e0
Merge pull request #14810 from Snuffleupagus/mozcentral-rm-errorWrapper-CSS
Stop bundling `errorWrapper` CSS rules in the MOZCENTRAL build
2022-04-20 19:50:57 +02:00
Jonas Jenwald
1d803451c3 Stop bundling errorWrapper CSS rules in the MOZCENTRAL build
Note that both the `errorWrapper` HTML and JavaScript code is being ignored in the MOZCENTRAL build, i.e. the *built-in* Firefox PDF Viewer, however the CSS rules are still being included.
That seems totally unnecessary, and while we currently don't have full build-target support in the CSS pre-processor we can actually improve things quite easily anyway. By (ab)using the existing CSS pre-processor, which will remove any non-Firefox CSS rules for the MOZCENTRAL build, it's possible to easily stop bundling any CSS rules by using comments that include a `-webkit`-string.

*Please note:* To easily test that this doesn't break the `errorWrapper` in GENERIC builds, try running e.g. `PDFViewerApplication._otherError("test");` in the web-console.
2022-04-20 14:35:09 +02:00
Jonas Jenwald
c91d2ac15a Remove the PresentationMode special-case from BaseViewer.update
This special-case was added because the original PresentationMode-implementation used some CSS-tricks to hide everything except the current page. With the changes in PR 14112, which added a PAGE scroll-mode, many of the old PresentationMode-specific hacks could thus be removed from both the JS and CSS code.

This patch is yet another (small) clean-up step, to reduce the number of PresentationMode special-cases used throughout the `BaseViewer`. Note in particular that `BaseViewer.update` now works just fine in PresentationMode[1], and that we only need to ensure that the active page won't *accidentally* change because of the PresentationMode-specific zooming that occurs during page-switching.

---
[1] In the event that we ever want to try and support spread-modes in PresentationMode, which I'm really not keen on doing since documents with varying page sizes will be annoying to handle, these changes would be necessary as well.
2022-04-20 12:17:00 +02:00
Tim van der Meij
c58ff7c301
Merge pull request #14801 from Snuffleupagus/findbar-simplify-button-styling
[GENERIC viewer] Simplify the styling of the previous/next findbar buttons
2022-04-19 21:29:41 +02:00
Tim van der Meij
5032e357d4
Merge pull request #14793 from Snuffleupagus/ensurePageViewVisible-spreads
Simplify spread-mode handling for the PAGE scroll-mode
2022-04-19 21:25:59 +02:00
Tim van der Meij
a115d17b43
Merge pull request #14795 from Snuffleupagus/CSS-reduce-duplication
Reduce more duplication in the CSS
2022-04-19 21:19:05 +02:00
Tim van der Meij
5f6ca2224e
Merge pull request #14790 from Snuffleupagus/rm-print-CSS
Remove some outdated CSS rules related to printing
2022-04-19 21:14:42 +02:00
Jonas Jenwald
fb90ef7b28 [GENERIC viewer] Simplify the styling of the previous/next findbar buttons
The styling of the previous/next-buttons and the findInput, with the elements being "glued" together, was supposed to mimic the styling used in the Firefox *browser* findbar. However, after the most recent re-styling of the Firefox browser UI these elements are now visually separated.
Hence it makes sense, as far as I'm concerned, to try and follow this styling for the findbar used in the GENERIC viewer. One benefit of doing this is that we get more consistent styling, since the buttons now look/behave identically in both the main toolbar and the findbar. Additionally this also simplifies the CSS a bit, since a lot of the existing findbar-specific rules can be removed.
2022-04-19 14:12:30 +02:00
Jonas Jenwald
1ea9740fdb Reduce more duplication in the CSS
This patch combines a couple of different CSS rules, thus reducing the overall size of the file.
2022-04-17 14:03:01 +02:00
Jonas Jenwald
03ec7a22f2 Simplify spread-mode handling for the PAGE scroll-mode
The spread-mode code in `BaseViewer.#ensurePageViewVisible`-method was initially copied from the `BaseViewer._updateSpreadMode`-method, which means that it's slightly more complicated than actually necessary.
In particular, in the PAGE scroll-mode there can only be *one* spread active at a time and we thus don't need to handle insertion of multiple spread-divs.
2022-04-17 10:58:14 +02:00
Jonas Jenwald
d7fd8d3883 Remove some outdated CSS rules related to printing
Given that no HTML element has used the `loadingBox`-id for many years, we obviously don't need to try and hide a non-existent element during printing.
Furthermore, we also shouldn't need to change the `overflow`-value for the `viewerContainer`-element during printing. Originally, many years ago now, we printed "directly" using the viewer and then this apparently made sense.
2022-04-16 16:03: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
fffce7910e
Merge pull request #14722 from Rob--W/scripting-manager-mousedown-grab-to-pan-conflict
PDFScriptingManager: Bind mousedown listener with capture=true
2022-04-15 11:59:18 +02:00
Tim van der Meij
3f5c31e203
Merge pull request #14780 from Snuffleupagus/rm-CSS-viewport-scale-factor
Replace the `--viewport-scale-factor` CSS variable
2022-04-14 21:12:29 +02:00
Tim van der Meij
c4a9fd635e
Merge pull request #14773 from Snuffleupagus/rm-dropdownToolbarButton-styling
Remove some `dropdownToolbarButton`-related CSS rules
2022-04-14 21:02:57 +02:00
Tim van der Meij
5ca26bcc05
Merge pull request #14772 from Snuffleupagus/rm-unneeded-CSS
Remove/simplify some CSS rules
2022-04-14 20:57:04 +02:00
Tim van der Meij
e9aedf2d91
Merge pull request #14771 from Snuffleupagus/dialog-backdrop-rm-user-select
Simplify the `dialog::backdrop` CSS rules (PR 14710 follow-up)
2022-04-14 20:54:22 +02:00
Tim van der Meij
97377085c1
Merge pull request #14770 from Snuffleupagus/sidebarContainer-transitionend
Always remove the `sidebarMoving` CSS class when the sidebar is closed
2022-04-14 20:47:49 +02:00
Jonas Jenwald
e67cd7fae0 Replace the --viewport-scale-factor CSS variable
This CSS variable is only used together with the `annotationCanvasMap`-functionality in the canvas-code, however its value can be *trivially* computed by using the older `--zoom-factor` CSS variable together with the `PixelsPerInch`-structure.
Rather than having *two different* CSS variables that are this closely linked, it seems better to simplify things by using just one CSS variable instead.
2022-04-14 12:43:57 +02:00
Jonas Jenwald
11b30c974e Remove some dropdownToolbarButton-related CSS rules
According to the CSS, there should be a visible "divider" after the "Page Width" zoom-option. However, this is being ignored in both Mozilla Firefox[1] and Google Chrome hence the rule is effectively useless now.
Furthermore, the "custom" zoom-option is already being `hidden` using the attribute (in the HTML code) and there should thus be no reason to duplicate this in the CSS as well.

---
[1] Support for *detailed* styling of `<select>`-elements was removed as part of the E10s project.
2022-04-12 16:05:23 +02:00
Jonas Jenwald
3752b8975b Reduce (some) duplication in the CSS rules for the sidebarViews
With just a couple of exceptions, for the `thumbnailView`, all of the sidebarViews share the same basic styling which thus allows for some simplification.
2022-04-12 13:51:50 +02:00
Jonas Jenwald
f788035a58 Remove unnecessary min-width CSS rules
- For the findbar/secondaryToolbar case, the `min-width` rule doesn't really make sense since it's way too small to be useful. Furthermore, the findbar is already specifying its own `min-width` and the secondaryToolbar will (thanks to its buttons) receive a correct/useful width.

 - The pageNumber-input already has an *explicit* `width` set, hence setting the `min-width` rule as well is completely unnecessary.

 - The treeItem-links are supposed to *compute* their `min-width`, and the static value was only added as a fallback for older browsers without `calc()` support.
2022-04-12 13:51:45 +02:00
Jonas Jenwald
93c5c6e5e9 Use background-color rather than background in a few CSS rules
In a couple of spots, mostly related to the debugging tools, we're unnecessarily using a somewhat "complex" `background`-format only to specify a solid color. This can be simplified by using `background-color` instead, and the patch also removes a `color`-rule that's being ignored anyway.
2022-04-12 12:41:34 +02:00
Jonas Jenwald
3aed103ce8 Simplify the dialog::backdrop CSS rules (PR 14710 follow-up)
After the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1761839, we no longer need this CSS work-around to prevent the entire `<dialog>` contents from becoming selected when the backdrop is clicked.
2022-04-12 12:41:29 +02:00
Jonas Jenwald
0fbe5832ab Always remove the sidebarMoving CSS class when the sidebar is closed
When the viewer becomes narrow enough that the sidebar is overlaying the document, which means that the `viewerContainer` is not moving when opening/closing the sidebar, we're currently not removing the `sidebarMoving` CSS class as intended.
While this doesn't cause any *visible* issues, it's nonetheless wrong and should be fixed.
2022-04-11 19:46:10 +02:00
Jonas Jenwald
0a83538e64 Remove unnecessary @media CSS rules (PR 8993 follow-up)
With the changes in PR 8993, a number of the `@media`-related CSS rules became unnecessary. However, it appears that some of these rule were *accidentally* left behind despite being unused now.
Note that previously, when opening the sidebar shifted the position of the main toolbar, we had to take both the sidebar opened *and* closed cases into account in these `@media` rules.
2022-04-11 10:08:48 +02:00
Tim van der Meij
143ba30bef
Merge pull request #14767 from Snuffleupagus/fileInput-refactor
[GENERIC viewer] Re-factor the `fileInput` initialization
2022-04-10 15:07:08 +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
bde6d9ffba Re-factor how PDFPresentationMode, internally, tracks the current PresentationModeState
With the changes in the previous patch, we can simplify the state-tracking by using the `PresentationModeState`-values directly in the `PDFPresentationMode` class.
2022-04-09 12:20:11 +02:00
Jonas Jenwald
8d61b7c088 Simplify handling of requestFullscreen errors in PDFPresentationMode
Since quite some time the `Element.requestFullscreen()` method has been returning a Promise, see https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#return_value
Hence we can utilize that to detect failures to enter fullscreen-mode, and remove our old `setTimeout`-based hacks that were used for this purpose.

According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#browser_compatibility, all browsers that we support have implemented this functionality. (Note that after PR 14606, we no longer support PresentationMode in Safari.)
2022-04-09 12:12:50 +02:00
Tim van der Meij
2b673a6941
Merge pull request #14750 from Snuffleupagus/rm-_getCurrentVisiblePage
Remove the `BaseViewer._getCurrentVisiblePage` helper method
2022-04-08 20:05:51 +02:00
Jonas Jenwald
bb25b6dec5 Use a bit more optional chaining in the viewer 2022-04-07 16:20:41 +02:00
Jonas Jenwald
55838303c7 Tweak the pdfOpenParams parameter, in the "updateviewarea" event, in PresentationMode
The `pdfOpenParams` parameter has never really made sense in PresentationMode, since e.g. the zoom-value doesn't (generally) agree with the value chosen by the user prior to entering PresentationMode.
This has never mattered all that much, since the `viewBookmark`-button isn't visible in PresentationMode (nor is any other toolbar button for that matter). However, in the `PDFHistory`-implementation we're currently forced to handle this case specifically since we don't want to populate the browser history with nonsensical state.
Hence it makes overall sense, as far as I'm concerned, to tweak the "updateviewarea" event to include a *simplified* `pdfOpenParams` parameter when PresentationMode is active. Given that the `viewer components` don't include PresentationMode functionality, this change thus shouldn't matter for third-party users.
2022-04-05 14:13:20 +02:00
Jonas Jenwald
5ef294b3a7 Remove the BaseViewer._getCurrentVisiblePage helper method
This method was originally added specifically to work-around bugs/issues related to PresentationMode in Google Chrome. Note that prior to PR 14112 we were using some CSS hacks to only show the current page in PresentationMode, and that could lead to the `getVisibleElements` function not always finding the correct elements.
However, after the changes in PR 14112 we're now using the Page-scrolling mode in PresentationMode and consequently there'll only be *a single* page visible at a time. Hence then `BaseViewer._getCurrentVisiblePage` helper method should no longer be needed, and when testing (locally) in Google Chrome everything seems to work correctly now.
2022-04-05 13:32:09 +02:00
Jonas Jenwald
27e738dff9
Merge pull request #14663 from Snuffleupagus/issue-14525
[GENERIC viewer] Try to improve a11y, for search results, in the findbar (issue 14525)
2022-04-04 19:10:55 +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
bc1cde238d Replace most loops in web/debugger.js with for...of loops
This leads to *slightly* more compact code overall. Also, uses object shorthand notation to remove some now unnecessary `function`-strings.
2022-04-02 11:58:10 +02:00
Jonas Jenwald
966da4babe [GENERIC viewer] Try to improve a11y, for search results, in the findbar (issue 14525)
Note that it seemed necessary to re-factor the `findResultsCount` and `findMsg` element grouping, in the HTML/CSS code, in order those elements to be correctly announced by a11y software in Firefox.

The following MDN articles may be helpful here:
 - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid
 - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live
2022-03-31 23:12:56 +02:00
Jonas Jenwald
f1b17773c0 Don't manually convert setAttribute values to strings (PR 14554 follow-up)
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute#parameters, non-string values will be automatically converted into strings. I should probably have read that article more carefully, to avoid unnecessary churn in the code; sorry about that!
2022-03-31 17:26:28 +02:00
Jonas Jenwald
c9f262c480 Add a <dialog> polyfill for the generic-legacy build
Please note that this patch is purposely quite basic, e.g. it doesn't add the polyfill-CSS in order to simplify the build process, and things such as `::backdrop` thus isn't working.
However, this patch does ensure that older browsers can at least still *access* all of the previous overlays and that things like e.g. opening of password-protected documents respectively printing still works.
2022-03-28 11:36:31 +02:00
Jonas Jenwald
b3d58e1000 Try to improve a11y for the PasswordPrompt and PDFDocumentProperties dialogs
This will hopefully improve the a11y a little bit in these dialogs, however there's most definately more things that can be done here (by someone more knowledgeable about a11y).
2022-03-28 11:36:31 +02:00
Jonas Jenwald
923bd52cdb Re-factor the OverlayManager class to use a WeakMap internally
This way we're able to store the `<dialog>` elements directly, which removes the need to use manually specified name-strings thus simplifying both the `OverlayManager` itself and its calling code.
2022-03-28 11:36:31 +02:00
Jonas Jenwald
f0aa08b464 Convert the existing overlays to use <dialog> elements (issue 14698)
This replaces our *custom* overlays with standard `<dialog>` DOM elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog, thus simplifying the related CSS, HTML, and JavaScript code.

With these changes, some of the functionality of the `OverlayManager` class is now handled natively (e.g. `Esc` to close the dialog). However, since we still need to be able to prevent dialogs from overlaying one another, it still makes sense to keep this functionality (as far as I'm concerned).
2022-03-28 11:36:29 +02:00
Rob Wu
dc6e2ed6f8 PDFScriptingManager: Bind mousedown listener with capture=true
PDFScriptingManager uses the `mousedown` and `mouseup` listeners to keep
track of whether the mouse pointer is pressed in the `isDown` flag.
These listeners were registered to run during the bubbling phase of the
event dispatch, which can be interrupted if any of the previous event
listeners stopped the event propagation. An example of that is by
`GrabToPan` in web/grab_to_pan.js.

Since the mousedown (and mouseup) listeners of PDFScriptingManager are
free of side effects, and the intention is to always run them, it makes
most sense to register them with the capture flag.
2022-03-28 02:34:00 +02:00
Tim van der Meij
20d60d92ba
Merge pull request #14715 from Snuffleupagus/issue-13230
Avoid the `textLayer` becoming visible in high contrast mode (issue 13230)
2022-03-27 14:22:35 +02:00
Jonas Jenwald
fd6e2e2ab3 Avoid the textLayer becoming visible in high contrast mode (issue 13230)
Unfortunately this CSS property is not yet available in Firefox, see https://developer.mozilla.org/en-US/docs/Web/CSS/forced-color-adjust#browser_compatibility which is tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1591210, however this patch seems to work when testing in Google Chrome.

Given that we really cannot do any more on the PDF.js-side of things, until this CSS feature is actually implemented in Firefox, I figured that submitting this patch cannot hurt in order to get rid of an open issue.
2022-03-24 14:20:27 +01:00
Jonas Jenwald
f8d60da94e Remove the remaining dir-dependent CSS rules
After the recent round of patches, I figured that we'd gone as far as possible in replacing `dir`-dependent CSS rules for the viewer.
However, it occurred that me that we could actually use a bit of CSS-trickery to get rid of the remaining ones. More specifically, this was done by defining a CSS variable whose value depends on the document direction and then using that variable together with `calc()` in the affected rules.

*Please note:* I suppose that this could perhaps be seen as a bit too "magical", hence I understand if this patch is ultimately rejected, however this is probably the only simple way to get rid of the remaining `dir`-dependent CSS rules.
2022-03-23 22:05:23 +01:00
Tim van der Meij
db4f3adc5e
Merge pull request #14691 from Snuffleupagus/border-inline
Replace `dir`-dependent `border`-rules with logical properties
2022-03-23 20:43:15 +01:00
Jonas Jenwald
cd133dbcac Change OverlayManager.open to always error if the overlay is already active
The old code would allow an overlay to force close *itself*, before immediately re-opening itself, which actually isn't very helpful in practice since that won't re-run any overlay-specific initialization code.
Given how the overlays are being used this really shouldn't have caused any issues, but it's a bug that we should fix nonetheless.
2022-03-22 09:50:28 +01:00
Jonas Jenwald
bace0623e5 Convert the OverlayManager class to use private fields/methods 2022-03-21 16:01:32 +01:00
Jonas Jenwald
477dc08b00 Replace dir-dependent border-rules with logical properties
*Please note:* This is the final step in a series of patches to simplify/modernize the viewer CSS, since the remaining `html[dir="rtl"]`-cases cannot be converted.

Rather than having to manually specify ltr/rtl-specific border-values in the CSS, we can use logical `border-inline-end`/`border-start-end-radius`/`border-end-end-radius` instead.
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we rely on the previously added PostCSS plugins in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/border-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/border-start-end-radius#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/border-end-end-radius#browser_compatibility
2022-03-20 12:45:37 +01:00
Jonas Jenwald
9eed8c3576 Replace dir-dependent left/right with logical properties
*Please note:* This is another step in a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific left/right-values in the CSS, we can use logical `inset-inline`/`inset-inline-start`/`inset-inline-end` instead.
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we rely on the previously added PostCSS plugins in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility
2022-03-19 14:44:01 +01:00
Jonas Jenwald
bc6ea6a878 Replace dir-dependent float with logical properties
*Please note:* This is another step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific float-values in the CSS, we can use logical `inline-start`/`inline-end` instead (and similar for some related left/right occurrences).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we rely on PostCSS plugins in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/float#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility
2022-03-19 14:03:20 +01:00
Jonas Jenwald
502fd7c80d Stop polyfilling the CSS calc functionality
At this point in time, all browsers that we support have native support for CSS variables; please see https://developer.mozilla.org/en-US/docs/Web/CSS/calc()#browser_compatibility and https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support

We can also remove the hack introduced back in PR 11567, which was only necessary to work-around an IE 11 specific bug.
2022-03-19 14:03:19 +01:00
Tim van der Meij
079dea2274
Merge pull request #14670 from Snuffleupagus/postcss-logical
Replace `dir`-dependent `margin`/`margin-left`/`margin-right` with logical properties
2022-03-19 13:53:39 +01:00
Jonas Jenwald
c99d558646 Replace dir-dependent margin/margin-left/margin-right with logical properties
*Please note:* This is another step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific margin-values in the CSS, we can use logical margin instead (and similar for some related left/right occurrences).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we need to use a couple of PostCSS plugins (see below) in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility

---

 - https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-logical
 - https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class
2022-03-19 13:35:24 +01:00
Jonas Jenwald
61a52e8043 Convert all "private" methods in PDFFindController into proper ones
Given that none of these methods are/were ever intended to be called manually, we can now enforce this with modern class-features.
2022-03-19 12:26:03 +01:00
Jonas Jenwald
cc1bca6268 Slightly simplify the PDFFindController._extractText method
Currently we're resolving the Promises in the `_extractTextPromises` Array with the page-index, despite that not really being necessary since the Promises in the Array are explicitly inserted in the correct order.
Furthermore, we can replace the standard `for`-loop with a `for...of`-loop which results in ever so slightly more compact code.
2022-03-19 12:13:29 +01:00
Tim van der Meij
489e9ff7d3
Merge pull request #14675 from Snuffleupagus/build-dev-CSS
Build the `web/viewer.css` file used in the development viewer (i.e. `gulp server`)
2022-03-16 20:14:02 +01:00
Tim van der Meij
00eb942c93
Merge pull request #14678 from Snuffleupagus/PDFDocumentProperties-private
Convert the `PDFDocumentProperties` class to use private methods
2022-03-16 20:10:45 +01:00
Jonas Jenwald
ba8dae696a Convert the PDFDocumentProperties class to use private methods
Given that none of these methods were ever intended to be accessed directly from the outside, we can use modern ECMAScript features to ensure that they are indeed private.

This patch also makes `fieldData` private, to remove the old hack used to prevent it from being modified from the outside.
2022-03-15 18:17:06 +01:00
Jonas Jenwald
c5574864e1 Remove the -webkit-mask-image/-webkit-mask-image CSS rules
Given that we're now *building* the `web/viewer.css` file used in the development viewer, i.e. with `gulp server`, we no longer need to hard-code these `-webkit`-prefixed rules and can instead let Autoprefixer handle that for us.
2022-03-15 13:37:46 +01:00
Jonas Jenwald
e59c2dc308 Build the web/viewer.css file used in the development viewer (i.e. gulp server)
To allow using modern CSS features that currently only Mozilla Firefox supports[1], while still enabling development/testing in recent Google Chrome versions, we'll have to start building the `web/viewer.css` file with `gulp server` as well.

In my testing, building the development CSS (and copying the images) takes *less than* `200 ms` on average which is hopefully an acceptable overhead for this sort of feature.

---
[1] In particular `float`, with `inline-start`/`inline-end` values.
2022-03-15 13:37:44 +01:00
Jonas Jenwald
ee2896dd1e Remove the custom grab/grabbing cursor image files
According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#browser_compatibility, all browsers that we now support should have these cursors available natively.
2022-03-14 14:36:38 +01:00
Tim van der Meij
90c5e9882b
Merge pull request #14669 from Snuffleupagus/padding-inline
Replace `dir`-dependent `padding-left`/`padding-right`/`text-align` with logical properties
2022-03-13 20:51:07 +01:00
Jonas Jenwald
331f4e72de Replace dir-dependent padding-left/padding-right/text-align with logical properties
*Please note:* This is small first step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to *manually* specify ltr/rtl-specific padding-values in the CSS, we can use logical padding instead (and similar for text-align).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Note that a number of logical CSS properties are new enough that we'll need to use PostCSS plugins, however the ones in this patch are natively supported in all browsers that we currently support:
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/text-align#browser_compatibility
2022-03-13 14:36:11 +01:00
Jonas Jenwald
3274972768 Revert Preferences to their previous values, when writing to storage failed
This patch fixes an old inconsistency, when using `BasePreferences.{reset, set}`, where the internal Preference values would be kept even if writing them to storage failed.
2022-03-12 17:25:45 +01:00
Jonas Jenwald
25d7420035 Convert the BasePreferences class to use private fields
Given that none of these fields were ever intended to be accessed directly from the *outside*, since that will lead to inconsistent/broken state, we can use modern ECMAScript features to ensure that they are indeed private.
2022-03-12 14:34:57 +01:00
Jonas Jenwald
4318bc8f86
Merge pull request #14554 from Snuffleupagus/issue-14526
Try to improve a11y for the "button groups" in the SecondaryToolbar/Sidebar (issue 14526)
2022-03-11 20:46:47 +01:00
Jonas Jenwald
48c64c6c8d Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer 2022-03-10 10:20:34 +01:00
Jonas Jenwald
d65169d754 Try to improve a11y for the "button groups" in the SecondaryToolbar/Sidebar (issue 14526)
*Please note:* I don't really know anything about a11y, hence it's possible that this patch either doesn't work correctly or at least isn't a complete solution.

In both the SecondaryToolbar and the Sidebar we have "button groups" that functionally acts essentially like radio-buttons. Based on skimming through [this MDN article](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/radio_role) it thus appears that we should tag them as such, using `role="radiogroup"` and `role="radio"`, and then utilize the `aria-checked` attribute to indicate to a11y software which button is currently active.
2022-03-06 16:54:27 +01:00
Tim van der Meij
6500aafd00
Use proper private methods in web/secondary_toolbar.js 2022-03-06 16:07:25 +01:00
Tim van der Meij
f33769db2d
Use proper private methods in web/pdf_find_bar.js 2022-03-06 16:07:07 +01:00
Tim van der Meij
a1d106dc5d
Use proper private methods in web/pdf_cursor_tools.js 2022-03-06 16:06:53 +01:00
Jonas Jenwald
939e6f0c4c Fix a couple of small typos in JSDoc typedef comments
While this doesn't affect the official API documentation, these cases should nonetheless be fixed.
2022-03-04 12:11:52 +01:00
Tim van der Meij
234aa9a50e
Merge pull request #14624 from Snuffleupagus/viewer-fallback-cleanup
Simplify the `fallback`-logic in the default viewer
2022-03-02 20:54:03 +01:00
Tim van der Meij
038c832719
Merge pull request #14623 from Snuffleupagus/viewer-deprecated-cleanup
Remove some deprecated code from the viewer
2022-03-02 20:46:27 +01:00
Tim van der Meij
636fc05843
Merge pull request #14617 from Snuffleupagus/rm-webkit-outer-spin-button
Remove the `-webkit-outer-spin-button` CSS rule
2022-03-02 20:40:37 +01: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
38d30f3be5 Remove the deprecated PDFFindController.executeCommand method
This *partially* reverts commit fa8c0ef616, since it's now been included in two official releases.
2022-03-02 11:23:14 +01:00