[webkit-changes] [WebKit/WebKit] 9bcbb8: Restructure CSS color parsing to be more declarative

Sam Weinig noreply at github.com
Sat May 4 00:45:17 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9bcbb8f9e5ddd017b61405c4b528aeb0bceb2b70
      https://github.com/WebKit/WebKit/commit/9bcbb8f9e5ddd017b61405c4b528aeb0bceb2b70
  Author: Sam Weinig <weinig at apple.com>
  Date:   2024-05-04 (Sat, 04 May 2024)

  Changed paths:
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    A Source/WebCore/css/color/CSSColorDescriptors.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Angle.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.cpp
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Meta.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Number.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Percent.cpp
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Percent.h

  Log Message:
  -----------
  Restructure CSS color parsing to be more declarative
https://bugs.webkit.org/show_bug.cgi?id=273372

Reviewed by Tim Nguyen.

Restructures CSS color parsing and normalization to use be driven
by a set of constexpr descriptors of the various different color
function types. This reduces redundancy, but the main goal is to
make late resolution of relative colors easier, needed for currentColor
support, easier in a forthcoming change.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    - Added CSSColorDescriptors.h.

* Source/WebCore/css/color/CSSColorDescriptors.h: Added.
(WebCore::RGBFunctionLegacy):
(WebCore::RGBFunctionModernAbsolute):
(WebCore::RGBFunctionModernRelative):
(WebCore::HSLFunctionLegacy):
(WebCore::HSLFunctionModern):
(WebCore::HWBFunction):
(WebCore::LabFunction):
(WebCore::LCHFunction):
(WebCore::OKLabFunction):
(WebCore::OKLCHFunction):
(WebCore::ColorRGBFunction):
(WebCore::ColorXYZFunction):
    - Added descriptors for all the CSS color functions that directly
      describe a color. The descriptors contain enough information to
      parse and normalize the the absolute and relative forms.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Angle.h:
(WebCore::CSSPropertyParserHelpers::ConsumerLookup<AngleOrNumberOrNoneRaw>::operator()):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Meta.h:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Number.h:
(WebCore::CSSPropertyParserHelpers::ConsumerLookup<NumberRaw>::operator()):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Percent.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Percent.h:
(WebCore::CSSPropertyParserHelpers::consumeNumberOrPercentRaw):
(WebCore::CSSPropertyParserHelpers::consumeNumberOrPercentOrNoneRaw):
(WebCore::CSSPropertyParserHelpers::consumePercentOrNoneRaw):
(WebCore::CSSPropertyParserHelpers::ConsumerLookup<PercentRaw>::operator()):
(WebCore::CSSPropertyParserHelpers::ConsumerLookup<NumberOrPercentRaw>::operator()):
(WebCore::CSSPropertyParserHelpers::ConsumerLookup<NumberOrPercentOrNoneRaw>::operator()):
    - Add support for invoking a consumer from a generic context based on
      the result type. For instance, if you want to consume a NumberOrPercentRaw,
      a caller now use `ConsumerLookup<NumberOrPercentRaw>()(args)` to call
      `consumeNumberOrPercentRaw(args)`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.cpp:
(WebCore::CSSPropertyParserHelpers::outsideSRGBGamut):
(WebCore::CSSPropertyParserHelpers::convertAbsoluteFunctionToColor):
(WebCore::CSSPropertyParserHelpers::convertRelativeFunctionToColor):
(WebCore::CSSPropertyParserHelpers::normalizeComponent):
(WebCore::CSSPropertyParserHelpers::normalizeAbsoluteComponents):
(WebCore::CSSPropertyParserHelpers::normalizeRelativeComponents):
(WebCore::CSSPropertyParserHelpers::consumeComponent):
(WebCore::CSSPropertyParserHelpers::consumeAlphaDelimiter):
(WebCore::CSSPropertyParserHelpers::consumeAbsoluteComponents):
(WebCore::CSSPropertyParserHelpers::consumeRelativeComponents):
(WebCore::CSSPropertyParserHelpers::consumeAndNormalizeAbsoluteComponents):
(WebCore::CSSPropertyParserHelpers::consumeAndNormalizeRelativeComponents):
(WebCore::CSSPropertyParserHelpers::parseGenericAbsoluteFunctionParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseGenericRelativeFunctionParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseGenericFunctionParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseRGBFunctionParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseHSLFunctionParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionRaw):
(WebCore::CSSPropertyParserHelpers::parseColorFunction):
(WebCore::CSSPropertyParserHelpers::normalizeLightnessPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeABPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeChromaPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeXYZPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeRGBPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeAlphaPercent): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeOriginColorRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeRGBOrHSLLegacyOptionalAlphaRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeOptionalAlphaRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::consumeOptionalAlphaRawAllowingSymbolTableIdent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeRGBFunctionComponent): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeRGBFunctionAlpha): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeRGBFunctionComponents): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeRGBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeRGBParametersLegacyRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeRGBParametersModernRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeRGBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRGBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::colorByResolvingHSLComponentsModern): Deleted.
(WebCore::CSSPropertyParserHelpers::colorByResolvingHSLComponentsLegacy): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeHSLParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeHSLParametersLegacyRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeHSLParametersModernRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeHSLParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseHSLParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::normalizeHWBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseHWBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeHWBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeHWBParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseLabParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeLabParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeLabParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseLCHParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeLCHParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeLCHParametersRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypesRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeColorFunctionForRGBTypes): Deleted.
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZTypesRaw): Deleted.
(WebCore::CSSPropertyParserHelpers::parseRelativeColorFunctionForXYZTypes): Deleted.
(WebCore::CSSPropertyParserHelpers::parseNonRelativeColorFunctionParameters): Deleted.
    - Merge most of the color function parsing and normalization into a
      shared set of "generic" parsers and normalizers. As the parsing is
      not entirely regular among all the types, we still have some code
      to start the parsing for the following cases:

      - `rgb()/rgba()` have their own entry point `parseRGBFunctionParametersRaw`
        to allow disambiguation between the modern and legacy syntaxes.
      - `hsl()/hsla()` have their own entry point `parseHSLFunctionParametersRaw`
        to allow disambiguation between the modern and legacy syntaxes.
        Sharing this with the `rgb()/rgba()` parser would be nice, but the
        `rgb()/rgba()` has an additional requirement that all the parameters
        have the same type when using the legacy form, and any sharing ended
        up being more code and more complicated.
      - `color()` (both rgb and xyz) have their own entry point `parseColorFunctionParametersRaw`
        to allow for the additional color space parameter.
      - Everything else (`hwb()`, `lab()`, `lch()`, `oklab()`, `oklch()`) uses
        `parseGenericFunctionParametersRaw` directly. The others end up calling
        the generic code after their disambiguation.

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



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list