Merge pull request #18296 from calixteman/bug1903589

[Editor] Correctly set the accessibility data when copying & pasting a stamp with an alt text (bug 1903589)
This commit is contained in:
calixteman 2024-06-20 15:35:22 +02:00 committed by GitHub
commit d09aed87d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 74 additions and 0 deletions

View file

@ -40,6 +40,8 @@ import { noContextMenu } from "../display_utils.js";
* Base class for editors. * Base class for editors.
*/ */
class AnnotationEditor { class AnnotationEditor {
#accessibilityData = null;
#allResizerDivs = null; #allResizerDivs = null;
#altText = null; #altText = null;
@ -993,6 +995,10 @@ class AnnotationEditor {
} }
AltText.initialize(AnnotationEditor._l10nPromise); AltText.initialize(AnnotationEditor._l10nPromise);
this.#altText = new AltText(this); this.#altText = new AltText(this);
if (this.#accessibilityData) {
this.#altText.data = this.#accessibilityData;
this.#accessibilityData = null;
}
await this.addEditToolbar(); await this.addEditToolbar();
} }
@ -1330,6 +1336,7 @@ class AnnotationEditor {
uiManager, uiManager,
}); });
editor.rotation = data.rotation; editor.rotation = data.rotation;
editor.#accessibilityData = data.accessibilityData;
const [pageWidth, pageHeight] = editor.pageDimensions; const [pageWidth, pageHeight] = editor.pageDimensions;
const [x, y, width, height] = editor.getRectInCurrentCoords( const [x, y, width, height] = editor.getRectInCurrentCoords(

View file

@ -14,12 +14,14 @@
*/ */
import { import {
applyFunctionToEditor,
awaitPromise, awaitPromise,
closePages, closePages,
getEditorDimensions, getEditorDimensions,
getEditorSelector, getEditorSelector,
getFirstSerialized, getFirstSerialized,
getRect, getRect,
getSerialized,
kbBigMoveDown, kbBigMoveDown,
kbBigMoveRight, kbBigMoveRight,
kbCopy, kbCopy,
@ -798,4 +800,53 @@ describe("Stamp Editor", () => {
); );
}); });
}); });
describe("Copy and paste a stamp with an alt text", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that the pasted image has an alt text", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToStamp(page);
await copyImage(page, "../images/firefox_logo.png", 0);
await page.waitForSelector(getEditorSelector(0));
await waitForSerialized(page, 1);
await applyFunctionToEditor(
page,
"pdfjs_internal_editor_0",
editor => {
editor.altTextData = {
altText: "Hello World",
decorative: false,
};
}
);
await page.waitForSelector(`${getEditorSelector(0)} .altText.done`);
await kbCopy(page);
await kbPaste(page);
await page.waitForSelector(`${getEditorSelector(1)} .altText.done`);
await waitForSerialized(page, 2);
const serialized = await getSerialized(
page,
x => x.accessibilityData?.alt
);
expect(serialized)
.withContext(`In ${browserName}`)
.toEqual(["Hello World", "Hello World"]);
})
);
});
});
}); });

View file

@ -233,6 +233,21 @@ async function waitForSerialized(page, nEntries) {
); );
} }
async function applyFunctionToEditor(page, editorId, func) {
return page.evaluate(
(id, f) => {
const editor =
window.PDFViewerApplication.pdfDocument.annotationStorage.getRawValue(
id
);
// eslint-disable-next-line no-eval
eval(`(${f})`)(editor);
},
editorId,
func.toString()
);
}
async function waitForSelectedEditor(page, selector) { async function waitForSelectedEditor(page, selector) {
return page.waitForSelector(`${selector}.selectedEditor`); return page.waitForSelector(`${selector}.selectedEditor`);
} }
@ -615,6 +630,7 @@ async function switchToEditor(name, page, disable = false) {
} }
export { export {
applyFunctionToEditor,
awaitPromise, awaitPromise,
clearInput, clearInput,
closePages, closePages,