Skip to content

Commit

Permalink
Merge pull request #17788 from calixteman/bug1881743
Browse files Browse the repository at this point in the history
[Editor] Improve the accessibility of the highlight editor (bug 1881743)
  • Loading branch information
calixteman authored Mar 11, 2024
2 parents b14f696 + f676c2c commit e647311
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/display/draw_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class DrawLayer {
#createSVG(box) {
const svg = DrawLayer._svgFactory.create(1, 1, /* skipDimensions = */ true);
this.#parent.append(svg);
svg.setAttribute("aria-hidden", true);
DrawLayer.#setBox(svg, box);

return svg;
Expand Down
1 change: 1 addition & 0 deletions src/display/editor/color_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ColorPicker {
button.addEventListener("keydown", this.#boundKeyDown);
const swatch = (this.#buttonSwatch = document.createElement("span"));
swatch.className = "swatch";
swatch.setAttribute("aria-hidden", true);
swatch.style.backgroundColor = this.#defaultColor;
button.append(swatch);
return button;
Expand Down
11 changes: 11 additions & 0 deletions src/display/editor/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class HighlightEditor extends AnnotationEditor {

#outlineId = null;

#text = "";

#thickness;

#methodOfCreation = "";
Expand Down Expand Up @@ -104,6 +106,7 @@ class HighlightEditor extends AnnotationEditor {
this.#opacity = params.opacity || HighlightEditor._defaultOpacity;
this.#boxes = params.boxes || null;
this.#methodOfCreation = params.methodOfCreation || "";
this.#text = params.text || "";
this._isDraggable = false;

if (params.highlightId > -1) {
Expand Down Expand Up @@ -558,13 +561,21 @@ class HighlightEditor extends AnnotationEditor {
}

const div = super.render();
if (this.#text) {
const mark = document.createElement("mark");
div.append(mark);
mark.append(document.createTextNode(this.#text));
// The text is invisible but it's still visible by a screen reader.
mark.className = "visuallyHidden";
}
if (this.#isFreeHighlight) {
div.classList.add("free");
} else {
this.div.addEventListener("keydown", this.#boundKeydown);
}
const highlightDiv = (this.#highlightDiv = document.createElement("div"));
div.append(highlightDiv);
highlightDiv.setAttribute("aria-hidden", "true");
highlightDiv.className = "internal";
highlightDiv.style.clipPath = this.#clipPathId;
const [parentWidth, parentHeight] = this.parentDimensions;
Expand Down
1 change: 1 addition & 0 deletions src/display/editor/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EditorToolbar {
render() {
const editToolbar = (this.#toolbar = document.createElement("div"));
editToolbar.className = "editToolbar";
editToolbar.setAttribute("role", "toolbar");
editToolbar.addEventListener("contextmenu", noContextMenu);
editToolbar.addEventListener("pointerdown", EditorToolbar.#pointerDown);

Expand Down
2 changes: 2 additions & 0 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ class AnnotationEditorUIManager {
return;
}
const { anchorNode, anchorOffset, focusNode, focusOffset } = selection;
const text = selection.toString();
const anchorElement =
anchorNode.nodeType === Node.TEXT_NODE
? anchorNode.parentElement
Expand All @@ -974,6 +975,7 @@ class AnnotationEditorUIManager {
anchorOffset,
focusNode,
focusOffset,
text,
});
break;
}
Expand Down
13 changes: 13 additions & 0 deletions web/annotation_editor_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
pointer;
}

/* The following class is used to hide an element but keep it available to
* for screen readers. */
.visuallyHidden {
position: absolute;
border: 0;
margin: 0;
padding: 0;
width: 0;
height: 0;
overflow: hidden;
white-space: nowrap;
}

.textLayer.highlighting {
cursor: var(--editorFreeHighlight-editing-cursor);

Expand Down

0 comments on commit e647311

Please sign in to comment.