Compare commits

..

No commits in common. "c00591c1b6910600f2d1128018752d81f2e531dc" and "58ac273f1f36b3d01b21f2a07b19f5884eca1b2a" have entirely different histories.

4 changed files with 5 additions and 82 deletions

View File

@ -544,71 +544,4 @@ describe("accessibility", () => {
);
});
});
describe("A TH in a TR itself in a TBody is rowheader", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait("bug2014080.pdf", ".textLayer");
});
afterEach(async () => {
await closePages(pages);
});
it("must check that the table has the right structure", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
let elementRole = await page.evaluate(() =>
Array.from(
document.querySelector(".structTree [role='table']").children
).map(child => child.getAttribute("role"))
);
// THeader and TBody must be rowgroup.
expect(elementRole)
.withContext(`In ${browserName}`)
.toEqual(["rowgroup", "rowgroup"]);
elementRole = await page.evaluate(() =>
Array.from(
document.querySelector(
".structTree [role='table'] > [role='rowgroup'] > [role='row']"
).children
).map(child => child.getAttribute("role"))
);
// THeader has 3 columnheader.
expect(elementRole)
.withContext(`In ${browserName}`)
.toEqual(["columnheader", "columnheader", "columnheader"]);
elementRole = await page.evaluate(() =>
Array.from(
document.querySelector(
".structTree [role='table'] > [role='rowgroup']:nth-child(2)"
).children
).map(child => child.getAttribute("role"))
);
// TBody has 5 rows.
expect(elementRole)
.withContext(`In ${browserName}`)
.toEqual(["row", "row", "row", "row", "row"]);
elementRole = await page.evaluate(() =>
Array.from(
document.querySelector(
".structTree [role='table'] > [role='rowgroup']:nth-child(2) > [role='row']:first-child"
).children
).map(child => child.getAttribute("role"))
);
// First row has a rowheader and 2 cells.
expect(elementRole)
.withContext(`In ${browserName}`)
.toEqual(["rowheader", "cell", "cell"]);
})
);
});
});
});

View File

@ -872,4 +872,3 @@
!page_with_number_and_link.pdf
!Brotli-Prototype-FileA.pdf
!bug2013793.pdf
!bug2014080.pdf

Binary file not shown.

View File

@ -61,8 +61,8 @@ const PDF_ROLE_TO_HTML_ROLE = {
TR: "row",
TH: "columnheader",
TD: "cell",
THead: "rowgroup",
TBody: "rowgroup",
THead: "columnheader",
TBody: null,
TFoot: null,
// Standard structure type Caption
Caption: null,
@ -353,7 +353,7 @@ class StructTreeLayerBuilder {
}
}
#walk(node, parentNodes = []) {
#walk(node) {
if (!node) {
return null;
}
@ -378,14 +378,7 @@ class StructTreeLayerBuilder {
element.setAttribute("role", "heading");
element.setAttribute("aria-level", match[1]);
} else if (PDF_ROLE_TO_HTML_ROLE[role]) {
element.setAttribute(
"role",
role === "TH" &&
parentNodes.at(-1)?.role === "TR" &&
parentNodes.at(-2)?.role === "TBody"
? "rowheader" // TH inside TR itself in TBody is a rowheader.
: PDF_ROLE_TO_HTML_ROLE[role]
);
element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
}
if (role === "Figure" && this.#addImageInTextLayer(node, element)) {
return element;
@ -430,11 +423,9 @@ class StructTreeLayerBuilder {
// parent node to avoid creating an extra span.
this.#setAttributes(node.children[0], element);
} else {
parentNodes.push(node);
for (const kid of node.children) {
element.append(this.#walk(kid, parentNodes));
element.append(this.#walk(kid));
}
parentNodes.pop();
}
}
return element;