Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WPT updates for highlight painting order (css-pseudo)
This patch updates four web platform tests involving CSS highlight painting order, which should help us rework our highlight paint code to comply with css-pseudo. • css/css-pseudo/selection-overlay-and-{grammar,spelling}-001.html • two manual tests, checking the relative painting order of ::selection and ::{grammar,spelling}-error overlays • added @contenteditable/@spellcheck/@lang to test element • added Selection#removeAllRanges call to work around API change • replaced the grammar test sentence with a more obvious example • rewrote most of the comments for clarity • css/css-pseudo/highlight-painting-order.html • new reftest, checking relative painting order of text, original shadows, ::selection background, and ::selection shadows • based on <https://bucket.daz.cat/work/igalia/0/3.html> • css/css-pseudo/selection-text-shadow-{006-manual,016{,-ref}}.html • one manual test, one reftest, checking that text-shadow:none in ::selection suppresses all original shadows (even if multiple) • dropped because they are no longer compliant (highlight overlays have their own shadows, independent of the content’s shadows) Bug: 1147859 Change-Id: I29bab589e3924778d555d96537d010dc33ed003f
- Loading branch information
1 parent
c9bb4ac
commit aba51be
Showing
8 changed files
with
156 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<style> | ||
p { | ||
font-size: 7em; | ||
text-shadow: 0.2500em 0.2500em #C0C000; | ||
position: relative; | ||
color: transparent; | ||
|
||
/* | ||
https://drafts.csswg.org/css-pseudo-4/#highlight-bounds | ||
For text, the corresponding overlay must cover at least | ||
the entire em box and may extend further above/below the | ||
em box to the line box edges. | ||
*/ | ||
line-height: 1; | ||
} | ||
p > span { | ||
position: absolute; | ||
color: initial; | ||
text-shadow: none; | ||
} | ||
p > span > span { | ||
background: #C0C0C0; | ||
text-shadow: 0.5000em 0.5000em #3838E0; | ||
} | ||
</style> | ||
<p><span>q<span>uic</span>k</span>quick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>CSS Pseudo-Elements Test: highlight painting order</title> | ||
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-painting"> | ||
<link rel="help" href="https://drafts.csswg.org/css-text-decor-4/#painting"> | ||
<link rel="help" href="https://www.w3.org/TR/CSS22/zindex.html#painting-order"> | ||
<link rel="match" href="highlight-painting-order-ref.html"> | ||
<meta name="assert" value="highlight overlays are painted in the correct order, including both the element’s shadows and the highlight’s shadows"> | ||
<style> | ||
p { | ||
font-size: 7em; | ||
text-shadow: 0.2500em 0.2500em #C0C000; | ||
|
||
/* | ||
https://drafts.csswg.org/css-pseudo-4/#highlight-bounds | ||
For text, the corresponding overlay must cover at least | ||
the entire em box and may extend further above/below the | ||
em box to the line box edges. | ||
*/ | ||
line-height: 1; | ||
} | ||
p::selection { | ||
background: #C0C0C0; | ||
text-shadow: 0.5000em 0.5000em #3838E0; | ||
} | ||
</style> | ||
<p>quick | ||
<script> | ||
const target = document.querySelector("p"); | ||
const range = document.createRange(); | ||
range.selectNodeContents(target); | ||
range.setStart(target.childNodes[0], 1); | ||
range.setEnd(target.childNodes[0], 4); | ||
const selection = getSelection(); | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Replaces the current selection (if any) with a new range, after | ||
* it’s configured by the given function. | ||
*/ | ||
function selectRangeWith(fun) { | ||
const selection = getSelection(); | ||
|
||
// Deselect any ranges that happen to be selected, to prevent the | ||
// Selection#addRange call from ignoring our new range (see | ||
// <https://www.chromestatus.com/feature/6680566019653632> for | ||
// more details). | ||
selection.removeAllRanges(); | ||
|
||
// Create and configure a range. | ||
const range = document.createRange(); | ||
fun(range); | ||
|
||
// Select our new range. | ||
selection.addRange(range); | ||
} | ||
|
||
/** | ||
* Replaces the current selection (if any) with a new range, spanning | ||
* the contents of the given node. | ||
*/ | ||
function selectNodeContents(node) { | ||
const previousActive = document.activeElement; | ||
|
||
selectRangeWith(range => range.selectNodeContents(node)); | ||
|
||
// If the selection update causes the node or an ancestor to be | ||
// focused (Chromium 80+), unfocus it, to avoid any focus-related | ||
// styling such as outlines. | ||
if (document.activeElement != previousActive) { | ||
document.activeElement.blur(); | ||
} | ||
} | ||
|
||
/** | ||
* Tries to convince a UA with lazy spellcheck to check and mark the | ||
* contents of the given nodes (form fields or @contenteditables). | ||
* | ||
* Both focus and selection can be used for this purpose, but only | ||
* focus works for @contenteditables. | ||
*/ | ||
function trySpellcheck(...nodes) { | ||
// This is inherently a flaky test risk, but Chromium (as of 87) | ||
// seems to cancel spellcheck on a node if it wasn’t the last one | ||
// focused for “long enough” (though immediate unfocus is ok). | ||
// setInterval(0) is usually not long enough. | ||
const interval = setInterval(() => { | ||
if (nodes.length > 0) { | ||
const node = nodes.shift(); | ||
node.focus(); | ||
node.blur(); | ||
} else { | ||
clearInterval(interval); | ||
} | ||
}, 250); | ||
} |