Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375) #15237

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
warn,
} from "../shared/util.js";
import {
AnnotationPrefix,
DOMSVGFactory,
getFilenameFromUrl,
PDFDateString,
Expand Down Expand Up @@ -1901,7 +1902,8 @@ class PopupElement {
}
if (this.hideElement.hidden) {
this.hideElement.hidden = false;
this.container.style.zIndex += 1;
this.container.style.zIndex =
parseInt(this.container.style.zIndex) + 1000;
}
}

Expand All @@ -1918,7 +1920,8 @@ class PopupElement {
}
if (!this.hideElement.hidden && !this.pinned) {
this.hideElement.hidden = true;
this.container.style.zIndex -= 1;
this.container.style.zIndex =
parseInt(this.container.style.zIndex) - 1000;
}
}
}
Expand Down Expand Up @@ -2465,6 +2468,19 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
*/

class AnnotationLayer {
static #appendElement(element, id, div, accessibilityManager) {
const contentElement = element.firstChild || element;
contentElement.id = `${AnnotationPrefix}${id}`;

div.append(element);
accessibilityManager?.moveElementInDOM(
div,
element,
contentElement,
/* isRemovable = */ false
);
}

/**
* Render a new annotation layer with all annotation elements.
*
Expand All @@ -2473,9 +2489,10 @@ class AnnotationLayer {
* @memberof AnnotationLayer
*/
static render(parameters) {
const { annotations, div, viewport } = parameters;
const { annotations, div, viewport, accessibilityManager } = parameters;

this.#setDimensions(div, viewport);
let zIndex = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate what, and why, all these z-index changes are for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this patch annotations are rendered in the order they're in the pdf.
With this patch they're reordered when they're inserted in order to respect the visual order, hence an annotation which should be above an other one, could now be underneath.
The z-index will help to respect the order of the annotation rendering.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation; some sort of (short) comment about that might not hurt :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I added one.


for (const data of annotations) {
if (data.annotationType !== AnnotationType.POPUP) {
Expand Down Expand Up @@ -2508,15 +2525,33 @@ class AnnotationLayer {
}
if (Array.isArray(rendered)) {
for (const renderedElement of rendered) {
div.append(renderedElement);
renderedElement.style.zIndex = zIndex++;
AnnotationLayer.#appendElement(
renderedElement,
data.id,
div,
accessibilityManager
);
}
} else {
// The accessibility manager will move the annotation in the DOM in
// order to match the visual ordering.
// But if an annotation is above an other one, then we must draw it
// after the other one whatever the order is in the DOM, hence the
// use of the z-index.
rendered.style.zIndex = zIndex++;

if (element instanceof PopupAnnotationElement) {
// Popup annotation elements should not be on top of other
// annotation elements to prevent interfering with mouse events.
div.prepend(rendered);
} else {
div.append(rendered);
AnnotationLayer.#appendElement(
rendered,
data.id,
div,
accessibilityManager
);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { BaseException, stringToBytes, Util, warn } from "../shared/util.js";

const SVG_NS = "http://www.w3.org/2000/svg";

const AnnotationPrefix = "pdfjs_internal_id_";

class PixelsPerInch {
static CSS = 96.0;

Expand Down Expand Up @@ -652,6 +654,7 @@ function getCurrentTransformInverse(ctx) {
}

export {
AnnotationPrefix,
binarySearchFirstItem,
deprecated,
DOMCanvasFactory,
Expand Down
Loading