Skip to content

Commit

Permalink
[css-pseudo] clarify paired cascade (#6386 + #6779 + #6774 + #7837) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
delan authored Oct 6, 2022
1 parent d82b2c9 commit 4acdbd8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 18 deletions.
9 changes: 6 additions & 3 deletions css-highlight-api-1/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ Applicable Properties</h4>
<h4 id=default-styles>
Default Styles</h4>

UAs must not define any styles for [=custom highlight pseudo-elements=] in the default UA
stylesheet. A [=custom highlight pseudo-element=] inherits the styles of its
[=originating element=].
UAs must not define any default UA stylesheet rules
or <a spec=css-pseudo>default highlight colors</a>
for any [=custom highlight pseudo-elements=].
In other words,
when some content is highlighted by an unstyled custom highlight,
its presentation must not change.

<h4 id=c-and-h>
Cascading and Inheritance</h4>
Expand Down
80 changes: 65 additions & 15 deletions css-pseudo-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ Styling Highlights</h3>

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

The 'color' property specifies the color of both the text
Note: The 'color' property sets the color of
both the text
and all line decorations (underline, overline, line-through)
and emphasis marks ('text-emphasis')
applied to the text
Expand Down Expand Up @@ -724,16 +725,68 @@ Default UA Styles</h3>
/* Represent default spelling/grammar error styling in an adjustable way */
:root::spelling-error { text-decoration-line: spelling-error; }
:root::grammar-error { text-decoration-line: grammar-error; }
/* Highlight targeted text */
:root::target-text { color: MarkText; background: Mark; }
</pre>

Some [=highlight pseudo-elements=]
should have <dfn>paired default highlight colors</dfn>--
a default 'color' and 'background-color'
provided by the UA
that are either used or overridden together,
see [[#paired-defaults]].
For ''::selection'' they should correspond to
''HighlightText'' and ''Highlight'',
while for ''::target-text'' they should correspond to
''MarkText'' and ''Mark''.

UAs may apply additional effects to enhance the presentation
of highlighted content,
for example dimming content other than the highlighted text
or transitioning out a highlight style based on user interactions or timing.
These are not controlled by CSS.

ISSUE: UA tweaks to the presentation of highlights
in ways that <em>are</em> controlled by CSS
are currently under discussion
in <a href='https://github.com/w3c/csswg-drafts/issues/6853'>Issue 6853</a>.

<h4 id="paired-defaults">
Paired Defaults</h4>

For compatibility reasons,
[=paired default highlight colors=]
must only be [=used value|used=]
when neither 'color' nor 'background-color'
yield a [=cascaded value=]
from the [=author origin=]
(or inherit their value from the author origin).
When a highlight color is ''revert'' or ''revert-layer'',
the origin <em>after</em> rolling back the cascade
determines the [=cascaded value=]’s [=cascade origin|origin=].

Note: Because this rule is for compatibility reasons,
it does not apply to other similar properties
like 'fill-color' or 'stroke-color'.

<div class="example">
For example,
given the following markup:
<pre class="lang-markup">
&lt;p>Highlight this &lt;em>and this&lt;/em>.&lt;/p>
</pre>
Any of the following rules
would suppress the default 'background-color'
for ''::selection''
in the <code>&lt;em></code> element
if given by the author:
<pre class="lang-css">
em::selection { color: initial; }
em::selection { color: inherit; }
em::selection { color: unset; }
em::selection { color: green; }
p::selection { color: green; }
</pre>
</div>

<h3 id=highlight-bounds>
Area of a Highlight</h3>

Expand Down Expand Up @@ -788,13 +841,21 @@ Cascading and Per-Element Highlight Styles</h3>
for which that element is the <a>originating element</a>.
When multiple styles conflict,
the winning style is determined by the cascade.

When any supported property is not given a value by the cascade,
its value is determined by inheritance from
or given a value of ''inherit'' or ''unset'',
its [=specified value=] is determined by inheritance from
the corresponding <a>highlight pseudo-element</a>
of its <a>originating element</a>'s parent element.
This occurs regardless of whether that property is an <a>inherited property</a>,
including [=registered custom properties=] where the [=inherits descriptor=] is false.

Additionally,
for [=highlight pseudo-elements=] originating from the root element,
the [=inherited value=] of 'color'
is ''currentColor'',
not the [=initial value=].

<wpt>
css/css-pseudo/active-selection-051.html
css/css-pseudo/active-selection-052.html
Expand Down Expand Up @@ -857,17 +918,6 @@ Cascading and Per-Element Highlight Styles</h3>
css/css-pseudo/cascade-highlight-002.html
</wpt>


The UA must use its own highlight colors for ''::selection'' only
when neither 'color' nor 'background-color' has been specified by the author.

Note: This paired-cascading behavior
does not allow using the normal cascade
(e.g. '':root::selection'' rules in the <a>UA style sheet</a>)
to represent the OS default selection colors.
However it has been interoperably implemented in browsers
and is thus probably a Web-compatibility requirement.

<h3 id="highlight-painting">
Painting the Highlight</h3>

Expand Down

0 comments on commit 4acdbd8

Please sign in to comment.