Skip to content

Commit 98a553c

Browse files
schenney-chromiummoz-wptsync-bot
authored andcommittedFeb 1, 2025
Bug 1944794 [wpt PR 50379] - Allow custom properties in highlight pseudos, a=testonly
Automatic update from web-platform-tests Allow custom properties in highlight pseudos This is a workaround for the use case of custom properties defined and used in the same rule for ::selection pseudos. The use case arises from tooling, particularly Tailwind CSS, and it caused a stable regression when Highlight Inheritance was launched. This change restores the original behavior in that highlight pseudos can use custom properties defined in the highlight itself. The custom properties are not inherited through the highlight inheritance chain, so this change does not result in confusion about the source of custom properties when Highlight Inheritance is enabled: the properties still come from the originating element and then the highlight pseudo itself, never it's parent highlight. CSS Spec PR: w3c/csswg-drafts#11528 Fixed: 381125910 Change-Id: I0f89e6b8ad96d097ce1e2b39c179a270d472991f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6053860 Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org> Commit-Queue: Stephen Chenney <schenney@chromium.org> Cr-Commit-Position: refs/heads/main@{#1413271} -- wpt-commits: 184a7bf8907297dd81a6dec8632a63c0b0a843cc wpt-pr: 50379
1 parent 8c97fef commit 98a553c

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed
 

‎testing/web-platform/tests/css/css-pseudo/highlight-cascade/highlight-cascade-008.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
--background-color: green;
1212
--decoration-color: yellow;
1313
}
14-
::selection {
14+
:root::selection {
1515
--background-color: cyan;
1616
--decoration-color: magenta;
1717
}
@@ -22,10 +22,10 @@
2222
text-decoration-color: var(--decoration-color, red);
2323
}
2424
span {
25-
--background-color: blue;
25+
--background-color: purple;
2626
}
2727
span::selection {
28-
--background-color: purple;
28+
--background-color: blue;
2929
background-color: var(--background-color, red);
3030
}
3131
</style>

‎testing/web-platform/tests/css/css-pseudo/highlight-cascade/highlight-cascade-009.html

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
<link rel="author" title="Stephen Chenney" href="mailto:schenney@chromium.org">
55
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-cascade">
66
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6641">
7-
<meta name="assert" content="This test verifies that custom properties used in highlight pseudos are taken from the originating element.">
7+
<meta name="assert" content="This test verifies that custom properties used in highlight pseudos are taken from the highlight and originating element.">
88
<script src="../support/selections.js"></script>
99
<link rel="stylesheet" href="../support/highlights.css">
1010
<script src="/resources/testharness.js"></script>
1111
<script src="/resources/testharnessreport.js"></script>
1212
<style>
13-
:root {
13+
body {
1414
--background-color: green;
1515
--decoration-color: green;
1616
}
17-
::selection {
17+
body::selection {
1818
--decoration-color: purple;
1919
}
2020
div::selection {
@@ -28,14 +28,17 @@
2828
<script>
2929
selectNodeContents(document.querySelector("body"));
3030

31+
const div_style = getComputedStyle(document.querySelector("div"));
3132
const body_selection = getComputedStyle(document.querySelector("body"), "::selection");
3233
const div_selection = getComputedStyle(document.querySelector("div"), "::selection");
3334
test(() => void assert_equals(body_selection.getPropertyValue("--background-color"), "green"),
3435
"body ::selection uses the originating custom property");
35-
test(() => void assert_equals(body_selection.getPropertyValue("--decoration-color"), "green"),
36+
test(() => void assert_equals(body_selection.getPropertyValue("--decoration-color"), "purple"),
3637
"body ::selection does not use its own custom property");
3738
test(() => void assert_equals(div_selection.getPropertyValue("--decoration-color"), "green"),
3839
"div::selection uses the originating element custom property");
39-
test(() => void assert_equals(div_selection.getPropertyValue("--background-color"), "green"),
40+
test(() => void assert_equals(div_selection.getPropertyValue("--background-color"), "blue"),
4041
"div::selection does not use its own custom property");
42+
test(() => void assert_equals(div_style.getPropertyValue("--background-color"), "green"),
43+
"div::selection properties are not present on the originating element");
4144
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>CSS Pseudo-Elements Test: highlight cascade: inheritance of custom properties</title>
4+
<link rel="author" title="Stephen Chenney" href="mailto:schenney@chromium.org">
5+
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-cascade">
6+
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/6641">
7+
<meta name="assert" content="This test verifies that custom properties used in highlight pseudos are taken from the highlight and originating element.">
8+
<script src="../support/selections.js"></script>
9+
<link rel="stylesheet" href="../support/highlights.css">
10+
<script src="/resources/testharness.js"></script>
11+
<script src="/resources/testharnessreport.js"></script>
12+
<style>
13+
:root::selection {
14+
--background-color: red;
15+
}
16+
div::selection {
17+
background-color: var(--background-color, green);
18+
}
19+
</style>
20+
<body>
21+
<div>Some text</div>
22+
</body>
23+
<script>
24+
selectNodeContents(document.querySelector("body"));
25+
26+
const div_selection = getComputedStyle(document.querySelector("div"), "::selection");
27+
test(() => void assert_equals(div_selection.backgroundColor, "rgb(0, 128, 0)"),
28+
"div::selection does not inherit custom properties from the highlight parent");
29+
test(() => void assert_equals(div_selection.getPropertyValue("--background-color"), ""),
30+
"--background-color has no computed value on div::selection");
31+
</script>

‎testing/web-platform/tests/css/css-pseudo/highlight-styling-001.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
<link rel="author" title="Delan Azabani" href="mailto:dazabani@igalia.com">
55
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-styling">
66
<link rel="match" href="highlight-styling-001-ref.html">
7-
<meta name="assert" value="This test verifies that ::selection styles cannot set custom properties.">
7+
<meta name="assert" value="This test verifies that ::selection styles can set custom properties and they over-ride the originating element.">
88
<script src="support/selections.js"></script>
99
<link rel="stylesheet" href="support/highlights.css">
1010
<style>
1111
main {
12+
--x: red;
1213
font-size: 7em;
1314
margin: 0.5em;
1415
}
1516
main::selection {
16-
--x: red;
17+
--x: green;
1718
color: white;
18-
background-color: var(--x, green);
19+
background-color: var(--x, blue);
1920
}
2021
</style>
2122
<p>Test passes if the text below is white on green.

0 commit comments

Comments
 (0)
Please sign in to comment.