Re: getComputedStyle and border property.

On Thursday 2011-12-29 15:12 -0300, Alexis Menard wrote:
> I was looking on implementing in WebKit the support of the border
> shorthand property that you can query from the computed style. I have
> a doubt on the implementation itself.

There are many shorthand properties that can't represent the full
space of the longhand properties that they set.  'border' is one of
them, since it cannot set different borders on each side.

> Given this declaration :
> 
> border: 20em solid red;
> 
> what we should return ?
> 
> 320px solid rgb(255, 0, 0), 320px solid rgb(255, 0, 0), 320px solid
> rgb(255, 0, 0), 320px solid rgb(255, 0, 0)
> 
> or
> 
> 320px solid rgb(255, 0, 0)

The latter; the former is not valid CSS.

> Now consider this declaration :
> 
> border: 20em solid red; border-top: 10px groove blue;
> 
> what we should return?
> 
> 10px groove rgb(0, 0, 255), 320px solid rgb(255, 0, 0), 320px solid
> rgb(255, 0, 0), 320px solid rgb(255, 0, 0)
> 
> or nothing?

Nothing.  This is specified both here:

  http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties
    (which isn't quite the right place since the spec should also
    apply this text to CSSStyleDeclaration; we just assume it does
    that)
  # However, if there is no shorthand declaration that could be
  # added to the ruleset without changing in any way the rules
  # already declared in the ruleset (i.e., by adding longhand rules
  # that were previously not declared in the ruleset), then the
  # empty string should be returned for the shorthand property.

and here:

  http://dev.w3.org/csswg/cssom/#serializing-css-values
  # If the value of a shorthand property is requested and it cannot
  # be computed because the properties associated with the shorthand
  # have values that cannot be represented by the shorthand the
  # serialization is the empty string.

  (Though I'd note that there are some aspects of the cssom editor's
  draft that don't have working group consensus yet.)

-David

-- 
𝄞   L. David Baron                         http://dbaron.org/   𝄂
𝄢   Mozilla                           http://www.mozilla.org/   𝄂

Received on Friday, 30 December 2011 14:19:58 UTC