[whatwg] New method for obtaining a CSS property
Ashley Sheridan
ash at ashleysheridan.co.uk
Thu Jan 27 23:43:01 PST 2011
"Boris Zbarsky" <bzbarsky at MIT.EDU> wrote:
>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
Ross, I think you're getting caught up in the "everything has its own class" thing with css. I've seen people look create code like this before just because they wanted to style the list items:
<ul class="some_list">
<li class="some_item">
<li class="some_item">
<li class="some_item">
</ul>
Every list element has the same class, just seemed as if nobody knew that "ul.some_list some_item" matched the li tags. With your suggested behaviours, things like these selector are ignored.
What would you have happen where you needed to get a property of the .special class in the following selectors:
p span.special
body.page1 p.special
body.page2 p.special span.special
With no document context, anything you get would be meaningless.
Thanks
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
More information about the whatwg
mailing list