Changeset 283752 in webkit
- Timestamp:
- Oct 7, 2021 4:05:49 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 10 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html (modified) (4 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/CSSFontPaletteValuesRule.cpp (modified) (5 diffs)
-
Source/WebCore/css/StyleRule.cpp (modified) (1 diff)
-
Source/WebCore/css/StyleRule.h (modified) (3 diffs)
-
Source/WebCore/css/parser/CSSParserImpl.cpp (modified) (3 diffs)
-
Source/WebCore/css/parser/CSSPropertyParser.cpp (modified) (2 diffs)
-
Source/WebCore/platform/graphics/FontPaletteValues.h (modified) (6 diffs)
-
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r283742 r283752 1 2021-10-07 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Stop parsing font palette things that we can't implement 4 https://bugs.webkit.org/show_bug.cgi?id=230799 5 <rdar://problem/83537772> 6 7 Reviewed by Simon Fraser. 8 9 * web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html: 10 1 11 2021-10-07 Aditya Keerthi <akeerthi@apple.com> 2 12 -
trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html
r283539 r283752 145 145 assert_not_equals(text.indexOf("base-palette: 2;"), -1); 146 146 assert_equals(text.indexOf("override-colors: \"a\""), -1); 147 assert_ equals(text.indexOf("override-colors: 3"), -1);148 assert_ not_equals(text.indexOf("override-colors: \"b\""), -1);147 assert_not_equals(text.indexOf("override-colors: 3"), -1); 148 assert_equals(text.indexOf("override-colors: \"b\""), -1); 149 149 }); 150 150 … … 154 154 assert_equals(rule.fontFamily, "bar"); 155 155 assert_equals(rule.basePalette, "2"); 156 assert_equals(rule.overrideColors, " \"b\"rgb(17, 34, 51)");156 assert_equals(rule.overrideColors, "3 rgb(17, 34, 51)"); 157 157 }); 158 158 … … 160 160 let text = rules[3].cssText; 161 161 assert_equals(text.indexOf("base-palette: \"foo\";"), -1); 162 assert_ equals(text.indexOf("base-palette: 1"), -1);163 assert_ not_equals(text.indexOf("base-palette: \"bar\";"), -1);162 assert_not_equals(text.indexOf("base-palette: 1"), -1); 163 assert_equals(text.indexOf("base-palette: \"bar\";"), -1); 164 164 assert_equals(text.indexOf("override-colors: 3"), -1); 165 165 assert_equals(text.indexOf("override-colors: \"baz\""), -1); … … 171 171 assert_equals(rule.name, "--D"); 172 172 assert_equals(rule.fontFamily, ""); 173 assert_equals(rule.basePalette, " bar");173 assert_equals(rule.basePalette, "1"); 174 174 assert_equals(rule.overrideColors.indexOf("),"), -1); 175 175 assert_equals(rule.overrideColors.indexOf("4 "), 0); -
trunk/Source/WebCore/ChangeLog
r283747 r283752 1 2021-10-07 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Stop parsing font palette things that we can't implement 4 https://bugs.webkit.org/show_bug.cgi?id=230799 5 <rdar://problem/83537772> 6 7 Reviewed by Simon Fraser. 8 9 We can't implement the <string> values in base-palette and override-colors. It's better 10 not to parse them, so this behavior can at least be feature detected by JS reading the 11 serialized value that was parsed. 12 13 I'm investigating changing the spec to disallow these unimplementable things in 14 https://github.com/w3c/csswg-drafts/issues/6627. 15 16 For base-palette, we were representing the absence of the descriptor by making the internal 17 representation hold a null string. Now that we're removing the string value from the internal 18 representation, this is now being represented by using an std::optional instead. 19 20 Test: imported/w3c/web-platform-tests/css/css-fonts/parsing/font-palette-values-valid.html 21 22 * css/CSSFontPaletteValuesRule.cpp: 23 (WebCore::CSSFontPaletteValuesRule::basePalette const): 24 (WebCore::CSSFontPaletteValuesRule::overrideColors const): 25 (WebCore::CSSFontPaletteValuesRule::cssText const): 26 * css/StyleRule.cpp: 27 (WebCore::StyleRuleFontPaletteValues::StyleRuleFontPaletteValues): 28 * css/StyleRule.h: 29 * css/parser/CSSParserImpl.cpp: 30 (WebCore::CSSParserImpl::consumeFontPaletteValuesRule): 31 * css/parser/CSSPropertyParser.cpp: 32 (WebCore::consumeBasePaletteDescriptor): 33 (WebCore::consumeOverrideColorsDescriptor): 34 * platform/graphics/FontPaletteValues.h: 35 (WebCore::FontPaletteIndex::operator bool const): 36 (WebCore::FontPaletteIndex::operator== const): 37 (WebCore::add): 38 (WebCore::FontPaletteValues::FontPaletteValues): 39 (WebCore::FontPaletteValues::basePalette const): 40 * platform/graphics/cocoa/FontCacheCoreText.cpp: 41 (WebCore::addAttributesForCustomFontPalettes): 42 1 43 2021-10-07 Tim Horton <timothy_horton@apple.com> 2 44 -
trunk/Source/WebCore/css/CSSFontPaletteValuesRule.cpp
r283736 r283752 59 59 String CSSFontPaletteValuesRule::basePalette() const 60 60 { 61 switch (m_fontPaletteValuesRule->basePalette().type) { 61 if (!m_fontPaletteValuesRule->basePalette()) 62 return StringImpl::empty(); 63 64 switch (m_fontPaletteValuesRule->basePalette()->type) { 62 65 case FontPaletteIndex::Type::Light: 63 66 return "light"_s; … … 65 68 return "dark"_s; 66 69 case FontPaletteIndex::Type::Integer: 67 return makeString(m_fontPaletteValuesRule->basePalette().integer); 68 case FontPaletteIndex::Type::String: 69 if (!m_fontPaletteValuesRule->basePalette().string.isNull()) 70 return m_fontPaletteValuesRule->basePalette().string; 71 return StringImpl::empty(); 70 return makeString(m_fontPaletteValuesRule->basePalette()->integer); 72 71 } 73 72 RELEASE_ASSERT_NOT_REACHED(); … … 81 80 result.append(", "); 82 81 const auto& item = m_fontPaletteValuesRule->overrideColors()[i]; 83 WTF::switchOn(item.first, [&] (const AtomString& string) { 84 result.append(serializeString(string)); 85 }, [&] (int64_t index) { 86 result.append(index); 87 }); 88 result.append(' ', serializationForCSS(item.second)); 82 result.append(item.first, ' ', serializationForCSS(item.second)); 89 83 } 90 84 return result.toString(); … … 98 92 builder.append("font-family: ", m_fontPaletteValuesRule->fontFamily(), "; "); 99 93 100 switch (m_fontPaletteValuesRule->basePalette().type) { 101 case FontPaletteIndex::Type::Light: 102 builder.append("base-palette: light; "); 103 break; 104 case FontPaletteIndex::Type::Dark: 105 builder.append("base-palette: dark; "); 106 break; 107 case FontPaletteIndex::Type::Integer: 108 builder.append("base-palette: ", m_fontPaletteValuesRule->basePalette().integer, "; "); 109 break; 110 case FontPaletteIndex::Type::String: 111 if (!m_fontPaletteValuesRule->basePalette().string.isNull()) 112 builder.append("base-palette: ", serializeString(m_fontPaletteValuesRule->basePalette().string), "; "); 113 break; 94 if (m_fontPaletteValuesRule->basePalette()) { 95 switch (m_fontPaletteValuesRule->basePalette()->type) { 96 case FontPaletteIndex::Type::Light: 97 builder.append("base-palette: light; "); 98 break; 99 case FontPaletteIndex::Type::Dark: 100 builder.append("base-palette: dark; "); 101 break; 102 case FontPaletteIndex::Type::Integer: 103 builder.append("base-palette: ", m_fontPaletteValuesRule->basePalette()->integer, "; "); 104 break; 105 } 114 106 } 115 107 … … 119 111 if (i) 120 112 builder.append(','); 121 builder.append(' '); 122 WTF::switchOn(m_fontPaletteValuesRule->overrideColors()[i].first, [&] (const AtomString& name) { 123 builder.append(serializeString(name.string())); 124 }, [&] (unsigned index) { 125 builder.append(index); 126 }); 127 builder.append(' ', serializationForCSS(m_fontPaletteValuesRule->overrideColors()[i].second)); 113 builder.append(' ', m_fontPaletteValuesRule->overrideColors()[i].first, ' ', serializationForCSS(m_fontPaletteValuesRule->overrideColors()[i].second)); 128 114 } 129 115 builder.append("; "); -
trunk/Source/WebCore/css/StyleRule.cpp
r283398 r283752 331 331 } 332 332 333 StyleRuleFontPaletteValues::StyleRuleFontPaletteValues(const AtomString& name, const AtomString& fontFamily, const FontPaletteIndex&basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors)333 StyleRuleFontPaletteValues::StyleRuleFontPaletteValues(const AtomString& name, const AtomString& fontFamily, std::optional<FontPaletteIndex> basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors) 334 334 : StyleRuleBase(StyleRuleType::FontPaletteValues) 335 335 , m_name(name) -
trunk/Source/WebCore/css/StyleRule.h
r283398 r283752 160 160 class StyleRuleFontPaletteValues final : public StyleRuleBase { 161 161 public: 162 static Ref<StyleRuleFontPaletteValues> create(const AtomString& name, const AtomString& fontFamily, const FontPaletteIndex&basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors)162 static Ref<StyleRuleFontPaletteValues> create(const AtomString& name, const AtomString& fontFamily, std::optional<FontPaletteIndex> basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors) 163 163 { 164 164 return adoptRef(*new StyleRuleFontPaletteValues(name, fontFamily, basePalette, WTFMove(overrideColors))); … … 182 182 } 183 183 184 const FontPaletteIndex&basePalette() const184 std::optional<FontPaletteIndex> basePalette() const 185 185 { 186 186 return m_fontPaletteValues.basePalette(); … … 195 195 196 196 private: 197 StyleRuleFontPaletteValues(const AtomString& name, const AtomString& fontFamily, const FontPaletteIndex&basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors);197 StyleRuleFontPaletteValues(const AtomString& name, const AtomString& fontFamily, std::optional<FontPaletteIndex> basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors); 198 198 StyleRuleFontPaletteValues(const StyleRuleFontPaletteValues&); 199 199 -
trunk/Source/WebCore/css/parser/CSSParserImpl.cpp
r283540 r283752 681 681 fontFamily = downcast<CSSPrimitiveValue>(*fontFamilyValue).fontFamily().familyName; 682 682 683 FontPaletteIndexbasePalette;683 std::optional<FontPaletteIndex> basePalette; 684 684 if (auto basePaletteValue = properties->getPropertyCSSValue(CSSPropertyBasePalette)) { 685 685 const auto& primitiveValue = downcast<CSSPrimitiveValue>(*basePaletteValue); 686 if (primitiveValue.isString()) 687 basePalette = FontPaletteIndex(primitiveValue.stringValue()); 688 else if (primitiveValue.isNumber()) 686 if (primitiveValue.isNumber()) 689 687 basePalette = FontPaletteIndex(primitiveValue.value<unsigned>()); 690 688 else if (primitiveValue.valueID() == CSSValueLight) … … 698 696 const auto& list = downcast<CSSValueList>(*overrideColorsValue); 699 697 for (const auto& item : list) { 700 FontPaletteValues::PaletteColorIndex key(nullAtom());701 698 const auto& pair = downcast<CSSFontPaletteValuesOverrideColorsValue>(item.get()); 702 if (pair.key().isString()) 703 key = pair.key().stringValue(); 704 else if (pair.key().isNumber()) 705 key = pair.key().value<unsigned>(); 706 else 699 if (!pair.key().isNumber()) 707 700 continue; 701 unsigned key = pair.key().value<unsigned>(); 708 702 Color color = pair.color().isRGBColor() ? pair.color().color() : StyleColor::colorFromKeyword(pair.color().valueID(), { }); 709 703 overrideColors.append(std::make_pair(key, color)); … … 711 705 } 712 706 713 return StyleRuleFontPaletteValues::create(name->stringValue(), fontFamily, basePalette, WTFMove(overrideColors));707 return StyleRuleFontPaletteValues::create(name->stringValue(), fontFamily, WTFMove(basePalette), WTFMove(overrideColors)); 714 708 } 715 709 -
trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp
r283742 r283752 4856 4856 if (auto result = consumeIdent<CSSValueLight, CSSValueDark>(range)) 4857 4857 return result; 4858 if (auto result = consumeString(range))4859 return result;4860 4858 return consumeInteger(range, 0); 4861 4859 } … … 4865 4863 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 4866 4864 do { 4867 RefPtr<CSSPrimitiveValue> key; 4868 if (range.peek().type() == StringToken) 4869 key = consumeString(range); 4870 else 4871 key = consumeInteger(range, 0); 4865 auto key = consumeInteger(range, 0); 4872 4866 if (!key) 4873 4867 return nullptr; -
trunk/Source/WebCore/platform/graphics/FontPaletteValues.h
r283398 r283752 52 52 } 53 53 54 FontPaletteIndex(const AtomString& string)55 : type(Type::String)56 , string(string)57 {58 }59 60 54 operator bool() const 61 55 { 62 return type != Type:: String || !string.isNull();56 return type != Type::Integer || integer; 63 57 } 64 58 … … 69 63 if (type == Type::Integer) 70 64 return integer == other.integer; 71 if (type == Type::String)72 return string == other.string;73 65 return true; 74 66 } … … 82 74 Light, 83 75 Dark, 84 Integer ,85 String86 } type { Type::String};76 Integer 77 }; 78 Type type { Type::Integer }; 87 79 88 80 unsigned integer { 0 }; 89 AtomString string;90 81 }; 91 82 … … 95 86 if (paletteIndex.type == FontPaletteIndex::Type::Integer) 96 87 add(hasher, paletteIndex.integer); 97 else if (paletteIndex.type == FontPaletteIndex::Type::String)98 add(hasher, paletteIndex.string);99 88 } 100 89 101 90 class FontPaletteValues { 102 91 public: 103 using PaletteColorIndex = Variant<AtomString, unsigned>; 104 using OverriddenColor = std::pair<PaletteColorIndex, Color>; 92 using OverriddenColor = std::pair<unsigned, Color>; 105 93 106 94 FontPaletteValues() = default; 107 95 108 FontPaletteValues( const FontPaletteIndex&basePalette, Vector<OverriddenColor>&& overrideColors)96 FontPaletteValues(std::optional<FontPaletteIndex> basePalette, Vector<OverriddenColor>&& overrideColors) 109 97 : m_basePalette(basePalette) 110 98 , m_overrideColors(WTFMove(overrideColors)) … … 112 100 } 113 101 114 const FontPaletteIndex&basePalette() const102 std::optional<FontPaletteIndex> basePalette() const 115 103 { 116 104 return m_basePalette; … … 138 126 139 127 private: 140 FontPaletteIndexm_basePalette;128 std::optional<FontPaletteIndex> m_basePalette; 141 129 Vector<OverriddenColor> m_overrideColors; 142 130 }; -
trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
r283536 r283752 458 458 } 459 459 460 static void addAttributesForCustomFontPalettes(CFMutableDictionaryRef attributes, const FontPaletteIndex& basePalette, const Vector<FontPaletteValues::OverriddenColor>& overrideColors) 461 { 462 switch (basePalette.type) { 463 case FontPaletteIndex::Type::Light: 464 addLightPalette(attributes); 465 break; 466 case FontPaletteIndex::Type::Dark: 467 addDarkPalette(attributes); 468 break; 469 case FontPaletteIndex::Type::Integer: { 470 int64_t rawIndex = basePalette.integer; // There is no kCFNumberUIntType. 471 auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &rawIndex)); 472 CFDictionaryAddValue(attributes, kCTFontPaletteAttribute, number.get()); 473 break; 474 } 475 case FontPaletteIndex::Type::String: 476 // This is unimplementable in Core Text. 477 break; 460 static void addAttributesForCustomFontPalettes(CFMutableDictionaryRef attributes, std::optional<FontPaletteIndex> basePalette, const Vector<FontPaletteValues::OverriddenColor>& overrideColors) 461 { 462 if (basePalette) { 463 switch (basePalette->type) { 464 case FontPaletteIndex::Type::Light: 465 addLightPalette(attributes); 466 break; 467 case FontPaletteIndex::Type::Dark: 468 addDarkPalette(attributes); 469 break; 470 case FontPaletteIndex::Type::Integer: { 471 int64_t rawIndex = basePalette->integer; // There is no kCFNumberUIntType. 472 auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &rawIndex)); 473 CFDictionaryAddValue(attributes, kCTFontPaletteAttribute, number.get()); 474 break; 475 } 476 } 478 477 } 479 478 … … 481 480 auto overrideDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 482 481 for (const auto& pair : overrideColors) { 483 const auto& paletteColorIndex = pair.first;484 482 const auto& color = pair.second; 485 WTF::switchOn(paletteColorIndex, [] (const AtomString&) { 486 // This is unimplementable in Core Text. 487 }, [&] (unsigned index) { 488 int64_t rawIndex = index; // There is no kCFNumberUIntType. 489 auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &rawIndex)); 490 auto colorObject = cachedCGColor(color); 491 CFDictionaryAddValue(overrideDictionary.get(), number.get(), colorObject); 492 }); 483 int64_t rawIndex = pair.first; // There is no kCFNumberUIntType. 484 auto number = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &rawIndex)); 485 auto colorObject = cachedCGColor(color); 486 CFDictionaryAddValue(overrideDictionary.get(), number.get(), colorObject); 493 487 } 494 488 if (CFDictionaryGetCount(overrideDictionary.get()))
Note: See TracChangeset
for help on using the changeset viewer.