Bug 138196 - Implement :role pseudo selector
Summary: Implement :role pseudo selector
Status: RESOLVED WORKSFORME
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on: 138310
Blocks:
  Show dependency treegraph
 
Reported: 2014-10-29 15:56 PDT by Dean Jackson
Modified: 2023-10-15 16:46 PDT (History)
5 users (show)

See Also:


Attachments
Patch (7.00 KB, patch)
2014-11-03 06:06 PST, Sukolsak Sakshuwong
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dean Jackson 2014-10-29 15:56:59 PDT
At TPAC 2014, the CSS WG agreed to add a :role(foo) pseudo-selector to match against the active ARIA role.

e.g. :role(button) would match
<button>
<input type="button">
<input type="submit">
<div role="button">
<div role="something-not-supported button">
etc

http://www.w3.org/TR/wai-aria/roles#button
Comment 1 Radar WebKit Bug Importer 2014-10-29 15:57:33 PDT
<rdar://problem/18818174>
Comment 2 Dean Jackson 2014-10-29 16:02:00 PDT
This should go into the spec soon:
http://dev.w3.org/csswg/mediaqueries-4/
Comment 3 Dean Jackson 2014-10-29 16:02:23 PDT
This should go into the spec soon:
http://dev.w3.org/csswg/mediaqueries-4/
Comment 5 Dean Jackson 2014-10-29 16:10:56 PDT
Turns out the Web Inspector already has some code for this.
Comment 6 Dean Jackson 2014-10-29 16:12:50 PDT
Copying some info from Ben into here:

Implementing this would involve: extending the CSS Parser to parse :role(), extend CSSSelector to store the information about :role(), extend Element to expose the active role, match the CSSSelector with the active role, ensure the correct style invalidation when the role changes.
Since this is a new feature, this also involves writing *a lot* of tests.
Comment 7 Dean Jackson 2014-10-29 16:18:32 PDT
I think the entry point is AccessibilityObject::computedRoleString()

which, given an element/node, you get to via something like:

if (AXObjectCache* axObjectCache = node->document().axObjectCache()) {
  AccessibilityObject* axObject = axObjectCache->getOrCreate(node);
  ...
Comment 8 James Craig 2014-10-29 16:21:56 PDT
Will need to discuss how to move the relevant portions (role/label) out of the accessibility-only code. We don't want to enable all the accessibility logic for everyone.
Comment 9 chris fleizach 2014-10-29 17:30:30 PDT
(In reply to comment #8)
> Will need to discuss how to move the relevant portions (role/label) out of
> the accessibility-only code. We don't want to enable all the accessibility
> logic for everyone.

So is this meant to apply to the resolved role, or the developer role?

I can imagine it might be confusing if the resolved role is different from what the user writes down
Comment 10 James Craig 2014-10-29 17:58:07 PDT
(In reply to comment #9)
> So is this meant to apply to the resolved role, or the developer role?

Computed role, not the content attribute. This may also be accessed as Element.computedRole() if a related change goes into DOM.

> I can imagine it might be confusing if the resolved role is different from
> what the user writes down

There are already attribute selectors, so if the dev needed the content attribute value, they already could already match on [role="whatever"]:

<button role="foo">test<button>

Would be matched by either:

*[role="foo"]
*:role(button)
Comment 11 Sukolsak Sakshuwong 2014-11-03 06:06:11 PST
Created attachment 240844 [details]
Patch
Comment 12 Sukolsak Sakshuwong 2014-11-03 06:13:54 PST
Sorry, I meant to submit this as a separate patch.
Comment 13 James Craig 2019-04-24 17:47:42 PDT
IIRC, we decided this was un-implementable in its current state, and would require an exhaustive rewrite of WebCore. Closing.
Comment 14 James Craig 2023-10-15 16:46:31 PDT
> IIRC, we decided this was un-implementable in its current state, and would require an exhaustive rewrite of WebCore.

A more complete version of that is captured in these comments:
- https://github.com/w3c/csswg-drafts/issues/3596#issuecomment-460135566
- https://github.com/w3c/csswg-drafts/issues/3596#issuecomment-1763539455