[Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375)

This patch doesn't structurally change the text layer: it just adds some aria-owns
attributes to some spans.
The aria-owns attribute expect to have an element id, hence it's why it adds back an
id on the element rendering an annotation, but this id is built in using crypto.randomUUID
to avoid any potential issues with the hash in the url.
The elements in the annotation layer are moved into the DOM in order to have them in the
same "order" as they visually are.
The overall goal is to help screen readers to present to the user the annotations as
they visually are and as they come in the text flow.
It is clearly not perfect, but it should improve readability for some people with visual
disabilities.
This commit is contained in:
Calixte Denizet 2022-07-28 17:59:03 +02:00
parent cef2ac99e5
commit f316300113
23 changed files with 436 additions and 246 deletions

View file

@ -29,6 +29,7 @@ import {
warn,
} from "../shared/util.js";
import {
AnnotationPrefix,
DOMSVGFactory,
getFilenameFromUrl,
PDFDateString,
@ -1901,7 +1902,8 @@ class PopupElement {
}
if (this.hideElement.hidden) {
this.hideElement.hidden = false;
this.container.style.zIndex += 1;
this.container.style.zIndex =
parseInt(this.container.style.zIndex) + 1000;
}
}
@ -1918,7 +1920,8 @@ class PopupElement {
}
if (!this.hideElement.hidden && !this.pinned) {
this.hideElement.hidden = true;
this.container.style.zIndex -= 1;
this.container.style.zIndex =
parseInt(this.container.style.zIndex) - 1000;
}
}
}
@ -2465,6 +2468,19 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
*/
class AnnotationLayer {
static #appendElement(element, id, div, accessibilityManager) {
const contentElement = element.firstChild || element;
contentElement.id = `${AnnotationPrefix}${id}`;
div.append(element);
accessibilityManager?.moveElementInDOM(
div,
element,
contentElement,
/* isRemovable = */ false
);
}
/**
* Render a new annotation layer with all annotation elements.
*
@ -2473,9 +2489,10 @@ class AnnotationLayer {
* @memberof AnnotationLayer
*/
static render(parameters) {
const { annotations, div, viewport } = parameters;
const { annotations, div, viewport, accessibilityManager } = parameters;
this.#setDimensions(div, viewport);
let zIndex = 0;
for (const data of annotations) {
if (data.annotationType !== AnnotationType.POPUP) {
@ -2508,15 +2525,33 @@ class AnnotationLayer {
}
if (Array.isArray(rendered)) {
for (const renderedElement of rendered) {
div.append(renderedElement);
renderedElement.style.zIndex = zIndex++;
AnnotationLayer.#appendElement(
renderedElement,
data.id,
div,
accessibilityManager
);
}
} else {
// The accessibility manager will move the annotation in the DOM in
// order to match the visual ordering.
// But if an annotation is above an other one, then we must draw it
// after the other one whatever the order is in the DOM, hence the
// use of the z-index.
rendered.style.zIndex = zIndex++;
if (element instanceof PopupAnnotationElement) {
// Popup annotation elements should not be on top of other
// annotation elements to prevent interfering with mouse events.
div.prepend(rendered);
} else {
div.append(rendered);
AnnotationLayer.#appendElement(
rendered,
data.id,
div,
accessibilityManager
);
}
}
}