-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
a19c25f
commit b6495ee
Showing
12 changed files
with
229 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tests/html/canvas/offscreen/fill-and-stroke-styles/2d.fillStyle.parse.system-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
2d.fillStyle.parse.system | ||
|
||
|
||
FAIL OffscreenCanvas test: 2d.fillStyle.parse.system assert_regexp_match: expected object "/^#(?!(FF0000|ff0000|f00)$)/" but got "#ff0000" | ||
PASS OffscreenCanvas test: 2d.fillStyle.parse.system | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.