Skip to content

Commit e842010

Browse files
committed
[css-pseudo-4] Rewrite ::selection et al. cascade using inheritance mechanism and make everything fit together into some kind of coherent model. w3c#2474
1 parent 82c63d5 commit e842010

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

css-pseudo-4/Overview.bs

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -491,28 +491,14 @@ Styling Highlights</h3>
491491

492492
Issue: Are there any other properties that should be included here?
493493

494-
Note: Historically (and at the time of writing)
495-
only 'color' and 'background-color' have been interoperably supported.
496-
497-
If 'color' is not specified, the text (and text decoration)'s
498-
unselected color must be used for the highlighted text.
499-
(As usual, the initial 'background-color' is ''transparent''.)
500-
501-
Issue: Can we reuse ''currentColor'' for this, now that it computes to itself?
502-
503-
The UA should use the OS-default highlight colors
504-
when neither 'color' nor 'background-color' has been specified by the author.
505-
506-
Note: This paired-cascading behavior
507-
does not allow <a href="http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html">using the normal cascade</a>
508-
to represent the OS default selection colors.
509-
However it has been interoperably implemented in browsers
510-
and is thus probably a Web-compatibility requirement.
511-
512494
The 'color' property specifies the color of both the text
513495
and all line decorations (underline, overline, line-through)
514496
and emphasis marks ('text-emphasis')
515-
applied to the text.
497+
applied to the text
498+
by the <a>originating element</a> and its ancestors and descendants.
499+
500+
Note: Historically (and at the time of writing)
501+
only 'color' and 'background-color' have been interoperably supported.
516502

517503
<h3 id=highlight-bounds>
518504
Area of a Highlight</h3>
@@ -552,12 +538,17 @@ Area of a Highlight</h3>
552538
<h3 id=highlight-cascade>
553539
Cascading and Per-Element Highlight Styles</h3>
554540

555-
Each element draws its own portion of the <a>highlight overlay</a>,
556-
which receives the styles specified by the <a>highlight pseudo-element</a> styles
557-
for which that element or one of its ancestors is the <a>originating element</a>.
541+
Each element draws its own active portions of the <a>highlight overlays</a>,
542+
which receives the styles specified by
543+
the corresponding <a>highlight pseudo-element</a> styles
544+
for which that element is the <a>originating element</a>.
558545
When multiple styles conflict,
559-
the winning style is the one belonging to the innermost element
560-
after cascading.
546+
the winning style is determined by the cascade.
547+
When any supported property is not given a value by the cascade,
548+
it's value is determined by inheritance from
549+
the corresponding <a>highlight pseudo-element</a>
550+
of its <a>originating element</a>'s parent element
551+
(regardless of whether that property is an <a>inherited property</a>).
561552

562553
<div class="example">
563554
For example, if the following rules were applied:
@@ -570,17 +561,11 @@ Cascading and Per-Element Highlight Styles</h3>
570561
<pre>
571562
&lt;p>Highlight this &lt;em>and this&lt;/em>.&lt;/p>
572563
</pre>
573-
The highlight would be green throughout,
564+
The selection highlight would be green throughout,
574565
with yellow text outside the <code>&lt;em></code> element
575566
and orange text inside it.
576567
</div>
577568

578-
Issue: This could alternately be described in terms of inheritance.
579-
The observable differences would be in how ''inherit'' and ''unset'' behave.
580-
Should it inherit from the parent ''::selection''
581-
or the <a>originating element</a>?
582-
Opera does the former, Gecko/Blink the latter.
583-
584569
<p class="advisement">
585570
Authors wanting multiple selections styles should use
586571
<strong>'':root::selection''</strong>
@@ -611,35 +596,57 @@ Cascading and Per-Element Highlight Styles</h3>
611596
</pre>
612597
</div>
613598

599+
The UA should use the OS-default highlight colors for ''::selection''
600+
when neither 'color' nor 'background-color' has been specified by the author.
601+
602+
Note: This paired-cascading behavior
603+
does not allow using the normal cascade
604+
to represent the OS default selection colors.
605+
However it has been interoperably implemented in browsers
606+
and is thus probably a Web-compatibility requirement.
607+
614608
<h3 id="highlight-painting">
615609
Painting the Highlight</h3>
616610

617611
Each <a>highlight pseudo-element</a> draws its background
618-
over the active portion of the overlay,
612+
over the corresponding portion of the <a>highlight overlay</a>,
619613
painting it
620614
immediately below any positioned descendants
621615
(i.e. just before step 8 in <a href="https://www.w3.org/TR/CSS21/zindex.html">CSS2.1&sect;E.2</a>).
622-
It also suppresses the drawing of any selected text
623-
(and any text decorations applied to that text)
624-
and instead redraws that text
616+
Its outline, if any, is painted immediately over its background.
617+
The ''::selection'' overlay is drawn
618+
over the ''::spelling-error'' overlay
619+
which is drawn over the ''::grammar-error'' overlay.
620+
621+
A <a>highlight pseudo-element</a>
622+
also suppresses the drawing of any selected text
623+
(and any text decorations applied to that text).
624+
Instead the topmost active <a>highlight overlay</a>
625+
redraws that text
625626
(and its decorations)
626-
over the <a>highlight overlay</a> background
627-
using the specified 'color'.
627+
over the <a>highlight overlay</a> backgrounds
628+
(and outlines, if any)
629+
using its own 'color',
630+
with ''currentColor'' representing the 'color'
631+
of the next <a>highlight pseudo-element</a> layer below,
632+
falling back finally to that of the <a>originating element</a>
633+
(the colors that would otherwise be used).
634+
Any text decorations introduced by each <a>highlight pseudo-element</a>
635+
are stacked in the same order as their backgrounds
636+
over the text’s original decorations
637+
and are all drawn, in their own colors.
628638

629639
Issue: What should happen with text shadows?
630640
Drawing them in their original color is disconcerting if that color is not a shade of gray.
641+
Maybe if the overlay has a background, suppress any text shadows below it?
631642

632643
For non-replaced content, the UA must honor the 'color' and 'background-color'
633644
(including their alpha channels) as specified.
634645
However, for replaced content, the UA should create a semi-transparent wash
635646
to coat the content so that it can show through the selection.
636647
This wash should be of the specified 'background-color' if that is not ''transparent'',
637648
else of the specified 'color';
638-
however the UA may adjust the alpha channel if it is opaque.
639-
640-
The ''::selection'' overlay is drawn
641-
over the ''::spelling-error'' overlay
642-
which is drawn over the ''::grammar-error'' overlay.
649+
however the UA may adjust the alpha channel.
643650

644651
<h3 id="highlight-security">
645652
Security and Privacy Considerations</h3>

0 commit comments

Comments
 (0)