[webkit-changes] [WebKit/WebKit] 19ef95: Add support for unbounded repetition terms in the ...

Sam Weinig noreply at github.com
Sun Nov 27 13:49:41 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 19ef95a624848a4b52b40c5c664357a3993fccc6
      https://github.com/WebKit/WebKit/commit/19ef95a624848a4b52b40c5c664357a3993fccc6
  Author: Sam Weinig <weinig at apple.com>
  Date:   2022-11-27 (Sun, 27 Nov 2022)

  Changed paths:
    M Source/WebCore/css/CSSPrimitiveValue.h
    M Source/WebCore/css/CSSProperties.json
    M Source/WebCore/css/StyleProperties.cpp
    M Source/WebCore/css/parser/CSSPropertyParser.cpp
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.h
    M Source/WebCore/css/process-css-properties.py
    M Tools/Scripts/webkitpy/style/checkers/jsonchecker.py

  Log Message:
  -----------
  Add support for unbounded repetition terms in the new property parser generator
https://bugs.webkit.org/show_bug.cgi?id=248355
rdar://102675501

Reviewed by Darin Adler.

Adds support for parsing unbounded comma separated lists via CSSProperties.json.
Specifically, this adds support for the `#` operator without range refinement
(e.g. no #{1,4}):

  """
   A hash mark (#) indicates that the preceding type, word, or group occurs
   one or more times, separated by comma tokens (which may optionally be
   surrounded by white space and/or comments).
  """
    -  https://www.w3.org/TR/css-values-4/#mult-comma

This brings with it support for a large collection (29) of longhands in the
animation, transition, background and mask families of properties.

To generate the matching for one of these lists, a new term type can be
specified in CSSProperties.json with 'kind' set to 'repetition' and 'value'
set to whatever should be repeatedly matched. As a shorthand, the spec syntax
utilizing a `#` can also be used. For instance, 'animation-duration', which
has a specified grammar of:

  `<'animation-duration'> = <time [0s,∞]#`

uses the following:

  "parser-grammar": "<time [0,inf]>#"

* Source/WebCore/css/CSSProperties.json:
Replaces use of custom-parser/parser-function with parser-grammar for the
newly supported properties and adds a set of new shared grammar rules for
implementing them.

* Source/WebCore/css/parser/CSSPropertyParser.cpp:
(WebCore::consumeCounterStyleRange): Adopt new consumeCommaSeparatedList* helper.
(WebCore::consumeCounterStyleAdditiveSymbols): Ditto.
(WebCore::consumeOverrideColorsDescriptor): Ditto.
(WebCore::isValidAnimationPropertyList): Moved from CSSPropertyParserHelpers as
now the only caller is in this file.
(WebCore::consumeAnimationValueForShorthand): Ditto. Also now implemented using
more exported shared grammar rules.
(WebCore::CSSPropertyParser::consumeAnimationShorthand): Adopt new
consumeCommaSeparatedList* helper
(WebCore::addBackgroundValue): Moved from CSSPropertyParserHelpers as now the only
caller is in this file.
(WebCore::CSSPropertyParser::consumeBackgroundShorthand): Split background-size and
mask size as they now have separate consume functions (though at the moment identical).

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeFontVariationSettings): Adopt new
consumeCommaSeparatedList* helper.
(WebCore::CSSPropertyParserHelpers::consumeFontFamily): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeKeyframesName): Added to allow "animation-name"
to be mostly generated. Unused CSSParserContext parameteter is a by product consumers called
from generated consumers are expected to take a CSSParserContext for the moment. This should
be refined to not be required in the future.
(WebCore::CSSPropertyParserHelpers::consumeSingleTransitionPropertyIdent):
(WebCore::CSSPropertyParserHelpers::consumeSingleTransitionPropertyOrNone):
(WebCore::CSSPropertyParserHelpers::consumeSingleTransitionProperty):
Split out shorthand and longhand behaviors into separate functions (with a shared
helper between them). Previously, the shorthand version (allowing "none") was used
in both places, and then a post consume check if any values were "none" was done.
Now that we are generating the repetition, doing the post consume check is non-trivial
so just doing the parse right makes more sense.
(WebCore::CSSPropertyParserHelpers::consumeSteps): Make static (and remove forward
declaration from header. Nothing outside this file uses this function.
(WebCore::CSSPropertyParserHelpers::consumeCubicBezier): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSpringFunction): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeTimingFunction): Renamed from
consumeAnimationTimingFunction to better reflect the spec naming and to indicate it used
for more than just animation as it transtions also use it.
(WebCore::CSSPropertyParserHelpers::consumeShadow): Make static (and remove forward
declaration from header. Nothing outside this file uses this function.
(WebCore::CSSPropertyParserHelpers::consumeScrollSnapType): Use auto.
(WebCore::CSSPropertyParserHelpers::consumeBasicShapeOrBox): Use a generated helper and
add a note about the spec ambiguity along with link to spec github issue filed:
https://github.com/w3c/fxtf-drafts/issues/481
(WebCore::CSSPropertyParserHelpers::consumeBaselineKeyword): Make static (and remove forward
declaration from header. Nothing outside this file uses this function
(WebCore::CSSPropertyParserHelpers::consumeBackgroundSize): Make this a template function
generic on CSSPropertyID as the callers all statically know which variant they want.
(WebCore::CSSPropertyParserHelpers::consumeRepeatStyle): Make static (and remove forward
declaration from header. Nothing outside this file uses this function
(WebCore::CSSPropertyParserHelpers::consumeSingleBackgroundRepeat): Added to make it a bit
more clear in consumeBackgroundComponent() what the behavior for each property is.
(WebCore::CSSPropertyParserHelpers::consumeSingleBackgroundPositionX): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleBackgroundPositionY): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleBackgroundSize): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleMaskRepeat): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleMaskSize): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleWebkitBackgroundSize): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleWebkitMaskPositionX): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeSingleWebkitMaskPositionY): Ditto.
(WebCore::CSSPropertyParserHelpers::consumeBackgroundComponent): Reordered to group families
of properties together and updated to use generated consumers where possible or the new
named consumers above.
(WebCore::CSSPropertyParserHelpers::consumeCommaSeparatedBackgroundComponent): Adopt new
consumeCommaSeparatedList* helper

