Skip to content

Commit

Permalink
[Interop] Allow later name sources to supersede empty alt attribute
Browse files Browse the repository at this point in the history
The Host Language Label step [1] of the accname computation algorithm
is unclear on whether the empty string should be used if that's
what the native markup provides.

I've filed an issue to clarify this at [2].

Meanwhile, other engines will allow a source later in the name
computation steps to provide a name even if an empty `alt` attribute
was set; see results for the "img with tooltip label with empty alt"
case in accname/name/comp_tooltip.html [3]. So, switch Blink's
behavior to match the other engines.

However, we still ensure that `name_source` is still set to
`kAttributeExplicitlyEmpty` returning
from`AXNodeObject::TextAlternative` if `alt` was set to the
empty string and a name was not provided from another source. This is
necessary to preserve the behavior where setting `alt=""` causes
the image to be treated as presentational and ignored. If a valid
name is provided from another source, however, the other name
overrides that behavior.

[1] https://w3c.github.io/accname/#comp_host_language_label
[2] w3c/accname#234
[3] https://wpt.fyi/results/accname/name/comp_tooltip.html?label=master&label=experimental&aligned&view=interop&q=label%3Ainterop-2024-accessibility

Bug: 325612090
Change-Id: I38e510ce27319afad406a9c128a47288c2c087ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5382253
Commit-Queue: Aaron Leventhal <[email protected]>
Reviewed-by: Aaron Leventhal <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1282227}
  • Loading branch information
dandclark authored and Chromium LUCI CQ committed Apr 3, 2024
1 parent 461df6f commit 0705ed8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# BUG? The expected result is 'title peanuts popcorn apple jacks'
image name='peanuts popcorn apple jacks' nameFrom=relatedElement
image name='title peanuts popcorn apple jacks' nameFrom=relatedElement
21 changes: 18 additions & 3 deletions third_party/blink/renderer/modules/accessibility/ax_node_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4639,11 +4639,16 @@ String AXNodeObject::TextAlternative(
text_alternative =
NativeTextAlternative(visited, name_from, related_objects, name_sources,
&found_text_alternative);
const bool has_text_alternative =
!text_alternative.empty() ||
// An explicitly empty native text alternative can still be overridden if a
// viable text alternative is found later in the search, so remember that it
// was explicitly empty here but don't terminate the search yet unless we
// already found something non-empty.
const bool has_explicitly_empty_native_text_alternative =
text_alternative.empty() &&
name_from == ax::mojom::blink::NameFrom::kAttributeExplicitlyEmpty;
if (has_text_alternative && !name_sources)
if (!text_alternative.empty() && !name_sources) {
return MaybeAppendFileDescriptionToName(text_alternative);
}

// Step 2F / 2G from: http://www.w3.org/TR/accname-aam-1.1 -- from content.
if (aria_label_or_description_root || SupportsNameFromContents(recursive)) {
Expand Down Expand Up @@ -4699,6 +4704,16 @@ String AXNodeObject::TextAlternative(
}
}

if (has_explicitly_empty_native_text_alternative) {
// If the native text alternative is explicitly empty and we
// never found another text alternative, then set name_source
// to reflect the fact that there was an explicitly empty text
// alternative. This is important because an empty `alt` attribute on an
// <img> can be used to indicate that the image is presentational and should
// be ignored by ATs.
name_from = ax::mojom::blink::NameFrom::kAttributeExplicitlyEmpty;
}

return String();
}

Expand Down

This file was deleted.

0 comments on commit 0705ed8

Please sign in to comment.