Selectors, vendor prefixes (again...) and IE9 and Opera and WebKit from Boris Zbarsky on 2010-05-14 (www-style@w3.org from May 2010) (original) (raw)

On 5/14/10 6:41 AM, Daniel Glazman wrote:

Mozilla, please also contribute a mail about ::-moz-selection possibly more precise than the contents of [1].

The behavior of ::-moz-selection is about (based on code inspection; I might have missed corner cases but I don't think I have) like this:

When it comes time to paint the selection for a "text box" (the object involved has no CSS spec equivalent, but roughly corresponds to a box for some text; it acts like an inline box with no margin/border/padding and dimensions determined by the text), the following steps are performed:

  1. Find the "selection element", which is the nearest ancestor element of the text. This search skips over pseudo-elements. In particular, for text in a ::before/::after the element found will be the parent element of the ::before/::after.
  2. Determine the set of matching rules by looking for rules that use the ::-moz-selection pseudo-element and match the "selection element" for the rest of the selector. If this set is empty, abort these steps and do selection painting in some other way.
  3. Determine the specified style for the ::-moz-selection using the set of rules determined in step 2.
  4. Determine the computed style for the -moz-selection by using the style of the "text box" as the parent style to inherit from and using the specified style determined in step 3.
  5. Use the resulting computed 'background-color' and 'color' to paint the selection.

This is all only true if the document is currently focused. If it's not focused, we use the OS-default styling for inactive selections, I believe.

Attached is a small HTML testcase showing some of the behavior. Obvious differences from other browsers I have here:

Opera:

Webkit nightly:

-Boris