[Editor] Make the text layer focusable before the editors (bug 1881746)

Keep the different layers in a constant order to avoid the use of a z-index
and a tab-index.
This commit is contained in:
Calixte Denizet 2024-03-11 17:03:44 +01:00
parent 0022310b9c
commit 1b00511301
14 changed files with 187 additions and 36 deletions

View file

@ -99,6 +99,14 @@ const DEFAULT_LAYER_PROPERTIES =
},
};
const LAYERS_ORDER = new Map([
["canvasWrapper", 0],
["textLayer", 1],
["annotationLayer", 2],
["annotationEditorLayer", 3],
["xfaLayer", 2],
]);
/**
* @implements {IRenderableView}
*/
@ -127,6 +135,8 @@ class PDFPageView {
#viewportMap = new WeakMap();
#layers = [null, null, null, null];
/**
* @param {PDFPageViewOptions} options
*/
@ -223,6 +233,19 @@ class PDFPageView {
}
}
#addLayer(div, name) {
const pos = LAYERS_ORDER.get(name);
this.#layers[pos] = div;
for (let i = pos - 1; i >= 0; i--) {
const layer = this.#layers[i];
if (layer) {
layer.after(div);
return;
}
}
this.div.prepend(div);
}
get renderingState() {
return this.#renderingState;
}
@ -392,7 +415,7 @@ class PDFPageView {
if (this.xfaLayer?.div) {
// Pause translation when inserting the xfaLayer in the DOM.
this.l10n.pause();
this.div.append(this.xfaLayer.div);
this.#addLayer(this.xfaLayer.div, "xfaLayer");
this.l10n.resume();
}
@ -531,6 +554,10 @@ class PDFPageView {
continue;
}
node.remove();
const layerIndex = this.#layers.indexOf(node);
if (layerIndex >= 0) {
this.#layers[layerIndex] = null;
}
}
div.removeAttribute("data-loaded");
@ -877,7 +904,8 @@ class PDFPageView {
// overflow will be hidden in Firefox.
const canvasWrapper = document.createElement("div");
canvasWrapper.classList.add("canvasWrapper");
div.append(canvasWrapper);
canvasWrapper.setAttribute("aria-hidden", true);
this.#addLayer(canvasWrapper, "canvasWrapper");
if (
!this.textLayer &&
@ -891,13 +919,13 @@ class PDFPageView {
accessibilityManager: this._accessibilityManager,
enablePermissions:
this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
onAppend: textLayerDiv => {
// Pause translation when inserting the textLayer in the DOM.
this.l10n.pause();
this.#addLayer(textLayerDiv, "textLayer");
this.l10n.resume();
},
});
this.textLayer.onAppend = textLayerDiv => {
// Pause translation when inserting the textLayer in the DOM.
this.l10n.pause();
this.div.append(textLayerDiv);
this.l10n.resume();
};
}
if (
@ -915,7 +943,6 @@ class PDFPageView {
this._annotationCanvasMap ||= new Map();
this.annotationLayer = new AnnotationLayerBuilder({
pageDiv: div,
pdfPage,
annotationStorage,
imageResourcesPath: this.imageResourcesPath,
@ -927,6 +954,9 @@ class PDFPageView {
fieldObjectsPromise,
annotationCanvasMap: this._annotationCanvasMap,
accessibilityManager: this._accessibilityManager,
onAppend: annotationLayerDiv => {
this.#addLayer(annotationLayerDiv, "annotationLayer");
},
});
}
@ -1042,13 +1072,15 @@ class PDFPageView {
if (!this.annotationEditorLayer) {
this.annotationEditorLayer = new AnnotationEditorLayerBuilder({
uiManager: annotationEditorUIManager,
pageDiv: div,
pdfPage,
l10n,
accessibilityManager: this._accessibilityManager,
annotationLayer: this.annotationLayer?.annotationLayer,
textLayer: this.textLayer,
drawLayer: this.drawLayer.getDrawLayer(),
onAppend: annotationEditorLayerDiv => {
this.#addLayer(annotationEditorLayerDiv, "annotationEditorLayer");
},
});
}
this.#renderAnnotationEditorLayer();