Re: [csswg-drafts] [cssom] Serialization of CSS declaration block returned from getComputedStyle

@zcorpan @carlosame 

>From the implementation side, computed style and specified style are usually stored in different forms in browsers, and when browsers are asked to serialize a computed value, they serialize it from its internal form directly (rather than, say, convert to specified value then serialize the latter), however, shorthand serialization algorithms are usually written to handle declaration block of specified values.

It means that to serialize declaration block from gCS per spec, browsers would need extra work either to implement all shorthand serialization algorithms on computed value as well, or create a declaration block containing every property in their specified value form, and then use the algorithm of specified declaration block to serialize them.

Doing such conversion is not impossible, though. Actually, at least in Gecko, we have such mechanism for animation and transition, because our cascading is based on specified value, but interpolation happens on computed value, so we need to "uncompute" value to cascade animation and transition correctly.

However, many properties are required to serialize differently for gCS, and the "uncompute" mechanism may not exactly match that requirement, so reusing it can potentially further complicate things.

>From the use case side, I'd argue that getting a serialization of a declaration block containing every property with shorthand serialized properly is hardly the ideal way for anything.

If you just want to persist and restore all values, you should just iterate all properties in that block, that would almost certainly be faster than relying on browser to generate the serialization of the huge declaration block, then parsing this huge serialization again, as can be seen in the discussion of webcompat/web-bugs#3822.

Also, shorthand serialization are usually for human readability, but would anyone want to read a declaration block serialization containing hundreds of properties?

Given that this needs probably non-trivial extra work on implementations, while it doesn't seem to be very useful, we should probably just make it as simple as possible so that implementations can be interoperable on the behavior.

-- 
GitHub Notification of comment by upsuper
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1033#issuecomment-386200717 using your GitHub account

Received on Thursday, 3 May 2018 06:19:41 UTC