mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 01:35:43 +02:00
[Editor] Improve a11y for newly added element (#15109)
- In the annotationEditorLayer, reorder the editors in the DOM according the position of the elements on the screen; - add an aria-owns attribute on the "nearest" element in the text layer which points to the added editor.
This commit is contained in:
parent
ad15532235
commit
624b26e1de
15 changed files with 467 additions and 96 deletions
|
@ -58,6 +58,8 @@ class InkEditor extends AnnotationEditor {
|
|||
|
||||
static _defaultThickness = 1;
|
||||
|
||||
static _l10nPromise;
|
||||
|
||||
constructor(params) {
|
||||
super({ ...params, name: "inkEditor" });
|
||||
this.color = params.color || null;
|
||||
|
@ -76,6 +78,15 @@ class InkEditor extends AnnotationEditor {
|
|||
this.#boundCanvasMousedown = this.canvasMousedown.bind(this);
|
||||
}
|
||||
|
||||
static initialize(l10n) {
|
||||
this._l10nPromise = new Map(
|
||||
["editor_ink_canvas_aria_label", "editor_ink_aria_label"].map(str => [
|
||||
str,
|
||||
l10n.get(str),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
static updateDefaultParams(type, value) {
|
||||
switch (type) {
|
||||
case AnnotationEditorParamsType.INK_THICKNESS:
|
||||
|
@ -390,6 +401,10 @@ class InkEditor extends AnnotationEditor {
|
|||
this.#fitToContent();
|
||||
|
||||
this.parent.addInkEditorIfNeeded(/* isCommitting = */ true);
|
||||
|
||||
// When commiting, the position of this editor is changed, hence we must
|
||||
// move it to the right position in the DOM.
|
||||
this.parent.moveDivInDOM(this);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -477,6 +492,10 @@ class InkEditor extends AnnotationEditor {
|
|||
this.canvas = document.createElement("canvas");
|
||||
this.canvas.width = this.canvas.height = 0;
|
||||
this.canvas.className = "inkEditorCanvas";
|
||||
|
||||
InkEditor._l10nPromise
|
||||
.get("editor_ink_canvas_aria_label")
|
||||
.then(msg => this.canvas?.setAttribute("aria-label", msg));
|
||||
this.div.append(this.canvas);
|
||||
this.ctx = this.canvas.getContext("2d");
|
||||
}
|
||||
|
@ -507,6 +526,11 @@ class InkEditor extends AnnotationEditor {
|
|||
}
|
||||
|
||||
super.render();
|
||||
|
||||
InkEditor._l10nPromise
|
||||
.get("editor_ink_aria_label")
|
||||
.then(msg => this.div?.setAttribute("aria-label", msg));
|
||||
|
||||
const [x, y, w, h] = this.#getInitialBBox();
|
||||
this.setAt(x, y, 0, 0);
|
||||
this.setDims(w, h);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue