diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 03c97a28789..4b458e032fc 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -2491,13 +2491,15 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con // E. Host Language Label: Otherwise, if the current node's native markup provides an attribute (e.g. alt) or // element (e.g. HTML label or SVG title) that defines a text alternative, return that alternative in the form - // of a flat string as defined by the host language, unless the element is marked as presentational - // (role="presentation" or role="none"). - // + // of a flat string as defined by the host language. // TODO: Confirm (through existing WPT test cases) whether HTMLLabelElement is already handled (by the code for // step C. “Embedded Control” above) in conformance with the spec requirements — and if not, then add handling. - if (role != ARIA::Role::presentation && role != ARIA::Role::none && is(*element)) - return element->alternative_text().release_value(); + // + // https://w3c.github.io/html-aam/#img-element-accessible-name-computation + // use alt attribute, even if its value is the empty string. + // See also https://wpt.fyi/results/accname/name/comp_tooltip.tentative.html. + if (is(*element) && element->has_attribute(HTML::AttributeNames::alt)) + return element->get_attribute(HTML::AttributeNames::alt).value(); // https://w3c.github.io/svg-aam/#mapping_additional_nd Optional title_element_text; diff --git a/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.tentative.txt new file mode 100644 index 00000000000..89715e306e4 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.tentative.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass img with tooltip label with empty alt \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.txt b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.txt index bc2df895889..0400e6dbd6b 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.txt @@ -1,14 +1,13 @@ Harness status: OK -Found 23 tests +Found 22 tests -23 Pass +22 Pass Pass link with img with tooltip label Pass link with text with tooltip label and no contents Pass link with text with tooltip label and contents Pass div with text with tooltip label Pass img with tooltip label without alt -Pass img with tooltip label with empty alt Pass img with tooltip label with alt Pass img with tooltip label without title Pass select with tooltip label diff --git a/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.html b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.html index 93e506bd0b3..d8864ca2d6d 100644 --- a/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.html +++ b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.html @@ -13,12 +13,11 @@

Tests the #comp_tooltip portions of the AccName Name Computation algorithm.

- + contents
contents
- alt alt diff --git a/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.tentative.html b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.tentative.html new file mode 100644 index 00000000000..10128588b6d --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.tentative.html @@ -0,0 +1,23 @@ + + + + Name Comp: Tooltip (Tentative) + + + + + + + + + +

Tests the tentative #comp_tooltip portions of the AccName Name Computation algorithm.

+ + + + + + +