Servo/StyleUpdateOnDOMChange
< Servo
Handling of style updates when the DOM changes
In what cases are style updates needed?
Throughout, we use the terms "selector" and "sequence of simple selectors" as defined in CSS3 Selectors. In addition, we use the term "subject sequence of simple selectors" to describe the sequence of simple selectors that must match elements that the full selector matches. In Selectors Level 3 this is the rightmost sequence of simple selectors, but there are proposals to allow this to be other parts of the selector.
DOM changes, broadly construed to include mutations of the structure of the DOM tree, changes to element attributes, and internal state changes on elements, can cause changes to styles in the following situations:
- Whether an element matches the subject sequence of simple selectors of some selector changes due to attribute or state changes on the element. The set of rules applying to that element then needs to be recomputed, and inheritance might need to be redone for descendants.
- Whether an element matches the subject sequence of simple selectors of some selector changes due to insertions or deletions of element subtrees in the DOM. This can be caused by + and ~ combinators, as well as by use of structural pseudo-classes like :nth-child, :empty, etc. The consequences are the same as for item 1. The hard part here is figuring out which elements are affected by a given insertion/deletion.
- Whether an element matches a non-subject sequence of simple selectors changes due to attribute or state changes on the element. The set of elements which now match the subject sequence of simple selectors needs to be recomputed. What that set is depends on the exact combinators used in the selector.