Page MenuHomePhabricator

Bug 1838740 - linear-gradient() and friends can parse a color interpolation method r=emilio
ClosedPublic

Authored by tlouw on Jun 15 2023, 9:37 PM.
Referenced Files
Unknown Object (File)
Thu, Apr 16, 9:01 AM
Unknown Object (File)
Dec 26 2025, 1:30 AM
Unknown Object (File)
Dec 16 2025, 9:13 PM
Unknown Object (File)
Nov 8 2025, 11:53 AM
Unknown Object (File)
Nov 8 2025, 11:51 AM
Unknown Object (File)
Nov 8 2025, 10:49 AM
Unknown Object (File)
Nov 8 2025, 5:22 AM
Unknown Object (File)
Nov 8 2025, 5:07 AM
Subscribers

Details

Summary

Allow the following syntax for gradients:
linear-gradient(in lab to right, red, blue)

The patch will parse and make available the interpolation method, but no
rendering changes are made, so all gradients will still render in srgb.

Event Timeline

tlouw created this revision.
phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".Jun 15 2023, 9:37 PM
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
This comment was removed by tlouw.
tlouw requested review of this revision.Jun 16 2023, 8:49 AM
tlouw added a reviewer: emilio.

The additional tests just happened to succeed by chance, so making them fail now should be fine. Also only happens on nightly.

emilio requested changes to this revision.Jun 16 2023, 10:14 AM

I think at the very least we should not enable this by default yet. It's fine to annotate tests to enable the pref tho. I have a couple suggestions, but rather minor.

I have a couple questions tho. With those and the comments addressed / replied this looks good, thanks!

modules/libpref/init/StaticPrefList.yaml
8587

Given it doesn't work at all I'd rather keep this as false and enable on the relevant tests.

servo/components/style/values/generics/image.rs
556–565

Probably:

let omit_color_interpolation_method = matches!(color_interpolation_method.space, ColorSpace::Srgb);
if !omit_color_interpolation_method {
    if !omit_shape || !omit_position {
        ...
    ...
}
servo/components/style/values/specified/image.rs
820

FnOnce is probably more reflective of what you want to do, though it doesn't matter here in practice.

822

I think this would be a bit cleaner with something like:

fn try_parse_interpolation_method(&ParserContext, &mut Parser..) -> Option<ColorInterpolationMethod> {
    if !gradient_color_interpolation_method_enabled() {
        return None;
    }
    input.try_parse(|p| ColorInterpolationMethod::parse(context, p)).ok()
}

Then you probably don't need this function at all, or it's not so useful. You can just:

let mut color_interpolation_method = Self::try_parse_interpolation_method(...);
let direction = input.try_parse(|i| LineDirection::parse(context, i, &mut compat_mode)).ok();
if color_interpolation_method.is_none() && direction.is_some() {
    color_interpolation_method = Self::try_parse_interpolation_method(..);
}

For example. But it's fine to keep this extra function if you want too.

testing/web-platform/meta/css/css-images/parsing/gradient-interpolation-method-computed.html.ini
16–17

Why are these failing?

1517

Curious why do these not work?

testing/web-platform/meta/css/css-images/parsing/gradient-interpolation-method-valid.html.ini
1283

Same, shouldn't these work? If not, why not/

This revision now requires changes to proceed.Jun 16 2023, 10:14 AM
tlouw marked 7 inline comments as done.
tlouw added inline comments.
testing/web-platform/meta/css/css-images/parsing/gradient-interpolation-method-computed.html.ini
16–17

Right now we omit the color space if it is srgb, even if it was specified like this.

The correct method involves calculating the default color space which could be oklab() or srgb(). Then when the specified color space matches the default, it should be omitted, but we don't do that yet.

1517

Same as above. In this case, oklab() is the default color space and should be omitted, but we only use srgb as the default, so the color space is present in serialization.

testing/web-platform/meta/css/css-images/parsing/gradient-interpolation-method-valid.html.ini
1283

Same again, because oklab() is the default here, so should be omitted, but it's not.

tlouw updated this revision to Diff 731010.
tlouw retitled this revision from WIP: Bug 1838740 - linear-gradient() and friends can parse a color interpolation method r=emilio to Bug 1838740 - linear-gradient() and friends can parse a color interpolation method r=emilio.
tlouw marked 3 inline comments as done.

r=me with the checks being consistent, and a bug on file for the wrong default.

servo/components/style/values/specified/image.rs
907

You can actually put this inside the following if to avoid trying to parse the interpolation method twice if there's nothing before the stops. Your call.

961

Same here (and remove the angle.is_ok() || position.is_ok(). But then again this might be more explicit. Feel free to instead do the equivalent above:

if color_interpolation_method.is_none() && (shape.is_ok() || position.is_some()) {
    ...
}
testing/web-platform/meta/css/css-images/parsing/gradient-interpolation-method-valid.html.ini
1283

Please file a follow-up for the oklab issue, and reference it from the code (where you default to srgb).

This revision is now accepted and ready to land.Jun 19 2023, 6:08 PM
tlouw marked 2 inline comments as done.
tlouw added inline comments.
testing/web-platform/meta/css/css-images/parsing/gradient-interpolation-method-valid.html.ini
1283
This revision is now accepted and ready to land.Jun 23 2023, 11:29 AM
This revision is now accepted and ready to land.Jun 23 2023, 3:50 PM