Skip to content

Commit

Permalink
[CSS] @font-palette-values override-colors accepts only absolute color
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=273888
rdar://127714701

Reviewed by NOBODY (OOPS!).

"The specified <color> must be an absolute color."

https://drafts.csswg.org/css-fonts/#override-color

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-invalid-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid-expected.txt:
* Source/WebCore/css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::absoluteColor const):
* Source/WebCore/css/CSSPrimitiveValue.h:
* Source/WebCore/css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeFontPaletteValuesRule):
  • Loading branch information
mdubet committed May 11, 2024
1 parent 91262be commit 5b400a6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
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

0 comments on commit 5b400a6

Please sign in to comment.