Re: [cssom][css-variables] value on CSSStyleDeclaration of longhand properties set by a shorthand with variable references

On Tue, Aug 27, 2013 at 5:18 PM, Cameron McCormack <cam@mcc.id.au> wrote:
> (Sorry for using "[css-om]" rather than "[cssom]" in the subject of my
> previous mail.)
>
> Consider:
>
>   <style>
>    p {
>     var-a: url("a") green;
>     background-color: red;
>     background: var(a);
>   }
>   </style>
>   <script>
>     var decl = document.styleSheets[0].cssRules[0].style;
>     alert(decl.getPropertyValue("background-color"));
>   </script>
>
> What should be alerted?
>
> Conceptually, I think of 'background-color' having a specified value of
> something like 'extract-background-color( var(a))'.  Setting 'background'
> overrides whatever value was given to 'background-color' earlier in the
> declaration.
>
> Chrome alerts "red", but that's misleading, since 'background-color' is
> overridden.  My WIP patches for Firefox return " var(a)" but that's also not
> right.
>
> I'd be happy with returning an empty string, in lieu of anything more
> useful.

I answered this same question when raised by someone else last
February: <http://lists.w3.org/Archives/Public/www-style/2013Feb/0636.html>

I said I'd edit it in, and then failed to do so.  It's *actually*
edited in now.  ^_^

(The answer is "" for your code.  If you called getComputedStyle(), it
would be "green".)

> Now, what do we alert with this:
>
>   alert(decl.getPropertyValue("background"));
>
> I would expect " var(a)", and that is what Chrome and my WIP patches return.
> CSSOM defines getPropertyValue with a shorthand property to concatenate all
> of the longhand property values from the declaration though, which won't get
> you the right result.  I think shorthands with variable references need to
> be treated specially here.

Defined!  If serializing a shorthand would involve building it out of
a longhand that's still pending its value, you instead serialize it as
its original value.

~TJ

Received on Thursday, 29 August 2013 23:34:34 UTC