Skip to content

Commit

Permalink
Split descriptors out of properties dictionary in CSSProperties.json
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=249558
rdar://103497902

Reviewed by Antti Koivisto.

Adds a new top level object to CSSProperties.json, "descriptors", which contains
mappings from CSS rule types (e.g. @font-face, @counter-style) to a map of the
descriptors that rule type supports. This allows us to remove the 'descriptor-only'
properties from the main 'properties' map, and also accurately specify the
descriptors that shared names with properties. This is important as some descriptors
share a name with a property but have different grammars.

With the new data in CSSProperties.json, we now generate parse functions for
the new rule types specified: @counter-style, @font-face, @font-palette-values.
and @Property. While not too many of the descriptors can be generated right now,
the main "parse...Descriptor" functions can be, and this adds the foundation for
generating more as we add more capabilities to the parser.

To differentiate between style properties and descriptors when exporting consumer
functions, descriptors have a prefix based on their rule type added. For example,
@font-face defines a "font-display" descriptor, which is needed elsewhere, so we
export a function called `CSSPropertyParsing::consumeFontFaceFontDisplay()`.

* Source/WebCore/css/CSSProperties.json:
Move/copy descriptors to new section. Remove support for descriptor-only now
that it can be inferred.

* Source/WebCore/css/parser/CSSParserFastPaths.cpp:
(WebCore::CSSParserFastPaths::isKeywordValidForStyleProperty):
(WebCore::CSSParserFastPaths::isKeywordFastPathEligibleStyleProperty):
(WebCore::parseKeywordValue):
(WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue): Deleted.
(WebCore::CSSParserFastPaths::isKeywordPropertyID): Deleted.
* Source/WebCore/css/parser/CSSParserFastPaths.h:
Update for more precise names that differentiate between properties
and descriptors.

* Source/WebCore/css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseValue):
Remove unnecessary passing of the CSSParserContext to a member
function. It can access it via *this.

(WebCore::CSSPropertyParser::parseSingleValue):
Update for rename from parse() to parseStyleProperty().

(WebCore::CSSPropertyParser::parseCounterStyleDescriptor):
(WebCore::CSSPropertyParser::parseFontFaceDescriptor):
(WebCore::CSSPropertyParser::parseFontFaceDescriptorShorthand):
(WebCore::CSSPropertyParser::parseFontPaletteValuesDescriptor):
Call through to the new generated parsers.

(WebCore::consumeCounterStyleSystem): Deleted.
(WebCore::consumeCounterStyleSymbol): Deleted.
(WebCore::consumeCounterStyleNegative): Deleted.
(WebCore::consumeCounterStyleRangeBound): Deleted.
(WebCore::consumeCounterStyleRange): Deleted.
(WebCore::consumeCounterStylePad): Deleted.
(WebCore::consumeCounterStyleSymbols): Deleted.
(WebCore::consumeCounterStyleAdditiveSymbols): Deleted.
(WebCore::consumeCounterStyleSpeakAs): Deleted.
(WebCore::consumeBasePaletteDescriptor): Deleted.
(WebCore::consumeOverrideColorsDescriptor): Deleted.
Moved to CSSPropertyParserHelpers.cpp for consistency.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeBackgroundSize):
(WebCore::CSSPropertyParserHelpers::consumeFontFaceFontFamily):
(WebCore::CSSPropertyParserHelpers::consumeFontPaletteValuesOverrideColors):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleSystem):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleSymbol):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleNegative):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleRangeBound):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleRange):
(WebCore::CSSPropertyParserHelpers::consumeCounterStylePad):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleSymbols):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleAdditiveSymbols):
(WebCore::CSSPropertyParserHelpers::consumeCounterStyleSpeakAs):
(WebCore::CSSPropertyParserHelpers::consumeFontFamilyDescriptor): Deleted.
* Source/WebCore/css/parser/CSSPropertyParserHelpers.h:
Moved functions from CSSPropertyParser. Renamed consumeFontFamilyDescriptor
to consumeFontFaceFontFamily to better align with naming convention.

