Skip to content

Commit 6ff1fe4

Browse files
Merge pull request #12333 from calixteman/tooltip
Add tooltip if any in annotations layer
2 parents 76e96d4 + 20b12d2 commit 6ff1fe4

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

src/core/annotation.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
15331533
this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
15341534
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
15351535
this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
1536+
this.data.isTooltipOnly = false;
15361537

15371538
if (this.data.checkBox) {
15381539
this._processCheckBox(params);
@@ -1780,11 +1781,13 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
17801781
}
17811782

17821783
_processPushButton(params) {
1783-
if (!params.dict.has("A")) {
1784+
if (!params.dict.has("A") && !this.data.alternativeText) {
17841785
warn("Push buttons without action dictionaries are not supported");
17851786
return;
17861787
}
17871788

1789+
this.data.isTooltipOnly = !params.dict.has("A");
1790+
17881791
Catalog.parseDestDictionary({
17891792
destDict: params.dict,
17901793
resultObj: this.data,

src/display/annotation_layer.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ class LinkAnnotationElement extends AnnotationElement {
293293
const isRenderable = !!(
294294
parameters.data.url ||
295295
parameters.data.dest ||
296-
parameters.data.action
296+
parameters.data.action ||
297+
parameters.data.isTooltipOnly
297298
);
298299
super(parameters, isRenderable);
299300
}
@@ -322,8 +323,10 @@ class LinkAnnotationElement extends AnnotationElement {
322323
});
323324
} else if (data.action) {
324325
this._bindNamedAction(link, data.action);
325-
} else {
326+
} else if (data.dest) {
326327
this._bindLink(link, data.dest);
328+
} else {
329+
this._bindLink(link, "");
327330
}
328331

329332
this.container.appendChild(link);
@@ -420,6 +423,10 @@ class WidgetAnnotationElement extends AnnotationElement {
420423
*/
421424
render() {
422425
// Show only the container for unsupported field types.
426+
if (this.data.alternativeText) {
427+
this.container.title = this.data.alternativeText;
428+
}
429+
423430
return this.container;
424431
}
425432
}
@@ -647,6 +654,11 @@ class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
647654
// as performing actions on form fields (resetting, submitting, et cetera).
648655
const container = super.render();
649656
container.className = "buttonWidgetAnnotation pushButton";
657+
658+
if (this.data.alternativeText) {
659+
container.title = this.data.alternativeText;
660+
}
661+
650662
return container;
651663
}
652664
}

test/unit/annotation_spec.js

+43
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,49 @@ describe("annotation", function () {
25202520
})
25212521
.catch(done.fail);
25222522
});
2523+
2524+
it("should handle push buttons", function (done) {
2525+
const buttonWidgetRef = Ref.get(124, 0);
2526+
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
2527+
buttonWidgetDict.set("A", "whatever");
2528+
2529+
const xref = new XRefMock([
2530+
{ ref: buttonWidgetRef, data: buttonWidgetDict },
2531+
]);
2532+
2533+
AnnotationFactory.create(
2534+
xref,
2535+
buttonWidgetRef,
2536+
pdfManagerMock,
2537+
idFactoryMock
2538+
).then(({ data }) => {
2539+
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
2540+
expect(data.pushButton).toEqual(true);
2541+
done();
2542+
}, done.fail);
2543+
});
2544+
2545+
it("should handle push buttons that act as a tooltip only", function (done) {
2546+
const buttonWidgetRef = Ref.get(124, 0);
2547+
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
2548+
buttonWidgetDict.set("TU", "An alternative text");
2549+
2550+
const xref = new XRefMock([
2551+
{ ref: buttonWidgetRef, data: buttonWidgetDict },
2552+
]);
2553+
2554+
AnnotationFactory.create(
2555+
xref,
2556+
buttonWidgetRef,
2557+
pdfManagerMock,
2558+
idFactoryMock
2559+
).then(({ data }) => {
2560+
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
2561+
expect(data.pushButton).toEqual(true);
2562+
expect(data.alternativeText).toEqual("An alternative text");
2563+
done();
2564+
}, done.fail);
2565+
});
25232566
});
25242567

25252568
describe("ChoiceWidgetAnnotation", function () {

0 commit comments

Comments
 (0)