diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index a6f3eb23a2b68..7c47b9147be0e 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -309,7 +309,7 @@ class AnnotationElement { return shadow(this, "_commonActions", { display: event => { const hidden = event.detail.display % 2 === 1; - event.target.style.visibility = hidden ? "hidden" : "visible"; + this.container.style.visibility = hidden ? "hidden" : "visible"; this.annotationStorage.setValue(this.data.id, { hidden, print: event.detail.display === 0 || event.detail.display === 3, @@ -321,7 +321,7 @@ class AnnotationElement { }); }, hidden: event => { - event.target.style.visibility = event.detail.hidden + this.container.style.visibility = event.detail.hidden ? "hidden" : "visible"; this.annotationStorage.setValue(this.data.id, { @@ -570,6 +570,7 @@ class LinkAnnotationElement extends AnnotationElement { render() { const { data, linkService } = this; const link = document.createElement("a"); + link.setAttribute("id", data.id); let isBound = false; if (data.url) { @@ -1429,7 +1430,14 @@ class PushButtonWidgetAnnotationElement extends LinkAnnotationElement { container.title = this.data.alternativeText; } - this._setDefaultPropertiesFromJS(container); + if (this.enableScripting && this.hasJSActions) { + const linkElement = container.lastChild; + this._setDefaultPropertiesFromJS(linkElement); + + linkElement.addEventListener("updatefromsandbox", jsEvent => { + this._dispatchEventFromSandbox({}, jsEvent); + }); + } return container; } diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index e50f371ddb07b..2e74500500151 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -1336,4 +1336,56 @@ describe("Interaction", () => { ); }); }); + + describe("in issue15053.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue15053.pdf", "#\\34 4R"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that a button and text field with a border are hidden", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); + + let visibility = await page.$eval( + "[data-annotation-id='35R']", + el => getComputedStyle(el).visibility + ); + expect(visibility) + .withContext(`In ${browserName}`) + .toEqual("visible"); + + visibility = await page.$eval( + "[data-annotation-id='51R']", + el => getComputedStyle(el).visibility + ); + expect(visibility) + .withContext(`In ${browserName}`) + .toEqual("visible"); + + await page.click("#\\34 4R"); + + visibility = await page.$eval( + "[data-annotation-id='35R']", + el => getComputedStyle(el).visibility + ); + expect(visibility).withContext(`In ${browserName}`).toEqual("hidden"); + + visibility = await page.$eval( + "[data-annotation-id='51R']", + el => getComputedStyle(el).visibility + ); + expect(visibility).withContext(`In ${browserName}`).toEqual("hidden"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index aa31a6d0125b6..854e1b3590370 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -527,3 +527,4 @@ !issue14705.pdf !bug1771477.pdf !bug1724918.pdf +!issue15053.pdf diff --git a/test/pdfs/issue15053.pdf b/test/pdfs/issue15053.pdf new file mode 100755 index 0000000000000..a0a6f75c38aee Binary files /dev/null and b/test/pdfs/issue15053.pdf differ