Skip to content

Commit

Permalink
Cherry-pick 80e4d73. rdar://problem/108683501
Browse files Browse the repository at this point in the history
    [CSS] Resolve "currentcolor" with style if possible
    https://bugs.webkit.org/show_bug.cgi?id=257255
    rdar://108683501

    Reviewed by Tim Nguyen.

    Ideally, we should never try to resolve "currentcolor" during
    style building.
    However, for the rare cases where we do it (gradient, drop-shadow)
    it's better to use the incomplete style than assuming an absolute color.

    * LayoutTests/fast/css/color-mix-various-expected.html: Added.
    * LayoutTests/fast/css/color-mix-various.html: Added.
    * Source/WebCore/style/ColorFromPrimitiveValue.cpp:
    (WebCore::Style::colorFromPrimitiveValueWithResolvedCurrentColor):
    * Source/WebCore/style/ElementRuleCollector.cpp:
    (WebCore::Style::ElementRuleCollector::addMatchedProperties):

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

Identifier: 259548.795@safari-7615-branch
  • Loading branch information
mdubet authored and MyahCobbs committed Jun 1, 2023
1 parent 92a6548 commit 32725f4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 14 additions & 0 deletions LayoutTests/fast/css/color-mix-various-expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<style>
body {
color: green;
}
span {
box-shadow: 5px 5px green;
text-shadow: 5px 5px green;
background: linear-gradient(green, green);
filter: drop-shadow(30px 10px 4px green);
}
</style>

<span> PASS if no crash and only green</span>

14 changes: 14 additions & 0 deletions LayoutTests/fast/css/color-mix-various.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<style>
body {
color: green;
}
span {
box-shadow: 5px 5px color-mix(in srgb, green, currentColor);
text-shadow: 5px 5px color-mix(in srgb, green, currentColor);
background: linear-gradient(green, color-mix(in srgb, green, currentcolor));
filter: drop-shadow(30px 10px 4px color-mix(in srgb, green, currentcolor));
}
</style>

<span> PASS if no crash and only green</span>

6 changes: 3 additions & 3 deletions Source/WebCore/style/ColorFromPrimitiveValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ StyleColor colorFromPrimitiveValue(const Document& document, RenderStyle& style,
Color colorFromPrimitiveValueWithResolvedCurrentColor(const Document& document, RenderStyle& style, const CSSPrimitiveValue& value)
{
// FIXME: 'currentcolor' should be resolved at use time to make it inherit correctly. https://bugs.webkit.org/show_bug.cgi?id=210005
if (StyleColor::isCurrentColor(value)) {
if (StyleColor::containsCurrentColor(value)) {
// Color is an inherited property so depending on it effectively makes the property inherited.
style.setHasExplicitlyInheritedProperties();
style.setDisallowsFastPathInheritance();
return style.color();
}

return colorFromPrimitiveValue(document, style, value, ForVisitedLink::No).absoluteColor();
auto color = colorFromPrimitiveValue(document, style, value, ForVisitedLink::No);
return style.colorResolvingCurrentColor(color);
}

} // namespace Style
Expand Down

0 comments on commit 32725f4

Please sign in to comment.