csswg-drafts icon indicating copy to clipboard operation
csswg-drafts copied to clipboard

[cssom][css-values] Serialization of <number-percentage>?

Open birtles opened this issue 7 years ago • 5 comments

This is possibly more of a Chrome bug than a spec issue but I thought I'd check: how should brightness(0.5) and brightness(50%) be serialized. As-is?

Given this fiddle in Firefox and Edge the two values are serialized as-is, but in Chrome both become brightness(0.5). Servo, I believe, does the same as Chrome here so I want to check that Chrome is in fact wrong before changing Servo.

birtles avatar Jun 21 '17 08:06 birtles

It would definitely be preferable if equivalent declarations serialized to the same value.

Furthermore, serializing to number is probably slightly preferable to percentages, as they are easier to use in JS.

But to make this a general rule (and not just something specific to filter) would require that <number-percentage> only be used when numbers and percentages are directly equivalent. Which I think was the agreement from the discussion of calc(), but I'm not sure.

AmeliaBR avatar Jun 21 '17 15:06 AmeliaBR

Serialization is really a matter of CSSOM spec, I believe.

In the serialization section of CSSOM, there is no individual rule for <number-percentage>, and from CSS Values spec, <number-percentage> is really just [ <number> | <percentage> ] so I would suggest we should just serialize it as [ <number> | <percentage> ], which means they should be serialized as-is in this case.

upsuper avatar Jun 23 '17 01:06 upsuper

Underspecified. I'd prefer they serialize to the same thing too, tho.

tabatkins avatar Jul 12 '17 21:07 tabatkins

WPTs show current browsers serializing specified values as supplied by the author, and serializing getComputedStyle() results using numbers.

ewilligers avatar Aug 29 '19 09:08 ewilligers

They are not generally compatible, so their specified values should be serialized as-is. As for the computed value serialization, that should depend on what the Computed Value is defined to be. It's up to the property/function to define that e.g. <percentage> values compute to equivalent <number>s or vice versa.

Retagging against Filters.

fantasai avatar Oct 19 '22 20:10 fantasai