Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Annotations] Widget annotations must be in front of the other ones (bug 1883609) #17776

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4964,4 +4964,5 @@ export {
getQuadPoints,
MarkupAnnotation,
PopupAnnotation,
WidgetAnnotation,
};
15 changes: 13 additions & 2 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import {
Util,
warn,
} from "../shared/util.js";
import { AnnotationFactory, PopupAnnotation } from "./annotation.js";
import {
AnnotationFactory,
PopupAnnotation,
WidgetAnnotation,
} from "./annotation.js";
import {
collectActions,
getInheritableProperty,
Expand Down Expand Up @@ -766,19 +770,26 @@ class Page {
}

const sortedAnnotations = [];
let popupAnnotations;
let popupAnnotations, widgetAnnotations;
// Ensure that PopupAnnotations are handled last, since they depend on
// their parent Annotation in the display layer; fixes issue 11362.
for (const annotation of await Promise.all(annotationPromises)) {
if (!annotation) {
continue;
}
if (annotation instanceof WidgetAnnotation) {
(widgetAnnotations ||= []).push(annotation);
continue;
}
if (annotation instanceof PopupAnnotation) {
(popupAnnotations ||= []).push(annotation);
continue;
}
sortedAnnotations.push(annotation);
}
if (widgetAnnotations) {
sortedAnnotations.push(...widgetAnnotations);
}
if (popupAnnotations) {
sortedAnnotations.push(...popupAnnotations);
}
Expand Down
29 changes: 29 additions & 0 deletions test/integration/annotation_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ describe("Annotation highlight", () => {
);
});
});

describe("Check that widget annotations are in front of highlight ones", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("bug1883609.pdf", "[data-annotation-id='23R']");
});

afterAll(async () => {
await closePages(pages);
});

it("must click on widget annotations", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
for (const i of [23, 22, 14]) {
await page.click(`[data-annotation-id='${i}R']`);
await page.waitForFunction(
id =>
document.activeElement ===
document.querySelector(`#pdfjs_internal_id_${id}R`),
{},
i
);
}
})
);
});
});
});

describe("Checkbox annotation", () => {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,4 @@
!issue17671.pdf
!bug1868759.pdf
!issue17730.pdf
!bug1883609.pdf
Binary file added test/pdfs/bug1883609.pdf
Binary file not shown.