Skip to content

Commit

Permalink
XFA - Add support for access property
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Jun 20, 2021
1 parent 248efb1 commit 9f376a5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/xfa/html_utils.js
Expand Up @@ -448,6 +448,18 @@ function fixTextIndent(styles) {
}
}

function setAccess(node, classNames) {
switch (node.access) {
case "nonInteractive":
case "readOnly":
classNames.push("xfaReadOnly");
break;
case "protected":
classNames.push("xfaDisabled");
break;
}
}

function getFonts(family) {
if (family.startsWith("'") || family.startsWith('"')) {
family = family.slice(1, family.length - 1);
Expand All @@ -466,6 +478,7 @@ export {
layoutClass,
layoutText,
measureToString,
setAccess,
setMinMaxDimensions,
toStyle,
};
9 changes: 9 additions & 0 deletions src/core/xfa/template.js
Expand Up @@ -72,6 +72,7 @@ import {
layoutClass,
layoutText,
measureToString,
setAccess,
setMinMaxDimensions,
toStyle,
} from "./html_utils.js";
Expand Down Expand Up @@ -2023,8 +2024,11 @@ class ExclGroup extends XFAObject {
const children = [];
const attributes = {
id: this[$uid],
class: [],
};

setAccess(this, attributes.class);

if (!this[$extra]) {
this[$extra] = Object.create(null);
}
Expand Down Expand Up @@ -2329,6 +2333,8 @@ class Field extends XFAObject {
class: classNames,
};

setAccess(this, classNames);

if (this.name) {
attributes.xfaName = this.name;
}
Expand Down Expand Up @@ -4171,8 +4177,11 @@ class Subform extends XFAObject {
const children = [];
const attributes = {
id: this[$uid],
class: [],
};

setAccess(this, attributes.class);

if (!this[$extra]) {
this[$extra] = Object.create(null);
}
Expand Down
11 changes: 11 additions & 0 deletions src/display/xfa_layer.js
Expand Up @@ -181,6 +181,17 @@ class XfaLayer {
childHtml.appendChild(document.createTextNode(child.value));
}
}

for (const el of rootDiv.querySelectorAll(
".xfaDisabled input, .xfaDisabled textarea"
)) {
el.setAttribute("disabled", true);
}
for (const el of rootDiv.querySelectorAll(
".xfaReadOnly input, .xfaReadOnly textarea"
)) {
el.setAttribute("readOnly", true);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/xfa_bug1716816.pdf.link
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9227455
8 changes: 8 additions & 0 deletions test/test_manifest.json
Expand Up @@ -938,6 +938,14 @@
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1716816",
"file": "pdfs/xfa_bug1716816.pdf",
"md5": "3051cd18db7839bc4953df35b52cf3e0",
"link": true,
"rounds": 1,
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1716809",
"file": "pdfs/xfa_bug1716809.pdf",
"md5": "7192f9e27e8b84776d107f57cbe353d5",
Expand Down
7 changes: 7 additions & 0 deletions web/xfa_layer_builder.css
Expand Up @@ -277,6 +277,13 @@
flex: 1;
}

.xfaDisabled input,
.xfaDisabled textarea,
.xfaReadOnly input,
.xfaReadOnly textarea {
background: initial;
}

@media print {
.xfaTextfield,
.xfaSelect {
Expand Down

0 comments on commit 9f376a5

Please sign in to comment.