Servo/StyleUpdateOnDOMChange: Difference between revisions

Line 28: Line 28:


=== Handling of insertions and deletions ===
=== Handling of insertions and deletions ===
When during selector matching a '~' or '+' combinator or a structural pseudo-class is encountered, Gecko sets a flag on the parent of the things being matched that indicates that it had children affected by "slow selectors".  There are actually 4 different flags here that handle different cases: :empty selectors, selectors like :nth-last-child which might require restyles on any append/removal/insertion, selectors like :only-child or :last-child or :first-child which only matter for the first/last kids of the element, and selectors like :nth-child which might require restyles on insertion and removal but NOT on append.
When an insertion or removal happens, if the parent of the node being inserted/removed has one of the slow selector flags, Gecko posts "recompute the set of matching rules" events on either the parent, or all its kids, or the kids that come after the insertion location, depending on which of the above flags are set.
This setup, again, makes sure that dynamic changes are not missed, while trying to optimize the common append case as much as possible.  But it will often be more pessimistic than it needs to be, and in particular can end up flagging with slow selector flags elements whose descendants don't actually match the selector with the structural pseudo-class or sibling combinator anyway, because of a simple selector further to the left which fails to match ancestors of the flagged element.
308

edits