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

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.fillStyle.colormix.currentcolor-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/fill-and-stroke-styles/2d.fillStyle.parse.system-expected.txt
    M Source/WebCore/css/color/CSSUnresolvedColorKeyword.cpp
    M Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.cpp
    M Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.h
    M Source/WebCore/html/canvas/CanvasGradient.cpp
    M Source/WebCore/html/canvas/CanvasGradient.h
    M Source/WebCore/html/canvas/CanvasGradient.idl
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h
    M Source/WebCore/html/canvas/CanvasStyle.cpp
    M Source/WebCore/html/canvas/CanvasStyle.h

  Log Message:
  -----------
  Support nested currentcolor resolution for canvas
https://bugs.webkit.org/show_bug.cgi?id=274120

Reviewed by Darin Adler.

Support for 'currentcolor' in canvas was previously hardcoded
to look for the explicit string, which made any nested usage,
such as in `color-mix()` broken.

To resolve this, we remove all special casing of `currentcolor`
in the canvas code (simplifying CanvasStyle considerably) and
use the CSSUnresolvedColorResolutionContext and its delegate
to resolve it at any nesting level.

* 
LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.fillStyle.colormix.currentcolor-expected.txt:
    - Update results now that we pass.

* Source/WebCore/css/color/CSSUnresolvedColorKeyword.cpp:
(WebCore::createColor):
    - Call the context's getter functions to allow lazy
      lookup of the color values.

* Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.cpp:
* Source/WebCore/css/color/CSSUnresolvedColorResolutionContext.h:
    - Re-work the resolution context to contain a delegate that allows
      the client to only compute color values if they are needed.
      The client is still able to use the context without a delegate,
      and explicitly set color values before hand if they want to.
      The keyword lookup code now calls the functions on the context,
      which check for the memoized value and then call the delegate
      if available and necessary.

* Source/WebCore/html/canvas/CanvasGradient.idl:
* Source/WebCore/html/canvas/CanvasGradient.cpp:
(WebCore::CanvasGradient::addColorStop):
    - Remove special casing of `currentcolor`, instead relying on
      the elementless `parseColor()` function doing the right thing
      by specifying `Color::black` for the resolved value. This also
      now more closely follows the spec text.
    - Update IDL to pass in a ScriptExecutionContext, which is now
      needed by the elementless `parseColor()` function.

* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::setStrokeStyle):
(WebCore::CanvasRenderingContext2DBase::setFillStyle):
    - With CanvasStyle no longer having its own invalid state,
      setStrokeStyle/setFillStyle get an additional overload
      with an std::optional<CanvasStyle>, which takes the place
      of the invalid state.
    - We also remove all the special casing of `currentcolor`
      that is no longer needed.

(WebCore::CanvasRenderingContext2DBase::setShadowColor):
(WebCore::CanvasRenderingContext2DBase::setShadow):
    - We can call the standard `parseColor()` now, as it
      supports `currentcolor`.

(WebCore::toStyleVariant):
    - Use the new `CanvasStyle.visit(...)` function rather
      than checking each type one at a time.

* Source/WebCore/html/canvas/CanvasStyle.h:
    - Removes the Invalid and CurrentColor states. CurrentColor is
      handled by the Color state now. Invalid was only used briefly
      by rendering context and has been replaced by a std::optional
      result from the create functions. By removing these states,
      the switchOn statements can now have all their states handled
      without ASSERT_NOT_REACHED(). The RefPtrs have also been
      replaced by Refs, as these are known non-null.

(WebCore::CanvasStyle::visit): Added.
    - Added a helper to switch over the different internal states,
      eagerly converting to a String for color, as that is what is
      expected by the canvas rendering context code.

(WebCore::CanvasStyle::color):
    - Add check that Color is the alternative held by the variant.
      Previously, this function was only called when all the other
      types had been ruled out, but could easily have caused a crash
      if misused.

(WebCore::CanvasStyle::isCurrentColor const): Deleted.
(WebCore::CanvasStyle::overrideAlpha const): Deleted.
(WebCore::CanvasStyle::CanvasStyle): Deleted.
(WebCore::CanvasStyle::srgbaColor const): Deleted.
    - Remove a bunch of unused functions.

* Source/WebCore/html/canvas/CanvasStyle.cpp:
(WebCore::CanvasStyleColorResolutionDelegate::CanvasStyleColorResolutionDelegate):
    - Implement a simple delegate for color resolution, moving the
      existing code for resolving `currentcolor` from below.

(WebCore::parseColor):
    - Bottleneck color parsing in two parse functions, one taking
      a CanvasBase, one a ScriptExecutionContext. The one taking
      a CanvasBase further refines itself based on whether the
      CanvasBase is a canvas element, in which case, it creates
      a resolution delegate for resolving `currentcolor` based
      on the element style.

      All other canvases are treated as elementless, getting a
      hardcoded `Color::black` for `currentcolor` and utilizing
      the execution context to determine if system colors are
      supported.

(WebCore::CanvasStyle::createFromString):
(WebCore::CanvasStyle::createFromStringWithOverrideAlpha):
    - Remove special casing for `currentcolor`, calling through to the
      shared `parseColor()` function.

(WebCore::CanvasStyle::applyStrokeColor const):
(WebCore::CanvasStyle::applyFillColor const):
    - Update switchOns for Ref use and removed states.

(WebCore::isCurrentColorString): Deleted.
(WebCore::currentColor): Deleted.
(WebCore::parseColorOrCurrentColor): Deleted.
    - Remove now unused functions.

Canonical link: https://commits.webkit.org/279017@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