diff --git a/src/core/annotation.js b/src/core/annotation.js index 36ffd9f7b..5cff3439e 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -4964,4 +4964,5 @@ export { getQuadPoints, MarkupAnnotation, PopupAnnotation, + WidgetAnnotation, }; diff --git a/src/core/document.js b/src/core/document.js index f783ef31d..ed9b0a897 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -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, @@ -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); } diff --git a/test/integration/annotation_spec.mjs b/test/integration/annotation_spec.mjs index 4b5ad229c..c03f952c2 100644 --- a/test/integration/annotation_spec.mjs +++ b/test/integration/annotation_spec.mjs @@ -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", () => { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 02bae0c28..be38029c5 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -633,3 +633,4 @@ !issue17671.pdf !bug1868759.pdf !issue17730.pdf +!bug1883609.pdf diff --git a/test/pdfs/bug1883609.pdf b/test/pdfs/bug1883609.pdf new file mode 100755 index 000000000..104a72040 Binary files /dev/null and b/test/pdfs/bug1883609.pdf differ