Merge pull request #16387 from calixteman/issue16384

[Annotations] Draw readonly annotations on their own canvas and show the HTML elements when there is a JS interaction (issue #16384)
This commit is contained in:
calixteman 2023-05-04 21:49:08 +02:00 committed by GitHub
commit f151a39d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View File

@ -1695,7 +1695,8 @@ class WidgetAnnotation extends Annotation {
if ( if (
renderForms && renderForms &&
!(this instanceof SignatureWidgetAnnotation) && !(this instanceof SignatureWidgetAnnotation) &&
!this.data.noHTML !this.data.noHTML &&
!this.data.hasOwnCanvas
) { ) {
return { return {
opList: new OperatorList(), opList: new OperatorList(),
@ -2425,6 +2426,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
constructor(params) { constructor(params) {
super(params); super(params);
this.data.hasOwnCanvas = this.data.readOnly && !this.data.noHTML;
this._hasText = true; this._hasText = true;
const dict = params.dict; const dict = params.dict;

View File

@ -889,6 +889,15 @@ class WidgetAnnotationElement extends AnnotationElement {
return this.container; return this.container;
} }
showElementAndHideCanvas(element) {
if (this.data.hasOwnCanvas) {
if (element.previousSibling?.nodeName === "CANVAS") {
element.previousSibling.hidden = true;
}
element.hidden = false;
}
}
_getKeyModifier(event) { _getKeyModifier(event) {
const { isWin, isMac } = FeatureTest.platform; const { isWin, isMac } = FeatureTest.platform;
return (isWin && event.ctrlKey) || (isMac && event.metaKey); return (isWin && event.ctrlKey) || (isMac && event.metaKey);
@ -1069,6 +1078,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
element.style.overflowX = "hidden"; element.style.overflowX = "hidden";
} }
} }
if (this.data.hasOwnCanvas) {
element.hidden = true;
}
GetElementsByNameSet.add(element); GetElementsByNameSet.add(element);
element.setAttribute("data-element-id", id); element.setAttribute("data-element-id", id);
@ -1118,6 +1130,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
}); });
element.addEventListener("updatefromsandbox", jsEvent => { element.addEventListener("updatefromsandbox", jsEvent => {
this.showElementAndHideCanvas(jsEvent.target);
const actions = { const actions = {
value(event) { value(event) {
elementData.userValue = event.detail.value ?? ""; elementData.userValue = event.detail.value ?? "";

View File

@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/11396519/2.2.2.2.pdf

View File

@ -7554,5 +7554,14 @@
}, },
"annotations": true, "annotations": true,
"type": "eq" "type": "eq"
},
{
"id": "issue16384",
"file": "pdfs/issue16384.pdf",
"md5": "2a4695a9ce6243832a06e989f1dc6599",
"rounds": 1,
"link": true,
"forms": true,
"type": "eq"
} }
] ]