Don't focus the viewer at startup (bug 1974863)

It's useless and it causes screen readers to not always read the document title.
This commit is contained in:
Calixte Denizet 2025-07-02 17:34:15 +02:00
parent f4043b03e2
commit aaae516894
3 changed files with 54 additions and 5 deletions

View File

@ -543,6 +543,14 @@ async function dragAndDrop(page, selector, translations, steps = 1) {
await page.waitForSelector("#viewer:not(.noUserSelect)"); await page.waitForSelector("#viewer:not(.noUserSelect)");
} }
function waitForPageChanging(page) {
return createPromise(page, resolve => {
window.PDFViewerApplication.eventBus.on("pagechanging", resolve, {
once: true,
});
});
}
function waitForAnnotationEditorLayer(page) { function waitForAnnotationEditorLayer(page) {
return createPromise(page, resolve => { return createPromise(page, resolve => {
window.PDFViewerApplication.eventBus.on( window.PDFViewerApplication.eventBus.on(
@ -944,6 +952,7 @@ export {
waitForEntryInStorage, waitForEntryInStorage,
waitForEvent, waitForEvent,
waitForNoElement, waitForNoElement,
waitForPageChanging,
waitForPageRendered, waitForPageRendered,
waitForPointerUp, waitForPointerUp,
waitForSandboxTrip, waitForSandboxTrip,

View File

@ -20,6 +20,7 @@ import {
getSpanRectFromText, getSpanRectFromText,
loadAndWait, loadAndWait,
scrollIntoView, scrollIntoView,
waitForPageChanging,
waitForPageRendered, waitForPageRendered,
} from "./test_utils.mjs"; } from "./test_utils.mjs";
import { PNG } from "pngjs"; import { PNG } from "pngjs";
@ -1273,4 +1274,48 @@ describe("PDF viewer", () => {
); );
}); });
}); });
describe("Keyboard scrolling on startup (bug 843653)", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".textLayer .endOfContent");
});
afterEach(async () => {
await closePages(pages);
});
it("must check that keyboard scrolling works without having to give the focus to the viewer", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const pdfViewer = await page.evaluateHandle(
() => window.PDFViewerApplication.pdfViewer
);
// The viewer should not have the focus.
const hasFocus = await pdfViewer.evaluate(viewer =>
viewer.container.contains(document.activeElement)
);
expect(hasFocus).withContext(`In ${browserName}`).toBeFalse();
let currentPageNumber = await pdfViewer.evaluate(
viewer => viewer.currentPageNumber
);
expect(currentPageNumber).withContext(`In ${browserName}`).toBe(1);
// Press the 'PageDown' key to check that it works.
const handle = await waitForPageChanging(page);
await page.keyboard.press("PageDown");
await awaitPromise(handle);
// The second page should be displayed.
currentPageNumber = await pdfViewer.evaluate(
viewer => viewer.currentPageNumber
);
expect(currentPageNumber).withContext(`In ${browserName}`).toBe(2);
})
);
});
});
}); });

View File

@ -1455,11 +1455,6 @@ const PDFViewerApplication = {
spreadMode, spreadMode,
}); });
this.eventBus.dispatch("documentinit", { source: this }); this.eventBus.dispatch("documentinit", { source: this });
// Make all navigation keys work on document load,
// unless the viewer is embedded in a web page.
if (!this.isViewerEmbedded) {
pdfViewer.focus();
}
// For documents with different page sizes, once all pages are // For documents with different page sizes, once all pages are
// resolved, ensure that the correct location becomes visible on load. // resolved, ensure that the correct location becomes visible on load.