W3C home > Mailing lists > Public > www-style@w3.org > April 2008

Re: Suggestion for CSS3 selectors (fwd)

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Mon, 28 Apr 2008 18:49:18 -0500
Message-ID: <4816627E.1010804@mit.edu>
To: "Brian J. Fink" <desertowl23@gmail.com>
CC: www-style@w3.org

> 1. Scan through the document, checking for selector1.
 > 2. At each occurence of selector1, check if its direct parent is selector2.
 > 3. Apply the style to that parent.

The thing is, the most common styling operation is not "what elements does this 
style apply to" but "what styles apply to this element"?  That is, given a 
DOMElement and a list of style rules, which of the rules apply?

So this description of the algorithm needed:

 > a. for Direct Ancestor, the browser would only have to check the
 > immediate children of the element, and only until it found a match,
 > and
 > b. for Indirect Ancestor, the browser could scan one level at a time
 > in the document tree, until a match was found.

is basically correct.

The "match the rightmost selector and then decide what to restyle accordingly" 
does work for dynamic changes, though something like "$A B" would involve 
restyling _all_ A that are ancestors of B, not just the first one found, which 
is all matching normally needs.  But for initial style resolution, you really do 
end up digging around in the subtree rooted at the "target" node.

I should note that for use cases like querySelector(All), where you plan to 
grovel the whole DOM anyway, there are other possible optimizations, but that 
involves having different matching algorithms for querySelector(All) and style 
resolution, which is undesirable, imo.

-Boris


-Boris
Received on Monday, 28 April 2008 23:51:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:05 GMT