* Source/WebCore/css/process-css-properties.py:
Adds support for the new 'descriptors' top level object and generalizes
parser code generation to support them.

* Source/WebCore/inspector/agents/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getSupportedCSSProperties):
Update for renames.

* Tools/Scripts/webkitpy/style/checkers/jsonchecker.py:
Add checker support for the new sections. Remove support for descriptor-only.

Canonical link: https://commits.webkit.org/258084@main
  • Loading branch information
weinig authored and Sam Weinig committed Dec 19, 2022
1 parent 87ae77e commit 229a3a2
Show file tree
Hide file tree
Showing 12 changed files with 1,453 additions and 827 deletions.
597 changes: 385 additions & 212 deletions Source/WebCore/css/CSSProperties.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Source/WebCore/css/parser/CSSParserFastPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,14 @@ std::optional<SRGBA<uint8_t>> CSSParserFastPaths::parseNamedColor(StringView str
return parseNamedColorInternal(string.characters16(), string.length());
}

bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID property, CSSValueID value, const CSSParserContext& context)
bool CSSParserFastPaths::isKeywordValidForStyleProperty(CSSPropertyID property, CSSValueID value, const CSSParserContext& context)
{
return CSSPropertyParsing::isKeywordValidForProperty(property, value, context);
return CSSPropertyParsing::isKeywordValidForStyleProperty(property, value, context);
}

bool CSSParserFastPaths::isKeywordPropertyID(CSSPropertyID property)
bool CSSParserFastPaths::isKeywordFastPathEligibleStyleProperty(CSSPropertyID property)
{
return CSSPropertyParsing::isKeywordProperty(property);
return CSSPropertyParsing::isKeywordFastPathEligibleStyleProperty(property);
}

static bool isUniversalKeyword(StringView string)
Expand All @@ -614,7 +614,7 @@ static RefPtr<CSSValue> parseKeywordValue(CSSPropertyID propertyId, StringView s
// FIXME: The "!context.enclosingRuleType" is suspicious.
ASSERT(!CSSProperty::isDescriptorOnly(propertyId) || parsingDescriptor || !context.enclosingRuleType);

if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) {
if (!CSSParserFastPaths::isKeywordFastPathEligibleStyleProperty(propertyId)) {
// All properties, including non-keyword properties, accept the CSS-wide keywords.
if (!isUniversalKeyword(string))
return nullptr;
Expand All @@ -636,7 +636,7 @@ static RefPtr<CSSValue> parseKeywordValue(CSSPropertyID propertyId, StringView s
if (!parsingDescriptor && isCSSWideKeyword(valueID))
return CSSValuePool::singleton().createIdentifierValue(valueID);

if (CSSParserFastPaths::isValidKeywordPropertyAndValue(propertyId, valueID, context))
if (CSSParserFastPaths::isKeywordValidForStyleProperty(propertyId, valueID, context))
return CSSValuePool::singleton().createIdentifierValue(valueID);
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/parser/CSSParserFastPaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class CSSParserFastPaths {
static RefPtr<CSSValue> maybeParseValue(CSSPropertyID, StringView, const CSSParserContext&);

// Properties handled here shouldn't be explicitly handled in CSSPropertyParser.
static bool isKeywordPropertyID(CSSPropertyID);
static bool isValidKeywordPropertyAndValue(CSSPropertyID, CSSValueID, const CSSParserContext&);
static bool isKeywordFastPathEligibleStyleProperty(CSSPropertyID);
static bool isKeywordValidForStyleProperty(CSSPropertyID, CSSValueID, const CSSParserContext&);

// Parses numeric and named colors.
static std::optional<SRGBA<uint8_t>> parseSimpleColor(StringView, bool strict = false);
Expand Down
Loading

0 comments on commit 229a3a2

Please sign in to comment.