Skip to content

[css-background] Question about serialization of multiple layers of css background #9254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joonghunpark opened this issue Aug 28, 2023 · 2 comments

Comments

@joonghunpark
Copy link

I was looking into the bugs of chromium, https://bugs.chromium.org/p/chromium/issues/detail?id=1473894,
and found that Firefox and chrome shows a different behavior for serialization of background shorthand
when they are used with its longhand properties in a mixed way.

FF: Serialize background shorthand + its longhand => longhands only
Chrome: Serialize background shorthand + its longhand => background shorthand only.

And as a result, chrome's serialization result is not matched with the result of its specified original statements.

For example, for style rule below, FF and chrome shows the different CSSStyleDeclaration result.

<style> input { background: #00ee00 no-repeat; background-image: linear-gradient(to bottom, #8ab73e, #8ab73e), linear-gradient(to bottom, #353535, #353535); background-size: 0 1px, 100% 1px; background-position: 50% 50%, 50% 100%; border: none; } </style>
  1. FF CSSStyleDeclaration
    input { background-color: rgb(0, 238, 0); background-repeat: no-repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-image: linear-gradient(rgb(138, 183, 62), rgb(138, 183, 62)), linear-gradient(rgb(53, 53, 53), rgb(53, 53, 53)); background-size: 0px 1px, 100% 1px; background-position: 50% 50%, 50% 100%; border: medium; }

  2. Chrome CSSStyleDeclaration
    input { background: linear-gradient(rgb(138, 183, 62), rgb(138, 183, 62)) 50% 50% / 0px 1px no-repeat, linear-gradient(rgb(53, 53, 53), rgb(53, 53, 53)) 50% 100% / 100% 1px rgb(0, 238, 0); border: none; }

Because 'background' shorthand's omitted properties uses their default values, meanwhile longhand properties repeats the list of values until there are enough if a property doesn’t have enough comma-separated values to match the number of layers,
so chrome's shorthand presentation of serialization result seems like a buggy behavior.

If we want to keep chrome's current behavior, it seems that we need to manipulate the shorthand 'background' serialization result to include the repeated value list(https://www.w3.org/TR/css-backgrounds-3/#layering),
but I'm not sure which way is the right one between the current FF and Chrome behaviors.

Is there a spec for 'background' shorthand property's serialization result?

I'd like to ask about it before I proceed the chromium bug further.

Thank you for your help!

@emilio
Copy link
Collaborator

emilio commented Aug 29, 2023

I don't think you can write that background property combination as a shorthand right now. So Firefox is right per https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block. You get to step 8 because https://drafts.csswg.org/cssom/#serialize-a-css-value has:

If there is no such shorthand or shorthand cannot exactly represent the values of all the properties in list, return the empty string.

@joonghunpark
Copy link
Author

Thank you for your kind explanation, Emilio. It clarified which steps are proceeded in serialization process and helped me a lot to find out which direction I should go on.
I think Blink should process it in the same way as specified in the spec you commented above.
I will proceed in the way.

Thank you for your help!

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 12, 2023
…longhands doesn't match each other.

If the specified list of longhand css declarations has different layer numbers
for each component longhand,
it can't be represented as a form of corresponding shorthand,
so return empty string as a result of 'background' shorthand serialization.

Firefox 116.0.2 have this behavior,
but Safari 16.6 shows the same behavior with Chrome of before this change.

The behavior is according to the spec,
https://drafts.csswg.org/cssom/#serialize-a-css-value
and the csswg issue,
w3c/csswg-drafts#9254.

Bug: 1473894
Change-Id: I6cfd8de7d735ac8ee01bbc90610dd67191a2580b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants