Skip to content

Commit 0f8c892

Browse files
committed
[css-ui] Add second value for caret-color
This controls the color of the text when it overlaps block carets. Closes #13723
1 parent a2fa0c1 commit 0f8c892

File tree

1 file changed

+86
-6
lines changed

1 file changed

+86
-6
lines changed

css-ui-4/Overview.bs

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,12 +1371,18 @@ Insertion caret</h3>
13711371
though it sometimes resembles a caret,
13721372
is not a caret (it's a cursor).
13731373

1374+
Within the context of this section, <dfn>character</dfn> is
1375+
to be understood as <em>extended grapheme cluster</em>,
1376+
as defined in [[!UAX29]], and <dfn>visible character</dfn>
1377+
means a character with a non-zero advance measure.
1378+
1379+
13741380
<h4 id="caret-color" caniuse="css-caret-color">
13751381
Coloring the Insertion Caret: the 'caret-color' property</h4>
13761382

13771383
<pre class="propdef">
13781384
Name: caret-color
1379-
Value: auto | <<color>>
1385+
Value: auto | <<color>> [auto | <<color>>]?
13801386
Initial: auto
13811387
Applies to: text or elements that [=accept text input=]
13821388
Inherited: yes
@@ -1416,6 +1422,8 @@ Coloring the Insertion Caret: the 'caret-color' property</h4>
14161422
</wpt>
14171423

14181424
This property controls the color of the [=insertion caret=].
1425+
It takes one or two values.
1426+
The first value has the following effects:
14191427

14201428
<dl>
14211429
<dt>auto
@@ -1443,6 +1451,83 @@ Coloring the Insertion Caret: the 'caret-color' property</h4>
14431451
</textarea>
14441452
</div>
14451453

1454+
The second value has no effect when 'caret-shape' is ''caret-shape/bar'', ''caret-shape/underscore'',
1455+
or ''caret-shape/auto'' behaving as either of these values.
1456+
If 'caret-shape' is ''caret-shape/block''--
1457+
or ''caret-shape/auto'' behaving as ''caret-shape/block''--
1458+
then it determines the color of the text [=overlapping the caret=].
1459+
If the second value is omitted,
1460+
the behavior is the same as if <code>auto</code> had been specified.
1461+
1462+
<dl>
1463+
<dt>auto
1464+
<dd>
1465+
User agents must automatically adjust the color of the text [=overlapping the caret=]
1466+
to ensure good visibility and contrast between the text
1467+
and the underlying ''caret-shape/block'' caret,
1468+
if using ''currentColor'' would result in poor readability.
1469+
The specifics of how to assess contrast
1470+
and how to pick a sufficiently contrasty color are up to the user agent.
1471+
1472+
<dt><<color>>
1473+
<dd>
1474+
The color of text [=overlapping the caret=] is the specified color.
1475+
1476+
Note: Authors wishing to ensure that the color of the text remains constant
1477+
regardless of the position of a ''caret-shape/block'' caret
1478+
can specify ''currentColor'' as the second value of 'caret-color'.
1479+
</dl>
1480+
1481+
Text considered to <dfn>overlap the caret</dfn>
1482+
is the next [=visible character=] after the insertion point, if any.
1483+
1484+
<div class=example id=caret-color-2-values>
1485+
This illustrates the effect of the second value of 'caret-color' on ''caret-shape/block'' carets.
1486+
In each of the sample renderings below,
1487+
the insertion point is between the letters u and m.
1488+
1489+
<style>
1490+
@keyframes caret-color-2-ref { 50% { background: transparent; color: inherit; } }
1491+
#caret-color-2 {
1492+
min-width: 25em;
1493+
}
1494+
#caret-color-2,
1495+
#caret-color-2 td,
1496+
#caret-color-2 th {
1497+
border: solid 1px;
1498+
}
1499+
#caret-color-2 td+td {
1500+
background:white;
1501+
color: black;
1502+
}
1503+
</style>
1504+
<table id="caret-color-2">
1505+
<tr>
1506+
<th>'caret-color:'
1507+
<th>Sample rendering
1508+
<th>Your browser<br>(focus each cell to see the [=caret=])
1509+
1510+
<tr>
1511+
<td>''black'' (or ''black auto'')
1512+
<td>Lorem ipsu<span style="background: #000; color: #fff; animation: caret-color-2-ref 1s step-end infinite;">m</span>
1513+
<td contentEditable=true style="caret-shape: block; caret-color: black;">Lorem Ipsum
1514+
1515+
<tr>
1516+
<td>''black yellow''
1517+
<td>Lorem ipsu<span style="background: #000; color: yellow; animation: caret-color-2-ref 1s step-end infinite;">m</span>
1518+
<td contentEditable=true style="caret-shape: block; caret-color: black yellow;">Lorem Ipsum
1519+
1520+
<tr>
1521+
<td>''black black''
1522+
<td>Lorem ipsu<span style="background: #000; animation: caret-color-2-ref 1s step-end infinite;">m</span>
1523+
<td contentEditable=true style="caret-shape: block; caret-color: black black;">Lorem Ipsum
1524+
</table>
1525+
</div>
1526+
1527+
Optionally, user agents may treat as overlapping only those parts of next [=visible character=]
1528+
which visually intersect with the ''caret-shape/block'',
1529+
and adjust the color of those parts only.
1530+
14461531

14471532
<h4 id="caret-animation">
14481533
Animation of the insertion caret: 'caret-animation'</h4>
@@ -1608,11 +1693,6 @@ Shape of the insertion caret: 'caret-shape'</h4>
16081693
This property allows authors to specify
16091694
the desired shape of the [=insertion caret=].
16101695

1611-
Within the context of this definition, <dfn>character</dfn> is
1612-
to be understood as <em>extended grapheme cluster</em>,
1613-
as defined in [[!UAX29]], and <dfn>visible character</dfn>
1614-
means a character with a non-zero advance measure.
1615-
16161696
<dl dfn-type=value dfn-for=caret-shape>
16171697
<dt><dfn>auto</dfn>
16181698
<dd>

0 commit comments

Comments
 (0)