(WebCore::CSSPropertyParserHelpers::consumeAutoOrLengthOrPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeMarginSide): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeSide): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeAnimationIterationCount): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeAnimationName): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeTransitionProperty): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeAnimationTimingFunction): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeAnimationValue): Deleted.
(WebCore::CSSPropertyParserHelpers::isValidAnimationPropertyList): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeAnimationPropertyList): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeBackgroundBlendMode): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeBackgroundAttachment): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeBackgroundBox): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeMaskClip): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeBackgroundClip): Deleted.
(WebCore::CSSPropertyParserHelpers::consumePrefixedMaskComposite): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeMaskComposite): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeWebkitMaskSourceType): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeWebkitMaskMode): Deleted.
(WebCore::CSSPropertyParserHelpers::consumePrefixedBackgroundBox): Deleted.
(WebCore::CSSPropertyParserHelpers::addBackgroundValue): Deleted.
Replaced by generated shared grammar rules or generated properties..

* Source/WebCore/css/parser/CSSPropertyParserHelpers.h:
(WebCore::CSSPropertyParserHelpers::consumeCommaSeparatedListWithSingleValueOptimization):
(WebCore::CSSPropertyParserHelpers::consumeCommaSeparatedListWithoutSingleValueOptimization):
Add two helpers which can consume a comma separated list, one with an optimization to return
the underlying CSSValue if there was only one element in the list (and a CSSValueList otherwise)
and the other which always returns a CSSValueList. This allows callers to maintain their
existing behavior.

* Source/WebCore/css/process-css-properties.py:
(Term.from_json): Create a RepetitionTerm if the 'kind' is 'repetition'.
(RepetitionTerm): RepetitionTerm has a unique 'single-value-optimization' flag
that can be set on it to indicate that it should the variant of consumeCommaSeparatedList*
that does the single value optimizaton.
(TermGeneratorRepetitionTerm:) To generate code for a RepetitionTerm, we utilize one of the
consumeCommaSeparatedList* functions and pass it a lambda which contains the submatch. The
new automatic indentation support really came in handy here to allow an arbitrarty set of
terms to generate inside the lambda without issue.

Canonical link: https://commits.webkit.org/257051@main




More information about the webkit-changes mailing list