Skip to content

Commit

Permalink
Merge pull request #16387 from calixteman/issue16384
Browse files Browse the repository at this point in the history
[Annotations] Draw readonly annotations on their own canvas and show the HTML elements when there is a JS interaction (issue #16384)
  • Loading branch information
calixteman authored May 4, 2023
2 parents a24e11a + 72da14f commit f151a39
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,8 @@ class WidgetAnnotation extends Annotation {
if (
renderForms &&
!(this instanceof SignatureWidgetAnnotation) &&
!this.data.noHTML
!this.data.noHTML &&
!this.data.hasOwnCanvas
) {
return {
opList: new OperatorList(),
Expand Down Expand Up @@ -2425,6 +2426,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
constructor(params) {
super(params);

this.data.hasOwnCanvas = this.data.readOnly && !this.data.noHTML;
this._hasText = true;

const dict = params.dict;
Expand Down
13 changes: 13 additions & 0 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,15 @@ class WidgetAnnotationElement extends AnnotationElement {
return this.container;
}

showElementAndHideCanvas(element) {
if (this.data.hasOwnCanvas) {
if (element.previousSibling?.nodeName === "CANVAS") {
element.previousSibling.hidden = true;
}
element.hidden = false;
}
}

_getKeyModifier(event) {
const { isWin, isMac } = FeatureTest.platform;
return (isWin && event.ctrlKey) || (isMac && event.metaKey);
Expand Down Expand Up @@ -1069,6 +1078,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
element.style.overflowX = "hidden";
}
}
if (this.data.hasOwnCanvas) {
element.hidden = true;
}
GetElementsByNameSet.add(element);
element.setAttribute("data-element-id", id);

Expand Down Expand Up @@ -1118,6 +1130,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
});

element.addEventListener("updatefromsandbox", jsEvent => {
this.showElementAndHideCanvas(jsEvent.target);
const actions = {
value(event) {
elementData.userValue = event.detail.value ?? "";
Expand Down
2 changes: 2 additions & 0 deletions test/pdfs/issue16384.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/11396519/2.2.2.2.pdf

9 changes: 9 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7554,5 +7554,14 @@
},
"annotations": true,
"type": "eq"
},
{
"id": "issue16384",
"file": "pdfs/issue16384.pdf",
"md5": "2a4695a9ce6243832a06e989f1dc6599",
"rounds": 1,
"link": true,
"forms": true,
"type": "eq"
}
]

0 comments on commit f151a39

Please sign in to comment.