Closed Bug 2007772 Opened 3 months ago Closed 19 days ago

Support color-mix() with multiple color arguments

Categories

(Core :: CSS Parsing and Computation, enhancement, P3)

Firefox 146
enhancement

Tracking

()

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: romainmenke, Assigned: tlouw)

References

(Blocks 2 open bugs)

Details

(Keywords: dev-doc-complete)

Attachments

(3 files)

Steps to reproduce:

Actual results:

white background

Expected results:

grey background

See: https://drafts.csswg.org/css-color-5/#color-mix-result

Type: enhancement → defect
Component: Untriaged → CSS Parsing and Computation
Product: Firefox → Core

Should be easy-ish to implement by changing this to stop hard-coding two colors. Romain do you know if there are any existing WPTs for this?

Severity: -- → S3
Status: UNCONFIRMED → NEW
Type: defect → enhancement
Ever confirmed: true
Priority: -- → P3
Summary: color-mix() with 1+ color arguments → Support color-mix() with multiple color arguments

There are no existing WPT's.
I started writing some but wasn't sure about serialization.

Some tests from my JavaScript implementation:
https://github.com/csstools/postcss-plugins/blob/1d4ef08e454c3399ffc67b1b06faeada813393c4/plugins/postcss-color-mix-variadic-function-arguments/test/basic.preserve-true.expect.css#L1-L26

There is also a new algorithm to mix the colors. Fairly straight forward.

The serialization issue I'm guessing is what to do with the last item if there are more than 2, which is where the old serialization rules break down a bit.

Mixing is not done by the exhanced mixing algorithm specified in:

https://drafts.csswg.org/css-color-5/#color-mix

This patch only implements the algorithm and forwards the original 2
color function to it, yielding the exact results as before.

To allow parsing multiple items in the color-mix function, change the
items to be single units.

The color-mix() function can now take multiple color/percentage pairs
and mix them all together using the new algorithm.

Added some tests here: https://github.com/web-platform-tests/wpt/pull/57234

Tests might not be 100%, but follows the implementation added here and can be updated as the spec gets updated.

Assignee: nobody → tlouw
Attachment #9536110 - Attachment description: WIP: Bug 2007772 - Add support for mixing multiple colors r=#layout → Bug 2007772 - Add support for mixing multiple colors r=#layout
Status: NEW → ASSIGNED
Attachment #9536111 - Attachment description: WIP: Bug 2007772 - Refactor color-mix items into a single unit. r=#layout → Bug 2007772 - Refactor color-mix items into a single unit. r=#layout
Attachment #9536112 - Attachment description: WIP: Bug 2007772 - Parse multiple items for color-mix() function r=#layout → Bug 2007772 - Parse multiple items for color-mix() function r=#layout
Pushed by tlouw@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a0842a4641dc https://hg.mozilla.org/integration/autoland/rev/5e48425b0ea8 Add support for mixing multiple colors r=layout-reviewers,firefox-style-system-reviewers,dshin https://github.com/mozilla-firefox/firefox/commit/f51305b5da4f https://hg.mozilla.org/integration/autoland/rev/adbf9eccc41b Refactor color-mix items into a single unit. r=layout-reviewers,firefox-style-system-reviewers,dshin https://github.com/mozilla-firefox/firefox/commit/999f556695d6 https://hg.mozilla.org/integration/autoland/rev/5a3e2895b47d Parse multiple items for color-mix() function r=layout-reviewers,firefox-style-system-reviewers,dshin
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch

Thanks for adding this, Tiaan! Are there already WPTs covering this? If not, they should be added.

Sebastian

Flags: needinfo?(tlouw)

Related issues and pull requests

Thank you for working on this Tiaan!

I noticed that a single color argument is not supported in Firefox 150.

https://drafts.csswg.org/css-color-5/#color-mix

To meet this need, the color-mix() function takes a list of one or more <color> specifications and returns the result of mixing them, in a given <color-space>, in the specified amounts.

color-mix() = color-mix( <color-interpolation-method>? , [ <color> && <percentage [0,100]>? ]#)

Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Let's file a separate bug for that please.

Well, it is the same thing.
It would be surprising for authors if it doesn't land together.

I don't mind filing another issue, but feels a bit weird given that this just seems like an oversight when implementing this?

It's easier to track when something lands, specially if it's been a month. I'll file.

Status: REOPENED → RESOLVED
Closed: 2 months ago19 days ago
Resolution: --- → FIXED

Got it, thank you Emilio

Blocks: 2024171

Added bug 2026914 for creating a WPT testing this.

Sebastian

Flags: needinfo?(tlouw)

As mentioned in the bug, there were tests added for 1+ components to color-mix() in bug 2023579

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: