[whatwg] New method for obtaining a CSS property

On 1/28/11 1:22 AM, Brett Zamir wrote:
> My point is that a selector can be tied to a property through the
> ruleset.

No, not really.  Something that _matches_ selectors an be tied to a 
property via seeing which selectors it matches and then considering the 
resulting declaration lists....

> I recognize there may be more than one declaration even with
> the same property being associated with the same selector, but I'm
> suggesting to define some rules for selecting the most logical match.

So rules for matching selectors to selectors, right?  Defining these 
could really get pretty complex, unless you're suggesting that it just 
be a string compare of the serializations or something.

>> You can do that right now using getComputedStyle, with a bit more
>> code, right?
>
> Yes, or by iterating through document.stylesheets.

Um... why would you do that?

> But as Ashley pointed out, it is needlessly complex to create one's own pseudo document

Why would you need to create a pseudo document?

> for this purpose, and I think it should be a simple operation to be able to
> do something as fundamental as following best practices.

Ideally, yes, but setting styles directly from script (as opposed to 
setting classes that are then styled by the stylesheet) is not exactly 
"best practices", unless we're looking at different best practices lists.

>>> Or, for canvas specifically. You draw an animated "Hello" and want the
>>> designer to be able to choose the fill color. You want to be able to
>>> query the stylesheet easily to get the styling info.
>>
>> Or just set a class on your canvas and let styles apply to it as normal?
>
> Maybe you are thinking of SVG here?

No, I'm not.  Per the canvas spec, if I read it right, doing this:

   myCanvas.className = "somethingStyled";
   myCanvas.fillStyle = "currentColor";

should set the fill style to the computed value of "color" on myCanvas 
(and in particular, to whatever that computed value is given the class 
"somethingStyled").  As it happens, Gecko doesn't implement this yet, 
but the spec says to do it.  See 
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-canvas 
paragraph starting "Whenever the CSS value currentColor".

> ..and even if one could, it would not be targeted to the specific shapes
> needing styling.

Canvas isn't retained-mode.  So you set your fill style, then draw the 
shapes that need to have that style.  If you want a different style for 
different shapes, you set the new fill style and draw those shapes. 
There's no magic targeting involved...

-Boris

Received on Thursday, 27 January 2011 23:15:27 UTC