Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c05a19a495bdffa90ca2c5707c651dee249b6870
      
https://github.com/WebKit/WebKit/commit/c05a19a495bdffa90ca2c5707c651dee249b6870
  Author: Sam Weinig <wei...@apple.com>
  Date:   2024-05-13 (Mon, 13 May 2024)

  Changed paths:
    M LayoutTests/TestExpectations
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-computed-relative-color-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-computed-relative-color.html
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-valid-relative-color-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-valid-relative-color.html
    M 
LayoutTests/imported/w3c/web-platform-tests/css/support/color-testcommon.js
    M Source/WTF/wtf/VectorTraits.h
    M Source/WTF/wtf/text/TextStream.h
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/css/CSSPrimitiveValue.cpp
    M Source/WebCore/css/CSSPrimitiveValue.h
    M Source/WebCore/css/calc/CSSCalcOperationNode.cpp
    M Source/WebCore/css/calc/CSSCalcSymbolNode.cpp
    M Source/WebCore/css/calc/CSSCalcSymbolNode.h
    A Source/WebCore/css/color/CSSAbsoluteColorResolver.h
    A Source/WebCore/css/color/CSSColorConversion+ToColor.h
    A Source/WebCore/css/color/CSSColorConversion+ToTypedColor.h
    M Source/WebCore/css/color/CSSColorDescriptors.h
    A Source/WebCore/css/color/CSSColorMixResolver.cpp
    A Source/WebCore/css/color/CSSColorMixResolver.h
    A Source/WebCore/css/color/CSSColorMixSerialization.cpp
    M Source/WebCore/css/color/CSSColorMixSerialization.h
    A Source/WebCore/css/color/CSSRelativeColorResolver.h
    A Source/WebCore/css/color/CSSRelativeColorSerialization.cpp
    A Source/WebCore/css/color/CSSRelativeColorSerialization.h
    R Source/WebCore/css/color/CSSResolvedColorMix.cpp
    R Source/WebCore/css/color/CSSResolvedColorMix.h
    A Source/WebCore/css/color/CSSUnresolvedAbsoluteColor.cpp
    A Source/WebCore/css/color/CSSUnresolvedAbsoluteColor.h
    M Source/WebCore/css/color/CSSUnresolvedColor.cpp
    M Source/WebCore/css/color/CSSUnresolvedColor.h
    A Source/WebCore/css/color/CSSUnresolvedColorHex.cpp
    A Source/WebCore/css/color/CSSUnresolvedColorHex.h
    A Source/WebCore/css/color/CSSUnresolvedColorKeyword.cpp
    A Source/WebCore/css/color/CSSUnresolvedColorKeyword.h
    M Source/WebCore/css/color/CSSUnresolvedColorMix.cpp
    M Source/WebCore/css/color/CSSUnresolvedColorMix.h
    A Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.cpp
    A Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.h
    M Source/WebCore/css/color/CSSUnresolvedLightDark.cpp
    M Source/WebCore/css/color/CSSUnresolvedLightDark.h
    A Source/WebCore/css/color/CSSUnresolvedRelativeColor.cpp
    A Source/WebCore/css/color/CSSUnresolvedRelativeColor.h
    M Source/WebCore/css/color/StyleAbsoluteColor.cpp
    M Source/WebCore/css/color/StyleAbsoluteColor.h
    M Source/WebCore/css/color/StyleColor.cpp
    M Source/WebCore/css/color/StyleColor.h
    M Source/WebCore/css/color/StyleColorMix.cpp
    M Source/WebCore/css/color/StyleColorMix.h
    M Source/WebCore/css/color/StyleCurrentColor.cpp
    M Source/WebCore/css/color/StyleCurrentColor.h
    A Source/WebCore/css/color/StyleRelativeColor.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.cpp
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.h
    A 
Source/WebCore/css/parser/CSSPropertyParserConsumer+ColorInterpolationMethod.cpp
    A 
