Skip to content

Commit f781a1c

Browse files
andruudchromium-wpt-export-bot
authored andcommitted
Let Node::ParentComputedStyle return nullptr for Document
During Element::RecalcOwnStyle, we call ParentComputedStyle(), which currently returns a non-nullptr ComputedStyle on the document element. This suggests that we will or should inherit from that style, and that is not right. Later in the style resolution process, we *do* correctly use nullptr in most cases [1], but for the new highlight code we set the parent override to ParentComputedStyle()'s result directly, causing problems. This CL: - Returns nullptr from ParentComputedStyle() if the parent is not an Element. - Moves ParentComputedStyle() to Element. - Allows pseudo-style-resolves without a parent override, since this is the correct thing to do for the new highlight pseudo behavior. - Fixes a bug where initial custom property values would not be available in :root::selection (etc). This is because those values are set up in InitialStyleForElement, and the highlight inheritance chain never used that function until now. Note that there is a still an initial-value bug for ::selection (etc) on non-:root, but a fix for that will come later. [1] ElementResolveContext::ParentStyle, which checks for IsElementNode Bug: 1024156 Change-Id: I3f0f2c1841cbe3e7ffeedb3a295b6f470957efc7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3173223 Reviewed-by: Rune Lillesveen <[email protected]> Reviewed-by: Delan Azabani <[email protected]> Commit-Queue: Anders Hartvoll Ruud <[email protected]> Cr-Commit-Position: refs/heads/main@{#924262}
1 parent 891bc02 commit f781a1c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<title>Initial custom property values in :root::selection rule</title>
3+
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-cascade">
4+
<script src="support/selections.js"></script>
5+
<style>
6+
:root::selection {
7+
background-color: green;
8+
}
9+
</style>
10+
<main>PASS if background-color is green when selected</main>
11+
<script>
12+
selectNodeContents(document.querySelector("main"));
13+
</script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<title>Initial custom property values in :root::selection rule</title>
3+
<link rel="help" href="https://drafts.csswg.org/css-pseudo-4/#highlight-cascade">
4+
<link rel="match" href="highlight-cascade-003-ref.html">
5+
<meta name="assert" value="This test verifies that the initial value given in a custom property registration is respected, when the property is referenced in ::selection styles but no value is defined. The initial value is not the guaranteed-invalid value, so the fallback value in var() is not used.">
6+
<script src="support/selections.js"></script>
7+
<style>
8+
@property --bg {
9+
syntax: "<color>";
10+
inherits: false;
11+
initial-value: green;
12+
}
13+
:root::selection {
14+
background-color: var(--bg, red);
15+
}
16+
</style>
17+
<main>PASS if background-color is green when selected</main>
18+
<script>
19+
selectNodeContents(document.querySelector("main"));
20+
</script>

0 commit comments

Comments
 (0)