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 new file mode 100644 index 00000000000..feaaea02d54 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_tooltip.txt @@ -0,0 +1,33 @@ +Summary + +Harness status: OK + +Rerun + +Found 23 tests + +23 Pass +Details +Result Test Name MessagePass 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 +Pass button with tooltip label +Pass checkbox input with tooltip label +Pass radio input with tooltip label +Pass text input with placeholder and tooltip label +Pass password input with placeholder and tooltip label +Pass number input with placeholder and tooltip label +Pass search input with placeholder and tooltip label +Pass tel input with placeholder and tooltip label +Pass email input with placeholder and tooltip label +Pass url input with placeholder and tooltip label +Pass textarea with placeholder and tooltip label +Pass abbr with tooltip label +Pass summary with tooltip label and contents +Pass iframe with tooltip label \ No newline at end of file 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 new file mode 100644 index 00000000000..93e506bd0b3 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_tooltip.html @@ -0,0 +1,70 @@ + + + + Name Comp: Tooltip + + + + + + + + + +

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

+ + + +contents +
contents
+ + +alt +alt + + + + + + + + + + + + + + + + + + + + + + +WPT + + + + + +
+ contents + details +
+ + + + + + + + diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 526365bcac0..5ee72e75edc 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -2188,6 +2189,7 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con if (is_element()) { auto const* element = static_cast(this); + auto role = element->role_or_default(); // 2. Compute the text alternative for the current node: // A. If the current node is hidden and is not directly referenced by aria-labelledby or aria-describedby, nor directly referenced by a native host language text alternative element (e.g. label in HTML) or attribute, return the empty string. // FIXME: Check for references @@ -2312,11 +2314,22 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con // - Otherwise, return the value of aria-label. return element->aria_label().value(); } - // TODO: D. Otherwise, if the current node's native markup provides an attribute (e.g. title) or element (e.g. HTML label) 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"). + + // 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"). + if (role != ARIA::Role::presentation && role != ARIA::Role::none) { + if (is(*element)) { + if (auto alt = element->get_attribute(HTML::AttributeNames::alt); alt.has_value()) + return alt.release_value(); + } + // TODO: Add handling for SVGTitleElement, and also 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 for it here. + } // F. Otherwise, if the current node's role allows name from content, or if the current node is referenced by aria-labelledby, aria-describedby, or is a native host language text alternative element (e.g. label in HTML), or is a descendant of a native host language text alternative element: - auto role = element->role_or_default(); if ((role.has_value() && ARIA::allows_name_from_content(role.value())) || is_descendant == IsDescendant::Yes) { // i. Set the accumulated text to the empty string. total_accumulated_text.clear(); @@ -2348,8 +2361,9 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con return IterationDecision::Continue; }); - // iv. Return the accumulated text. - return total_accumulated_text.to_string(); + // v. Return the accumulated text if it is not the empty string (""). + if (!total_accumulated_text.is_empty()) + return total_accumulated_text.to_string(); // Important: Each node in the subtree is consulted only once. If text has been collected from a descendant, but is referenced by another IDREF in some descendant node, then that second, or subsequent, reference is not followed. This is done to avoid infinite loops. } }