diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index cb87086fd..b65ec9f4a 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -50,6 +50,7 @@ import { $searchNode, $setSetAttributes, $setValue, + $tabIndex, $text, $toHTML, $toStyle, @@ -132,6 +133,36 @@ function* getContainedChildren(node) { } } +function setTabIndex(node) { + while (node) { + if (!node.traversal || node[$tabIndex]) { + return; + } + + let next = null; + for (const child of node.traversal[$getChildren]()) { + if (child.operation === "next") { + next = child; + break; + } + } + + if (!next || !next.ref) { + return; + } + + const root = node[$getTemplateRoot](); + node[$tabIndex] = ++root[$tabIndex]; + + const ref = root[$searchNode](next.ref, node); + if (!ref) { + return; + } + + node = ref[0]; + } +} + function valueToHtml(value) { return HTMLResult.success({ name: "span", @@ -2467,6 +2498,8 @@ class Field extends XFAObject { } [$toHTML](availableSpace) { + setTabIndex(this); + if ( !this.ui || this.presence === "hidden" || @@ -2601,6 +2634,14 @@ class Field extends XFAObject { return HTMLResult.success(createWrapper(this, html), bbox); } + if (this[$tabIndex]) { + if (ui.children && ui.children[0]) { + ui.children[0].attributes.tabindex = this[$tabIndex]; + } else { + ui.attributes.tabindex = this[$tabIndex]; + } + } + if (!ui.attributes.style) { ui.attributes.style = Object.create(null); } @@ -4883,6 +4924,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; } [$isSplittable]() { diff --git a/src/core/xfa/xfa_object.js b/src/core/xfa/xfa_object.js index 0dac161cc..f0dbaa0e8 100644 --- a/src/core/xfa/xfa_object.js +++ b/src/core/xfa/xfa_object.js @@ -79,6 +79,7 @@ const $searchNode = Symbol(); const $setId = Symbol(); const $setSetAttributes = Symbol(); const $setValue = Symbol(); +const $tabIndex = Symbol(); const $text = Symbol(); const $toHTML = Symbol(); const $toString = Symbol(); @@ -1100,6 +1101,7 @@ export { $setId, $setSetAttributes, $setValue, + $tabIndex, $text, $toHTML, $toString,