Source/WebCore/css/parser/CSSPropertyParserConsumer+ColorInterpolationMethod.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+RawTypes.cpp
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+RawTypes.h
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.cpp
    M Source/WebCore/css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.h
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
    M Source/WebCore/css/process-css-properties.py
    M Source/WebCore/html/canvas/CanvasStyle.cpp
    M Source/WebCore/platform/graphics/ColorSerialization.cpp
    M Source/WebCore/platform/graphics/ColorSerialization.h
    M Source/WebCore/style/ColorFromPrimitiveValue.cpp
    M Source/WebCore/style/ColorFromPrimitiveValue.h

  Log Message:
  -----------
  Relative color syntax doesn't work with currentColor or system colors
https://bugs.webkit.org/show_bug.cgi?id=245970
rdar://problem/100981965

Reviewed by Darin Adler.

Adds support for late resolution of relative colors, matching the
model set by color-mix.

Re-works color parsing to completely split resolution from consuming,
allowing for a single implementation of the parsing code, all returning
CSSUnresolvedColor values. This allows us to delay resolving relative
colors until needed, storing the components first as a 
CSSUnresolvedRelativeColor
and then a StyleRelativeColor (mirroring CSSUnresolvedColorMix and
StyleColorMix).

* LayoutTests/TestExpectations:
    - Removes skips for now passing currentColor tests.

* 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-computed-relative-color-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-computed-relative-color.html:
    - Added tests for currentColor at computed value time.

* 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-valid-relative-color-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-valid-relative-color.html:
    - Updated tests to match spec (and new implementation) which preserves
      declared values for declared value serialization of relative colors.

* LayoutTests/imported/w3c/web-platform-tests/css/support/color-testcommon.js:
    - Add helper which allows fuzzy testing using a specific property, rather
      than always hardcoding it to use "color".

* Source/WTF/wtf/VectorTraits.h:
    - Add UniqueRef to the set of smart pointers which get the simple class
      traits, needed to use UniqueRef with FixedVector.

* Source/WTF/wtf/text/TextStream.h:
(WTF::streamSizedContainer):
(WTF::operator<<):
    - Extract sized container serialization into a helper and use to replace
      duplicated implementations. Also add overload for FixedVector.

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    - Add new files.

* Source/WebCore/css/CSSPrimitiveValue.cpp:
* Source/WebCore/css/CSSPrimitiveValue.h:
    - Expose number serialization helper to allow identical serialization when
      not using CSSPrimitiveValue for numeric values.

* Source/WebCore/css/calc/CSSCalcOperationNode.cpp:
(WebCore::CSSCalcOperationNode::buildCSSTextRecursive):
    - Ensure that symbols get serialized when they are part of a calc().

* Source/WebCore/css/calc/CSSCalcSymbolNode.cpp:
* Source/WebCore/css/calc/CSSCalcSymbolNode.h:
(WebCore::CSSCalcSymbolNode::customCSSText const):
    - Expose serialization of a symbol node utilizing 
`nameLiteralForSerialization`.

* Source/WebCore/css/color/CSSAbsoluteColorResolver.h: Added.
    - Factor out code to resolve a parsed absolute color into a concrete Color.

* Source/WebCore/css/color/CSSColorConversion+ToColor.h: Added.
    - Factor out code to convert a "typed color" into a concrete Color, applying
      the rules specified by the descriptor provided.

* Source/WebCore/css/color/CSSColorConversion+ToTypedColor.h: Added.
    - Factor out code to convert a "parsed color" into a "typed color", 
normalizing
      values according to the color descriptor provided.

* Source/WebCore/css/color/CSSColorDescriptors.h:
    - Moves descriptors out of CSSPropertyParserHelpers, they are now used 
outside
      of that area.
    - Add additional helpers for working with the descriptors that compute the
      component types at various stages, such as when calc and raw symbols have
      not yet been evaluated.
    - Add additional per-descriptor data to support serialization of relative
      color functions that have not been fully resolved.

* Source/WebCore/css/color/CSSColorMixResolver.cpp: Renamed from 
Source/WebCore/css/color/CSSResolvedColorMix.cpp.
* Source/WebCore/css/color/CSSColorMixResolver.h: Renamed from 
Source/WebCore/css/color/CSSResolvedColorMix.h.
    - Renamed to follow the same pattern we are using with relative color 
resolution.

