Skip to content

Commit c801c26

Browse files
dandclarkchromium-wpt-export-bot
authored andcommitted
currentColor for highlight pseudos uses the correct originating element
Per the resolutions in [1], for a highlight pseudo with currentColor as its color, getComputedStyle(element, "::highlight(...)").color should return the color of the originating element (since this is the color that would be painted if that highlight were the only one applied). This is currently achieved by having Color::ApplyValue grab the color from the originating element for highlights using currentColor. This hits a problem when we do getComputedStyle(element, "::highlight(...)") on an element that doesn't directly match a highlight pseudo, but is a child of an element matching a highlight pseudo. In that case we end up reusing the computed style for the highlight that was built for the ancestor element. That highlight style still uses the color from the ancestor element, which is the wrong result. Here we fix this by having StyleAdjuster::AdjustComputedStyle adjust the style to use the color from the correct originating element. [1] w3c/csswg-drafts#6818 (comment) Bug: 1321540 Change-Id: Ibbc9126811fe52ecadb358713857df05c1143708 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3690272 Reviewed-by: Delan Azabani <[email protected]> Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Dan Clark <[email protected]> Cr-Commit-Position: refs/heads/main@{#1012045}
1 parent 0663e2d commit c801c26

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle for currentcolor</title>
4+
<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">
5+
<link rel="match" href="reference/highlight-pseudos-currentcolor-inheritance-computed-002-ref.html">
6+
<p>Pass if text below is green on lime, and the text itself represents green, not initial (black).</p>
7+
<main>FAIL</main>
8+
<main>FAIL</main>
9+
<style>
10+
main { color: green; }
11+
:root::selection { background-color: lime; }
12+
:root::highlight(foo) { background-color: lime;}
13+
</style>
14+
<script>
15+
const [selection, highlight] = document.querySelectorAll("main");
16+
17+
let selectionRange = new Range();
18+
selectionRange.selectNode(selection);
19+
window.getSelection().addRange(selectionRange);
20+
selection.textContent = getComputedStyle(selection, "::selection").color;
21+
22+
let highlightRange = new Range();
23+
highlightRange.selectNode(highlight);
24+
CSS.highlights.set("foo", new Highlight(highlightRange));
25+
highlight.textContent = getComputedStyle(highlight, "::highlight(foo)").color;
26+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>CSS Reftest Reference</title>
4+
<p>Pass if text below is green on lime, and the text itself represents green, not initial (black).</p>
5+
<main>rgb(0, 128, 0)</main>
6+
<main>rgb(0, 128, 0)</main>
7+
<style>
8+
main { color: green; }
9+
main::selection { background-color: lime; color: green; }
10+
main::highlight(foo) { background-color: lime; color: green; }
11+
</style>
12+
<script>
13+
const [selection, highlight] = document.querySelectorAll("main");
14+
15+
let selectionRange = new Range();
16+
selectionRange.selectNode(selection);
17+
window.getSelection().addRange(selectionRange);
18+
19+
let highlightRange = new Range();
20+
highlightRange.selectNode(highlight);
21+
CSS.highlights.set("foo", new Highlight(highlightRange));
22+
</script>

0 commit comments

Comments
 (0)