[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.
This commit is contained in:
Calixte Denizet 2022-06-17 15:20:40 +02:00
parent b8688128e3
commit 7e3941da9d
4 changed files with 64 additions and 3 deletions

View File

@ -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;
}

View File

@ -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");
})
);
});
});
});

View File

@ -527,3 +527,4 @@
!issue14705.pdf
!bug1771477.pdf
!bug1724918.pdf
!issue15053.pdf

BIN
test/pdfs/issue15053.pdf Executable file

Binary file not shown.