-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support nested currentcolor resolution for canvas #28505
Support nested currentcolor resolution for canvas #28505
Conversation
EWS run on previous version of this PR (hash 8d77c36) |
This fixes support resolving nested Adding support would be really trivial, we just need set the |
8d77c36
to
523805c
Compare
EWS run on previous version of this PR (hash 523805c) |
523805c
to
9b41de2
Compare
EWS run on previous version of this PR (hash 9b41de2) |
I don't think we should propagate information to a worker it might not otherwise have access to. That would have to be standardized in some fashion first. It does make sense that |
This needs rebaselining: |
9b41de2
to
695d39c
Compare
EWS run on current version of this PR (hash 695d39c) |
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
695d39c
to
b6495ee
Compare
Committed 279017@main (b6495ee): https://commits.webkit.org/279017@main Reviewed commits have been landed. Closing PR #28505 and removing active labels. |
b6495ee
695d39c
π π§ͺ unsafe-merge