Bug 226513 - Add support for "relative color syntax" for color()
Summary: Add support for "relative color syntax" for color()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-06-01 13:37 PDT by Sam Weinig
Modified: 2021-06-02 10:40 PDT (History)
10 users (show)

See Also:


Attachments
Patch (29.94 KB, patch)
2021-06-01 15:01 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (78.91 KB, patch)
2021-06-01 18:16 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (79.38 KB, patch)
2021-06-02 08:17 PDT, Sam Weinig
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (79.38 KB, patch)
2021-06-02 08:40 PDT, Sam Weinig
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (79.38 KB, patch)
2021-06-02 08:43 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2021-06-01 13:37:59 PDT
Add support for "relative color syntax" for color()
Comment 1 Sam Weinig 2021-06-01 15:01:06 PDT Comment hidden (obsolete)
Comment 2 Sam Weinig 2021-06-01 18:16:05 PDT
Created attachment 430312 [details]
Patch
Comment 3 Darin Adler 2021-06-01 18:31:14 PDT
Comment on attachment 430312 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=430312&action=review

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1566
> +    ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba);

Wouldn’t we want the more precise assertion?

    ASSERT(range.peek().functionId() == (Mode == RGBFunctionMode::RGB ? CSSValueRgb : CSSValueRgba));

Or is my assertion wrong?

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1583
> +    return convertColor<SRGBA<uint8_t>>(HSLA<float> { static_cast<float>(normalizedHue), static_cast<float>(normalizedSaturation), static_cast<float>(normalizedLightness), static_cast<float>(normalizedAlpha) });

This explicit conversion to SRGBA really does need a comment. I know it’s not new. The fact that we do not create an extended color, but instead round and clamp to SRGBA intentionally really does not go without saying!

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1659
> +    ASSERT(range.peek().functionId() == CSSValueHsl || range.peek().functionId() == CSSValueHsla);

Same thought about the assertion.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1720
> +    return convertColor<SRGBA<uint8_t>>(HWBA<float> { static_cast<float>(normalizedHue), static_cast<float>(normalizedWhitness), static_cast<float>(normalizedBlackness), static_cast<float>(*alpha) });

Same thought about the comment.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1929
> +    for (int i = 0; i < 3; ++i) {

for (auto& channel : channels) {

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1932
> +        if (!value)
> +            break;

All unspecified channels are set to 0? Peculiar syntax!
Comment 4 Sam Weinig 2021-06-02 08:17:22 PDT Comment hidden (obsolete)
Comment 5 Sam Weinig 2021-06-02 08:40:08 PDT Comment hidden (obsolete)
Comment 6 Sam Weinig 2021-06-02 08:42:49 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 430312 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=430312&action=review
> 
> > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1566
> > +    ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba);
> 
> Wouldn’t we want the more precise assertion?
> 
>     ASSERT(range.peek().functionId() == (Mode == RGBFunctionMode::RGB ?
> CSSValueRgb : CSSValueRgba));
> 
> Or is my assertion wrong?

Nope. Great idea. The template parameter and the assertion were added at different times and I didn't put them together. Done.

> 
> > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1583
> > +    return convertColor<SRGBA<uint8_t>>(HSLA<float> { static_cast<float>(normalizedHue), static_cast<float>(normalizedSaturation), static_cast<float>(normalizedLightness), static_cast<float>(normalizedAlpha) });
> 
> This explicit conversion to SRGBA really does need a comment. I know it’s
> not new. The fact that we do not create an extended color, but instead round
> and clamp to SRGBA intentionally really does not go without saying!

Totally agree. Added.

> 
> > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1659
> > +    ASSERT(range.peek().functionId() == CSSValueHsl || range.peek().functionId() == CSSValueHsla);
> 
> Same thought about the assertion.

Done.

> 
> > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1720
> > +    return convertColor<SRGBA<uint8_t>>(HWBA<float> { static_cast<float>(normalizedHue), static_cast<float>(normalizedWhitness), static_cast<float>(normalizedBlackness), static_cast<float>(*alpha) });
> 
> Same thought about the comment.

Done.

> 
> > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1929
> > +    for (int i = 0; i < 3; ++i) {
> 
> for (auto& channel : channels) {

Done.

> 
> > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:1932
> > +        if (!value)
> > +            break;
> 
> All unspecified channels are set to 0? Peculiar syntax!

So odd. It has to do with the fact that a custom profile can have any number of components, so it just defaults everything to 0, but I think they should just special case the predefined ones to require the right number of components, but I think I lost that argument.
Comment 7 Sam Weinig 2021-06-02 08:43:29 PDT
Created attachment 430363 [details]
Patch
Comment 8 EWS 2021-06-02 10:39:05 PDT
Committed r278364 (238394@main): <https://commits.webkit.org/238394@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 430363 [details].
Comment 9 Radar WebKit Bug Importer 2021-06-02 10:40:21 PDT
<rdar://problem/78771441>