Source/WebCore/ChangeLog

 12021-09-18 Myles C. Maxfield <mmaxfield@apple.com>
 2
 3 Parsing support for font-palette
 4 https://bugs.webkit.org/show_bug.cgi?id=230394
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This is a pretty straightforward parsing patch. The grammar is just
 9 font-palette: none | normal | light | dark | <palette-identifier>.
 10 A <palette-identifier> is a <custom-ident>.
 11
 12 I'm implementing parsing support for @font-palette-values in
 13 https://bugs.webkit.org/show_bug.cgi?id=230337.
 14
 15 Tests: imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-computed.html
 16 imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-invalid.html
 17 imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-valid.html
 18
 19 * WebCore.xcodeproj/project.pbxproj:
 20 * css/CSSComputedStyleDeclaration.cpp:
 21 (WebCore::fontPaletteFromStyle):
 22 (WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
 23 * css/CSSProperties.json:
 24 * css/CSSValueKeywords.in:
 25 * css/parser/CSSPropertyParser.cpp:
 26 (WebCore::consumeFontPalette):
 27 (WebCore::CSSPropertyParser::parseSingleValue):
 28 * platform/graphics/FontCache.h:
 29 (WebCore::FontDescriptionKey::FontDescriptionKey):
 30 (WebCore::FontDescriptionKey::operator== const):
 31 (WebCore::add):
 32 * platform/graphics/FontCascadeDescription.cpp:
 33 * platform/graphics/FontCascadeDescription.h:
 34 (WebCore::FontCascadeDescription::initialFontPalette):
 35 * platform/graphics/FontDescription.cpp:
 36 (WebCore::FontDescription::FontDescription):
 37 * platform/graphics/FontDescription.h:
 38 (WebCore::FontDescription::fontPalette const):
 39 (WebCore::FontDescription::setFontPalette):
 40 (WebCore::FontDescription::operator== const):
 41 (WebCore::FontDescription::encode const):
 42 (WebCore::FontDescription::decode):
 43 * platform/graphics/FontPalette.h: Added.
 44 (WebCore::FontPaletteNone::operator== const):
 45 (WebCore::FontPaletteNone::operator!= const):
 46 (WebCore::add):
 47 (WebCore::FontPaletteNormal::operator== const):
 48 (WebCore::FontPaletteNormal::operator!= const):
 49 (WebCore::FontPaletteLight::operator== const):
 50 (WebCore::FontPaletteLight::operator!= const):
 51 (WebCore::FontPaletteDark::operator== const):
 52 (WebCore::FontPaletteDark::operator!= const):
 53 (WebCore::FontPaletteCustom::operator== const):
 54 (WebCore::FontPaletteCustom::operator!= const):
 55 * style/StyleBuilderConverter.h:
 56 (WebCore::Style::BuilderConverter::convertFontPalette):
 57
1582021-09-17 Simon Fraser <simon.fraser@apple.com>
259
360 Replace all the complex math in ScrollAnimationSmooth with a single call into a CubicBezierTimingFunction

Source/WebCore/Headers.cmake

@@set(WebCore_PRIVATE_FRAMEWORK_HEADERS
12591259 platform/graphics/FontFamilySpecificationNull.h
12601260 platform/graphics/FontGenericFamilies.h
12611261 platform/graphics/FontMetrics.h
 1262 platform/graphics/FontPalette.h
12621263 platform/graphics/FontPlatformData.h
12631264 platform/graphics/FontRanges.h
12641265 platform/graphics/FontSelectionAlgorithm.h

Source/WebCore/WebCore.xcodeproj/project.pbxproj

653653 1C6626111C6E7CA600AB527C /* FontFace.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C66260F1C6E7CA600AB527C /* FontFace.h */; };
654654 1C73A7132185757E004CCEA5 /* TextUnderlineOffset.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CB6B4FB217B83940093B9CD /* TextUnderlineOffset.h */; settings = {ATTRIBUTES = (Private, ); }; };
655655 1C73A71521857587004CCEA5 /* TextDecorationThickness.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CB6B4F8217B83930093B9CD /* TextDecorationThickness.h */; settings = {ATTRIBUTES = (Private, ); }; };
 656 1C7A6EB526F5D8F50096D8C7 /* FontPalette.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4674FD26F4843600B61273 /* FontPalette.h */; settings = {ATTRIBUTES = (Private, ); }; };
