1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[Editor] Make the stamp annotations alt text readable by either VO or NVDA (bug 1912001)

This commit is contained in:
Calixte Denizet 2024-09-03 16:49:22 +02:00
parent 0676ea19cf
commit deedbd1c4f
5 changed files with 110 additions and 37 deletions

View file

@ -22,6 +22,8 @@
/** @typedef {import("../../web/interfaces").IPDFLinkService} IPDFLinkService */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/editor/tools.js").AnnotationEditorUIManager} AnnotationEditorUIManager */
// eslint-disable-next-line max-len
/** @typedef {import("../../web/struct_tree_layer_builder.js").StructTreeLayerBuilder} StructTreeLayerBuilder */
import {
AnnotationBorderStyleType,
@ -2952,6 +2954,7 @@ class StampAnnotationElement extends AnnotationElement {
render() {
this.container.classList.add("stampAnnotation");
this.container.setAttribute("role", "img");
if (!this.data.popupRef && this.hasPopupData) {
this._createPopup();
@ -3059,6 +3062,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
* @property {TextAccessibilityManager} [accessibilityManager]
* @property {AnnotationEditorUIManager} [annotationEditorUIManager]
* @property {StructTreeLayerBuilder} [structTreeLayer]
*/
/**
@ -3071,6 +3075,8 @@ class AnnotationLayer {
#editableAnnotations = new Map();
#structTreeLayer = null;
constructor({
div,
accessibilityManager,
@ -3078,10 +3084,12 @@ class AnnotationLayer {
annotationEditorUIManager,
page,
viewport,
structTreeLayer,
}) {
this.div = div;
this.#accessibilityManager = accessibilityManager;
this.#annotationCanvasMap = annotationCanvasMap;
this.#structTreeLayer = structTreeLayer || null;
this.page = page;
this.viewport = viewport;
this.zIndex = 0;
@ -3104,9 +3112,16 @@ class AnnotationLayer {
return this.#editableAnnotations.size > 0;
}
#appendElement(element, id) {
async #appendElement(element, id) {
const contentElement = element.firstChild || element;
contentElement.id = `${AnnotationPrefix}${id}`;
const annotationId = (contentElement.id = `${AnnotationPrefix}${id}`);
const ariaAttributes =
await this.#structTreeLayer?.getAriaAttributes(annotationId);
if (ariaAttributes) {
for (const [key, value] of ariaAttributes) {
contentElement.setAttribute(key, value);
}
}
this.div.append(element);
this.#accessibilityManager?.moveElementInDOM(
@ -3183,7 +3198,7 @@ class AnnotationLayer {
if (data.hidden) {
rendered.style.visibility = "hidden";
}
this.#appendElement(rendered, data.id);
await this.#appendElement(rendered, data.id);
if (element._isEditable) {
this.#editableAnnotations.set(element.data.id, element);