* Source/WebCore/css/color/CSSColorMixSerialization.cpp: Copied from 
Source/WebCore/css/color/CSSColorMixSerialization.h.
* Source/WebCore/css/color/CSSColorMixSerialization.h:
    - Moved a few non-template functions into an implementation file to avoid
      unnecessary inlining for non-perf critical code.

* Source/WebCore/css/color/CSSRelativeColorResolver.h: Added.
    - Factor out code to resolve a parsed relative color with its origin already
      resolved into a concrete Color. Resolution is performed in stages:

        1. If any components are raw symbols, replace them with a their value
           in the symbol table.
        2. If any components are `calc()` values, evaluate the `calc()` passing
           the symbol table for any symbolic values they retain.
        3. At this point, all the components are raw values of some type 
(number,
           percent, or angle), normalize those raw components into a typed color
           (e.g. SRGBA<float>, OKLab<float>, etc.).
        4. Wrap the typed color in the type-erased wrapper, Color.

* Source/WebCore/css/color/CSSRelativeColorSerialization.cpp: Added.
* Source/WebCore/css/color/CSSRelativeColorSerialization.h: Added.
    - Factor out code to serialize relative colors.

* Source/WebCore/css/color/CSSUnresolvedAbsoluteColor.cpp: Added.
* Source/WebCore/css/color/CSSUnresolvedAbsoluteColor.h: Added.
    - Type to represent fully resolved colors that are part of 
CSSUnresolvedColor tree.
      Currently used for absolute color values and the soon to be removed 
color-contrast().

* Source/WebCore/css/color/CSSUnresolvedColor.cpp:
* Source/WebCore/css/color/CSSUnresolvedColor.h:
    - Add all remaining color types to the value variant to represent declared 
color
      values. To retain the enough information for correct resolution of 
relative
      colors, the variant holds a fully specified CSSUnresolvedRelativeColor 
for each
      relative color supported. Hex and Keyword types were also added to allow 
removing
      use of CSSPrimitiveValue in the CSSUnresolvedColor tree. Now, child 
colors are
      represented as UniqueRef<CSSUnresolvedColor>.
    - The new createColor() function allows eager resolution of unresolved 
colors as
      needed by the `parseColorRaw()` functions that Canvas uses.

* Source/WebCore/css/color/CSSUnresolvedColorHex.cpp: Added.
* Source/WebCore/css/color/CSSUnresolvedColorHex.h: Added
    - Type to represent hex colors in the CSSUnresolvedColor tree.

* Source/WebCore/css/color/CSSUnresolvedColorKeyword.cpp: Added.
* Source/WebCore/css/color/CSSUnresolvedColorKeyword.h: Added.
    - Type to represent keyword colors in the CSSUnresolvedColor tree.

* Source/WebCore/css/color/CSSUnresolvedColorMix.cpp:
* Source/WebCore/css/color/CSSUnresolvedColorMix.h:
    - Re-worked to remove use of CSSPrimitiveValue representations of mix 
components,
      instead using `UniqueRef<CSSUnresolvedColor>` for the origin colors and
      `std::variant<PercentRaw, UnevaluatedCalc<PercentRaw>>` for the 
percentages.
      This preserves the type information and makes these usable in workers 
without
      extensive CSSValuePool piping.

* Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.cpp: Added.
* Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.h: Added.
    - Context used by the `parseColorRaw()` functions to resolve colors without
      going through the style system. Currently the context contains explicit
      values, but if pre-computing these turns out of be expensive, this can
      be converted into a delegate to allow lazy evaluation.

* Source/WebCore/css/color/CSSUnresolvedLightDark.cpp:
* Source/WebCore/css/color/CSSUnresolvedLightDark.h:
    - Like CSSUnresolvedColorMix, re-worked to remove use of CSSPrimitiveValue.

* Source/WebCore/css/color/CSSUnresolvedRelativeColor.cpp: Added.
* Source/WebCore/css/color/CSSUnresolvedRelativeColor.h: Added.
    - Type to represent relative color in the CSSUnresolvedColor tree.
    - Uses a color descriptor to define component types and stores the
      origin as a UniqueRef<CSSUnresolvedColor>.
    - Converts to the new StyleRelativeColor at style resolution time
      allowing a currentColor origin value to be preserved as late as
      possible.

