[Editor] Use the alt text to descibe the canvas used to display the image
This commit is contained in:
parent
59d94b549f
commit
e3fbe2908a
@ -927,6 +927,9 @@ class AnnotationEditor {
|
|||||||
if (!tooltip.parentNode) {
|
if (!tooltip.parentNode) {
|
||||||
button.append(tooltip);
|
button.append(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const element = this.getImageForAltText();
|
||||||
|
element?.setAttribute("aria-describedby", tooltip.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#toggleAltTextButton(enabled = false) {
|
#toggleAltTextButton(enabled = false) {
|
||||||
@ -960,6 +963,9 @@ class AnnotationEditor {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the alt text data.
|
||||||
|
*/
|
||||||
set altTextData({ altText, decorative }) {
|
set altTextData({ altText, decorative }) {
|
||||||
if (this.#altText === altText && this.#altTextDecorative === decorative) {
|
if (this.#altText === altText && this.#altTextDecorative === decorative) {
|
||||||
return;
|
return;
|
||||||
@ -1369,6 +1375,13 @@ class AnnotationEditor {
|
|||||||
*/
|
*/
|
||||||
enterInEditMode() {}
|
enterInEditMode() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {HTMLElement | null} the element requiring an alt text.
|
||||||
|
*/
|
||||||
|
getImageForAltText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the div which really contains the displayed content.
|
* Get the div which really contains the displayed content.
|
||||||
* @returns {HTMLDivElement | undefined}
|
* @returns {HTMLDivElement | undefined}
|
||||||
|
@ -32,6 +32,8 @@ class StampEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
#bitmapFile = null;
|
#bitmapFile = null;
|
||||||
|
|
||||||
|
#bitmapFileName = "";
|
||||||
|
|
||||||
#canvas = null;
|
#canvas = null;
|
||||||
|
|
||||||
#observer = null;
|
#observer = null;
|
||||||
@ -104,6 +106,9 @@ class StampEditor extends AnnotationEditor {
|
|||||||
this.#bitmapId = data.id;
|
this.#bitmapId = data.id;
|
||||||
this.#isSvg = data.isSvg;
|
this.#isSvg = data.isSvg;
|
||||||
}
|
}
|
||||||
|
if (data.file) {
|
||||||
|
this.#bitmapFileName = data.file.name;
|
||||||
|
}
|
||||||
this.#createCanvas();
|
this.#createCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +337,9 @@ class StampEditor extends AnnotationEditor {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.addAltTextButton();
|
this.addAltTextButton();
|
||||||
|
if (this.#bitmapFileName) {
|
||||||
|
canvas.setAttribute("aria-label", this.#bitmapFileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -438,6 +446,11 @@ class StampEditor extends AnnotationEditor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
|
getImageForAltText() {
|
||||||
|
return this.#canvas;
|
||||||
|
}
|
||||||
|
|
||||||
#serializeBitmap(toUrl) {
|
#serializeBitmap(toUrl) {
|
||||||
if (toUrl) {
|
if (toUrl) {
|
||||||
if (this.#isSvg) {
|
if (this.#isSvg) {
|
||||||
|
@ -249,9 +249,34 @@ describe("Stamp Editor", () => {
|
|||||||
]);
|
]);
|
||||||
}, data);
|
}, data);
|
||||||
|
|
||||||
await page.keyboard.down("Control");
|
let hasPasteEvent = false;
|
||||||
await page.keyboard.press("v");
|
while (!hasPasteEvent) {
|
||||||
await page.keyboard.up("Control");
|
// We retry to paste if nothing has been pasted before 500ms.
|
||||||
|
const promise = Promise.race([
|
||||||
|
page.evaluate(
|
||||||
|
() =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
document.addEventListener(
|
||||||
|
"paste",
|
||||||
|
e => resolve(e.clipboardData.items.length !== 0),
|
||||||
|
{
|
||||||
|
once: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
),
|
||||||
|
page.evaluate(
|
||||||
|
() =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
setTimeout(() => resolve(false), 500);
|
||||||
|
})
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
await page.keyboard.down("Control");
|
||||||
|
await page.keyboard.press("v");
|
||||||
|
await page.keyboard.up("Control");
|
||||||
|
hasPasteEvent = await promise;
|
||||||
|
}
|
||||||
|
|
||||||
await waitForImage(page, getEditorSelector(0));
|
await waitForImage(page, getEditorSelector(0));
|
||||||
|
|
||||||
@ -277,6 +302,11 @@ describe("Stamp Editor", () => {
|
|||||||
const saveButtonSelector = "#altTextDialog #altTextSave";
|
const saveButtonSelector = "#altTextDialog #altTextSave";
|
||||||
await page.click(saveButtonSelector);
|
await page.click(saveButtonSelector);
|
||||||
|
|
||||||
|
// Check that the canvas has an aria-describedby attribute.
|
||||||
|
await page.waitForSelector(
|
||||||
|
`${getEditorSelector(0)} canvas[aria-describedby]`
|
||||||
|
);
|
||||||
|
|
||||||
// Wait for the alt-text button to have the correct icon.
|
// Wait for the alt-text button to have the correct icon.
|
||||||
await page.waitForSelector(`${buttonSelector}:not([hidden]).done`);
|
await page.waitForSelector(`${buttonSelector}:not([hidden]).done`);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user