Skip to content

Commit c73950e

Browse files
andruudchromium-wpt-export-bot
authored andcommitted
[:is/:where] Drop pseudo_id when matching nested complex selectors
If the pseudo_id is set, the SelectorChecker::MatchSelector call for each subselector will fail completely because the dynamic_pseudo of the inner result will not match context.pseudo_id. This check does not make sense to perform for nested complex selectors, since pseudo elements are not valid in nested complex selectors. Hence, we can just set the pseudo_id to kPseudoIdNone at the :is/:where boundary. This fixes a bug where selectors such as ":is(.a .b)::before" would never match. This CL also adds a basic test for pseudo classes. (Not related to the fix). Bug: 568705 Change-Id: I119265836ac0f1b77868537c7685690300c265fd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466278 Reviewed-by: Rune Lillesveen <[email protected]> Commit-Queue: Anders Hartvoll Ruud <[email protected]> Cr-Commit-Position: refs/heads/master@{#816500}
1 parent b1a9ac1 commit c73950e

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<title>:is() combined with pseudo-classes</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<link rel="help" href="https://drafts.csswg.org/selectors-4/#matches">
6+
<link rel="help" href="https://drafts.csswg.org/selectors/#useraction-pseudos">
7+
<style>
8+
button {
9+
color: black;
10+
}
11+
/* Selects #a, #c */
12+
:is(main :where(main #a), #c:nth-child(odd), #d):is(:enabled) {
13+
color: green;
14+
}
15+
/* Selects #b, #d, #f */
16+
button:is(:nth-child(even), span #e):is(:enabled, :where(:disabled)) {
17+
color: blue;
18+
}
19+
</style>
20+
<main>
21+
<button id=a>A</button>
22+
<button id=b>B</button>
23+
<button id=c>C</button>
24+
<button id=d disabled>D</button>
25+
<button id=e disabled>E</button>
26+
<button id=f disabled>F</button>
27+
</main>
28+
<script>
29+
test(function() {
30+
assert_equals(getComputedStyle(a).color, 'rgb(0, 128, 0)');
31+
assert_equals(getComputedStyle(b).color, 'rgb(0, 0, 255)');
32+
assert_equals(getComputedStyle(c).color, 'rgb(0, 128, 0)');
33+
assert_equals(getComputedStyle(d).color, 'rgb(0, 0, 255)');
34+
assert_equals(getComputedStyle(e).color, 'rgb(0, 0, 0)');
35+
assert_equals(getComputedStyle(f).color, 'rgb(0, 0, 255)');
36+
}, ':is() combined with pseudo-classes');
37+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<title>:is() combined with pseudo elements</title>
3+
<link rel="help" href="https://drafts.csswg.org/selectors-4/#matches">
4+
<style>
5+
#b::before, #d::before {
6+
content: "before ";
7+
color: green;
8+
}
9+
#e::after, #h::after {
10+
content: " after";
11+
color: green;
12+
}
13+
#a::first-letter, #b::first-letter {
14+
color: blue;
15+
}
16+
#g::first-line, #l::first-line {
17+
color: magenta;
18+
}
19+
</style>
20+
<main id=main>
21+
<div id=a>a</div>
22+
<div id=b>b</div>
23+
<div id=c>c</div>
24+
<div id=d>d</div>
25+
<div id=e>e</div>
26+
<div id=f>f</div>
27+
<div id=g>g</div>
28+
<div id=h>h</div>
29+
<div id=j>j</div>
30+
<div id=k>k</div>
31+
<div id=l>l<br>l2</div>
32+
</main>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<title>:is() combined with pseudo elements</title>
3+
<link rel="help" href="https://drafts.csswg.org/selectors-4/#matches">
4+
<link rel="match" href="is-where-pseudo-elements-ref.html">
5+
<style>
6+
:is(#a, #c) + :is(main :is(#b, #d))::before {
7+
content: "before ";
8+
color: green;
9+
}
10+
:is(#d + div, #d ~ #h)::after {
11+
content: " after";
12+
color: green;
13+
}
14+
:is(main > #a, #b)::first-letter {
15+
color: blue;
16+
}
17+
:is(:where(main > div + #g, #k + #l))::first-line {
18+
color: magenta;
19+
}
20+
</style>
21+
<main id=main>
22+
<div id=a>a</div>
23+
<div id=b>b</div>
24+
<div id=c>c</div>
25+
<div id=d>d</div>
26+
<div id=e>e</div>
27+
<div id=f>f</div>
28+
<div id=g>g</div>
29+
<div id=h>h</div>
30+
<div id=j>j</div>
31+
<div id=k>k</div>
32+
<div id=l>l<br>l2</div>
33+
</main>

0 commit comments

Comments
 (0)