* Source/WebCore/css/color/StyleColor.cpp:
* Source/WebCore/css/color/StyleColor.h:
    - Like CSSUnresolvedColor, the relative color types are added to the
      the kind variant, fully specified by color descriptor. One slightly
      unfortunate duplication is that all the relative colors require their
      own constructor functions in order to keep instantiation of the variant
      to the implementation file.
    - Like StyleColorMix, the StyleRelativeColor types are stored in UniqueRefs
      to avoid bloating the size for the relatively uncommon case of 
currentColor
      as part of the origin.
    - Also like StyleColorMix, the StyleRelativeColor types are first checked
      to see if they can be resolved, and if so, are stored as absolute colors
      instead.

* Source/WebCore/css/color/StyleColorMix.cpp:
* Source/WebCore/css/color/StyleColorMix.h:
    - Use PercentRaw for the Percentage to allow for clearer serialization.
    - Factor out check if the origin is absolute into a function to match
      relative color.
    - Sort functions to match other style color types.

* Source/WebCore/css/color/StyleCurrentColor.cpp:
* Source/WebCore/css/color/StyleCurrentColor.h:
    - Sort functions to match other style color types.

* Source/WebCore/css/color/StyleRelativeColor.h: Added.
    - Type to represent relative colors in the StyleColor tree.
    - Utilizes code shared with CSSUnresolvedRelativeColor for resolution
      and serialization.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.h:
    - Major rework of the parsing logic. Big takeaways:

        - Only does the consuming now, resolution has all been moved to
          other files.
        - Only one set of consumer functions, all working to return a
          CSSUnresolvedColor value. Now more separate normal vs raw
          distinction outside of exposed functions. The exposed functions
          consume the CSSUnresolvedColor, and resolve it to either
          a CSSPrimitiveValue or a raw Color.
        - ColorInterpolationMethod consuming was moved to its own
          file to continue to split things up.
        - Exposed functions have been merged where possible, with all
          now taking CSSColorParsingOptions, and all the raw functions
          also taking a CSSUnresolvedColorResolutionContext.
        - All the functions are now equally worker safe (or at least
          as worker safe as the one labeled worker safe used to be),
          so the worker safe exposed function has been removed.

* 
Source/WebCore/css/parser/CSSPropertyParserConsumer+ColorInterpolationMethod.cpp:
 Added.
* 
Source/WebCore/css/parser/CSSPropertyParserConsumer+ColorInterpolationMethod.h: 
Added.
    Moved from CSSPropertyParserConsumer+Color.h/cpp.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+RawTypes.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+RawTypes.h:
    - Added serialization of raw types, used generically by the relative color
      and color mix serialization code.
    - Removed a number of FooOrBarRaw type definitions that were only used by
      the old color parsing code.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.h:
    - Added serialization of UnevaluatedCalc, used generically by the relative 
color
      and color mix serialization code.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeBorderColor):
(WebCore::CSSPropertyParserHelpers::consumeFontPaletteValuesOverrideColors):
    - Switched to use the CSSColorParsingOptions when calling consumeColor 
allowing us
      to remove overload.

* Source/WebCore/css/process-css-properties.py:
    - Switched to use the CSSColorParsingOptions when calling consumeColor 
allowing us
      to remove overload.

* Source/WebCore/html/canvas/CanvasStyle.cpp:
    - Switched to use the plain parseColorRaw with "System" colors not in the 
allow set,
      rather than worker safe variant, since they are both the same now.
    - Removed hsl clamp opt setting, as that has been a no-op for a bit now.

* Source/WebCore/platform/graphics/ColorSerialization.cpp:
* Source/WebCore/platform/graphics/ColorSerialization.h:
    - Expose serialization of the color space names for use by relative color 
serialization.

* Source/WebCore/style/ColorFromPrimitiveValue.cpp:
* Source/WebCore/style/ColorFromPrimitiveValue.h:
    - Factor out conversion from CSS value keyword to StyleColor into its own 
function
      for use by CSSUnresolvedColorKeyword.

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to