From e49fe384d1e4c5e996b511f1d8bea9a4bfe6d322 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Sat, 7 Dec 2024 18:21:31 +0900 Subject: [PATCH] =?UTF-8?q?LibWeb:=20Align=20default=20=E2=80=9Cth?= =?UTF-8?q?=E2=80=9D=20and=20=E2=80=9Ctd=E2=80=9D=20roles=20with=20HTML-AA?= =?UTF-8?q?M=20spec=20and=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change aligns the default roles for “th” and “td” elements with the requirements in the HTML-AAM spec, and with the corresponding WPT tests at https://wpt.fyi/results/html-aam/table-roles.html, and with the behavior in other engines. Otherwise, without this change, the default role values for “th” and “td” elements in some cases don’t match the behavior in other engines, and don’t match the expected results for the corresponding WPT tests. --- .../LibWeb/HTML/HTMLTableCellElement.cpp | 35 +++-- .../wpt-import/html-aam/table-roles.txt | 12 ++ .../wpt-import/wai-aria/role/table-roles.txt | 14 ++ .../wpt-import/html-aam/table-roles.html | 53 +++++++ .../wpt-import/wai-aria/role/table-roles.html | 148 ++++++++++++++++++ 5 files changed, 252 insertions(+), 10 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html-aam/table-roles.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/table-roles.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html-aam/table-roles.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/wai-aria/role/table-roles.html diff --git a/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index a482a628d70..a745ce363ed 100644 --- a/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -196,16 +196,31 @@ WebIDL::Long HTMLTableCellElement::cell_index() const Optional HTMLTableCellElement::default_role() const { - // TODO: For td: - // role=cell if the ancestor table element is exposed as a role=table - // role=gridcell if the ancestor table element is exposed as a role=grid or treegrid - // No corresponding role if the ancestor table element is not exposed as a role=table, grid or treegrid - // For th: - // role=columnheader, rowheader or cell if the ancestor table element is exposed as a role=table - // role=columnheader, rowheader or gridcell if the ancestor table element is exposed as a role=grid or treegrid - // No corresponding role if the ancestor table element is not exposed as a role=table, grid or treegrid - // https://www.w3.org/TR/html-aria/#el-td - // https://www.w3.org/TR/html-aria/#el-th + if (local_name() == TagNames::th) { + for (auto const* ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) { + // AD-HOC: The ancestor checks here aren’t explicitly defined in the spec, but implicitly follow from what + // the spec does state, and from the physical placement/layout of elements. Also, the el-th and el-th-in-row + // tests at https://wpt.fyi/results/html-aam/table-roles.html require doing these ancestor checks — and + // implementing them causes the behavior to match that of other engines. + // https://w3c.github.io/html-aam/#el-th-columnheader + if (get_attribute(HTML::AttributeNames::scope) == "columnheader" || ancestor->local_name() == TagNames::thead) + return ARIA::Role::columnheader; + // https://w3c.github.io/html-aam/#el-th-rowheader + if (get_attribute(HTML::AttributeNames::scope) == "rowheader" || ancestor->local_name() == TagNames::tbody) + return ARIA::Role::rowheader; + } + } + auto const* table_element = first_ancestor_of_type(); + // https://w3c.github.io/html-aam/#el-td + // https://w3c.github.io/html-aam/#el-th/ + // (ancestor table element has table role) + if (table_element->role_or_default() == ARIA::Role::table) + return ARIA::Role::cell; + // https://w3c.github.io/html-aam/#el-td-gridcell + // https://w3c.github.io/html-aam/#el-th-gridcell + // (ancestor table element has grid or treegrid role) + if (first_is_one_of(table_element->role_or_default(), ARIA::Role::grid, ARIA::Role::gridcell)) + return ARIA::Role::gridcell; return {}; } diff --git a/Tests/LibWeb/Text/expected/wpt-import/html-aam/table-roles.txt b/Tests/LibWeb/Text/expected/wpt-import/html-aam/table-roles.txt new file mode 100644 index 00000000000..ee75a8ab898 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html-aam/table-roles.txt @@ -0,0 +1,12 @@ +Harness status: OK + +Found 7 tests + +7 Pass +Pass el-table +Pass el-caption +Pass el-tr-thead +Pass el-th +Pass el-tr-tbody +Pass el-th-in-row +Pass el-td \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/table-roles.txt b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/table-roles.txt new file mode 100644 index 00000000000..6111915e656 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/table-roles.txt @@ -0,0 +1,14 @@ +Harness status: OK + +Found 9 tests + +9 Pass +Pass div role is caption (in div with table role) +Pass orphan p role is caption +Pass span role is cell (in div with row role, in div with rowgroup role, in div with table role) +Pass orphan span role is cell +Pass span role is columnheader (in div with row role, in div with rowgroup role, in div with table role) +Pass div role is row (in div with rowgroup role, in div with table role) +Pass div role is rowgroup (in div with table role) +Pass role is rowheader (in div with row role, in div with rowgroup role, in div with table role) +Pass div role is table \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html-aam/table-roles.html b/Tests/LibWeb/Text/input/wpt-import/html-aam/table-roles.html new file mode 100644 index 00000000000..9ed64cd4f39 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html-aam/table-roles.html @@ -0,0 +1,53 @@ + + + + HTML-AAM Role Verification Tests + + + + + + + + + +

Tests the computedrole mappings for the table-related roles defined in HTML-AAM. Most test names correspond to unique ID defined in the spec.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
caption
abc
123
456
xyz
+ + + + + \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/wai-aria/role/table-roles.html b/Tests/LibWeb/Text/input/wpt-import/wai-aria/role/table-roles.html new file mode 100644 index 00000000000..9ce6b330349 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/wai-aria/role/table-roles.html @@ -0,0 +1,148 @@ + + + + Table Role Verification Tests + + + + + + + + +

Tests table and related roles.

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
x
+
+ +

x

+ + +
+
+
+ x + x +
+
+
+
+ x + x +
+
+
+ + x + + +
+
+
+ x + x + x +
+
+
+
+ x + x + x +
+
+
+ + +
+
+
+ x +
+
+
+
+ x +
+
+
+ + +
+
+
+ x + x +
+
+
+
+ x + x +
+
+
+ + +
+
+
+ x + x + x +
+
+
+
+ x + x + x + x +
+
+
+ + +
+
+ x + x +
+
+ x + x +
+
+ + + + + \ No newline at end of file