Expose CSS content alt text in the a11y tree
Categories
(Core :: Disability Access APIs, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox128 | --- | fixed |
People
(Reporter: Jamie, Assigned: Jamie)
References
(Blocks 1 open bug)
Details
Attachments
(6 files)
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review |
Spun off bug 1878355 comment 4.
Now that bug 1281158 is fixed, we can get alt text from the CSS content property from layout. However, this isn't sufficient alone to get this exposed in the a11y tree.
Simple test case for pseudo-element:
data:text/html,<style> button::before { content: url("https://via.placeholder.com/10x10.png") / "before"; } </style><button>button
For this case, we should expose an image Accessible in the tree.
Simple test case for replaced element:
data:text/html,<blockquote style="content: url('https://via.placeholder.com/10x10.png') / 'before';">replaced
This one is a bit trickier. Layout creates an image frame for the replacement image, but that frame becomes the primary frame for the blockquote element. There is no child DOM node (not even an anonymous one), so we can't create a child Accessible. We can't use an image accessible because we'd lose the semantics of this being a blockquote element. So, we need to expose a block quote accessible, but with the CSS alt text as the name. This is also what Chromium does.
Assignee | ||
Comment 1•1 year ago
•
|
||
There is a third case: alt text for text content:
data:text/html,<style>button::before { content: "before" / "alt-before"; } </style><button>content
This seems like a terrible use case IMO, but it is what it is. 😒
Unfortunately, the WPT tests in accname/name/comp_name_from_content.html test exactly this case.
Assignee | ||
Comment 2•1 year ago
|
||
All of these cases can have multiple alt strings:
data:text/html,<style> button::before { content: url("https://via.placeholder.com/10x10.png") / "be" "fore"; } </style><button>button
Assignee | ||
Comment 3•1 year ago
|
||
The alt text can also come from an attribute:
data:text/html,<style> button::before { content: url("https://via.placeholder.com/10x10.png") / attr(alt); } </style><button alt="before">button
Assignee | ||
Comment 4•1 year ago
|
||
Without this, a new source file introduced in a subsequent patch causes the compiler to become confused about which TreeWalker we mean: a11y::TreeWalker or dom::TreeWalker.
I don't really understand why this starts happening, but I'm guessing it is related to our unified builds.
Assignee | ||
Comment 5•1 year ago
|
||
This allows us to check for alt text and also to output all of it to a string.
For now, this only supports plain strings.
Assignee | ||
Comment 6•1 year ago
|
||
This directly handles the case where the CSS content property replaces the content of an element with an image plus alt text.
It is also needed to correctly return the alt text for a pseudo-element ImageAccessible, as implemented in a subsequent patch.
Assignee | ||
Comment 7•1 year ago
|
||
Assignee | ||
Comment 8•1 year ago
|
||
CSS alt text makes most sense for an image.
However, even when the content property specifies text, you can still specify alt text!
To support this, this patch does two things:
- Uses the alt text for the TextLeafAccessible instead of the primary text.
- Tweaks nsTextEquivUtils to use the alt text when gathering text from a subtree.
Assignee | ||
Comment 9•1 year ago
|
||
As well as plain strings, alt text items can get their text from an attribute on the Element.
Updated•1 year ago
|
Assignee | ||
Updated•1 year ago
|
Comment 10•1 year ago
|
||
I feel nervous introducing this stuff without proper change notification and cache updates, as uncommon as this type of content is. How hard would it be to do that in a followup?
Assignee | ||
Comment 11•1 year ago
|
||
That's fair. I'm mostly just trying to get us over the Interop hump without investing a lot of time in rare edge cases, but I agree it's not ideal to not handle changes correctly. Some cases probably already work, but handling the others could be a bit tricky. I'll put some time into at least writing tests for the cases that do work and scoping out the effort for a follow-up.
Assignee | ||
Comment 12•1 year ago
|
||
I ended up just updating all the patches to support changes.
Comment 13•1 year ago
|
||
Comment 14•1 year ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/23d81ef2bcec
https://hg.mozilla.org/mozilla-central/rev/dd7609ef8621
https://hg.mozilla.org/mozilla-central/rev/d1e948377369
https://hg.mozilla.org/mozilla-central/rev/0a769799cf8f
https://hg.mozilla.org/mozilla-central/rev/b0624a5487a0
https://hg.mozilla.org/mozilla-central/rev/64e531b3346f
Assignee | ||
Updated•3 months ago
|
Description
•