XFA - Add support for traversal and traverse element
- For now, just implement the "next" target in using tabindex attribute of html elements.
This commit is contained in:
parent
0afc785c7d
commit
ccac125623
@ -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]() {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user