656657 1C81B95A0E97330800266E07 /* InspectorController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C81B9560E97330800266E07 /* InspectorController.h */; settings = {ATTRIBUTES = (Private, ); }; };
657658 1C81B95C0E97330800266E07 /* InspectorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C81B9580E97330800266E07 /* InspectorClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
658659 1CAF34810A6C405200ABE06E /* WebScriptObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CAF347E0A6C405200ABE06E /* WebScriptObject.h */; settings = {ATTRIBUTES = (Private, ); }; };

70427043 1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCacheCoreText.cpp; sourceTree = "<group>"; };
70437044 1C43DE6822AB4B8A001527D9 /* LocalCurrentTraitCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalCurrentTraitCollection.h; sourceTree = "<group>"; };
70447045 1C43DE6A22AB4B8A001527D9 /* LocalCurrentTraitCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentTraitCollection.mm; sourceTree = "<group>"; };
 7046 1C4674FD26F4843600B61273 /* FontPalette.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontPalette.h; sourceTree = "<group>"; };
70457047 1C4D0DD124D9F0DB003D7498 /* GlyphBufferMembers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlyphBufferMembers.h; sourceTree = "<group>"; };
70467048 1C50C49522C84F2400A6E4BE /* WHLSLStandardLibraryFunctionMap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLStandardLibraryFunctionMap.cpp; sourceTree = "<group>"; };
70477049 1C66260E1C6E7CA600AB527C /* FontFace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFace.cpp; sourceTree = "<group>"; };

2700527007 E44EE3A617576E5500EEE8CF /* FontGenericFamilies.cpp */,
2700627008 E44EE3A717576E5500EEE8CF /* FontGenericFamilies.h */,
2700727009 0845680712B90DA600960A9F /* FontMetrics.h */,
 27010 1C4674FD26F4843600B61273 /* FontPalette.h */,
2700827011 84B62684133138F90095A489 /* FontPlatformData.cpp */,
2700927012 B5320D69122A24E9002D1440 /* FontPlatformData.h */,
2701027013 371F4FFB0D25E7F300ECE0D5 /* FontRanges.cpp */,

3249532498 658436860AE01B7400E53743 /* FontLoadRequest.h in Headers */,
3249632499 BC4A532F256057CD0028C592 /* FontLoadTimingOverride.h in Headers */,
3249732500 0845680812B90DA600960A9F /* FontMetrics.h in Headers */,
 32501 1C7A6EB526F5D8F50096D8C7 /* FontPalette.h in Headers */,
3249832502 B5320D6B122A24E9002D1440 /* FontPlatformData.h in Headers */,
3249932503 371F4FFC0D25E7F300ECE0D5 /* FontRanges.h in Headers */,
3250032504 BC4A5339256063980028C592 /* FontRenderingMode.h in Headers */,

Source/WebCore/css/CSSComputedStyleDeclaration.cpp

