Skip to content

Annotation & XFA: Add focus outlines on different fields (bug 1723615, bug 1718528) #13875

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

Merged
merged 1 commit into from
Aug 5, 2021
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
21 changes: 18 additions & 3 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ const MAX_ATTEMPTS_FOR_LRTB_LAYOUT = 2;
// the loop after having MAX_EMPTY_PAGES empty pages.
const MAX_EMPTY_PAGES = 3;

// Default value to start with for the tabIndex property.
const DEFAULT_TAB_INDEX = 5000;

function getBorderDims(node) {
if (!node || !node.border) {
return { w: 0, h: 0 };
Expand Down Expand Up @@ -173,7 +176,12 @@ function* getContainedChildren(node) {

function setTabIndex(node) {
while (node) {
if (!node.traversal || node[$tabIndex]) {
if (!node.traversal) {
node[$tabIndex] = node[$getParent]()[$tabIndex];
return;
}

if (node[$tabIndex]) {
return;
}

Expand All @@ -186,6 +194,7 @@ function setTabIndex(node) {
}

if (!next || !next.ref) {
node[$tabIndex] = node[$getParent]()[$tabIndex];
return;
}

Expand Down Expand Up @@ -1755,6 +1764,8 @@ class Draw extends XFAObject {
}

[$toHTML](availableSpace) {
setTabIndex(this);

if (this.presence === "hidden" || this.presence === "inactive") {
return HTMLResult.EMPTY;
}
Expand Down Expand Up @@ -2309,6 +2320,7 @@ class ExclGroup extends XFAObject {
}

[$toHTML](availableSpace) {
setTabIndex(this);
if (
this.presence === "hidden" ||
this.presence === "inactive" ||
Expand Down Expand Up @@ -2611,6 +2623,8 @@ class Field extends XFAObject {
}

[$toHTML](availableSpace) {
setTabIndex(this);

if (!this.ui) {
// It's allowed to not have an ui, specs say:
// If the UI element contains no children or is not present,
Expand Down Expand Up @@ -2642,7 +2656,6 @@ class Field extends XFAObject {
this.ui[$appendChild](node);
}

setTabIndex(this);
if (
!this.ui ||
this.presence === "hidden" ||
Expand Down Expand Up @@ -4833,6 +4846,8 @@ class Subform extends XFAObject {
}

[$toHTML](availableSpace) {
setTabIndex(this);

if (this.break) {
// break element is deprecated so plug it on one of its replacement
// breakBefore or breakAfter.
Expand Down Expand Up @@ -5255,7 +5270,7 @@ class Template extends XFAObject {
if (this.subform.children.length >= 2) {
warn("XFA - Several subforms in template node: please file a bug.");
}
this[$tabIndex] = 1000;
this[$tabIndex] = DEFAULT_TAB_INDEX;
}

[$isSplittable]() {
Expand Down
6 changes: 6 additions & 0 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
import { AnnotationStorage } from "./annotation_storage.js";
import { ColorConverters } from "../shared/scripting_utils.js";

const DEFAULT_TAB_INDEX = 1000;

/**
* @typedef {Object} AnnotationElementParameters
* @property {Object} data
Expand Down Expand Up @@ -722,6 +724,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
element.type = "text";
element.setAttribute("value", textContent);
}
element.tabIndex = DEFAULT_TAB_INDEX;

elementData.userValue = textContent;
element.setAttribute("id", id);
Expand Down Expand Up @@ -978,6 +981,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
element.setAttribute("checked", true);
}
element.setAttribute("id", id);
element.tabIndex = DEFAULT_TAB_INDEX;

element.addEventListener("change", function (event) {
const name = event.target.name;
Expand Down Expand Up @@ -1052,6 +1056,7 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
element.setAttribute("checked", true);
}
element.setAttribute("id", id);
element.tabIndex = DEFAULT_TAB_INDEX;

element.addEventListener("change", function (event) {
const { target } = event;
Expand Down Expand Up @@ -1148,6 +1153,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
selectElement.disabled = this.data.readOnly;
selectElement.name = this.data.fieldName;
selectElement.setAttribute("id", id);
selectElement.tabIndex = DEFAULT_TAB_INDEX;

selectElement.style.fontSize = `${fontSize}px`;

Expand Down
8 changes: 8 additions & 0 deletions web/annotation_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
border: 1px solid transparent;
}

.annotationLayer .textWidgetAnnotation input :focus,
.annotationLayer .textWidgetAnnotation textarea :focus,
.annotationLayer .choiceWidgetAnnotation select :focus,
.annotationLayer .buttonWidgetAnnotation.checkBox :focus,
.annotationLayer .buttonWidgetAnnotation.radioButton :focus {
outline: auto;
}

.annotationLayer .buttonWidgetAnnotation.checkBox input:checked:before,
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked:after,
.annotationLayer .buttonWidgetAnnotation.radioButton input:checked:before {
Expand Down
8 changes: 7 additions & 1 deletion web/xfa_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@
.xfaSelect:focus {
background-image: none;
background-color: transparent;
outline: none;
outline: auto;
outline-offset: -1px;
}

.xfaCheckbox:focus,
.xfaRadio:focus {
outline: auto;
}

.xfaTextfield,
Expand Down