Diff
Added: trunk/LayoutTests/fast/text/font-shorthand-resolution-expected.txt (0 => 295476)
--- trunk/LayoutTests/fast/text/font-shorthand-resolution-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/text/font-shorthand-resolution-expected.txt 2022-06-11 23:44:42 UTC (rev 295476)
@@ -0,0 +1,10 @@
+PASS style.getPropertyValue('font-family') is not 'UICTFontTextStyleBody'
+PASS isNaN(parseInt(style.getPropertyValue('font-size'))) is true
+PASS style.getPropertyValue('font-style') is not 'normal'
+PASS isNaN(parseInt(style.getPropertyValue('font-weight'))) is true
+PASS style.getPropertyValue('font-variant-caps') is not 'normal'
+PASS style.getPropertyValue('line-height') is not 'normal'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/text/font-shorthand-resolution.html (0 => 295476)
--- trunk/LayoutTests/fast/text/font-shorthand-resolution.html (rev 0)
+++ trunk/LayoutTests/fast/text/font-shorthand-resolution.html 2022-06-11 23:44:42 UTC (rev 295476)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<style id="style">
+foo {
+ font: -apple-system-body;
+}
+</style>
+</head>
+<body>
+<script>
+let style = document.getElementById("style").sheet.cssRules[0].style;
+shouldNotBe("style.getPropertyValue('font-family')", "'UICTFontTextStyleBody'");
+shouldBeTrue("isNaN(parseInt(style.getPropertyValue('font-size')))");
+shouldNotBe("style.getPropertyValue('font-style')", "'normal'");
+shouldBeTrue("isNaN(parseInt(style.getPropertyValue('font-weight')))");
+shouldNotBe("style.getPropertyValue('font-variant-caps')", "'normal'");
+shouldNotBe("style.getPropertyValue('line-height')", "'normal'");
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/css/CSSProperties.json (295475 => 295476)
--- trunk/Source/WebCore/css/CSSProperties.json 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/css/CSSProperties.json 2022-06-11 23:44:42 UTC (rev 295476)
@@ -573,7 +573,8 @@
"codegen-properties": {
"name-for-methods": "VariantCaps",
"font-property": true,
- "high-priority": true
+ "high-priority": true,
+ "converter": "FontVariantCaps"
},
"specification": {
"category": "css-fonts",
Modified: trunk/Source/WebCore/css/StyleProperties.cpp (295475 => 295476)
--- trunk/Source/WebCore/css/StyleProperties.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/css/StyleProperties.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -465,6 +465,82 @@
commonValue = String();
}
+std::optional<CSSValueID> StyleProperties::isSingleFontShorthand() const
+{
+ // Intentionally don't check font-stretch here, because it isn't set by the font shorthand in CSSPropertyParser::consumeSystemFont().
+
+ auto sizePropertyIndex = findPropertyIndex(CSSPropertyFontSize);
+ auto familyPropertyIndex = findPropertyIndex(CSSPropertyFontFamily);
+ auto stylePropertyIndex = findPropertyIndex(CSSPropertyFontStyle);
+ auto variantCapsPropertyIndex = findPropertyIndex(CSSPropertyFontVariantCaps);
+ auto weightPropertyIndex = findPropertyIndex(CSSPropertyFontWeight);
+ auto lineHeightPropertyIndex = findPropertyIndex(CSSPropertyLineHeight);
+
+ if (sizePropertyIndex == -1
+ || familyPropertyIndex == -1
+ || stylePropertyIndex == -1
+ || variantCapsPropertyIndex == -1
+ || weightPropertyIndex == -1
+ || lineHeightPropertyIndex == -1)
+ return std::nullopt;
+
+ auto sizeProperty = propertyAt(sizePropertyIndex);
+ auto familyProperty = propertyAt(familyPropertyIndex);
+ auto styleProperty = propertyAt(stylePropertyIndex);
+ auto variantCapsProperty = propertyAt(variantCapsPropertyIndex);
+ auto weightProperty = propertyAt(weightPropertyIndex);
+ auto lineHeightProperty = propertyAt(lineHeightPropertyIndex);
+
+ if (sizeProperty.isImplicit()
+ || familyProperty.isImplicit()
+ || styleProperty.isImplicit()
+ || variantCapsProperty.isImplicit()
+ || weightProperty.isImplicit()
+ || lineHeightProperty.isImplicit())
+ return std::nullopt;
+
+ auto* sizeValue = sizeProperty.value();
+ auto* familyValue = familyProperty.value();
+ auto* styleValue = styleProperty.value();
+ auto* variantCapsValue = variantCapsProperty.value();
+ auto* weightValue = weightProperty.value();
+ auto* lineHeightValue = lineHeightProperty.value();
+
+ if (!is<CSSPrimitiveValue>(sizeValue)
+ || !is<CSSPrimitiveValue>(familyValue)
+ || !is<CSSPrimitiveValue>(styleValue)
+ || !is<CSSPrimitiveValue>(variantCapsValue)
+ || !is<CSSPrimitiveValue>(weightValue)
+ || !is<CSSPrimitiveValue>(lineHeightValue))
+ return std::nullopt;
+
+ auto& sizePrimitiveValue = downcast<CSSPrimitiveValue>(*sizeValue);
+ auto& familyPrimitiveValue = downcast<CSSPrimitiveValue>(*familyValue);
+ auto& stylePrimitiveValue = downcast<CSSPrimitiveValue>(*styleValue);
+ auto& variantCapsPrimitiveValue = downcast<CSSPrimitiveValue>(*variantCapsValue);
+ auto& weightPrimitiveValue = downcast<CSSPrimitiveValue>(*weightValue);
+ auto& lineHeightPrimitiveValue = downcast<CSSPrimitiveValue>(*lineHeightValue);
+
+ auto sizeValueID = sizePrimitiveValue.valueID();
+ auto familyValueID = familyPrimitiveValue.valueID();
+ auto styleValueID = stylePrimitiveValue.valueID();
+ auto variantCapsValueID = variantCapsPrimitiveValue.valueID();
+ auto weightValueID = weightPrimitiveValue.valueID();
+ auto lineHeightValueID = lineHeightPrimitiveValue.valueID();
+
+ if (sizeValueID != familyValueID
+ || sizeValueID != styleValueID
+ || sizeValueID != variantCapsValueID
+ || sizeValueID != weightValueID
+ || sizeValueID != lineHeightValueID)
+ return std::nullopt;
+
+ if (sizeValueID == CSSValueInvalid)
+ return std::nullopt;
+
+ return sizeValueID;
+}
+
String StyleProperties::fontValue() const
{
int fontSizePropertyIndex = findPropertyIndex(CSSPropertyFontSize);
@@ -477,6 +553,9 @@
if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit())
return emptyString();
+ if (auto shorthand = isSingleFontShorthand())
+ return getValueNameAtomString(shorthand.value());
+
String commonValue = fontSizeProperty.value()->cssText();
StringBuilder result;
appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue);
Modified: trunk/Source/WebCore/css/StyleProperties.h (295475 => 295476)
--- trunk/Source/WebCore/css/StyleProperties.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/css/StyleProperties.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -167,6 +167,7 @@
String textDecorationSkipValue() const;
String offsetValue() const;
void appendFontLonghandValueIfExplicit(CSSPropertyID, StringBuilder& result, String& value) const;
+ std::optional<CSSValueID> isSingleFontShorthand() const;
bool shorthandHasVariableReference(CSSPropertyID, String&) const;
StringBuilder asTextInternal() const;
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (295475 => 295476)
--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -5192,22 +5192,22 @@
bool CSSPropertyParser::consumeSystemFont(bool important)
{
CSSValueID systemFontID = m_range.consumeIncludingWhitespace().id();
- ASSERT(systemFontID >= CSSValueCaption && systemFontID <= CSSValueStatusBar);
+ ASSERT(CSSPropertyParserHelpers::isSystemFontShorthand(systemFontID));
if (!m_range.atEnd())
return false;
+
+ // It's illegal to look up properties (weight, size, etc.) of the system font here,
+ // because those values can change (e.g. accessibility font sizes, or accessibility bold).
+ // Parsing (correctly) doesn't re-run in response to updateStyleAfterChangeInEnvironment().
+ // Instead, we stuff sentinel values into the outputted CSSValues, which are later replaced by
+ // real system font values inside Style::BuilderCustom and Style::BuilderConverter.
- auto fontDescription = RenderTheme::singleton().systemFont(systemFontID);
- if (!fontDescription.isAbsoluteSize())
- return false;
-
- addProperty(CSSPropertyFontStyle, CSSPropertyFont, CSSFontStyleValue::create(CSSValuePool::singleton().createIdentifierValue(isItalic(fontDescription.italic()) ? CSSValueItalic : CSSValueNormal)), important);
- addProperty(CSSPropertyFontWeight, CSSPropertyFont, CSSValuePool::singleton().createValue(static_cast<float>(fontDescription.weight())), important);
- addProperty(CSSPropertyFontSize, CSSPropertyFont, CSSValuePool::singleton().createValue(fontDescription.specifiedSize(), CSSUnitType::CSS_PX), important);
- Ref<CSSValueList> fontFamilyList = CSSValueList::createCommaSeparated();
- fontFamilyList->append(CSSValuePool::singleton().createFontFamilyValue(fontDescription.familyAt(0), FromSystemFontID::Yes));
- addProperty(CSSPropertyFontFamily, CSSPropertyFont, WTFMove(fontFamilyList), important);
- addProperty(CSSPropertyFontVariantCaps, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
- addProperty(CSSPropertyLineHeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important);
+ addProperty(CSSPropertyFontStyle, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(systemFontID), important);
+ addProperty(CSSPropertyFontWeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(systemFontID), important);
+ addProperty(CSSPropertyFontSize, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(systemFontID), important);
+ addProperty(CSSPropertyFontFamily, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(systemFontID), important);
+ addProperty(CSSPropertyFontVariantCaps, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(systemFontID), important);
+ addProperty(CSSPropertyLineHeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(systemFontID), important);
// FIXME_NEWPARSER: What about FontVariantNumeric and FontVariantLigatures?
@@ -6384,7 +6384,7 @@
return consumeOverscrollBehaviorShorthand(important);
case CSSPropertyFont: {
const CSSParserToken& token = m_range.peek();
- if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar)
+ if (CSSPropertyParserHelpers::isSystemFontShorthand(token.id()))
return consumeSystemFont(important);
return consumeFont(important);
}
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h (295475 => 295476)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -1,5 +1,5 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2022 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -37,6 +37,7 @@
#include "CSSValuePool.h"
#include "Length.h" // For ValueRange
#include "StyleColor.h"
+#include "SystemFontDatabase.h"
#include <variant>
#include <wtf/OptionSet.h>
#include <wtf/Vector.h>
@@ -247,7 +248,20 @@
return angleInDegrees > -90 && angleInDegrees < 90;
}
+inline bool isSystemFontShorthand(CSSValueID valueID)
+{
+ // This needs to stay in sync with SystemFontDatabase::FontShorthand.
+ static_assert(CSSValueStatusBar - CSSValueCaption == static_cast<SystemFontDatabase::FontShorthandUnderlyingType>(SystemFontDatabase::FontShorthand::StatusBar));
+ return valueID >= CSSValueCaption && valueID <= CSSValueStatusBar;
+}
+inline SystemFontDatabase::FontShorthand lowerFontShorthand(CSSValueID valueID)
+{
+ // This needs to stay in sync with SystemFontDatabase::FontShorthand.
+ ASSERT(isSystemFontShorthand(valueID));
+ return static_cast<SystemFontDatabase::FontShorthand>(valueID - CSSValueCaption);
+}
+
} // namespace CSSPropertyParserHelpers
} // namespace WebCore
Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (295475 => 295476)
--- trunk/Source/WebCore/editing/EditingStyle.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -32,6 +32,7 @@
#include "CSSFontFamily.h"
#include "CSSFontStyleValue.h"
#include "CSSParser.h"
+#include "CSSPropertyParserHelpers.h"
#include "CSSRuleList.h"
#include "CSSStyleRule.h"
#include "CSSValueList.h"
@@ -269,7 +270,9 @@
if (primitiveValue.isCSSWideKeyword())
return false;
- switch (primitiveValue.valueID()) {
+ auto valueID = primitiveValue.valueID();
+
+ switch (valueID) {
case CSSValueNormal:
return false;
case CSSValueBold:
@@ -278,6 +281,9 @@
break;
}
+ if (CSSPropertyParserHelpers::isSystemFontShorthand(valueID))
+ return false;
+
ASSERT(primitiveValue.isNumber());
return primitiveValue.floatValue() >= static_cast<float>(boldThreshold());
}
Modified: trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp (295475 => 295476)
--- trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -33,8 +33,8 @@
#include "CommonVM.h"
#include "GraphicsContext.h"
#include "Page.h"
-#include "RenderTheme.h"
#include "ResourceUsageThread.h"
+#include "SystemFontDatabase.h"
#include <_javascript_Core/VM.h>
#include <wtf/text/StringConcatenateNumbers.h>
@@ -75,7 +75,11 @@
ResourceUsageOverlayPainter(ResourceUsageOverlay& overlay)
: m_overlay(overlay)
{
- auto fontDescription = RenderTheme::singleton().systemFont(CSSValueMessageBox);
+ auto& systemFontDatabase = SystemFontDatabase::singleton();
+ auto messageBox = SystemFontDatabase::FontShorthand::MessageBox;
+ FontCascadeDescription fontDescription;
+ fontDescription.setOneFamily(systemFontDatabase.systemFontShorthandFamily(messageBox));
+ fontDescription.setWeight(systemFontDatabase.systemFontShorthandWeight(messageBox));
fontDescription.setComputedSize(gFontSize);
m_textFont = FontCascade(WTFMove(fontDescription), 0, 0);
m_textFont.update(nullptr);
Modified: trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h (295475 => 295476)
--- trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/platform/graphics/SystemFontDatabase.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -38,7 +38,7 @@
WEBCORE_EXPORT static SystemFontDatabase& singleton();
enum class FontShorthand {
- // This needs to be kept in sync with CSSValue.
+ // This needs to be kept in sync with CSSValue and CSSPropertyParserHelpers::lowerFontShorthand().
Caption,
Icon,
Menu,
@@ -68,6 +68,7 @@
#endif
StatusBar, // This has to be kept in sync with SystemFontShorthandCache below.
};
+ using FontShorthandUnderlyingType = std::underlying_type<FontShorthand>::type;
const AtomString& systemFontShorthandFamily(FontShorthand);
float systemFontShorthandSize(FontShorthand);
Modified: trunk/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp (295475 => 295476)
--- trunk/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/platform/graphics/wpe/SystemFontDatabaseWPE.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -39,7 +39,7 @@
return database.get();
}
-auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand fontShorthand) -> SystemFontShorthandInfo
+auto SystemFontDatabase::platformSystemFontShorthandInfo(FontShorthand) -> SystemFontShorthandInfo
{
notImplemented();
return { WebKitFontFamilyNames::standardFamily, 16, normalWeightValue() };
Modified: trunk/Source/WebCore/rendering/RenderTheme.h (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderTheme.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderTheme.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -187,7 +187,6 @@
virtual Seconds caretBlinkInterval() const { return 500_ms; }
// System fonts and colors for CSS.
- virtual FontCascadeDescription systemFont(CSSValueID) const = 0;
virtual Color systemColor(CSSValueID, OptionSet<StyleColorOptions>) const;
virtual int minimumMenuListSize(const RenderStyle&) const { return 0; }
Modified: trunk/Source/WebCore/rendering/RenderThemeAdwaita.h (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeAdwaita.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeAdwaita.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -56,8 +56,6 @@
bool supportsListBoxSelectionForegroundColors(OptionSet<StyleColorOptions>) const final { return true; }
bool shouldHaveCapsLockIndicator(const HTMLInputElement&) const final;
- FontCascadeDescription systemFont(CSSValueID) const override { return FontCascadeDescription(); };
-
Color platformActiveSelectionBackgroundColor(OptionSet<StyleColorOptions>) const final;
Color platformInactiveSelectionBackgroundColor(OptionSet<StyleColorOptions>) const final;
Color platformActiveSelectionForegroundColor(OptionSet<StyleColorOptions>) const final;
Modified: trunk/Source/WebCore/rendering/RenderThemeCocoa.h (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeCocoa.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeCocoa.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -46,8 +46,6 @@
bool paintApplePayButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
#endif
- FontCascadeDescription systemFont(CSSValueID systemFontID) const override;
-
#if ENABLE(VIDEO) && ENABLE(MODERN_MEDIA_CONTROLS)
String mediaControlsStyleSheet() override;
Vector<String, 2> mediaControlsScripts() override;
Modified: trunk/Source/WebCore/rendering/RenderThemeCocoa.mm (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeCocoa.mm 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeCocoa.mm 2022-06-11 23:44:42 UTC (rev 295476)
@@ -196,150 +196,4 @@
return FontSelectionValue(900);
}
-FontCascadeDescription RenderThemeCocoa::systemFont(CSSValueID valueID) const
-{
- auto cocoaFontClass = [] {
-#if PLATFORM(IOS_FAMILY)
- return PAL::getUIFontClass();
-#else
- return NSFont.class;
-#endif
- };
- // FIXME: Hook up locale strings.
- RetainPtr<CTFontDescriptorRef> fontDescriptor;
- CFStringRef textStyle = nullptr;
- AtomString style;
- switch (valueID) {
- case CSSValueAppleSystemHeadline:
- textStyle = kCTUIFontTextStyleHeadline;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemBody:
- textStyle = kCTUIFontTextStyleBody;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemTitle0:
- textStyle = kCTUIFontTextStyleTitle0;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemTitle1:
- textStyle = kCTUIFontTextStyleTitle1;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemTitle2:
- textStyle = kCTUIFontTextStyleTitle2;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemTitle3:
- textStyle = kCTUIFontTextStyleTitle3;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemTitle4:
- textStyle = kCTUIFontTextStyleTitle4;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemSubheadline:
- textStyle = kCTUIFontTextStyleSubhead;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemFootnote:
- textStyle = kCTUIFontTextStyleFootnote;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemCaption1:
- textStyle = kCTUIFontTextStyleCaption1;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemCaption2:
- textStyle = kCTUIFontTextStyleCaption2;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemShortHeadline:
- textStyle = kCTUIFontTextStyleShortHeadline;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemShortBody:
- textStyle = kCTUIFontTextStyleShortBody;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemShortSubheadline:
- textStyle = kCTUIFontTextStyleShortSubhead;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemShortFootnote:
- textStyle = kCTUIFontTextStyleShortFootnote;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemShortCaption1:
- textStyle = kCTUIFontTextStyleShortCaption1;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueAppleSystemTallBody:
- textStyle = kCTUIFontTextStyleTallBody;
- fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), nullptr));
- break;
- case CSSValueSmallCaption: {
- style = "system-ui"_s;
- auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() smallSystemFontSize]];
- fontDescriptor = static_cast<CTFontDescriptorRef>(font.fontDescriptor);
- break;
- }
- case CSSValueMenu:
- style = "-apple-menu"_s;
- fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontMenuItem, [cocoaFontClass() systemFontSize], nullptr));
- break;
- case CSSValueStatusBar: {
- style = "-apple-status-bar"_s;
- fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, [cocoaFontClass() labelFontSize], nullptr));
- break;
- }
- case CSSValueWebkitMiniControl: {
- style = "system-ui"_s;
-#if PLATFORM(IOS_FAMILY)
- fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontMiniSystem, 0, nullptr));
-#else
- auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeMini]];
- fontDescriptor = static_cast<CTFontDescriptorRef>(font.fontDescriptor);
-#endif
- break;
- }
- case CSSValueWebkitSmallControl: {
- style = "system-ui"_s;
-#if PLATFORM(IOS_FAMILY)
- fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSmallSystem, 0, nullptr));
-#else
- auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeSmall]];
- fontDescriptor = static_cast<CTFontDescriptorRef>(font.fontDescriptor);
-#endif
- break;
- }
- case CSSValueWebkitControl: {
- style = "system-ui"_s;
-#if PLATFORM(IOS_FAMILY)
- fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, 0, nullptr));
-#else
- auto font = [cocoaFontClass() systemFontOfSize:[cocoaFontClass() systemFontSizeForControlSize:NSControlSizeRegular]];
- fontDescriptor = static_cast<CTFontDescriptorRef>(font.fontDescriptor);
-#endif
- break;
- }
- default:
- style = "system-ui"_s;
- fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, 0, nullptr));
- }
-
- if (style.isNull())
- style = textStyle;
-
- ASSERT(fontDescriptor);
- auto font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr));
- FontCascadeDescription fontDescription;
- fontDescription.setIsAbsoluteSize(true);
- fontDescription.setOneFamily(style);
- fontDescription.setSpecifiedSize(CTFontGetSize(font.get()));
- fontDescription.setWeight(cssWeightOfSystemFont(font.get()));
- fontDescription.setItalic(normalItalicValue());
- return fontDescription;
}
-
-}
Modified: trunk/Source/WebCore/rendering/RenderThemeGtk.cpp (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeGtk.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeGtk.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -37,38 +37,6 @@
return theme;
}
-FontCascadeDescription RenderThemeGtk::systemFont(CSSValueID) const
-{
- GtkSettings* settings = gtk_settings_get_default();
- if (!settings)
- return FontCascadeDescription();
-
- // This will be a font selection string like "Sans 10" so we cannot use it as the family name.
- GUniqueOutPtr<gchar> fontName;
- g_object_get(settings, "gtk-font-name", &fontName.outPtr(), nullptr);
- if (!fontName || !fontName.get()[0])
- return FontCascadeDescription();
-
- PangoFontDescription* pangoDescription = pango_font_description_from_string(fontName.get());
- if (!pangoDescription)
- return FontCascadeDescription();
-
- FontCascadeDescription fontDescription;
- fontDescription.setOneFamily(AtomString::fromLatin1(pango_font_description_get_family(pangoDescription)));
-
- int size = pango_font_description_get_size(pangoDescription) / PANGO_SCALE;
- // If the size of the font is in points, we need to convert it to pixels.
- if (!pango_font_description_get_size_is_absolute(pangoDescription))
- size = size * (screenDPI() / 72.0);
-
- fontDescription.setSpecifiedSize(size);
- fontDescription.setIsAbsoluteSize(true);
- fontDescription.setWeight(normalWeightValue());
- fontDescription.setItalic(FontSelectionValue());
- pango_font_description_free(pangoDescription);
- return fontDescription;
-}
-
Seconds RenderThemeGtk::caretBlinkInterval() const
{
gboolean shouldBlink;
Modified: trunk/Source/WebCore/rendering/RenderThemeGtk.h (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeGtk.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeGtk.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -29,7 +29,6 @@
private:
virtual ~RenderThemeGtk() = default;
- FontCascadeDescription systemFont(CSSValueID) const override;
Seconds caretBlinkInterval() const override;
};
Modified: trunk/Source/WebCore/rendering/RenderThemePlayStation.cpp (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemePlayStation.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemePlayStation.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -37,10 +37,4 @@
return theme;
}
-FontCascadeDescription RenderThemePlayStation::systemFont(CSSValueID) const
-{
- notImplemented();
- return FontCascadeDescription();
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/RenderThemeWin.cpp (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeWin.cpp 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeWin.cpp 2022-06-11 23:44:42 UTC (rev 295476)
@@ -308,60 +308,6 @@
return platformActiveSelectionForegroundColor(options);
}
-FontCascadeDescription RenderThemeWin::systemFont(CSSValueID valueID) const
-{
- static bool initialized;
- static NONCLIENTMETRICS ncm;
-
- if (!initialized) {
- initialized = true;
- ncm.cbSize = sizeof(NONCLIENTMETRICS);
- ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
- }
-
- LOGFONT logFont;
- bool shouldUseDefaultControlFontPixelSize = false;
- switch (valueID) {
- case CSSValueIcon:
- ::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0);
- break;
- case CSSValueMenu:
- logFont = ncm.lfMenuFont;
- break;
- case CSSValueMessageBox:
- logFont = ncm.lfMessageFont;
- break;
- case CSSValueStatusBar:
- logFont = ncm.lfStatusFont;
- break;
- case CSSValueCaption:
- logFont = ncm.lfCaptionFont;
- break;
- case CSSValueSmallCaption:
- logFont = ncm.lfSmCaptionFont;
- break;
- case CSSValueWebkitSmallControl:
- case CSSValueWebkitMiniControl: // Just map to small.
- case CSSValueWebkitControl: // Just map to small.
- shouldUseDefaultControlFontPixelSize = true;
- FALLTHROUGH;
- default: { // Everything else uses the stock GUI font.
- HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
- if (!hGDI)
- return FontCascadeDescription();
- if (::GetObject(hGDI, sizeof(logFont), &logFont) <= 0)
- return FontCascadeDescription();
- }
- }
- FontCascadeDescription fontDescription;
- fontDescription.setIsAbsoluteSize(true);
- fontDescription.setOneFamily(logFont.lfFaceName);
- fontDescription.setSpecifiedSize(shouldUseDefaultControlFontPixelSize ? defaultControlFontPixelSize : abs(logFont.lfHeight));
- fontDescription.setWeight(logFont.lfWeight >= 700 ? boldWeightValue() : normalWeightValue()); // FIXME: Use real weight.
- fontDescription.setIsItalic(logFont.lfItalic);
- return fontDescription;
-}
-
bool RenderThemeWin::supportsFocus(ControlPart appearance) const
{
switch (appearance) {
Modified: trunk/Source/WebCore/rendering/RenderThemeWin.h (295475 => 295476)
--- trunk/Source/WebCore/rendering/RenderThemeWin.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/rendering/RenderThemeWin.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -139,9 +139,6 @@
RenderThemeWin();
virtual ~RenderThemeWin();
- // System fonts.
- FontCascadeDescription systemFont(CSSValueID) const override;
-
void addIntrinsicMargins(RenderStyle&) const;
void close();
Modified: trunk/Source/WebCore/style/StyleBuilderConverter.h (295475 => 295476)
--- trunk/Source/WebCore/style/StyleBuilderConverter.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/style/StyleBuilderConverter.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
- * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -42,6 +42,7 @@
#include "CSSOffsetRotateValue.h"
#include "CSSPrimitiveValue.h"
#include "CSSPrimitiveValueMappings.h"
+#include "CSSPropertyParserHelpers.h"
#include "CSSRayValue.h"
#include "CSSReflectValue.h"
#include "CSSSubgridValue.h"
@@ -149,6 +150,7 @@
static FontSelectionValue convertFontWeight(BuilderState&, const CSSValue&);
static FontSelectionValue convertFontStretch(BuilderState&, const CSSValue&);
static FontSelectionValue convertFontStyle(BuilderState&, const CSSValue&);
+ static FontVariantCaps convertFontVariantCaps(BuilderState&, const CSSValue&);
static FontVariationSettings convertFontVariationSettings(BuilderState&, const CSSValue&);
static SVGLengthValue convertSVGLengthValue(BuilderState&, const CSSValue&);
static Vector<SVGLengthValue> convertSVGLengthVector(BuilderState&, const CSSValue&);
@@ -1364,10 +1366,22 @@
return FontCascadeDescription::bolderWeight(builderState.parentStyle().fontDescription().weight());
if (valueID == CSSValueLighter)
return FontCascadeDescription::lighterWeight(builderState.parentStyle().fontDescription().weight());
+ if (CSSPropertyParserHelpers::isSystemFontShorthand(valueID))
+ return SystemFontDatabase::singleton().systemFontShorthandWeight(CSSPropertyParserHelpers::lowerFontShorthand(valueID));
}
return convertFontWeightFromValue(value);
}
+inline FontVariantCaps BuilderConverter::convertFontVariantCaps(BuilderState&, const CSSValue& value)
+{
+ auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
+ auto valueID = primitiveValue.valueID();
+ if (CSSPropertyParserHelpers::isSystemFontShorthand(valueID))
+ return FontVariantCaps::Normal;
+
+ return static_cast<FontVariantCaps>(primitiveValue);
+}
+
inline FontSelectionValue BuilderConverter::convertFontStretch(BuilderState&, const CSSValue& value)
{
return convertFontStretchFromValue(value);
@@ -1559,9 +1573,13 @@
inline std::optional<Length> BuilderConverter::convertLineHeight(BuilderState& builderState, const CSSValue& value, float multiplier)
{
auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
- if (primitiveValue.valueID() == CSSValueNormal)
+ auto valueID = primitiveValue.valueID();
+ if (valueID == CSSValueNormal)
return RenderStyle::initialLineHeight();
+ if (CSSPropertyParserHelpers::isSystemFontShorthand(valueID))
+ return RenderStyle::initialLineHeight();
+
if (primitiveValue.isLength()) {
auto conversionData = builderState.cssToLengthConversionData().copyForLineHeight(zoomWithTextZoomFactor(builderState));
Length length = primitiveValue.computeLength<Length>(conversionData);
@@ -1703,5 +1721,5 @@
});
}
-}
-}
+} // namespace Style
+} // namespace WebCore
Modified: trunk/Source/WebCore/style/StyleBuilderCustom.h (295475 => 295476)
--- trunk/Source/WebCore/style/StyleBuilderCustom.h 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebCore/style/StyleBuilderCustom.h 2022-06-11 23:44:42 UTC (rev 295476)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
- * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1045,38 +1045,47 @@
inline void BuilderCustom::applyValueFontFamily(BuilderState& builderState, CSSValue& value)
{
- auto& valueList = downcast<CSSValueList>(value);
-
auto fontDescription = builderState.fontDescription();
// Before mapping in a new font-family property, we should reset the generic family.
bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
Vector<AtomString> families;
- families.reserveInitialCapacity(valueList.length());
- for (auto& item : valueList) {
- auto& contentValue = downcast<CSSPrimitiveValue>(item.get());
- AtomString family;
- bool isGenericFamily = false;
- if (contentValue.isFontFamily()) {
- const CSSFontFamily& fontFamily = contentValue.fontFamily();
- family = AtomString { fontFamily.familyName };
- // If the family name was resolved by the CSS parser from a system font ID, then it is generic.
- isGenericFamily = fontFamily.fromSystemFontID;
- } else {
- if (contentValue.valueID() == CSSValueWebkitBody)
- family = AtomString { builderState.document().settings().standardFontFamily() };
- else {
- isGenericFamily = true;
- family = CSSPropertyParserHelpers::genericFontFamily(contentValue.valueID());
+ if (is<CSSPrimitiveValue>(value)) {
+ auto valueID = downcast<CSSPrimitiveValue>(value).valueID();
+ ASSERT(CSSPropertyParserHelpers::isSystemFontShorthand(valueID));
+ AtomString family = SystemFontDatabase::singleton().systemFontShorthandFamily(CSSPropertyParserHelpers::lowerFontShorthand(valueID));
+ ASSERT(!family.isEmpty());
+ fontDescription.setIsSpecifiedFont(false);
+ families.reserveInitialCapacity(1);
+ families.uncheckedAppend(family);
+ } else {
+ auto& valueList = downcast<CSSValueList>(value);
+ families.reserveInitialCapacity(valueList.length());
+ for (auto& item : valueList) {
+ auto& contentValue = downcast<CSSPrimitiveValue>(item.get());
+ AtomString family;
+ bool isGenericFamily = false;
+ if (contentValue.isFontFamily()) {
+ const CSSFontFamily& fontFamily = contentValue.fontFamily();
+ family = AtomString { fontFamily.familyName };
+ // If the family name was resolved by the CSS parser from a system font ID, then it is generic.
+ isGenericFamily = fontFamily.fromSystemFontID;
+ } else {
+ if (contentValue.valueID() == CSSValueWebkitBody)
+ family = AtomString { builderState.document().settings().standardFontFamily() };
+ else {
+ isGenericFamily = true;
+ family = CSSPropertyParserHelpers::genericFontFamily(contentValue.valueID());
+ }
}
+
+ if (family.isEmpty())
+ continue;
+ if (families.isEmpty())
+ fontDescription.setIsSpecifiedFont(!isGenericFamily);
+ families.uncheckedAppend(family);
}
-
- if (family.isEmpty())
- continue;
- if (families.isEmpty())
- fontDescription.setIsSpecifiedFont(!isGenericFamily);
- families.uncheckedAppend(family);
}
if (families.isEmpty())
@@ -1822,6 +1831,17 @@
inline void BuilderCustom::applyValueFontStyle(BuilderState& builderState, CSSValue& value)
{
+ if (is<CSSPrimitiveValue>(value)) {
+ auto valueID = downcast<CSSPrimitiveValue>(value).valueID();
+ ASSERT_UNUSED(valueID, CSSPropertyParserHelpers::isSystemFontShorthand(valueID));
+
+ auto fontDescription = builderState.fontDescription();
+ fontDescription.setItalic(std::nullopt);
+ fontDescription.setFontStyleAxis(FontStyleAxis::slnt);
+ builderState.setFontDescription(WTFMove(fontDescription));
+ return;
+ }
+
auto& fontStyleValue = downcast<CSSFontStyleValue>(value);
auto fontDescription = builderState.fontDescription();
fontDescription.setItalic(BuilderConverter::convertFontStyleFromValue(fontStyleValue));
@@ -1838,11 +1858,13 @@
bool parentIsAbsoluteSize = builderState.parentStyle().fontDescription().isAbsoluteSize();
auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
- float size;
+ float size = 0;
if (CSSValueID ident = primitiveValue.valueID()) {
- fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize && (ident == CSSValueLarger || ident == CSSValueSmaller || ident == CSSValueWebkitRubyText));
+ fontDescription.setIsAbsoluteSize((parentIsAbsoluteSize && (ident == CSSValueLarger || ident == CSSValueSmaller || ident == CSSValueWebkitRubyText)) || CSSPropertyParserHelpers::isSystemFontShorthand(ident));
- // Keywords are being used.
+ if (CSSPropertyParserHelpers::isSystemFontShorthand(ident))
+ size = SystemFontDatabase::singleton().systemFontShorthandSize(CSSPropertyParserHelpers::lowerFontShorthand(ident));
+
switch (ident) {
case CSSValueXxSmall:
case CSSValueXSmall:
@@ -1865,7 +1887,7 @@
size = determineRubyTextSizeMultiplier(builderState) * parentSize;
break;
default:
- return;
+ break;
}
} else {
fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize || !(primitiveValue.isPercentage() || primitiveValue.isFontRelativeLength()));
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (295475 => 295476)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2022-06-11 23:44:42 UTC (rev 295476)
@@ -142,6 +142,7 @@
#import <WebCore/ShadowRoot.h>
#import <WebCore/SharedBuffer.h>
#import <WebCore/StyleProperties.h>
+#import <WebCore/SystemFontDatabase.h>
#import <WebCore/TextIndicator.h>
#import <WebCore/TextIterator.h>
#import <WebCore/TextPlaceholderElement.h>
@@ -4387,6 +4388,7 @@
void WebPage::contentSizeCategoryDidChange(const String& contentSizeCategory)
{
setContentSizeCategory(contentSizeCategory);
+ SystemFontDatabase::singleton().clear();
Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
}
Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (295475 => 295476)
--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2022-06-11 22:32:52 UTC (rev 295475)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2022-06-11 23:44:42 UTC (rev 295476)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -83,6 +83,7 @@
#import <WebCore/RuntimeEnabledFeatures.h>
#import <WebCore/SWContextManager.h>
#import <WebCore/SystemBattery.h>
+#import <WebCore/SystemFontDatabase.h>
#import <WebCore/SystemSoundManager.h>
#import <WebCore/UTIUtilities.h>
#import <WebCore/WebMAudioUtilitiesCocoa.h>
@@ -1019,6 +1020,8 @@
auto invertColorsEnabled = preferences.invertColorsEnabled;
if (_AXSInvertColorsEnabledApp(appID) != invertColorsEnabled)
_AXSInvertColorsSetEnabledApp(invertColorsEnabled, appID);
+ SystemFontDatabase::singleton().clear();
+ Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
#endif
}