Re: UA's implementation of ::selection

From: "Alan Gresley" <alan@css-class.com>
> François REMY wrote:
>> Why do you want to create a pseudo element for each
>> element of the DOM? It would be sufficient to use a
>> ::selection object for the root element. Or at least only
>> one for each element of the DOM needing a special
>> styling. It's not needed to create a new instance of
>> the selection styling object for each element of the
>> DOM. They can share the same.
>>
>> Or is that impossible ?
>
>
> I am amazed to see 'selection' classed as a 'pseudo element' at all.
>
> For me it behaves much like a 'dynamic pseudo class' or 'UI element states 
> pseudo-class'. Both types for which there is a user action.
>
> When I highlight text nodes, I see a different background-color (not the 
> default selection color) when I use this.
>
> *::selection {background:red;}
>
> But since this happen by user action, I as a author would expect to be 
> using something like this.
>
> *:selection {background:red;}
>

I agree with you ::selection isn't a true pseudo-element.
But we can't consider it as a pseudo-class either. Why ?
Because when a selection occur, an additionnal layer is
drawn between the background and the text layer, and
the color of the selected text changed.

So, it sounds it's a kind of pseudo-element in the sense
it's, as ::marker, something that's drawn, that holds to an
element, but which is not represented in the DOM.

The only problem I see is that a selection works accross
multiple elements of the DOM. So, each element should
be responsible to draw the selection in their own bound,
but only on the part of their bound no other child element
is responsible of. This is this part of the work that's the
most complex to define.

My intuition is that the only rule that should matter is "the
nearest element of this pixel is A, so A is responsible of the
drawing of the selection layer at this point".

I've looked at what Safari does, I've found it to be a lot more
complex, and it wasn't adapted to ::selection in the sense an
element may have ::selection { background: red } and still have
parts of it beeing blue-selectionned (the part which is after
the last text line, for example).

Are there people interested that I realise images illustrating
the concept of selection based on a selection layer put bet-
ween the text and the background layer, and how we can
give the UA some piece of freedom to make sure they could
stil behave in a way that's compatible with their own OS
integration ?

F. Remy 

Received on Sunday, 16 May 2010 08:43:12 UTC