Skip to content
Permalink
Browse files
font-variant-alternates: historical-forms doesn't reflect properly …
…via StylePropertyMap

https://bugs.webkit.org/show_bug.cgi?id=249337

Reviewed by Tim Nguyen.

`font-variant-alternates: historical-forms` doesn't reflect properly via
StylePropertyMap. Even though `historical-forms` is a supported keyword for
this CSS property [1], we wouldn't get a CSSKeywordValue when reading the
property value back. The issue is that we convert to a FontVariantAlternates
internally and then back to a CSSValue. The function to convert back to a
CSSValue (fontVariantAlternatesPropertyValue) was only handling the `normal`
keyword but not the `historical-forms` one.

[1] https://w3c.github.io/csswg-drafts/css-fonts/#font-variant-alternates-prop

* LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/the-stylepropertymap/properties/font-variant-alternates-expected.txt:
* Source/WebCore/css/ComputedStyleExtractor.cpp:
(WebCore::fontVariantAlternatesPropertyValue):

Canonical link: https://commits.webkit.org/257955@main
  • Loading branch information
cdumez committed Dec 15, 2022
1 parent 6198c51 commit 37f48652e37e505cc21a3a655d024de17fcc02ce
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
@@ -0,0 +1,15 @@
Testing for the font-variant-alternates computed values

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


target.style.fontVariantAlternates = 'historical-forms swash(flowing)';
PASS getComputedStyle(target).fontVariantAlternates is "historical-forms swash(flowing)"
target.style.fontVariantAlternates = 'historical-forms';
PASS getComputedStyle(target).fontVariantAlternates is "historical-forms"
target.style.fontVariantAlternates = 'normal';
PASS getComputedStyle(target).fontVariantAlternates is "normal"
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="target"></div>
<script>
description("Testing for the font-variant-alternates computed values");

const target = document.getElementById("target");
evalAndLog("target.style.fontVariantAlternates = 'historical-forms swash(flowing)';");
shouldBeEqualToString("getComputedStyle(target).fontVariantAlternates", "historical-forms swash(flowing)");

evalAndLog("target.style.fontVariantAlternates = 'historical-forms';");
shouldBeEqualToString("getComputedStyle(target).fontVariantAlternates", "historical-forms");

evalAndLog("target.style.fontVariantAlternates = 'normal';");
shouldBeEqualToString("getComputedStyle(target).fontVariantAlternates", "normal");
</script>
</body>
</html>
@@ -5,7 +5,7 @@ PASS Can set 'font-variant-alternates' to CSS-wide keywords: unset
PASS Can set 'font-variant-alternates' to CSS-wide keywords: revert
PASS Can set 'font-variant-alternates' to var() references: var(--A)
PASS Can set 'font-variant-alternates' to the 'normal' keyword: normal
FAIL Can set 'font-variant-alternates' to the 'historical-forms' keyword: historical-forms assert_equals: expected "CSSKeywordValue" but got "CSSStyleValue"
PASS Can set 'font-variant-alternates' to the 'historical-forms' keyword: historical-forms
PASS Setting 'font-variant-alternates' to a length: 0px throws TypeError
PASS Setting 'font-variant-alternates' to a length: -3.14em throws TypeError
PASS Setting 'font-variant-alternates' to a length: 3.14cm throws TypeError
@@ -1473,10 +1473,19 @@ static Ref<CSSValue> fontVariantNumericPropertyValue(FontVariantNumericFigure fi
return valueList;
}

static FontVariantAlternatesValues historicalFormsValues()
{
FontVariantAlternatesValues values;
values.historicalForms = true;
return values;
}

static Ref<CSSValue> fontVariantAlternatesPropertyValue(FontVariantAlternates alternates)
{
if (alternates.isNormal())
return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
if (alternates.values() == historicalFormsValues())
return CSSValuePool::singleton().createIdentifierValue(CSSValueHistoricalForms);

return CSSFontVariantAlternatesValue::create(WTFMove(alternates));
}

0 comments on commit 37f4865

Please sign in to comment.