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

[css-shapes][css3-backgrounds] No explicit <position> serialization steps in background spec

Open Manishearth opened this issue 7 years ago • 11 comments

https://drafts.csswg.org/css-shapes/#basic-shape-serialization

https://drafts.csswg.org/css-backgrounds-3/#position

The basic-shape spec mentions:

The values (including the defaults) in ellipse() and circle() serialize to their 2- and 4-value forms only, preferring the 2-value form when it can be expressed without calc(), preferring left and top origins, and preferring 0% over a zero length.

The backgrounds spec does not have serialization steps mentioned at all. Can we assume the same serialization steps?

(This doesn't match existing behavior -- browsers serialize center center as center center instead of 50% 50% for background position)

Manishearth avatar Aug 02 '16 07:08 Manishearth

I don't think we want to change that behavior. It seems to me functions usually have special serialization rules, but not general property values.

upsuper avatar Aug 09 '16 04:08 upsuper

Does this mean we can serialize any way we want provided that it parses to the same thing?

Manishearth avatar Aug 09 '16 04:08 Manishearth

I don't think so. For one thing it makes writing web-platform-tests hard (not to mention making life hard for scripts that want to parse the result of getComputedStyle). We recently specced <timing-function> serialization (and fixed it in Gecko so far, Blink later) so we can write interop tests. We should probably spec background-position / <position> too.

birtles avatar Aug 09 '16 08:08 birtles

It doesn't seem to me serialization of general specified value is defined anywhere... If we are trying to define it, it should match what engines are currently doing.

My guess is that engines general just put the parsed tokens in the grammar order, so top center => center top.

upsuper avatar Aug 09 '16 09:08 upsuper

This should probably be defined in css-values spec I suppose.

upsuper avatar Aug 09 '16 09:08 upsuper

There's a fair bit of serialization defined in CSSOM, e.g. serializing a CSS value. But I don't think it covers <position>.

birtles avatar Aug 09 '16 23:08 birtles

I was looking for issues related to the serialization of <position> (ie. the "generic" <position>) and <bg-position> because I do not understand the rationale for the following (quoted from CSS Shapes, 3.3 Serialization of Basic Shapes), which is matching the current browser outputs and WPT tests:

Omitting components means that some default values do not show up in the serialization. But since always uses the 2- or 4-value form, a default is not omitted.

circle(closest-side at center) serializes as circle(at 50% 50%)

I guess that always uses the 2- or 4-value form comes from an old version of CSS Shape, but why this rule is also applied to <bg-position>? And why would it be required? Furthermore, the following (quoted from CSSOM, 6.7.2 Serializing CSS Values) is a normative text against it:

If component values can be omitted or replaced with a shorter representation without changing the meaning of the value, omit/replace them.

circle(), circle(at center), circle(at 50%), ... are all valid and means the same value, and my guess would have been to serialize them as circle(). I am not claiming that they should be serialized like this, but I just woud like to understand the current browser outputs.

cdoublev avatar Nov 26 '21 09:11 cdoublev

@cdoublev (and others) take a look at the discussion in https://github.com/w3c/csswg-drafts/issues/2274 for some of the things that led us to decide to only serialize to 2- and 4-value forms. The text in css-shapes was also supposed to also go in css-backgrounds-3 (I remember having plans to remove as much as I could from css-shapes and just refer to bg-position serialization when I could)

astearns avatar Nov 27 '21 17:11 astearns

Thanks, I would have found this issue if I had searched on this topic without the css-shapes label.

If I understood correctly :

  1. a list of values matching <position> or <bg-position> should serialize to at least 2 values, ie. it should not be simplified either to a single value, because it would complicate round-tripping and parsing transform-origin would become ambiguous, or to 3 values (eg. from circle(at left 10px bottom 10%) to circle(at left 10px 90%)
  2. a list of values matching the 3-value syntax <bg-position> should serialize to 4 values by adding a missing offset (percentage) or by replacing center by top 50% or left 50%
  3. the specified values are serialized, ie. a keyword is not replaced by a percentage and vice-versa (except for 2)

cdoublev avatar Nov 29 '21 08:11 cdoublev

This is now edited into css-values-4, see https://github.com/w3c/csswg-drafts/commit/0742ad6e372782b46cca9708fa293e2b5abab219

Marking Needs Edits for CSS Shapes

fantasai avatar Oct 12 '22 20:10 fantasai

The issue seems also about missing serialization steps for background-position in CSS Backgrounds, noting that CSS Backgrounds 3 uses <bg-position>, and CSS Backgrounds 4 uses <position> (related).

cdoublev avatar Oct 13 '22 04:10 cdoublev