[cssom] CSS Value API

Last night I blogged about the direction I think we need to go in:

   http://annevankesteren.nl/2010/03/cssom-css-value-api

Basically, extend CSSStyleDeclaration with a new member, values, that  
returns CSSStyleDeclarationValue. The CSS property attributes on that  
object return CSSValue objects which depending on the CSS property  
implement specialized interfaces. In case of 'color' this object would  
e.g. have red, green, blue, and alpha attributes that you can set and get.  
However, it seems the setup needs to be slightly more complicated. E.g. in  
case of 'width' you probably want to know whether the current value is in  
px, em, %, etc. besides the ability to manipulate each of those. And for  
'max-width' you might need to know if it is the 'none' keyword in addition  
to those.

Now all CSS values consist of one or more CSS value components and each  
CSS value component in such a value can potentially be of several types:  
<color>, <ident>, <string>, <uri>, etc. So maybe we should have  
CSSValueComponent.type that indicates by means of a constant (or should we  
go for strings here as that gives easier extensibility even though it is  
inconsistent with everything else?) what type of CSS value component it  
is. For e.g. <length> this type attribute would have several values, so  
you know whether it is e.g. px or em.

The various values of this type attribute as well as the specific  
CSSValueComponent interfaces would be somewhat closely bound to what can  
actually be serialized I suppose as is drafted in  
http://dev.w3.org/csswg/cssom/#serializing-css-values though we can of  
course add convenience attributes if desired.

Thoughts on this are very much welcome. Some brainstorming during the F2F  
might also be a good use of time if we limit the amount of time :-)


-- 
Anne van Kesteren
http://annevankesteren.nl/

Received on Thursday, 25 March 2010 15:11:35 UTC