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

[CSS] @font-palette-values override-colors accepts only absolute color #28398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -7431,7 +7431,3 @@ webkit.org/b/272417 imported/w3c/web-platform-tests/svg/path/property/priority.s

# re-import css/css-align WPT failure
webkit.org/b/271692 imported/w3c/web-platform-tests/css/css-align/blocks/align-content-block-break-overflow-020.html [ ImageOnlyFailure ]

# re-import css/css-fonts/parsing crash. Skip until https://bugs.webkit.org/show_bug.cgi?id=273888 is fixed
webkit.org/b/273888 imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid.html [ Skip ]
webkit.org/b/273888 imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html [ Skip ]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PASS CSS Fonts Module Level 4: parsing @font-palette-values 18
PASS CSS Fonts Module Level 4: parsing @font-palette-values 19
PASS CSS Fonts Module Level 4: parsing @font-palette-values 20
PASS CSS Fonts Module Level 4: parsing @font-palette-values 21
FAIL CSS Fonts Module Level 4: parsing @font-palette-values 22 assert_equals: expected -1 but got 27
PASS CSS Fonts Module Level 4: parsing @font-palette-values 22
PASS CSS Fonts Module Level 4: parsing @font-palette-values 23
PASS CSS Fonts Module Level 4: parsing @font-palette-values 24

Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ PASS CSS Fonts Module Level 4: parsing @font-palette-values 29
PASS CSS Fonts Module Level 4: parsing @font-palette-values 30
PASS CSS Fonts Module Level 4: parsing @font-palette-values 31
PASS CSS Fonts Module Level 4: parsing @font-palette-values 32
FAIL CSS Fonts Module Level 4: parsing @font-palette-values 33 assert_equals: expected "0 color-mix(in lch, red, blue)" but got "0 rgba(0, 0, 0, 0)"
FAIL CSS Fonts Module Level 4: parsing @font-palette-values 33 assert_equals: expected "0 color-mix(in lch, red, blue)" but got ""

15 changes: 15 additions & 0 deletions Source/WebCore/css/CSSPrimitiveValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ CSSPrimitiveValue::CSSPrimitiveValue(Color color)
new (reinterpret_cast<Color*>(&m_value.colorAsInteger)) Color(WTFMove(color));
}

Color CSSPrimitiveValue::absoluteColor() const
{
if (isColor())
return color();

// FIXME: there are some cases where we can resolve a dynamic color at parse time, we should support them.
if (isUnresolvedColor())
return { };

if (StyleColor::isAbsoluteColorKeyword(valueID()))
return StyleColor::colorFromAbsoluteKeyword(valueID());

return { };
}

CSSPrimitiveValue::CSSPrimitiveValue(StaticCSSValueTag, CSSValueID valueID)
: CSSValue(PrimitiveClass)
{
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/css/CSSPrimitiveValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class CSSPrimitiveValue final : public CSSValue {
bool isColor() const { return primitiveUnitType() == CSSUnitType::CSS_RGBCOLOR; }
const Color& color() const { ASSERT(isColor()); return *reinterpret_cast<const Color*>(&m_value.colorAsInteger); }

// Return an absolute color if possible, otherwise an invalid color.
// https://drafts.csswg.org/css-color-5/#absolute-color
Color absoluteColor() const;

static Ref<CSSPrimitiveValue> createCustomIdent(String);
bool isCustomIdent() const { return primitiveUnitType() == CSSUnitType::CustomIdent; }

Expand Down
5 changes: 4 additions & 1 deletion Source/WebCore/css/parser/CSSParserImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,10 @@ RefPtr<StyleRuleFontPaletteValues> CSSParserImpl::consumeFontPaletteValuesRule(C
if (!pair.key().isInteger())
continue;
unsigned key = pair.key().value<unsigned>();
Color color = pair.color().isColor() ? pair.color().color() : StyleColor::colorFromKeyword(pair.color().valueID(), { });
auto color = pair.color().absoluteColor();
// Ignore non absolute color https://drafts.csswg.org/css-fonts/#override-color
if (!color.isValid())
continue;
overrideColors.append(std::make_pair(key, color));
}
}
Expand Down