W3C home > Mailing lists > Public > www-style@w3.org > August 2013

Re: [cssom] Methods instead of attributes for usedStyle et al

From: Simon Pieters <simonp@opera.com>
Date: Tue, 13 Aug 2013 21:34:52 +0200
To: "www-style@w3.org" <www-style@w3.org>, François REMY <francois.remy.dev@outlook.com>
Message-ID: <op.w1rsoeayidj3kv@simons-macbook-pro.local>
On Tue, 13 Aug 2013 20:02:53 +0200, François REMY  
<francois.remy.dev@outlook.com> wrote:

>> While trying to use WebIDL's new [SameObject] and [NewObject] extended
>> attributes where applicable in CSSOM [1], I noticed that the  
>> GetStyleUtils
>> members return new objects each time but doing so is discouraged for
>> attributes [2]. I don't think it makes sense for these to return the  
>> same
>> object each time since that would mean having to keep the object live
>> which is probably quite expensive.
>
> Why? You don't actually have to "keep the object live", it's exactly  
> similar to getComputedStyle(element) works (or element.currentStyle in  
> IE, for what it's worth): the object is a sort of proxy and when you ask  
> for a propery it returns from cache the value is up-to-date or modify  
> the cache if it's not (or not anymore). It doesn't cost more than  
> calling the getSomeStyle() function again and again every time.
>
> In fact, I would argue it's better because the issue if you outputs a  
> static object is that you've to compute the value of every property  
> straight when calling the function, while you can do so lazily  
> per-property on demand with a live object.
>
> Thoughts? 		 	   		

You're right. For some reason I thought getComputedStyle was static in  
implementations, but it's live in WebKit/Blink/Gecko/IE10:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2448

So the spec needs to be fixed to say that getComputedStyle is live.

This information also means that the GetStyleUtils can be changed back to  
attributes, and we can make them return the same live object each time.


getComputedStyle returns a new object each time even if it gets invoked  
with the same arguments in WebKit/Blink/Gecko, but not in IE10:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2449

Does anyone have an opinion about which is better, or should I just go  
with the majority? Is getComputedStyle often invoked with the same  
arguments in a tight loop in the wild?

-- 
Simon Pieters
Opera Software
Received on Tuesday, 13 August 2013 19:29:55 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:33 UTC