Implement style resolution for stateful pseudo classes #448
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, notSelector#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.