Skip to content

Commit aaae516

Browse files
committed
Don't focus the viewer at startup (bug 1974863)
It's useless and it causes screen readers to not always read the document title.
1 parent f4043b0 commit aaae516

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

test/integration/test_utils.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ async function dragAndDrop(page, selector, translations, steps = 1) {
543543
await page.waitForSelector("#viewer:not(.noUserSelect)");
544544
}
545545

546+
function waitForPageChanging(page) {
547+
return createPromise(page, resolve => {
548+
window.PDFViewerApplication.eventBus.on("pagechanging", resolve, {
549+
once: true,
550+
});
551+
});
552+
}
553+
546554
function waitForAnnotationEditorLayer(page) {
547555
return createPromise(page, resolve => {
548556
window.PDFViewerApplication.eventBus.on(
@@ -944,6 +952,7 @@ export {
944952
waitForEntryInStorage,
945953
waitForEvent,
946954
waitForNoElement,
955+
waitForPageChanging,
947956
waitForPageRendered,
948957
waitForPointerUp,
949958
waitForSandboxTrip,

test/integration/viewer_spec.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
getSpanRectFromText,
2121
loadAndWait,
2222
scrollIntoView,
23+
waitForPageChanging,
2324
waitForPageRendered,
2425
} from "./test_utils.mjs";
2526
import { PNG } from "pngjs";
@@ -1273,4 +1274,48 @@ describe("PDF viewer", () => {
12731274
);
12741275
});
12751276
});
1277+
1278+
describe("Keyboard scrolling on startup (bug 843653)", () => {
1279+
let pages;
1280+
1281+
beforeEach(async () => {
1282+
pages = await loadAndWait("tracemonkey.pdf", ".textLayer .endOfContent");
1283+
});
1284+
1285+
afterEach(async () => {
1286+
await closePages(pages);
1287+
});
1288+
1289+
it("must check that keyboard scrolling works without having to give the focus to the viewer", async () => {
1290+
await Promise.all(
1291+
pages.map(async ([browserName, page]) => {
1292+
const pdfViewer = await page.evaluateHandle(
1293+
() => window.PDFViewerApplication.pdfViewer
1294+
);
1295+
1296+
// The viewer should not have the focus.
1297+
const hasFocus = await pdfViewer.evaluate(viewer =>
1298+
viewer.container.contains(document.activeElement)
1299+
);
1300+
expect(hasFocus).withContext(`In ${browserName}`).toBeFalse();
1301+
1302+
let currentPageNumber = await pdfViewer.evaluate(
1303+
viewer => viewer.currentPageNumber
1304+
);
1305+
expect(currentPageNumber).withContext(`In ${browserName}`).toBe(1);
1306+
1307+
// Press the 'PageDown' key to check that it works.
1308+
const handle = await waitForPageChanging(page);
1309+
await page.keyboard.press("PageDown");
1310+
await awaitPromise(handle);
1311+
1312+
// The second page should be displayed.
1313+
currentPageNumber = await pdfViewer.evaluate(
1314+
viewer => viewer.currentPageNumber
1315+
);
1316+
expect(currentPageNumber).withContext(`In ${browserName}`).toBe(2);
1317+
})
1318+
);
1319+
});
1320+
});
12761321
});

web/app.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,11 +1455,6 @@ const PDFViewerApplication = {
14551455
spreadMode,
14561456
});
14571457
this.eventBus.dispatch("documentinit", { source: this });
1458-
// Make all navigation keys work on document load,
1459-
// unless the viewer is embedded in a web page.
1460-
if (!this.isViewerEmbedded) {
1461-
pdfViewer.focus();
1462-
}
14631458

14641459
// For documents with different page sizes, once all pages are
14651460
// resolved, ensure that the correct location becomes visible on load.

0 commit comments

Comments
 (0)