Skip to content

Commit 47e3fdd

Browse files
committed
Fix popup for highlights without popup (follow-up of mozilla#12505)
* remove 1st param of _createPopup (almost useless for a method) * prepend popup div to avoid to have them on top of some highlights (and so "disable" partially mouse events) * add a ref test for issue mozilla#12504
1 parent 8b652d6 commit 47e3fdd

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

src/display/annotation_layer.js

+32-19
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ class AnnotationElement {
262262
quadPoint[1].y,
263263
];
264264
this.data.rect = rect;
265-
quadrilaterals.push(this._createContainer(ignoreBorder));
265+
const quad = this._createContainer(ignoreBorder);
266+
quad.className = "highlightAnnotation";
267+
quadrilaterals.push(quad);
266268
}
267269
this.data.rect = savedRect;
268270
return quadrilaterals;
@@ -274,12 +276,17 @@ class AnnotationElement {
274276
* are of a type that works with popups (such as Highlight annotations).
275277
*
276278
* @private
277-
* @param {HTMLSectionElement} container
278279
* @param {HTMLDivElement|HTMLImageElement|null} trigger
279280
* @param {Object} data
280281
* @memberof AnnotationElement
281282
*/
282-
_createPopup(container, trigger, data) {
283+
_createPopup(trigger, data) {
284+
let container = this.container;
285+
if (this.quadrilaterals) {
286+
trigger = trigger || this.quadrilaterals;
287+
container = this.quadrilaterals[0];
288+
}
289+
283290
// If no trigger element is specified, create it.
284291
if (!trigger) {
285292
trigger = document.createElement("div");
@@ -433,7 +440,7 @@ class TextAnnotationElement extends AnnotationElement {
433440
image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
434441

435442
if (!this.data.hasPopup) {
436-
this._createPopup(this.container, image, this.data);
443+
this._createPopup(image, this.data);
437444
}
438445

439446
this.container.appendChild(image);
@@ -790,6 +797,7 @@ class PopupAnnotationElement extends AnnotationElement {
790797
constructor(parameters) {
791798
const isRenderable = !!(parameters.data.title || parameters.data.contents);
792799
super(parameters, isRenderable);
800+
this.popup = true;
793801
}
794802

795803
/**
@@ -885,7 +893,6 @@ class PopupElement {
885893
// disappear too. In that special case, hiding the wrapper suffices.
886894
this.hideElement = this.hideWrapper ? wrapper : this.container;
887895
this.hideElement.setAttribute("hidden", true);
888-
889896
const popup = document.createElement("div");
890897
popup.className = "popup";
891898

@@ -1027,7 +1034,7 @@ class FreeTextAnnotationElement extends AnnotationElement {
10271034
this.container.className = "freeTextAnnotation";
10281035

10291036
if (!this.data.hasPopup) {
1030-
this._createPopup(this.container, null, this.data);
1037+
this._createPopup(null, this.data);
10311038
}
10321039
return this.container;
10331040
}
@@ -1078,7 +1085,7 @@ class LineAnnotationElement extends AnnotationElement {
10781085

10791086
// Create the popup ourselves so that we can bind it to the line instead
10801087
// of to the entire container (which is the default).
1081-
this._createPopup(this.container, line, data);
1088+
this._createPopup(line, data);
10821089

10831090
return this.container;
10841091
}
@@ -1132,7 +1139,7 @@ class SquareAnnotationElement extends AnnotationElement {
11321139

11331140
// Create the popup ourselves so that we can bind it to the square instead
11341141
// of to the entire container (which is the default).
1135-
this._createPopup(this.container, square, data);
1142+
this._createPopup(square, data);
11361143

11371144
return this.container;
11381145
}
@@ -1186,7 +1193,7 @@ class CircleAnnotationElement extends AnnotationElement {
11861193

11871194
// Create the popup ourselves so that we can bind it to the circle instead
11881195
// of to the entire container (which is the default).
1189-
this._createPopup(this.container, circle, data);
1196+
this._createPopup(circle, data);
11901197

11911198
return this.container;
11921199
}
@@ -1248,7 +1255,7 @@ class PolylineAnnotationElement extends AnnotationElement {
12481255

12491256
// Create the popup ourselves so that we can bind it to the polyline
12501257
// instead of to the entire container (which is the default).
1251-
this._createPopup(this.container, polyline, data);
1258+
this._createPopup(polyline, data);
12521259

12531260
return this.container;
12541261
}
@@ -1285,7 +1292,7 @@ class CaretAnnotationElement extends AnnotationElement {
12851292
this.container.className = "caretAnnotation";
12861293

12871294
if (!this.data.hasPopup) {
1288-
this._createPopup(this.container, null, this.data);
1295+
this._createPopup(null, this.data);
12891296
}
12901297
return this.container;
12911298
}
@@ -1347,7 +1354,7 @@ class InkAnnotationElement extends AnnotationElement {
13471354

13481355
// Create the popup ourselves so that we can bind it to the polyline
13491356
// instead of to the entire container (which is the default).
1350-
this._createPopup(this.container, polyline, data);
1357+
this._createPopup(polyline, data);
13511358

13521359
svg.appendChild(polyline);
13531360
}
@@ -1379,9 +1386,10 @@ class HighlightAnnotationElement extends AnnotationElement {
13791386
this.container.className = "highlightAnnotation";
13801387

13811388
if (!this.data.hasPopup) {
1382-
this._createPopup(this.container, null, this.data);
1389+
this._createPopup(null, this.data);
13831390
}
13841391
return this.quadrilaterals || this.container;
1392+
// return this.container;
13851393
}
13861394
}
13871395

@@ -1406,7 +1414,7 @@ class UnderlineAnnotationElement extends AnnotationElement {
14061414
this.container.className = "underlineAnnotation";
14071415

14081416
if (!this.data.hasPopup) {
1409-
this._createPopup(this.container, null, this.data);
1417+
this._createPopup(null, this.data);
14101418
}
14111419
return this.container;
14121420
}
@@ -1433,7 +1441,7 @@ class SquigglyAnnotationElement extends AnnotationElement {
14331441
this.container.className = "squigglyAnnotation";
14341442

14351443
if (!this.data.hasPopup) {
1436-
this._createPopup(this.container, null, this.data);
1444+
this._createPopup(null, this.data);
14371445
}
14381446
return this.container;
14391447
}
@@ -1460,7 +1468,7 @@ class StrikeOutAnnotationElement extends AnnotationElement {
14601468
this.container.className = "strikeoutAnnotation";
14611469

14621470
if (!this.data.hasPopup) {
1463-
this._createPopup(this.container, null, this.data);
1471+
this._createPopup(null, this.data);
14641472
}
14651473
return this.container;
14661474
}
@@ -1487,7 +1495,7 @@ class StampAnnotationElement extends AnnotationElement {
14871495
this.container.className = "stampAnnotation";
14881496

14891497
if (!this.data.hasPopup) {
1490-
this._createPopup(this.container, null, this.data);
1498+
this._createPopup(null, this.data);
14911499
}
14921500
return this.container;
14931501
}
@@ -1528,7 +1536,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
15281536
trigger.addEventListener("dblclick", this._download.bind(this));
15291537

15301538
if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
1531-
this._createPopup(this.container, trigger, this.data);
1539+
this._createPopup(trigger, this.data);
15321540
}
15331541

15341542
this.container.appendChild(trigger);
@@ -1615,7 +1623,12 @@ class AnnotationLayer {
16151623
parameters.div.appendChild(renderedElement);
16161624
}
16171625
} else {
1618-
parameters.div.appendChild(rendered);
1626+
if (element.popup) {
1627+
// popup div mustn't be on top of an annotation
1628+
parameters.div.prepend(rendered);
1629+
} else {
1630+
parameters.div.appendChild(rendered);
1631+
}
16191632
}
16201633
}
16211634
}

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
!noembed-identity.pdf
291291
!noembed-identity-2.pdf
292292
!noembed-jis7.pdf
293+
!issue12504.pdf
293294
!noembed-eucjp.pdf
294295
!noembed-sjis.pdf
295296
!vertical.pdf

test/pdfs/issue12504.pdf

24.9 KB
Binary file not shown.

test/test_manifest.json

+7
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,13 @@
14271427
"type": "eq",
14281428
"about": "Type3 fonts with image resources; both pages need to be tested, otherwise the bug won't manifest."
14291429
},
1430+
{ "id": "issue12504",
1431+
"file": "pdfs/issue12504.pdf",
1432+
"md5": "04fcc87f3e7e9e925e3ef83cf0bf49f4",
1433+
"rounds": 1,
1434+
"type": "eq",
1435+
"annotations": true
1436+
},
14301437
{ "id": "close-path-bug",
14311438
"file": "pdfs/close-path-bug.pdf",
14321439
"md5": "48dd17ef58393857d2d038d33699cac5",

0 commit comments

Comments
 (0)