Re: WebKit now supports CSS Variables

So, let's go for another try.

Feel free to say what you think of it :
=> David Hyatt : Is this realisable, for the UA ? Easily or not ?
=> Everybody : Are my ideas close of your vision of the variables ?

/*
    If no propagation is defined, "public" is used as default value.
    If no media is defined, "all "is used as default value.

    Multiple propagation are proposed because it can be useful in some case 
to have
    both PUBLIC and PRIVATE propagation (see later)

    FRIEND is also eligible for PRIVATE search, so you can't use FRIEND and 
PRIVATE
    at same time because FRIEND already "implements" PRIVATE.

    Multiple media can be defined too.

    So the current specification is not breaked.
    This new proposal only allow some other possibilities
*/
@variables (public(\s*(friend|private))?|friend|private)? 
(MEDIA_TYPE(,\s+(MEDIA_TYPE))*)? {
  myVar: {STRING};
}

Way the variables are computed (some better spec will be wrotten later in 
this mail) :
> If some PRIVATE variable is defined in a stylesheet, then it'll be used
> Else if some FRIEND variable is defined in a parent stylesheet*, then 
> it'll be used
> Else look at some PUBLIC variable

* A parent stylesheet is any steelsheet that own the specified stylesheet
>> style1.css { @import url('style2.css'); } /* style1 ownes style2 */

/*
    To resolve any "var(x)" in the CSS, this function must be called with 
"x, null" or "x".
*/
DOMStyleSheet.getVariableValue(variableName, [propagation=null], 
[media=currentDocumentMedia]) {
    1: If "propagation" is equal to "PUBLIC"
        1b: Look for any child stylesheet (beginning by the end of the 
stylesheet)
        1c: Set "RESULT" = childStyleSheet.getVariableValue(variableName, 
PUBLIC, media)
            1cb: If "RESULT" is not "null"
                1cbb: Return "RESULT"
    /* NOTE that FRIEND is also eligible for PRIVATE, but that PRIVATE is 
not eligible for FRIEND */
    2: Look for any @variable block that have a propagation attribute equals 
to "propagation" in the stylesheet (beginning by the end of the stylesheet)
        2b: Look for any variableName variable's declaration in it.
        2c: Return it's value.
    3: If "propagation" is not equal to "null" or "FRIEND"
        3b: Return "null"
    4: Look for the parent stylesheet
        4b: Return this.parentStyleSheet.getVariableValue(variableName, 
FRIEND, media)
    5: If "propagation is equal to "FRIEND"
        5b : Return "null"
    6: Return this.ownerDocument.getVariableValue(variableName, media)
}

DOMDocument.getVariableValue(variableName, [media=currentDocumentMedia]) {
    1: Look for any stylesheet in the document that are enabled (beginning 
by the end of the document)
        1b: Set "RESULT" = stylesheet.getVariableValue(variableName, PUBLIC, 
media);
        1c: If "RESULT" is not "null"
            1cb: Return "RESULT"
    2: Return "null"
}


Some test case now :
link:stylesheet1.css {
        @variables friend { bgColor: red};
        s1 { color: var(bgColor); }
    }
    @import:stylesheet1a.css {
            @variables public { bgColor: green; }
            s2 { color: var(bgColor); }
    }
    @import;stylesheet1b.css {
            @variables private { bgColor: orange; }
            s3 { color: var(bgColor); }
    }
        @import:stylesheet1ba.css {
                @variables public friend { bgColor: blue; }
                s4 { color: var(bgColor); }
        }
link:stylesheet2.css {
        s5 { color: var(bgColor); }
}

body:style:color:"var(bgColor)"

>> s1: red (friend is eligible for private)
>> s2: red (public is not eligible for private, parent stylesheet has a 
>> friend variable)
>> s3: orange (private var in the style sheet)
>> s4: blue (friend is eligible for private)
>> s5: blue (the last stylesheet that define a public "bgColor" is 
>> "1ba.css")
>> body: idem as s5

Am I clear enough ?

Fremy


--------------------------------------------------
From: "David Woolley" <forums@david-woolley.me.uk>
Sent: Sunday, June 29, 2008 8:28 PM
To: "www-style list" <www-style@w3.org>
Subject: Re: WebKit now supports CSS Variables

>
> David Hyatt wrote:
>
>> I agree.  I think the model of just allowing variables to be defined at 
>> the document-level is simple and intuitive.  It allows for centralized 
>> variable definition and reuse.
>>
>
> I think the only way you can make this work and still retain the cascade 
> philosophy is if you require includes and link elements, through which 
> variables propagate outwards to have an explicit qualifier to request 
> this.
>
> That way any stylesheet can re=define a variable without caring whether 
> the name is already in used, and have the scope of that variable limited 
> to itself, or the sheets it includes, but still have the option of 
> defining a global set of variables.
>
> This is not perfect, because it only really allows one set of variables to 
> propagate sideways at any level, e.g. you can't have a set of corporate 
> variables and a conflicting set of variables for one department, 
> contributing multiple sheets, then have another (matrix management?) 
> department having following style sheets, but which use the corporate 
> variables.
>
>
> From the comments being made about corporate rules and the involvement of 
> Apple, I think this is being introduced for a market that considers the 
> cascade a nuisance, because that market believes in central control of 
> presentation.
>
> -- 
> David Woolley
> Emails are not formal business letters, whatever businesses may want.
> RFC1855 says there should be an address here, but, in a world of spam,
> that is no longer good advice, as archive address hiding may not work.
> 

Received on Sunday, 29 June 2008 20:14:05 UTC