Skip to content

Commit 5b0e164

Browse files
ffiorichromium-wpt-export-bot
authored andcommitted
Paint ::selection foreground over other pseudos
This CL paints ::selection foreground overlay following the spec that says it should be painted on top (see https://drafts.csswg.org/css-pseudo-4/#highlight-text). Although this is not a complete fix that takes the code to comply with the specifications, it makes it closer to them and it fixes cases like the one in the example "Selecting highlighted text" from the set of examples hosted here https://codepen.io/dazabani13/pen/KKqzOJp (note that the example requires the flag --experimental-web-platform-features to be enabled to see the highlights). Also rebaselined tests that were painting underline squiggles over text when it actually should be below (see https://www.w3.org/TR/css-text-decor/#painting-order). Bug: 1147859 Change-Id: Ie150fe3861807fcb74343d7371f1ee7009745272 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3155369 Commit-Queue: Fernando Fiori <[email protected]> Reviewed-by: Rune Lillesveen <[email protected]> Reviewed-by: Dan Clark <[email protected]> Reviewed-by: Delan Azabani <[email protected]> Cr-Commit-Position: refs/heads/main@{#922211}
1 parent d965d8b commit 5b0e164

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<meta charset="UTF-8">
3+
<style>
4+
#highlighted {
5+
background: cyan;
6+
color: blue;
7+
}
8+
::selection {
9+
background: blue;
10+
color: cyan;
11+
}
12+
</style>
13+
<body><span id="highlighted">Text should be blue over cyan here and <span id="selected">cyan over blue here</span>.</span>
14+
<script>
15+
getSelection().setBaseAndExtent(selected, 0, selected, 1);
16+
</script>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<meta charset="UTF-8">
3+
<title>CSS Highlight API Test: </title>
4+
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
5+
<link rel="match" href="custom-highlight-painting-below-selection-ref.html">
6+
<meta name="assert" value="Highlight overlay is painted below selection overlay">
7+
<style>
8+
::highlight(foo) {
9+
background: cyan;
10+
color: blue;
11+
}
12+
::selection {
13+
background: blue;
14+
color: cyan;
15+
}
16+
</style>
17+
<body>Text should be blue over cyan here and <span id="selected">cyan over blue here</span>.
18+
<script>
19+
let highlightRange = new Range();
20+
highlightRange.setStart(document.body.firstChild, 0);
21+
highlightRange.setEnd(document.body.lastChild, 0);
22+
CSS.highlights.set("foo", new Highlight(highlightRange));
23+
getSelection().setBaseAndExtent(selected, 0, selected, 1);
24+
</script>

0 commit comments

Comments
 (0)