mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
XFA - Support aria heading and table structure. (bug 1723421) (bug 1723425)
https://bugzilla.mozilla.org/show_bug.cgi?id=1723421 https://bugzilla.mozilla.org/show_bug.cgi?id=1723425
This commit is contained in:
parent
849bab973c
commit
a38d1122d8
2 changed files with 167 additions and 19 deletions
|
@ -121,6 +121,8 @@ const MAX_EMPTY_PAGES = 3;
|
|||
// Default value to start with for the tabIndex property.
|
||||
const DEFAULT_TAB_INDEX = 5000;
|
||||
|
||||
const HEADING_PATTERN = /^H(\d+)$/;
|
||||
|
||||
function getBorderDims(node) {
|
||||
if (!node || !node.border) {
|
||||
return { w: 0, h: 0 };
|
||||
|
@ -210,6 +212,40 @@ function setTabIndex(node) {
|
|||
}
|
||||
}
|
||||
|
||||
function applyAssist(obj, attributes) {
|
||||
const assist = obj.assist;
|
||||
if (assist) {
|
||||
const assistTitle = assist[$toHTML]();
|
||||
if (assistTitle) {
|
||||
attributes.title = assistTitle;
|
||||
}
|
||||
const role = assist.role;
|
||||
const match = role.match(HEADING_PATTERN);
|
||||
if (match) {
|
||||
const ariaRole = "heading";
|
||||
const ariaLevel = match[1];
|
||||
attributes.role = ariaRole;
|
||||
attributes["aria-level"] = ariaLevel;
|
||||
}
|
||||
}
|
||||
// XXX: We could end up in a situation where the obj has a heading role and
|
||||
// is also a table. For now prioritize the table role.
|
||||
if (obj.layout === "table") {
|
||||
attributes.role = "table";
|
||||
} else if (obj.layout === "row") {
|
||||
attributes.role = "row";
|
||||
} else {
|
||||
const parent = obj[$getParent]();
|
||||
if (parent.layout === "row") {
|
||||
if (parent.assist && parent.assist.role === "TH") {
|
||||
attributes.role = "columnheader";
|
||||
} else {
|
||||
attributes.role = "cell";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ariaLabel(obj) {
|
||||
if (!obj.assist) {
|
||||
return null;
|
||||
|
@ -1849,10 +1885,7 @@ class Draw extends XFAObject {
|
|||
children: [],
|
||||
};
|
||||
|
||||
const assist = this.assist ? this.assist[$toHTML]() : null;
|
||||
if (assist) {
|
||||
html.attributes.title = assist;
|
||||
}
|
||||
applyAssist(this, attributes);
|
||||
|
||||
const bbox = computeBbox(this, html, availableSpace);
|
||||
|
||||
|
@ -2475,10 +2508,7 @@ class ExclGroup extends XFAObject {
|
|||
children,
|
||||
};
|
||||
|
||||
const assist = this.assist ? this.assist[$toHTML]() : null;
|
||||
if (assist) {
|
||||
html.attributes.title = assist;
|
||||
}
|
||||
applyAssist(this, attributes);
|
||||
|
||||
delete this[$extra];
|
||||
|
||||
|
@ -2816,10 +2846,7 @@ class Field extends XFAObject {
|
|||
children,
|
||||
};
|
||||
|
||||
const assist = this.assist ? this.assist[$toHTML]() : null;
|
||||
if (assist) {
|
||||
html.attributes.title = assist;
|
||||
}
|
||||
applyAssist(this, attributes);
|
||||
|
||||
const borderStyle = this.border ? this.border[$toStyle]() : null;
|
||||
const bbox = computeBbox(this, html, availableSpace);
|
||||
|
@ -5105,10 +5132,7 @@ class Subform extends XFAObject {
|
|||
children,
|
||||
};
|
||||
|
||||
const assist = this.assist ? this.assist[$toHTML]() : null;
|
||||
if (assist) {
|
||||
html.attributes.title = assist;
|
||||
}
|
||||
applyAssist(this, attributes);
|
||||
|
||||
const result = HTMLResult.success(createWrapper(this, html), bbox);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue