RESOLVED FIXED 234798
Add resolved/unresolved color type accessors to require users to be explicit about whether they will handle missing/none color components
https://bugs.webkit.org/show_bug.cgi?id=234798
Summary Add resolved/unresolved color type accessors to require users to be explicit ...
Sam Weinig
Reported 2022-01-02 11:11:13 PST
As a precursor to 233526 ([CSS Color 4] Add support for "Missing"/"none" color components), which will require allowing color types to have components with NaN values to indicate missing and powerless components, we should use the type system to require users who want to access components to declare whether they will handle those values, or want the existing behavior (and the behavior used for rendering) where those components are converted to 0. To do this, color types will no longer expose their components publicly, but rather, will only allow access to them via new subclasses, ResolvedColorType<ColorType> and UnresolvedColorType<ColorType> (the former doing the conversion to 0, the later doing nothing). Theses subclasses will expose the components publicly (via using directives). This will require call sites to change from: auto [r, g, b, alpha] = myColorType; to: auto [r, g, b, alpha] = myColorType.resolved();
Attachments
Patch (152.16 KB, patch)
2022-01-02 12:10 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (153.02 KB, patch)
2022-01-02 12:28 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (154.47 KB, patch)
2022-01-02 14:46 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (155.40 KB, patch)
2022-01-02 17:11 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (156.51 KB, patch)
2022-01-02 17:47 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (156.51 KB, patch)
2022-01-02 18:02 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (157.55 KB, patch)
2022-01-02 18:40 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (157.95 KB, patch)
2022-01-02 19:34 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (157.11 KB, patch)
2022-01-02 21:00 PST, Sam Weinig
koivisto: review+
Patch (157.11 KB, patch)
2022-01-03 09:59 PST, Sam Weinig
no flags
Sam Weinig
Comment 1 2022-01-02 12:10:27 PST Comment hidden (obsolete)
Sam Weinig
Comment 2 2022-01-02 12:28:49 PST Comment hidden (obsolete)
Sam Weinig
Comment 3 2022-01-02 14:46:02 PST Comment hidden (obsolete)
Sam Weinig
Comment 4 2022-01-02 17:11:33 PST Comment hidden (obsolete)
Sam Weinig
Comment 5 2022-01-02 17:47:52 PST Comment hidden (obsolete)
Sam Weinig
Comment 6 2022-01-02 18:02:47 PST Comment hidden (obsolete)
Sam Weinig
Comment 7 2022-01-02 18:40:18 PST Comment hidden (obsolete)
Sam Weinig
Comment 8 2022-01-02 19:34:23 PST Comment hidden (obsolete)
Sam Weinig
Comment 9 2022-01-02 21:00:09 PST
Antti Koivisto
Comment 10 2022-01-03 09:11:57 PST
Comment on attachment 448202 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=448202&action=review > Source/WebCore/ChangeLog:33 > + opertunity to replace all its uses with the generic toColorTypeLossy<SRGBA<>>. spelling "opertunity" > Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp:95 > + auto [r, g, b, a] = bgColor.toColorTypeLossy<SRGBA<uint8_t>>().resolved(); There is a lot of this. Could we have a template-free shortcut for this apparently common case with a sensible name that hints the proper use? One should be able to write WebKit code without becoming a color space expert or mindlessly copy-pasting. > Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:827 > - auto [r, g, b, a] = bgColor.toSRGBALossy<uint8_t>(); > + auto [r, g, b, a] = bgColor..toColorTypeLossy<SRGBA<uint8_t>>().resolved(); what's up with those double ..? > Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:833 > + auto [r, g, b, a] = fgColor..toColorTypeLossy<SRGBA<uint8_t>>().resolved(); here too > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1534 > + auto originColorAsSRGB = originColor.toColorTypeLossy<SRGBA<float>>().resolved(); Similarly maybe this could have a shortcut?
Sam Weinig
Comment 11 2022-01-03 09:58:13 PST
(In reply to Antti Koivisto from comment #10) > Comment on attachment 448202 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=448202&action=review > > > Source/WebCore/ChangeLog:33 > > + opertunity to replace all its uses with the generic toColorTypeLossy<SRGBA<>>. > > spelling "opertunity" Always taking "opertunities" to innovate in the spelling game. > > > Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp:95 > > + auto [r, g, b, a] = bgColor.toColorTypeLossy<SRGBA<uint8_t>>().resolved(); > > There is a lot of this. Could we have a template-free shortcut for this > apparently common case with a sensible name that hints the proper use? > > One should be able to write WebKit code without becoming a color space > expert or mindlessly copy-pasting. Heh, I removed the shortcut I had because I didn't think it was useful, but I don't think the shortcut really resolved this problem. The old one was: 'color.toSRGBALossy<>()' What I have found so far is that making these very explicit has made it much less likely for people to make mistakes with the color code (or at the very least, made it easy to notice when things are being done incorrectly after the fact). For the most part, you almost never need to access color channels directly like this, and when you do, you really need to know which color space you want it in. I would love to figure out ways to simplify these things, but so far I haven't found any silver bullets. The main way I have been trying to make it easier for people is by removing the needs for accessing the color channels directly by having shared utilities for the common uses (interpolation, contrasting, etc.). Its certainly something we should continue to improve. > > > Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:827 > > - auto [r, g, b, a] = bgColor.toSRGBALossy<uint8_t>(); > > + auto [r, g, b, a] = bgColor..toColorTypeLossy<SRGBA<uint8_t>>().resolved(); > > what's up with those double ..? > > > Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:833 > > + auto [r, g, b, a] = fgColor..toColorTypeLossy<SRGBA<uint8_t>>().resolved(); > > here too They are what we call in the industry...bugs :). I guess those files don't get compiled in any of the EWS bots. Will fix. > > > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1534 > > + auto originColorAsSRGB = originColor.toColorTypeLossy<SRGBA<float>>().resolved(); > > Similarly maybe this could have a shortcut? One tiny shortcut would be to have resolved and unresolved versions of toColorTypeLossy (e.g. toResolvedColorTypeLossy and toUnresolvedColorTypeLossy) which do the call after for you, but I am not sure that really helps. Thanks for the review. I will continue looking into ways to make this simpler. I would also love to try and do a little more education in this area, so that more people can become more comfortable with it. The concepts aren't too tricky once they are explained, but finding good resources to learn them was harder than it should have been. Maybe one thing I could do is make one of those pages like we have for RefPtr on it?
Sam Weinig
Comment 12 2022-01-03 09:59:54 PST
EWS
Comment 13 2022-01-03 10:57:28 PST
Committed r287552 (245687@main): <https://commits.webkit.org/245687@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 448248 [details].
Radar WebKit Bug Importer
Comment 14 2022-01-03 10:58:16 PST
Note You need to log in before you can comment on or make changes to this bug.