1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +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:
Calixte Denizet 2022-06-28 18:21:32 +02:00
parent ad15532235
commit 624b26e1de
15 changed files with 467 additions and 96 deletions

View file

@ -77,6 +77,7 @@ class AnnotationEditorLayerBuilder {
this.div = document.createElement("div");
this.div.className = "annotationEditorLayer";
this.div.tabIndex = 0;
this.pageDiv.append(this.div);
this.annotationEditorLayer = new AnnotationEditorLayer({
uiManager: this.#uiManager,
@ -84,6 +85,7 @@ class AnnotationEditorLayerBuilder {
annotationStorage: this.annotationStorage,
pageIndex: this.pdfPage._pageIndex,
l10n: this.l10n,
viewport: clonedViewport,
});
const parameters = {
@ -94,12 +96,11 @@ class AnnotationEditorLayerBuilder {
};
this.annotationEditorLayer.render(parameters);
this.pageDiv.append(this.div);
}
cancel() {
this._cancelled = true;
this.destroy();
}
hide() {
@ -121,8 +122,8 @@ class AnnotationEditorLayerBuilder {
return;
}
this.pageDiv = null;
this.div.remove();
this.annotationEditorLayer.destroy();
this.div.remove();
}
}

View file

@ -83,6 +83,9 @@ const DEFAULT_L10N_STRINGS = {
"Web fonts are disabled: unable to use embedded PDF fonts.",
free_text_default_content: "Enter text…",
editor_free_text_aria_label: "FreeText Editor",
editor_ink_aria_label: "Ink Editor",
editor_ink_canvas_aria_label: "User-created image",
};
function getL10nFallback(key, args) {

View file

@ -17,9 +17,9 @@
/** @typedef {import("./event_utils").EventBus} EventBus */
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
import { binarySearchFirstItem, scrollIntoView } from "./ui_utils.js";
import { createPromiseCapability } from "pdfjs-lib";
import { binarySearchFirstItem, createPromiseCapability } from "pdfjs-lib";
import { getCharacterType } from "./pdf_find_utils.js";
import { scrollIntoView } from "./ui_utils.js";
const FindState = {
FOUND: 0,

View file

@ -13,6 +13,8 @@
* limitations under the License.
*/
import { binarySearchFirstItem } from "pdfjs-lib";
const DEFAULT_SCALE_VALUE = "auto";
const DEFAULT_SCALE = 1.0;
const DEFAULT_SCALE_DELTA = 1.1;
@ -221,38 +223,6 @@ function removeNullCharacters(str, replaceInvisible = false) {
return str.replace(NullCharactersRegExp, "");
}
/**
* Use binary search to find the index of the first item in a given array which
* passes a given condition. The items are expected to be sorted in the sense
* that if the condition is true for one item in the array, then it is also true
* for all following items.
*
* @returns {number} Index of the first array element to pass the test,
* or |items.length| if no such element exists.
*/
function binarySearchFirstItem(items, condition, start = 0) {
let minIndex = start;
let maxIndex = items.length - 1;
if (maxIndex < 0 || !condition(items[maxIndex])) {
return items.length;
}
if (condition(items[minIndex])) {
return minIndex;
}
while (minIndex < maxIndex) {
const currentIndex = (minIndex + maxIndex) >> 1;
const currentItem = items[currentIndex];
if (condition(currentItem)) {
maxIndex = currentIndex;
} else {
minIndex = currentIndex + 1;
}
}
return minIndex; /* === maxIndex */
}
/**
* Approximates float number as a fraction using Farey sequence (max order
* of 8).
@ -840,7 +810,6 @@ export {
approximateFraction,
AutoPrintRegExp,
backtrackBeforeAllVisibleElements, // only exported for testing
binarySearchFirstItem,
DEFAULT_SCALE,
DEFAULT_SCALE_DELTA,
DEFAULT_SCALE_VALUE,