[Annotations] Show buttons even if they've no actions

- it's a regression from PR #14247:
 - before the PR, the button was rendered on the canvas whatever its status was;
 - after the PR, the button image has been moved in an other canvas so when the button is not renderable
   (because it has no actions) then the image is not added the HTML element.
- the buttons in the pdf in bug 1737260 or in the pdf in #14308 were not visible
- make the button always renderable but don't add the link element if it's useless.
This commit is contained in:
Calixte Denizet 2022-02-19 16:47:49 +01:00
parent 9bdf27e8e0
commit 66b513fc00
3 changed files with 26 additions and 17 deletions

View File

@ -563,36 +563,29 @@ class AnnotationElement {
class LinkAnnotationElement extends AnnotationElement {
constructor(parameters, options = null) {
const isRenderable = !!(
parameters.data.url ||
parameters.data.dest ||
parameters.data.action ||
parameters.data.isTooltipOnly ||
parameters.data.resetForm ||
(parameters.data.actions &&
(parameters.data.actions.Action ||
parameters.data.actions["Mouse Up"] ||
parameters.data.actions["Mouse Down"]))
);
super(parameters, {
isRenderable,
isRenderable: true,
ignoreBorder: !!options?.ignoreBorder,
createQuadrilaterals: true,
});
this.isTooltipOnly = parameters.data.isTooltipOnly;
}
render() {
const { data, linkService } = this;
const link = document.createElement("a");
let isBound = false;
if (data.url) {
linkService.addLinkAttributes(link, data.url, data.newWindow);
isBound = true;
} else if (data.action) {
this._bindNamedAction(link, data.action);
isBound = true;
} else if (data.dest) {
this._bindLink(link, data.dest);
isBound = true;
} else {
let hasClickAction = false;
if (
data.actions &&
(data.actions.Action ||
@ -601,14 +594,16 @@ class LinkAnnotationElement extends AnnotationElement {
this.enableScripting &&
this.hasJSActions
) {
hasClickAction = true;
this._bindJSAction(link, data);
isBound = true;
}
if (data.resetForm) {
this._bindResetFormAction(link, data.resetForm);
} else if (!hasClickAction) {
isBound = true;
} else if (this.isTooltipOnly && !isBound) {
this._bindLink(link, "");
isBound = true;
}
}
@ -623,7 +618,10 @@ class LinkAnnotationElement extends AnnotationElement {
}
this.container.className = "linkAnnotation";
this.container.appendChild(link);
if (isBound) {
this.container.appendChild(link);
}
return this.container;
}
@ -2528,7 +2526,9 @@ class AnnotationLayer {
}
const { firstChild } = element;
if (firstChild.nodeName === "CANVAS") {
if (!firstChild) {
element.appendChild(canvas);
} else if (firstChild.nodeName === "CANVAS") {
element.replaceChild(canvas, firstChild);
} else {
element.insertBefore(canvas, firstChild);

View File

@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9247258

View File

@ -6528,5 +6528,13 @@
"value": "1"
}
}
},
{ "id": "bug1737260",
"file": "pdfs/bug1737260.pdf",
"md5": "8bd4f810d30972764b07ae141a4afbc4",
"rounds": 1,
"link": true,
"type": "eq",
"annotations": true
}
]