Skip to content

[cssom] Define serialization for background shorthand #418

@Manishearth

Description

@Manishearth
div = document.createElement('div');
div.style.background = "url(a), url(b)";
div.style.backgroundRepeat="no-repeat, no-repeat, no-repeat";
console.log(div.style.background);

This returns "" on Firefox and "url("a") no-repeat, url("b") no-repeat, no-repeat" on Chrome.

div = document.createElement('div');
div.style.background = "url(a), url(b), url(c)";
div.style.backgroundRepeat="no-repeat, repeat,";
console.log(div.style.background);

This returns "" on Firefox and "url("a") no-repeat, url("b") repeat, url("c")" on Chrome.

In case the number of values set is the same, Firefox does return a value:

div = document.createElement('div');
div.style.background = "url(a), url(b), url(c)";
div.style.backgroundRepeat="no-repeat, repeat, no-repeat";
console.log(div.style.background);

("url("a") no-repeat scroll 0% 0%, url("b") repeat scroll 0% 0%, transparent url("c") no-repeat scroll 0% 0%" on Firefox, "url("a") no-repeat, url("b") repeat, url("c") no-repeat" on Chrome)

Firefox seems to only serialize when all set longhands are of the same length (and when it does, it serializes to all default values). Chrome always serializes, and just prints out whatever was set.

This should probably be specced. Important questions to answer:

  • Should we truncate everything to the length of the background-image longhand?
  • For underspecified longhands, should we cycle through them to make them the same length as background-image?
  • Should we be explicit (like FIrefox) or implicit (like Chrome)?
  • Is serialization (of a shorthand) allowed to fail if parsing hasn't?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions