Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement style resolution for stateful pseudo classes #448

Merged
merged 5 commits into from
Oct 9, 2020

Conversation

kasperisager
Copy link
Contributor

@kasperisager kasperisager commented Oct 8, 2020

This pull request implements style resolution for the following stateful pseudo classes:

  • :hover
  • :active
  • :focus
  • :focus-within
  • :focus-visible
  • :link
  • :visited

A new class, Context, has been introduced to model context-dependant information during selector matching, such as which element is currently in focus, which elements have been visited, and so on. This class is heavily inspired by Servo (components/selectors/context.rs) and works by modelling state as bit flags associated with elements. As an example, this means that it's up to the caller, not Selector#matches(), to decide if a given element links to a resource that has been visited; Selector#matches() simply checks the associated state, not the actual URL of the element being matched against.

This pull request also introduces changes to the way cascade is managed to allow efficiently re-computing cascade for elements when context changes. The Cascade class is now no longer immutable, but instead incrementally builds up a rule tree and caches entries for elements keyed on context. A "baseline" cascade is performed at construction time and computes cascade for all elements in a document with an empty context to benefit from ancestor filtering during selector matching. From then, matching declarations for individual elements can be queried with an optional context that defaults to an empty context. Whenever a non-yet-seen context is passed for an element, the rule tree is extended with matching declarations for the element and associated context.

Closes #447.

@kasperisager kasperisager added the major Backwards-incompatible change that touches public API label Oct 8, 2020
@kasperisager kasperisager self-assigned this Oct 8, 2020
@kasperisager kasperisager marked this pull request as ready for review October 9, 2020 10:40
@kasperisager kasperisager requested a review from Jym77 October 9, 2020 10:41
packages/alfa-selector/src/context.ts Show resolved Hide resolved
packages/alfa-selector/src/selector.ts Outdated Show resolved Hide resolved
packages/alfa-selector/src/selector.ts Outdated Show resolved Hide resolved
@kasperisager kasperisager requested a review from Jym77 October 9, 2020 13:00
@kasperisager kasperisager merged commit 6c1cc13 into master Oct 9, 2020
@kasperisager kasperisager deleted the style-states branch October 9, 2020 14:04
kasperisager added a commit that referenced this pull request Oct 19, 2020
* master: (190 commits)
  Bump jest from 26.5.2 to 26.5.3 (#453)
  Bump @types/jquery from 3.5.2 to 3.5.3 (#455)
  Bump webdriverio from 6.6.2 to 6.6.6 (#458)
  Bump @types/node from 14.11.7 to 14.11.10 (#460)
  Bump @types/react from 16.9.51 to 16.9.53 (#461)
  Bump mdn-browser-compat-data from 1.0.40 to 1.1.0 (#451)
  Bump webdriverio from 6.6.0 to 6.6.2 (#449)
  Implement style resolution for stateful pseudo classes (#448)
  Bump @types/node from 14.11.5 to 14.11.7 (#450)
  Bump @angular/core from 10.1.4 to 10.1.5 (#446)
  Fix several `Element#tabIndex()` cases (#445)
  Implement presentational role inheritance (#443)
  Improve handling of cyclic `aria-owns` references (#442)
  Bump jest from 26.5.0 to 26.5.2 (#441)
  Bump webdriverio from 6.5.2 to 6.6.0 (#440)
  Implement traversal API for `Graph` (#426)
  Exclude from the accessibility tree text nodes of parent elements with `visibility: hidden` (#437)
  Implement step 2H of the name computation (#430)
  Bump @types/node from 14.11.2 to 14.11.5 (#436)
  Bump @types/node from 14.11.2 to 14.11.4 (#431)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major Backwards-incompatible change that touches public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement style resolution for stateful pseudo classes
2 participants