Skip to content

Commit 7e3941d

Browse files
committed
[JS] Hide field borders and buttons (#15053)
- Since the border belongs to the section containing the HTML counterpart of an annotation, this section must be hidden when a JS action requires it; - it wasn't possible to hide a button in using JS.
1 parent b868812 commit 7e3941d

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

src/display/annotation_layer.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class AnnotationElement {
309309
return shadow(this, "_commonActions", {
310310
display: event => {
311311
const hidden = event.detail.display % 2 === 1;
312-
event.target.style.visibility = hidden ? "hidden" : "visible";
312+
this.container.style.visibility = hidden ? "hidden" : "visible";
313313
this.annotationStorage.setValue(this.data.id, {
314314
hidden,
315315
print: event.detail.display === 0 || event.detail.display === 3,
@@ -321,7 +321,7 @@ class AnnotationElement {
321321
});
322322
},
323323
hidden: event => {
324-
event.target.style.visibility = event.detail.hidden
324+
this.container.style.visibility = event.detail.hidden
325325
? "hidden"
326326
: "visible";
327327
this.annotationStorage.setValue(this.data.id, {
@@ -570,6 +570,7 @@ class LinkAnnotationElement extends AnnotationElement {
570570
render() {
571571
const { data, linkService } = this;
572572
const link = document.createElement("a");
573+
link.setAttribute("id", data.id);
573574
let isBound = false;
574575

575576
if (data.url) {
@@ -1429,7 +1430,14 @@ class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
14291430
container.title = this.data.alternativeText;
14301431
}
14311432

1432-
this._setDefaultPropertiesFromJS(container);
1433+
if (this.enableScripting && this.hasJSActions) {
1434+
const linkElement = container.lastChild;
1435+
this._setDefaultPropertiesFromJS(linkElement);
1436+
1437+
linkElement.addEventListener("updatefromsandbox", jsEvent => {
1438+
this._dispatchEventFromSandbox({}, jsEvent);
1439+
});
1440+
}
14331441

14341442
return container;
14351443
}

test/integration/scripting_spec.js

+52
Original file line numberDiff line numberDiff line change
@@ -1336,4 +1336,56 @@ describe("Interaction", () => {
13361336
);
13371337
});
13381338
});
1339+
1340+
describe("in issue15053.pdf", () => {
1341+
let pages;
1342+
1343+
beforeAll(async () => {
1344+
pages = await loadAndWait("issue15053.pdf", "#\\34 4R");
1345+
});
1346+
1347+
afterAll(async () => {
1348+
await closePages(pages);
1349+
});
1350+
1351+
it("must check that a button and text field with a border are hidden", async () => {
1352+
await Promise.all(
1353+
pages.map(async ([browserName, page]) => {
1354+
await page.waitForFunction(
1355+
"window.PDFViewerApplication.scriptingReady === true"
1356+
);
1357+
1358+
let visibility = await page.$eval(
1359+
"[data-annotation-id='35R']",
1360+
el => getComputedStyle(el).visibility
1361+
);
1362+
expect(visibility)
1363+
.withContext(`In ${browserName}`)
1364+
.toEqual("visible");
1365+
1366+
visibility = await page.$eval(
1367+
"[data-annotation-id='51R']",
1368+
el => getComputedStyle(el).visibility
1369+
);
1370+
expect(visibility)
1371+
.withContext(`In ${browserName}`)
1372+
.toEqual("visible");
1373+
1374+
await page.click("#\\34 4R");
1375+
1376+
visibility = await page.$eval(
1377+
"[data-annotation-id='35R']",
1378+
el => getComputedStyle(el).visibility
1379+
);
1380+
expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
1381+
1382+
visibility = await page.$eval(
1383+
"[data-annotation-id='51R']",
1384+
el => getComputedStyle(el).visibility
1385+
);
1386+
expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
1387+
})
1388+
);
1389+
});
1390+
});
13391391
});

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,4 @@
527527
!issue14705.pdf
528528
!bug1771477.pdf
529529
!bug1724918.pdf
530+
!issue15053.pdf

test/pdfs/issue15053.pdf

106 KB
Binary file not shown.

0 commit comments

Comments
 (0)