From 66b513fc007f1bdee9fe3d50dfc639be0c6c6801 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Sat, 19 Feb 2022 16:47:49 +0100 Subject: [PATCH] [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. --- src/display/annotation_layer.js | 34 ++++++++++++++++----------------- test/pdfs/bug1737260.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 test/pdfs/bug1737260.pdf.link diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 66fd47d16..32ec62641 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -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); diff --git a/test/pdfs/bug1737260.pdf.link b/test/pdfs/bug1737260.pdf.link new file mode 100644 index 000000000..7ade01a75 --- /dev/null +++ b/test/pdfs/bug1737260.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=9247258 diff --git a/test/test_manifest.json b/test/test_manifest.json index f88ba2255..1f28dafac 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6528,5 +6528,13 @@ "value": "1" } } + }, + { "id": "bug1737260", + "file": "pdfs/bug1737260.pdf", + "md5": "8bd4f810d30972764b07ae141a4afbc4", + "rounds": 1, + "link": true, + "type": "eq", + "annotations": true } ]