Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing color scheme does not update gradients with system colors or light-dark() #25394

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

pxlcoder
Copy link
Member

@pxlcoder pxlcoder commented Mar 3, 2024

5596316

Changing color scheme does not update gradients with system colors or `light-dark()`
https://bugs.webkit.org/show_bug.cgi?id=267790
rdar://121285450

Reviewed by Matthieu Dubet.

`CSSGradientValue`s cache their generated `StyleImage` when possible. Currently,
caching is disallowed when the gradient contains one of the following color
keywords as a color stop: "-internal-document-text", "-webkit-link",
"-webkit-active-link", and "currentcolor".

However, that denylist is not comprehensive with respect to dynamic colors.
Notably, it excludes almost all system color keywords, and `light-dark()`.
Consequently, the same cached `StyleImage` is used even when the used color
scheme of an element changes.

Fix by updating `BuilderState::isColorFromPrimitiveValueDerivedFromElement`
to account for other scenarios where colors change dynamically.

* LayoutTests/imported/w3c/web-platform-tests/css/css-images/gradient/color-scheme-dependent-color-stops-expected.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-images/gradient/color-scheme-dependent-color-stops-ref.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-images/gradient/color-scheme-dependent-color-stops.html: Added.
* Source/WebCore/css/StyleColor.cpp:
(WebCore::StyleColor::colorFromKeyword):

Drive-by style fix.

(WebCore::StyleColor::containsColorSchemeDependentColor):

System colors, `light-dark()`, and any other unresolved colors containing
either of those, are color-scheme dependent colors.

* Source/WebCore/css/StyleColor.h:
* Source/WebCore/css/color/CSSUnresolvedColor.cpp:
(WebCore::CSSUnresolvedColor::containsColorSchemeDependentColor const):
* Source/WebCore/css/color/CSSUnresolvedColor.h:
* Source/WebCore/style/StyleBuilderState.cpp:
(WebCore::Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement):

Update to cover colors that are color-scheme dependent.

Canonical link: https://commits.webkit.org/275645@main

bbaae52

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 tv ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 tv-sim ✅ 🧪 mac-wk2-stress
✅ 🛠 🧪 merge ✅ 🛠 watch
✅ 🛠 watch-sim

@pxlcoder pxlcoder self-assigned this Mar 3, 2024
@pxlcoder pxlcoder added the CSS Cascading Style Sheets implementation label Mar 3, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 4, 2024
@pxlcoder pxlcoder removed the merging-blocked Applied to prevent a change from being merged label Mar 4, 2024
Copy link
Contributor

@mdubet mdubet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we convert the test to a WPT one ?

@@ -132,6 +132,17 @@ bool StyleColor::containsCurrentColor(const CSSPrimitiveValue& value)
return false;
}

bool StyleColor::containsColorSchemeDependentColor(const CSSPrimitiveValue& value)
{
if (StyleColor::isSystemColorKeyword(value.valueID()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does all system colors depend on color scheme ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of them do, and even the ones that do can be platform-specific. On Cocoa platforms, the majority of them are color-scheme dependent.

However, I think that using an allowlist or denylist for that set of system colors would be complicated to maintain, for limited benefit. Both an allowlist and denylist would have the problem of knowing the keep the list up-to-date, as new colors are added, or colors change their dependency on color-scheme.

Let me know if you feel strongly about a more specific list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, having a platform specific list would require some more code (stuff in /platform..etc..) I will follow your judgment for the cost-benefit ratio

@nt1m
Copy link
Member

nt1m commented Mar 4, 2024

I agree with Matthieu, would be nice to create WPTs

@pxlcoder
Copy link
Member Author

pxlcoder commented Mar 4, 2024

Rewrote the test as a WPT.

@pxlcoder pxlcoder added the merge-queue Applied to send a pull request to merge-queue label Mar 4, 2024
… `light-dark()`

https://bugs.webkit.org/show_bug.cgi?id=267790
rdar://121285450

Reviewed by Matthieu Dubet.

`CSSGradientValue`s cache their generated `StyleImage` when possible. Currently,
caching is disallowed when the gradient contains one of the following color
keywords as a color stop: "-internal-document-text", "-webkit-link",
"-webkit-active-link", and "currentcolor".

However, that denylist is not comprehensive with respect to dynamic colors.
Notably, it excludes almost all system color keywords, and `light-dark()`.
Consequently, the same cached `StyleImage` is used even when the used color
scheme of an element changes.

Fix by updating `BuilderState::isColorFromPrimitiveValueDerivedFromElement`
to account for other scenarios where colors change dynamically.

* LayoutTests/imported/w3c/web-platform-tests/css/css-images/gradient/color-scheme-dependent-color-stops-expected.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-images/gradient/color-scheme-dependent-color-stops-ref.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/css-images/gradient/color-scheme-dependent-color-stops.html: Added.
* Source/WebCore/css/StyleColor.cpp:
(WebCore::StyleColor::colorFromKeyword):

Drive-by style fix.

(WebCore::StyleColor::containsColorSchemeDependentColor):

System colors, `light-dark()`, and any other unresolved colors containing
either of those, are color-scheme dependent colors.

* Source/WebCore/css/StyleColor.h:
* Source/WebCore/css/color/CSSUnresolvedColor.cpp:
(WebCore::CSSUnresolvedColor::containsColorSchemeDependentColor const):
* Source/WebCore/css/color/CSSUnresolvedColor.h:
* Source/WebCore/style/StyleBuilderState.cpp:
(WebCore::Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement):

Update to cover colors that are color-scheme dependent.

Canonical link: https://commits.webkit.org/275645@main
@webkit-commit-queue
Copy link
Collaborator

Committed 275645@main (5596316): https://commits.webkit.org/275645@main

Reviewed commits have been landed. Closing PR #25394 and removing active labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Cascading Style Sheets implementation
Projects
None yet
6 participants