1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Improve highlightments and popups in HCM (bug 1830850)

- Modify the text and background colors in popup to fit a11y requirements
- Add a backdrop filter on clickable areas in using a svg filter mapping
  canvas colors to Highlight and HighlightText ones.
This commit is contained in:
Calixte Denizet 2023-06-23 15:47:59 +02:00
parent ccb72073b0
commit c519cc821b
6 changed files with 248 additions and 69 deletions

View file

@ -30,6 +30,7 @@
--input-disabled-border-color: GrayText;
--input-hover-border-color: Highlight;
--link-outline: 1.5px solid LinkText;
--hcm-highligh-filter: invert(100%);
}
.annotationLayer .textWidgetAnnotation :is(input, textarea):required,
.annotationLayer .choiceWidgetAnnotation select:required,
@ -40,7 +41,30 @@
}
.annotationLayer .linkAnnotation:hover {
backdrop-filter: invert(100%);
backdrop-filter: var(--hcm-highligh-filter);
}
.annotationLayer .linkAnnotation > a:hover {
opacity: 0 !important;
background: none !important;
box-shadow: none;
}
.annotationLayer .popupAnnotation .popup {
outline: calc(1.5px * var(--scale-factor)) solid CanvasText !important;
background-color: ButtonFace !important;
color: ButtonText !important;
}
.annotationLayer .highlightArea:hover::after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
backdrop-filter: var(--hcm-highligh-filter);
content: "";
pointer-events: none;
}
.annotationLayer .popupAnnotation.focused .popup {

View file

@ -13,6 +13,8 @@
* limitations under the License.
*/
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/base_factory.js").BaseFilterFactory} BaseFilterFactory */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
// eslint-disable-next-line max-len
@ -84,6 +86,8 @@ import { XfaLayerBuilder } from "./xfa_layer_builder.js";
* @property {IL10n} [l10n] - Localization service.
* @property {function} [layerProperties] - The function that is used to lookup
* the necessary layer-properties.
* @property {BaseFilterFactory} [filterFactory] - Factory to create some SVG
* filters.
*/
const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216;
@ -203,6 +207,21 @@ class PDFPageView {
"--scale-factor",
this.scale * PixelsPerInch.PDF_TO_CSS_UNITS
);
if (
options.filterFactory &&
(this.pageColors?.foreground === "CanvasText" ||
this.pageColors?.background === "Canvas")
) {
container?.style.setProperty(
"--hcm-highligh-filter",
options.filterFactory.addHighlightHCMFilter(
"CanvasText",
"Canvas",
"HighlightText",
"Highlight"
)
);
}
const { optionalContentConfigPromise } = options;
if (optionalContentConfigPromise) {

View file

@ -883,6 +883,20 @@ class PDFViewer {
// Ensure that the various layers always get the correct initial size,
// see issue 15795.
this.viewer.style.setProperty("--scale-factor", viewport.scale);
if (
this.pageColors?.foreground === "CanvasText" ||
this.pageColors?.background === "Canvas"
) {
this.viewer.style.setProperty(
"--hcm-highligh-filter",
pdfDocument.filterFactory.addHighlightHCMFilter(
"CanvasText",
"Canvas",
"HighlightText",
"Highlight"
)
);
}
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
const pageView = new PDFPageView({
@ -902,6 +916,7 @@ class PDFViewer {
pageColors: this.pageColors,
l10n: this.l10n,
layerProperties,
filterFactory: pdfDocument.filterFactory,
});
this._pages.push(pageView);
}