Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix font-variant shorthand serialization
https://bugs.webkit.org/show_bug.cgi?id=247919 rdar://102339716 Reviewed by Darin Adler. - Fixed bug where font-variant-ligatures: none + another non-default longhand would serialize even if it not possible - Clean up fontValue()/fontVariantValue() to not consider implicit/explicit anymore used to represent default/system values - Refactor to remove appendFontLonghandValueIfExplicit() * LayoutTests/fast/text/font-variant-shorthand-expected.txt: * LayoutTests/fast/text/font-variant-shorthand.html: * LayoutTests/fast/css/font-property-priority-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/cssom/font-shorthand-serialization-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/cssom/font-variant-shorthand-serialization-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/font-variant-shorthand-serialization.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/cssom/font-shorthand-serialization-expected.txt: * Source/WebCore/css/CSSProperties.json: Updated ordering to match order from the spec (which matters for serialization). * Source/WebCore/css/StyleProperties.cpp: (WebCore::StyleProperties::fontValue const): Inlined parts of appendFontLonghandValueIfExplicit, simplified font-stretch handling. (WebCore::StyleProperties::fontVariantValue const): Rewrite to stop using appendFontLonghandValueIfExplicit, fix various serialization issues when collapsing longhands. (WebCore::canUseShorthandForLonghand): Add notes on why collapsing is not possible. (WebCore::StyleProperties::appendFontLonghandValueIfExplicit const): Deleted. * Source/WebCore/css/StyleProperties.h: * Source/WebCore/css/parser/CSSPropertyParser.cpp: (WebCore::CSSPropertyParser::consumeFontVariantShorthand): Canonical link: https://commits.webkit.org/256681@main
- Loading branch information
Showing
9 changed files
with
226 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ported/w3c/web-platform-tests/css/cssom/font-variant-shorthand-serialization-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
PASS font-variant: normal serialization | ||
PASS font-variant: none serialization | ||
PASS font-variant-ligatures: none serialization with non-default value for another longhand | ||
PASS font-variant: normal with non-default longhands | ||
PASS CSS-wide keyword in one longhand | ||
PASS CSS-wide keyword in shorthand | ||
PASS font: menu serialization | ||
|
130 changes: 130 additions & 0 deletions
130
...Tests/imported/w3c/web-platform-tests/css/cssom/font-variant-shorthand-serialization.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<!doctype html> | ||
<html> | ||
<meta charset="utf-8"> | ||
<title>Serialization of font-variant shorthand</title> | ||
<link rel="help" href="https://drafts.csswg.org/cssom-1/#serialize-a-css-declaration-block"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" /> | ||
<div id="target"></div> | ||
<script> | ||
const cssWideKeywords = ["initial", "inherit", "unset", "revert", "revert-layer"]; | ||
function test_serialization_set(expected) { | ||
for (const [property, value] of Object.entries(expected)) { | ||
if (!CSS.supports(`${property}: initial`)) | ||
continue; | ||
assert_equals(target.style[property], value, `${property} was set`); | ||
} | ||
} | ||
function setWithValue(value) { | ||
return { | ||
"font-variant-ligatures": value, | ||
"font-variant-caps": value, | ||
"font-variant-alternates": value, | ||
"font-variant-numeric": value, | ||
"font-variant-east-asian": value, | ||
"font-variant-position": value, | ||
"font-variant-emoji": value, | ||
"font-variant": value | ||
}; | ||
} | ||
const emptySet = setWithValue(""); | ||
const normalSet = setWithValue("normal"); | ||
const nonDefaultValues = { | ||
"font-variant-ligatures": "common-ligatures discretionary-ligatures", | ||
"font-variant-caps": "small-caps", | ||
"font-variant-alternates": "historical-forms", | ||
"font-variant-numeric": "oldstyle-nums stacked-fractions", | ||
"font-variant-east-asian": "ruby", | ||
"font-variant-position": "sub", | ||
"font-variant-emoji": "emoji", | ||
}; | ||
test(function(t) { | ||
target.style.fontVariant = "normal"; | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
|
||
test_serialization_set(normalSet); | ||
}, "font-variant: normal serialization"); | ||
|
||
test(function(t) { | ||
target.style.fontVariant = "normal"; | ||
target.style.fontVariantLigatures = "none"; | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
|
||
const expected = Object.assign({}, normalSet); | ||
expected["font-variant-ligatures"] = "none"; | ||
expected["font-variant"] = "none"; | ||
|
||
test_serialization_set(expected); | ||
}, "font-variant: none serialization"); | ||
|
||
test(function(t) { | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
for (const [property, value] of Object.entries(nonDefaultValues)) { | ||
if (property == "font-variant-ligatures" || !CSS.supports(`${property}: initial`)) | ||
continue; | ||
target.style.fontVariant = "normal"; | ||
target.style.fontVariantLigatures = "none"; | ||
target.style[property] = value; | ||
|
||
const expected = Object.assign({}, normalSet); | ||
expected["font-variant-ligatures"] = "none"; | ||
expected["font-variant"] = ""; | ||
expected[property] = value; | ||
|
||
test_serialization_set(expected); | ||
target.removeAttribute("style"); | ||
} | ||
}, "font-variant-ligatures: none serialization with non-default value for another longhand"); | ||
|
||
test(function(t) { | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
|
||
for (const [property, value] of Object.entries(nonDefaultValues)) { | ||
if (!CSS.supports(`${property}: initial`)) | ||
continue; | ||
target.style.fontVariant = "normal"; | ||
target.style[property] = value; | ||
|
||
const expected = Object.assign({}, normalSet); | ||
expected[property] = value; | ||
expected["font-variant"] = value; | ||
test_serialization_set(expected); | ||
|
||
target.removeAttribute("style"); | ||
} | ||
}, "font-variant: normal with non-default longhands"); | ||
|
||
test(function(t) { | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
for (const keyword of cssWideKeywords) { | ||
target.style.fontVariant = "normal"; | ||
target.style.fontVariantLigatures = keyword; | ||
|
||
const expected = Object.assign({}, normalSet); | ||
expected["font-variant-ligatures"] = keyword; | ||
expected["font-variant"] = ""; | ||
test_serialization_set(expected); | ||
target.removeAttribute("style"); | ||
} | ||
}, "CSS-wide keyword in one longhand"); | ||
|
||
test(function(t) { | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
|
||
for (const keyword of cssWideKeywords) { | ||
target.style.fontVariant = keyword; | ||
test_serialization_set(setWithValue(keyword)); | ||
target.removeAttribute("style"); | ||
} | ||
}, "CSS-wide keyword in shorthand"); | ||
|
||
test(function(t) { | ||
target.style.fontVariant = "normal"; | ||
target.style.font = "menu"; | ||
t.add_cleanup(() => target.removeAttribute("style")); | ||
|
||
test_serialization_set(emptySet); | ||
}, "font: menu serialization"); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.