Commit Graph

3256 Commits

Author SHA1 Message Date
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
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
Jonas Jenwald
f2c9a6bc24 Revert "[GENERIC viewer] Add fallback logic for the old PDFPageView.update method signature"
This reverts commit 8466204384, since it's now been included in three official releases.
2022-03-02 11:15:18 +01:00
Jonas Jenwald
fdd06fa393 Remove the -webkit-outer-spin-button CSS rule
Unfortunately simply using `appearance: textfield;`, or even `-webkit-appearance: textfield;`, doesn't actually hide the "spinner" in number-input elements in e.g. Google Chrome.
Hence we need to use a work-around with the `-webkit-inner-spin-button` rule, however in our CSS code we also have `-webkit-outer-spin-button` currently. According to both [the MDN compatibility data](https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-outer-spin-button#browser_compatibility) and also manual testing in Google Chrome Beta 99, the `-webkit-outer-spin-button` rule is no longer necessary and we can thus clean-up the CSS a tiny bit.
2022-02-28 12:16:32 +01:00
Jonas Jenwald
047a971093 Remove the -webkit-overflow-scrolling: touch; CSS rules (PR 4516 follow-up)
This was added in PR 4516 specifically for Safari on iOS devices, but according to MDN it should no longer be necessary now; see https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling#browser_compatibility

According to the MDN compatibility data, this CSS feature:
 - Was never implemented anywhere *except* for Safari on iOS.
 - Was never standardized and thus never existed in an *unprefixed* version.
 - Has now been removed, starting with Safari version 13.

Given that [the FAQ](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support) already lists Safari as "Mostly" supported, and that the default viewer is written primarily for Mozilla Firefox, it ought to be fine to remove these CSS rules now.
2022-02-27 22:09:19 +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
Jonas Jenwald
cadc4d2f61 Replace all "private" methods in PDFPresentationMode with proper ones
Now that the there's ECMAScript support for properly private methods on `class`es, we can use that instead and thus remove all of the `@private` JSDocs comments.
2022-02-25 14:49:12 +01:00
Tim van der Meij
8e234a16d4
Merge pull request #14578 from Snuffleupagus/rm-backingStorePixelRatio
Remove the `backingStorePixelRatio`-part of the `getOutputScale` helper function
2022-02-19 14:54:30 +01:00
Jonas Jenwald
dde4e43b4a Use the (viewer) parseQueryString helper function in the reference tests
Rather than re-implementing this functionality in the `Driver` class, we can simply re-use the existing `parseQueryString` helper function instead.
2022-02-19 09:41:04 +01:00
Jonas Jenwald
36cb82e517 Convert the getOutputScale helper function into a OutputScale class
Given the previous patch in particular, this seems like an overall nicer format since it avoids duplicating the `scaled` getter in each instance.
2022-02-18 16:45:38 +01:00
Jonas Jenwald
0928d26d54 Replace the scaled property, in the getOutputScale return, with a getter
In some cases, in the `PDFPageView` implementation, we're modifying the `sx`/`sy` properties when CSS-only zooming is being used.
Currently this requires that you remember to *manually* update the `scaled` property to prevent issues, which doesn't feel all that nice and also seems error-prone. By replacing the `scaled` property with a getter, this is now handled automatically instead.
2022-02-18 13:10:42 +01:00
Jonas Jenwald
0159ec0a12 Remove the backingStorePixelRatio-part of the getOutputScale helper function
The `CanvasRenderingContext2D.backingStorePixelRatio` property was never standardized, and only Safari set (its prefixed version of) it to anything other than `1`.
Note that e.g. MDN doesn't contain any information about this property, and one of the few sources of information (at this point) is the following post: https://stackoverflow.com/questions/24332639/why-context2d-backingstorepixelratio-deprecated

Hence we can simplify the `getOutputScale` helper function, by removing some dead code, and now it no longer requires any parameters when called.
2022-02-18 13:03:48 +01:00