11/*
22 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3  * Copyright (C) 2004-2019 Apple Inc. All rights reserved.
 3 * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
44 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
55 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
66 * Copyright (C) 2011 Sencha, Inc. All rights reserved.

@@static Ref<CSSPrimitiveValue> fontSizeFromStyle(const RenderStyle& style)
18411841 return zoomAdjustedPixelValue(style.fontDescription().computedSize(), style);
18421842}
18431843
 1844static Ref<CSSPrimitiveValue> fontPaletteFromStyle(const RenderStyle& style)
 1845{
 1846 auto fontPalette = style.fontDescription().fontPalette();
 1847 return WTF::switchOn(fontPalette, [] (FontPaletteNone) {
 1848 return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
 1849 }, [] (FontPaletteNormal) {
 1850 return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
 1851 }, [] (FontPaletteLight) {
 1852 return CSSValuePool::singleton().createIdentifierValue(CSSValueLight);
 1853 }, [] (FontPaletteDark) {
 1854 return CSSValuePool::singleton().createIdentifierValue(CSSValueDark);
 1855 }, [] (const FontPaletteCustom& fontPaletteCustom) {
 1856 return CSSValuePool::singleton().createCustomIdent(fontPaletteCustom.identifier);
 1857 });
 1858}
 1859
18441860Ref<CSSPrimitiveValue> ComputedStyleExtractor::fontNonKeywordWeightFromStyleValue(FontSelectionValue weight)
18451861{
18461862 return CSSValuePool::singleton().createValue(static_cast<float>(weight), CSSUnitType::CSS_NUMBER);

@@RefPtr<CSSValue> ComputedStyleExtractor::valueForPropertyInStyle(const RenderSty
29442960 return fontVariantFromStyle(style);
29452961 case CSSPropertyFontWeight:
29462962 return fontNonKeywordWeightFromStyle(style);
 2963 case CSSPropertyFontPalette:
 2964 return fontPaletteFromStyle(style);
29472965 case CSSPropertyFontSynthesis:
29482966 return fontSynthesisFromStyle(style);
29492967 case CSSPropertyFontFeatureSettings: {

Source/WebCore/css/CSSProperties.json

478478 "url": "https://drafts.csswg.org/css-fonts-3/#font-kerning-prop"
479479 }
480480 },
 481 "font-palette": {
 482 "inherited": true,
 483 "codegen-properties": {
 484 "converter": "FontPalette",
 485 "font-property": true,
 486 "high-priority": true
 487 },
 488 "specification": {
 489 "category": "css-fonts",
 490 "url": "https://drafts.csswg.org/css-fonts/#font-palette-prop"
 491 }
 492 },
481493 "-webkit-font-smoothing": {
482494 "inherited": true,
483495 "values": [

Source/WebCore/css/CSSValueKeywords.in

@@more
14861486less
14871487// no-preference
14881488
1489 #if defined(ENABLE_DARK_MODE_CSS) && ENABLE_DARK_MODE_CSS
1490 // prefers-color-scheme
 1489// prefers-color-scheme, font-palette
14911490light
14921491dark
14931492
 1493#if defined(ENABLE_DARK_MODE_CSS) && ENABLE_DARK_MODE_CSS
14941494// color-scheme
14951495only
14961496// light

Source/WebCore/css/parser/CSSPropertyParser.cpp

@@static RefPtr<CSSPrimitiveValue> consumeFontWeight(CSSParserTokenRange& range)
924924 return nullptr;
925925}
926926
 927static RefPtr<CSSPrimitiveValue> consumeFontPalette(CSSParserTokenRange& range)
 928{
 929 if (auto result = consumeIdent<CSSValueNone, CSSValueNormal, CSSValueLight, CSSValueDark>(range))
 930 return result;
 931 return consumeCustomIdent(range);
 932}
 933
927934static RefPtr<CSSValue> consumeFamilyName(CSSParserTokenRange& range)
928935{
929936 auto familyName = consumeFamilyNameRaw(range);

@@RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSS
40184025 return consumeFontFamily(m_range);
40194026 case CSSPropertyFontWeight:
40204027 return consumeFontWeight(m_range);
 4028 case CSSPropertyFontPalette:
 4029 return consumeFontPalette(m_range);
40214030 case CSSPropertyFontStretch:
40224031 return consumeFontStretch(m_range, CSSValuePool::singleton());
40234032 case CSSPropertyFontStyle:

Source/WebCore/platform/graphics/FontCache.h

3737#include "Timer.h"
3838#include <array>
3939#include <limits.h>
 40#include <wtf/FastMalloc.h>
4041#include <wtf/Forward.h>
4142#include <wtf/HashTraits.h>
4243#include <wtf/ListHashSet.h>

@@using IMLangFontLinkType = IMLangFontLink2;
7879using IMLangFontLinkType = IMLangFontLink;
7980#endif
8081
 82struct FontDescriptionKeyRareData : public RefCounted<FontDescriptionKeyRareData> {
 83 WTF_MAKE_FAST_ALLOCATED;
 84public:
 85 static Ref<FontDescriptionKeyRareData> create(FontFeatureSettings&& featureSettings, FontVariationSettings&& variationSettings, FontPalette&& fontPalette)
 86 {
 87 return adoptRef(*new FontDescriptionKeyRareData(WTFMove(featureSettings), WTFMove(variationSettings), WTFMove(fontPalette)));
 88 }
 89
 90 const FontFeatureSettings& featureSettings() const
 91 {
 92 return m_featureSettings;
 93 }
 94
 95 const FontVariationSettings& variationSettings() const
 96 {
 97 return m_variationSettings;
 98 }
 99
 100 const FontPalette& fontPalette() const
 101 {
 102 return m_fontPalette;
 103 }
 104
 105 bool operator==(const FontDescriptionKeyRareData& other) const
 106 {
 107 return m_featureSettings == other.m_featureSettings
 108 && m_variationSettings == other.m_variationSettings
 109 && m_fontPalette == other.m_fontPalette;
 110 }
 111
 112private:
 113 FontDescriptionKeyRareData(FontFeatureSettings&& featureSettings, FontVariationSettings&& variationSettings, FontPalette&& fontPalette)
 114 : m_featureSettings(WTFMove(featureSettings))
 115 , m_variationSettings(WTFMove(variationSettings))
 116 , m_fontPalette(WTFMove(fontPalette))
 117 {
 118 }
 119
 120 FontFeatureSettings m_featureSettings;
 121 FontVariationSettings m_variationSettings;
 122 FontPalette m_fontPalette;
 123};
 124
 125inline void add(Hasher& hasher, const FontDescriptionKeyRareData& key)
 126{
 127 add(hasher, key.featureSettings(), key.variationSettings(), key.fontPalette());
 128}
 129
81130// This key contains the FontDescription fields other than family that matter when fetching FontDatas (platform fonts).
82131struct FontDescriptionKey {
83132 FontDescriptionKey() = default;

@@struct FontDescriptionKey {
87136 , m_fontSelectionRequest(description.fontSelectionRequest())
88137 , m_flags(makeFlagsKey(description))
89138 , m_locale(description.specifiedLocale())
90  , m_featureSettings(description.featureSettings())
91  , m_variationSettings(description.variationSettings())
92  { }
 139 {
 140 auto featureSettings = description.featureSettings();
 141 auto variationSettings = description.variationSettings();
 142 auto fontPalette = description.fontPalette();
 143 if (!featureSettings.isEmpty() || !variationSettings.isEmpty() || !WTF::holds_alternative<FontPaletteNormal>(fontPalette))
 144 m_rareData = FontDescriptionKeyRareData::create(WTFMove(featureSettings), WTFMove(variationSettings), WTFMove(fontPalette));
 145 }
93146
94147 explicit FontDescriptionKey(WTF::HashTableDeletedValueType)
95148 : m_isDeletedValue(true)

@@struct FontDescriptionKey {
97150
98151 bool operator==(const FontDescriptionKey& other) const
99152 {
100  return m_isDeletedValue == other.m_isDeletedValue
 153 if (m_isDeletedValue == other.m_isDeletedValue
101154 && m_size == other.m_size
102155 && m_fontSelectionRequest == other.m_fontSelectionRequest
103156 && m_flags == other.m_flags
104  && m_locale == other.m_locale
105  && m_variationSettings == other.m_variationSettings
106  && m_featureSettings == other.m_featureSettings;
 157 && m_locale == other.m_locale) {
 158 if (!m_rareData && !other.m_rareData)
 159 return true;
 160 return m_rareData && other.m_rareData && *m_rareData == *other.m_rareData;
 161 }
 162 return false;
107163 }
108164
109165 bool operator!=(const FontDescriptionKey& other) const

@@private:
152208 FontSelectionRequest m_fontSelectionRequest;
153209 std::array<unsigned, 2> m_flags {{ 0, 0 }};
154210 AtomString m_locale;
155  FontFeatureSettings m_featureSettings;
156  FontVariationSettings m_variationSettings;
 211 RefPtr<FontDescriptionKeyRareData> m_rareData;
157212};
158213
159214inline void add(Hasher& hasher, const FontDescriptionKey& key)
160215{
161  add(hasher, key.m_size, key.m_fontSelectionRequest, key.m_flags, key.m_locale, key.m_featureSettings, key.m_variationSettings);
 216 add(hasher, key.m_size, key.m_fontSelectionRequest, key.m_flags, key.m_locale);
 217 if (key.m_rareData)
 218 add(hasher, *key.m_rareData);
162219}
163220
164221struct FontDescriptionKeyHash {

Source/WebCore/platform/graphics/FontCascadeDescription.cpp

11/*
22 * Copyright (C) 2007 Nicholas Shanks <contact@nickshanks.com>
3  * Copyright (C) 2008, 2013 Apple Inc. All rights reserved.
 3 * Copyright (C) 2008 - 2021 Apple Inc. All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions

@@namespace WebCore {
3737struct SameSizeAsFontCascadeDescription {
3838 Vector<void*> vector;
3939 Vector<void*> vector2;
 40 FontPalette palette;
4041 AtomString string;
4142 AtomString string2;
4243 int16_t fontSelectionRequest[3];

Source/WebCore/platform/graphics/FontCascadeDescription.h

22 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
33 * (C) 2000 Antti Koivisto (koivisto@kde.org)
44 * (C) 2000 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
 5 * Copyright (C) 2003 - 2021 Apple Inc. All rights reserved.
66 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
77 *
88 * This library is free software; you can redistribute it and/or

@@public:
133133 static FontVariantAlternates initialVariantAlternates() { return FontVariantAlternates::Normal; }
134134 static FontOpticalSizing initialOpticalSizing() { return FontOpticalSizing::Enabled; }
135135 static const AtomString& initialSpecifiedLocale() { return nullAtom(); }
 136 static FontPalette initialFontPalette() { return FontPaletteNormal { }; }
136137
137138private:
138139 RefCountedArray<AtomString> m_families { 1 };

Source/WebCore/platform/graphics/FontDescription.cpp

11/*
22 * Copyright (C) 2007 Nicholas Shanks <contact@nickshanks.com>
3  * Copyright (C) 2008, 2013 - 2020 Apple Inc. All rights reserved.
 3 * Copyright (C) 2008, 2013 - 2021 Apple Inc. All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions

3737namespace WebCore {
3838
3939FontDescription::FontDescription()
40  : m_fontSelectionRequest { FontCascadeDescription::initialWeight(), FontCascadeDescription::initialStretch(), FontCascadeDescription::initialItalic() }
 40 : m_fontPalette(FontPaletteNormal { })
 41 , m_fontSelectionRequest { FontCascadeDescription::initialWeight(), FontCascadeDescription::initialStretch(), FontCascadeDescription::initialItalic() }
4142 , m_orientation(static_cast<unsigned>(FontOrientation::Horizontal))
4243 , m_nonCJKGlyphOrientation(static_cast<unsigned>(NonCJKGlyphOrientation::Mixed))
4344 , m_widthVariant(static_cast<unsigned>(FontWidthVariant::RegularWidth))

Source/WebCore/platform/graphics/FontDescription.h

22 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
33 * (C) 2000 Antti Koivisto (koivisto@kde.org)
44 * (C) 2000 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
 5 * Copyright (C) 2003 - 2021 Apple Inc. All rights reserved.
66 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
77 *
88 * This library is free software; you can redistribute it and/or

2424
2525#pragma once
2626
 27#include "FontPalette.h"
2728#include "FontRenderingMode.h"
2829#include "FontSelectionAlgorithm.h"
2930#include "FontTaggedSettings.h"

@@public:
9899 FontStyleAxis fontStyleAxis() const { return m_fontStyleAxis ? FontStyleAxis::ital : FontStyleAxis::slnt; }
99100 AllowUserInstalledFonts shouldAllowUserInstalledFonts() const { return static_cast<AllowUserInstalledFonts>(m_shouldAllowUserInstalledFonts); }
100101 bool shouldDisableLigaturesForSpacing() const { return m_shouldDisableLigaturesForSpacing; }
 102 FontPalette fontPalette() const { return m_fontPalette; }
101103
102104 void setComputedSize(float s) { m_computedSize = clampToFloat(s); }
103105 void setItalic(std::optional<FontSelectionValue> italic) { m_fontSelectionRequest.slope = italic; }

@@public:
132134 void setFontStyleAxis(FontStyleAxis axis) { m_fontStyleAxis = axis == FontStyleAxis::ital; }
133135 void setShouldAllowUserInstalledFonts(AllowUserInstalledFonts shouldAllowUserInstalledFonts) { m_shouldAllowUserInstalledFonts = static_cast<unsigned>(shouldAllowUserInstalledFonts); }
134136 void setShouldDisableLigaturesForSpacing(bool shouldDisableLigaturesForSpacing) { m_shouldDisableLigaturesForSpacing = shouldDisableLigaturesForSpacing; }
 137 void setFontPalette(FontPalette fontPalette) { m_fontPalette = fontPalette; }
135138
136139 static AtomString platformResolveGenericFamily(UScriptCode, const AtomString& locale, const AtomString& familyName);
137140

@@private:
145148 // FIXME: Investigate moving these into their own object on the heap (to save memory).
146149 FontFeatureSettings m_featureSettings;
147150 FontVariationSettings m_variationSettings;
 151 FontPalette m_fontPalette;
148152 AtomString m_locale;
149153 AtomString m_specifiedLocale;
150154

@@inline bool FontDescription::operator==(const FontDescription& other) const
209213 && m_opticalSizing == other.m_opticalSizing
210214 && m_fontStyleAxis == other.m_fontStyleAxis
211215 && m_shouldAllowUserInstalledFonts == other.m_shouldAllowUserInstalledFonts
212  && m_shouldDisableLigaturesForSpacing == other.m_shouldDisableLigaturesForSpacing;
 216 && m_shouldDisableLigaturesForSpacing == other.m_shouldDisableLigaturesForSpacing
 217 && m_fontPalette == other.m_fontPalette;
213218}
214219
215220template<class Encoder>

@@void FontDescription::encode(Encoder& encoder) const
247252 encoder << fontStyleAxis();
248253 encoder << shouldAllowUserInstalledFonts();
249254 encoder << shouldDisableLigaturesForSpacing();
 255 encoder << fontPalette();
250256}
251257
252258template<class Decoder>

@@std::optional<FontDescription> FontDescription::decode(Decoder& decoder)
413419 if (!shouldDisableLigaturesForSpacing)
414420 return std::nullopt;
415421
 422 std::optional<FontPalette> fontPalette;
 423 decoder >> fontPalette;
 424 if (!fontPalette)
 425 return std::nullopt;
 426
416427 fontDescription.setFeatureSettings(WTFMove(*featureSettings));
417428 fontDescription.setVariationSettings(WTFMove(*variationSettings));
418429 fontDescription.setSpecifiedLocale(*locale);

@@std::optional<FontDescription> FontDescription::decode(Decoder& decoder)
445456 fontDescription.setFontStyleAxis(*fontStyleAxis);
446457 fontDescription.setShouldAllowUserInstalledFonts(*shouldAllowUserInstalledFonts);
447458 fontDescription.setShouldDisableLigaturesForSpacing(*shouldDisableLigaturesForSpacing);
 459 fontDescription.setFontPalette(*fontPalette);
448460
449461 return fontDescription;
450462}

Source/WebCore/platform/graphics/FontPalette.h

 1/*
 2 * Copyright (C) 2021 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include <wtf/Hasher.h>
 29#include <wtf/Variant.h>
 30#include <wtf/text/AtomString.h>
 31
 32namespace WebCore {
 33
 34struct FontPaletteNone {
 35 bool operator==(const FontPaletteNone&) const
 36 {
 37 return true;
 38 }
 39
 40 bool operator!=(const FontPaletteNone&) const
 41 {
 42 return false;
 43 }
 44};
 45
 46inline void add(Hasher&, const FontPaletteNone&)
 47{
 48}
 49
 50struct FontPaletteNormal {
 51 bool operator==(const FontPaletteNormal&) const
 52 {
 53 return true;
 54 }
 55
 56 bool operator!=(const FontPaletteNormal&) const
 57 {
 58 return false;
 59 }
 60};
 61
 62inline void add(Hasher&, const FontPaletteNormal&)
 63{
 64}
 65
 66struct FontPaletteLight {
 67 bool operator==(const FontPaletteLight&) const
 68 {
 69 return true;
 70 }
 71
 72 bool operator!=(const FontPaletteLight&) const
 73 {
 74 return false;
 75 }
 76};
 77
 78inline void add(Hasher&, const FontPaletteLight&)
 79{
 80}
 81
 82struct FontPaletteDark {
 83 bool operator==(const FontPaletteDark&) const
 84 {
 85 return true;
 86 }
 87
 88 bool operator!=(const FontPaletteDark&) const
 89 {
 90 return false;
 91 }
 92};
 93
 94inline void add(Hasher&, const FontPaletteDark&)
 95{
 96}
 97
 98struct FontPaletteCustom {
 99 bool operator==(const FontPaletteCustom& other) const
 100 {
 101 return identifier == other.identifier;
 102 }
 103
 104 bool operator!=(const FontPaletteCustom& other) const
 105 {
 106 return !(*this == other);
 107 }
 108
 109 AtomString identifier;
 110};
 111
 112inline void add(Hasher& hasher, const FontPaletteCustom& request)
 113{
 114 add(hasher, request.identifier);
 115}
 116
 117using FontPalette = Variant<FontPaletteNone, FontPaletteNormal, FontPaletteLight, FontPaletteDark, FontPaletteCustom>;
 118
 119}

Source/WebCore/style/StyleBuilderConverter.h

11/*
22 * Copyright (C) 2013 Google Inc. All rights reserved.
3  * Copyright (C) 2014 Apple Inc. All rights reserved.
 3 * Copyright (C) 2014 - 2021 Apple Inc. All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions

4444#include "CSSReflectValue.h"
4545#include "CalcExpressionLength.h"
4646#include "CalcExpressionOperation.h"
 47#include "FontPalette.h"
4748#include "FontSelectionValueInlines.h"
4849#include "Frame.h"
4950#include "GridPositionsResolver.h"

@@public:
151152 static GlyphOrientation convertGlyphOrientationOrAuto(BuilderState&, const CSSValue&);
152153 static std::optional<Length> convertLineHeight(BuilderState&, const CSSValue&, float multiplier = 1.f);
153154 static FontSynthesis convertFontSynthesis(BuilderState&, const CSSValue&);
 155 static FontPalette convertFontPalette(BuilderState&, const CSSValue&);
154156
155157 static BreakBetween convertPageBreakBetween(BuilderState&, const CSSValue&);
156158 static BreakInside convertPageBreakInside(BuilderState&, const CSSValue&);

@@inline FontSynthesis BuilderConverter::convertFontSynthesis(BuilderState&, const
15471549
15481550 return result;
15491551}
 1552
 1553inline FontPalette BuilderConverter::convertFontPalette(BuilderState&, const CSSValue& value)
 1554{
 1555 ASSERT(is<CSSPrimitiveValue>(value));
 1556 const auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
 1557 switch (primitiveValue.valueID()) {
 1558 case CSSValueNone:
 1559 return FontPaletteNone { };
 1560 case CSSValueNormal:
 1561 return FontPaletteNormal { };
 1562 case CSSValueLight:
 1563 return FontPaletteLight { };
 1564 case CSSValueDark:
 1565 return FontPaletteDark { };
 1566 case CSSValueInvalid:
 1567 ASSERT(primitiveValue.isCustomIdent());
 1568 return FontPaletteCustom { primitiveValue.stringValue() };
 1569 default:
 1570 ASSERT_NOT_REACHED();
 1571 return FontPaletteNormal { };
 1572 }
 1573}
15501574
15511575inline OptionSet<SpeakAs> BuilderConverter::convertSpeakAs(BuilderState&, const CSSValue& value)
15521576{

LayoutTests/imported/w3c/ChangeLog

 12021-09-18 Myles C. Maxfield <mmaxfield@apple.com>
 2
 3 Parsing support for font-palette
 4 https://bugs.webkit.org/show_bug.cgi?id=230394
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This is being upstreamed at https://github.com/web-platform-tests/wpt/pull/30845.
 9
 10 * web-platform-tests/css/css-fonts/parsing/font-palette-computed-expected.txt: Added.
 11 * web-platform-tests/css/css-fonts/parsing/font-palette-computed.html: Added.
 12 * web-platform-tests/css/css-fonts/parsing/font-palette-invalid-expected.txt: Added.
 13 * web-platform-tests/css/css-fonts/parsing/font-palette-invalid.html: Added.
 14 * web-platform-tests/css/css-fonts/parsing/font-palette-valid-expected.txt: Added.
 15 * web-platform-tests/css/css-fonts/parsing/font-palette-valid.html: Added.
 16
1172021-09-17 Simon Fraser <simon.fraser@apple.com>
218
319 css/cssom-view/mouseEvent-offsetXY-svg.html passes now

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-computed-expected.txt

 1
 2PASS Property font-palette value 'none'
 3PASS Property font-palette value 'normal'
 4PASS Property font-palette value 'light'
 5PASS Property font-palette value 'dark'
 6PASS Property font-palette value 'pitchfork'
 7

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-computed.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<meta charset="utf-8">
 5<title>CSS Fonts Module Level 4: getComputedStyle().fontPalette</title>
 6<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-prop">
 7<meta name="assert" content="font-palette computed value is as specified.">
 8<script src="/resources/testharness.js"></script>
 9<script src="/resources/testharnessreport.js"></script>
 10<script src="/css/support/computed-testcommon.js"></script>
 11</head>
 12<body>
 13<div id="target"></div>
 14<script>
 15test_computed_value('font-palette', 'none');
 16test_computed_value('font-palette', 'normal');
 17test_computed_value('font-palette', 'light');
 18test_computed_value('font-palette', 'dark');
 19test_computed_value('font-palette', 'pitchfork');
 20</script>
 21</body>
 22</html>

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-invalid-expected.txt

 1
 2PASS e.style['font-palette'] = "normal none" should not set the property value
 3PASS e.style['font-palette'] = "none, light" should not set the property value
 4

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-invalid.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<meta charset="utf-8">
 5<title>CSS Fonts Module Level 4: parsing font-palette with invalid values</title>
 6<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-prop">
 7<meta name="assert" content="font-palette supports only the grammar 'none | normal | light | dark | <palette-identifier>'.">
 8<script src="/resources/testharness.js"></script>
 9<script src="/resources/testharnessreport.js"></script>
 10<script src="/css/support/parsing-testcommon.js"></script>
 11</head>
 12<body>
 13<script>
 14test_invalid_value('font-palette', 'normal none');
 15test_invalid_value('font-palette', 'none, light');
 16</script>
 17</body>
 18</html>

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-valid-expected.txt

 1
 2PASS e.style['font-palette'] = "none" should set the property value
 3PASS e.style['font-palette'] = "normal" should set the property value
 4PASS e.style['font-palette'] = "light" should set the property value
 5PASS e.style['font-palette'] = "dark" should set the property value
 6PASS e.style['font-palette'] = "pitchfork" should set the property value
 7

LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-valid.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<meta charset="utf-8">
 5<title>CSS Fonts Module Level 4: parsing font-palette with valid values</title>
 6<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-palette-prop">
 7<meta name="assert" content="font-palette supports the full grammar 'none | normal | light | dark | <palette-identifier>'.">
 8<script src="/resources/testharness.js"></script>
 9<script src="/resources/testharnessreport.js"></script>
 10<script src="/css/support/parsing-testcommon.js"></script>
 11</head>
 12<body>
 13<script>
 14test_valid_value('font-palette', 'none');
 15test_valid_value('font-palette', 'normal');
 16test_valid_value('font-palette', 'light');
 17test_valid_value('font-palette', 'dark');
 18test_valid_value('font-palette', 'pitchfork');
 19</script>
 20</body>
 21</html>