1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #19640 from Snuffleupagus/secondaryToolbar-fix-close

Don't close the `secondaryToolbar` when clicking inside it (PR 18385 follow-up)
This commit is contained in:
Jonas Jenwald 2025-03-11 19:42:36 +01:00 committed by GitHub
commit d74619847d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 70 additions and 5 deletions

View file

@ -1096,4 +1096,68 @@ describe("PDF viewer", () => {
});
});
});
describe("SecondaryToolbar", () => {
let pages;
function normalizeRotation(rotation) {
return ((rotation % 360) + 360) % 360;
}
function waitForRotationChanging(page, pagesRotation) {
return page.evaluateHandle(
rotation => [
new Promise(resolve => {
const { eventBus } = window.PDFViewerApplication;
eventBus.on("rotationchanging", function handler(e) {
if (rotation === undefined || e.pagesRotation === rotation) {
resolve();
eventBus.off("rotationchanging", handler);
}
});
}),
],
normalizeRotation(pagesRotation)
);
}
beforeAll(async () => {
pages = await loadAndWait("issue18694.pdf", ".textLayer .endOfContent");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that the SecondaryToolbar doesn't close between rotations", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.click("#secondaryToolbarToggleButton");
await page.waitForSelector("#secondaryToolbar", { hidden: false });
for (let i = 1; i <= 4; i++) {
const secondaryToolbarIsOpen = await page.evaluate(
() => window.PDFViewerApplication.secondaryToolbar.isOpen
);
expect(secondaryToolbarIsOpen)
.withContext(`In ${browserName}`)
.toBeTrue();
const rotation = i * 90;
const handle = await waitForRotationChanging(page, rotation);
await page.click("#pageRotateCw");
await awaitPromise(handle);
const pagesRotation = await page.evaluate(
() => window.PDFViewerApplication.pdfViewer.pagesRotation
);
expect(pagesRotation)
.withContext(`In ${browserName}`)
.toBe(normalizeRotation(rotation));
}
})
);
});
});
});

View file

@ -2683,18 +2683,19 @@ function onWheel(evt) {
}
}
function closeSecondaryToolbar(evt) {
function closeSecondaryToolbar({ target }) {
if (!this.secondaryToolbar?.isOpen) {
return;
}
const appConfig = this.appConfig;
const { toolbar, secondaryToolbar } = this.appConfig;
if (
this.pdfViewer.containsElement(evt.target) ||
(appConfig.toolbar?.container.contains(evt.target) &&
this.pdfViewer.containsElement(target) ||
(toolbar?.container.contains(target) &&
!secondaryToolbar?.toolbar.contains(target) &&
// TODO: change the `contains` for an equality check when the bug:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1921984
// is fixed.
!appConfig.secondaryToolbar?.toggleButton.contains(evt.target))
!secondaryToolbar?.toggleButton.contains(target))
) {
this.secondaryToolbar.close();
}