Skip to content

Commit 5745733

Browse files
committed
[css-pseudo] Initial draft of ::selection
1 parent d1e8d47 commit 5745733

2 files changed

Lines changed: 279 additions & 36 deletions

File tree

css-pseudo/Overview.bs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,116 @@ Styling the ''::first-letter'' Pseudo-element</h4>
417417
approximate font sizes, for example to align baselines. Also, the glyph
418418
outline may be taken into account when formatting.
419419

420+
<h2 id="highlight-pseudos">
421+
Highlight Range Pseudo-element: ''::selection''</h2>
422+
423+
The <dfn>::selection</dfn> pseudo-element represents
424+
the portion of a document that has been highlighted by the user.
425+
This also applies, for example, to selected text within an editable text field.
426+
427+
Issue: We want to add other types of selections, such as spelling-error highlights.
428+
429+
Issue: Active vs. inactive selections are often styled differently. Currently no way to distinguish.
430+
431+
<p>The <dfn>root highlight</dfn> is a multi-piece overlay
432+
over the entire tree,
433+
portions of which are selected and correspond to the ''::selection'' pseudo-element.
434+
Each box owns the piece of of the overlay corresponding to any text or replaced content
435+
directly contained by the box.
436+
For text, the corresponding overlay must cover at least the entire em box
437+
and may extend further above/below the em box to the line box edges.
438+
Spacing between two characters may also be part of the overlay,
439+
in which case it belongs to the innermost element that contains both characters
440+
and is selected when both characters are selected
441+
For replaced content, the associated overlay must cover at least the entire replaced object,
442+
and may extend outward to include the element's entire content box.
443+
The overlay may also include other other areas within the border-box of an element;
444+
in this case, those areas belong to the innermost such element that contains the area.
445+
446+
Issue: See
447+
<a href="http://lists.w3.org/Archives/Public/www-style/2008Nov/0022.html">F2F minutes</a>,
448+
<a href="http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html">dbaron's message</a>,
449+
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0247.html">Daniel's thread</a>,
450+
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0261.html">Gecko notes</a>,
451+
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0366.html">Opera notes</a>,
452+
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0280.html">Webkit notes</a>
453+
454+
Each element draws its own portion of the highlighted overlay,
455+
which receives the styles specified by the ''::selection'' pseudo-element styles
456+
for which it or one of its ancestors is the <i>originating element</i>.
457+
When multiple styles conflict,
458+
the winning style is the one belonging to the innermost element
459+
after cascading.
460+
461+
Issue: This could alternately be described in terms of inheritance.
462+
So, how do we want ''inherit'' to behave here?
463+
Should it inherit from the parent ''::selection''
464+
or the <i>originating element</i>?
465+
Opera does the former, Gecko/Blink the latter.
466+
467+
<p class="advisement">
468+
Authors wanting multiple selections styles should use
469+
<strong>'':root::selection''</strong>
470+
for their document-wide selection style,
471+
since this will allow clean overriding in descendants.
472+
(''::selection'' alone would apply to every element in the tree,
473+
overriding the more specific styles of any ancestors.)
474+
475+
<h3 id="highlight-styling">
476+
Styling Highlighted Ranges</h3>
477+
478+
The following properties apply to ''::selection'' pseudo-elements:
479+
480+
<ul>
481+
<li>'color'
482+
<li>'background-color'
483+
<li>'cursor' (optional)
484+
<li>'outline' and its longhands (optional)
485+
<li>'text-decoration' and its associated properties (optional)
486+
</ul>
487+
488+
Issue: What properties should be included here?
489+
Only color and bgcolor seem supported; but text-decoration is needed for spellcheck.
490+
491+
If 'color' is not specified, the text's actual color must be used for the highlight.
492+
<span class="issue">Can we reuse ''currentColor'' for this, now that it computes to itself?</span>
493+
(As usual, the initial 'background-color' is ''transparent''.)
494+
495+
The UA should use the OS-default selection color
496+
when neither 'color' nor 'background-color' has been specified by the author.
497+
498+
Issue: This behavior does not let us use the normal cascade for representing the OS colors
499+
and thus violates <a href="http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html">dbaron's #2 requirement</a>. :(
500+
Can we do anything about that?
501+
502+
The ''::selection'' pseudo element draws its background
503+
over the selected portion of the element,
504+
immediately below any positioned descendants
505+
(i.e. just before step 8 in <a href="http://www.w3.org/TR/CSS21/zindex.html">CSS2.1&sect;E.2</a>).
506+
It also suppresses the drawing of any selected text
507+
and instead redraws that text
508+
(and any text decorations)
509+
over that background.
510+
511+
Issue: Implementations seem to redraw text decorations and text shadows over the selection background.
512+
This seems particularly weird if the text decoration color doesn't match the text.
513+
Perhaps the only thing visible should be the text itself (unless the background is transparent)
514+
and any text decorations specified for the selection itself.
515+
(Alternately the decorations should get the color of the selected text,
516+
not the unselected text.)
517+
518+
For non-replaced content, the UA must honor the 'color' and 'background-color'
519+
(including their alpha channels) as specified.
520+
However, for replaced content, the UA should create a semi-transparent wash
521+
to coat the content so that it can show through the selection.
522+
This wash should be of the specified 'background-color' if that is not ''transparent'',
523+
else the specified 'color';
524+
however the UA may adjust the alpha channel if it is opaque.
525+
526+
Issue: The wash requirement is a minor update on WebKit's behavior. Gecko & Opera just use the default selection color for the wash.
527+
528+
Issue: This whole section needs vocabulary cleanup.
529+
420530
<h2 id="generated-content">
421531
Generated Content Pseudo-elements: ''::before'' and ''::after''</h2>
422532

0 commit comments

Comments
 (0)