Skip to content

Commit

Permalink
CSS highlight pseudos: resolve styles for ::search-text
Browse files Browse the repository at this point in the history
This patch resolves the styles for ::search-text twice during element
style recalc (once for :current, once for :not(:current)), and once
for :not(:current) only during getComputedStyle [1].

We use StyleRequest::SearchTextRequest to tell the resolver which
state we want styles for, which then gets plumbed to the selector
checker via ElementRuleCollector, ContextWithStyleScopeFrame, and
SelectorCheckingContext.

SelectorChecker then uses that request to decide whether a selector
with :current is a match, but only when the last dynamic pseudo was
::search-text (using a SelectorCheckingContext flag, like we do for
::selection:window-inactive).

[1] <w3c/csswg-drafts#10297>

Bug: 339298411
Change-Id: Id8cb1cc14399318a18d305f54b64b686a5c6d60a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5528894
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Delan Azabani <dazabani@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1301073}
  • Loading branch information
delan authored and chromium-wpt-export-bot committed May 15, 2024
1 parent e079109 commit 3a7dc02
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle</title>
<link rel="author" name="Delan Azabani" href="mailto:dazabani@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#target::search-text {
background-color: blue;
color: lime;
}
#target::search-text:not(:current) {
background-color: green;
}
#target::search-text:current {
/* FAIL if this matches */
background-color: red;
}
</style>
<div id="target"></div>
<script>
for (const pseudo of ["::search-text"]) {
test(() => {
let style = getComputedStyle(target, pseudo);
assert_equals(style.backgroundColor, "rgb(0, 128, 0)", "Background color is green.");
assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");
}, `getComputedStyle() for ${pseudo}`);

for (illFormedPseudo of [`${pseudo}:`, `${pseudo})`, `${pseudo}(`, `${pseudo}(foo)`, `${pseudo}()`, `:${pseudo}`, `${pseudo}.`]) {
test(() => {
let style = getComputedStyle(target, illFormedPseudo);
let defaultStyle = getComputedStyle(target);
assert_equals(style.backgroundColor, "");
assert_equals(style.color, "");
}, `getComputedStyle() for ${illFormedPseudo} should return an empty CSSStyleDeclaration`);
}
}
</script>

0 comments on commit 3a7dc02

Please sign in to comment.