Re: Selectors, vendor prefixes (again...) and IE9 and Opera and WebKit

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:
   * Gecko doesn't allow selecting generated content, Opera does
   * Opera seems to do something quite weird for
     "color: currentColor"; in particular, it treats it differently
     from "color: inherit".

Webkit nightly:
   * Selection inside ::first-line doesn't seem to inherit from
     the first-line pseudo-element in webkit
   * The text inside ::first-letter is not selectable in webkit.
   * Webkit seems to ignore the specified background on ::selection if
     it's specified as "none" and uses the default background color. In
     particular, "background: none" and "background: transparent" have
     different behavior in webkit, which is rather weird.

-Boris

Received on Friday, 14 May 2010 15:59:11 UTC