- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Mon, 19 Apr 2010 11:26:45 -0400
- To: Anne van Kesteren <annevk@opera.com>
- CC: www-style@w3.org
On 4/19/10 2:52 AM, Anne van Kesteren wrote: > For elements outside the tree that is being rendered on screen Opera and > Chrome return the empty string for properties. Firefox however seems to > apply style rules and return a computed style. I.e. marginTop gives > "16px" for <p> elements. If you have style rules set for this element > those are also taken into account it seems. > > http://dump.testsuite.org/2009/getcomputedstyle/liveness/002.htm > demonstrates this. > > http://dump.testsuite.org/2009/getcomputedstyle/liveness/003.htm is a > slightly more interesting demonstration where the element in question is > coming from a different document (that also has style rules). Here > Firefox applies the style rules from the document that is fetching the > other document to the element from the document that is fetched. Gecko's behavior for win.getComputedStyle(elt) is to take the element elt and compute its style based on the styles of the current document of window |win|. This means that selector matching will be performed based on the DOM (fragment) the element is in, but using the list of rules from window |win|. This applies to not only document rules but UA rules too (so if the document in |win| is in quirks mode, quirks rules will be applied to the element). This was a conscious design decision in an area where the spec was ... somewhat underspecific. We did consider throwing in this situation, but decided against it because it was simpler to just write the code without assuming anything about window identity, etc. > My question is whether this is a bug in Firefox or a feature I should > somehow (how?) keep. There may be things that depend on the "element not in dom tree" behavior. At least I seem to recall seeing bugs on that. The other is mostly a source of developer confusion when they use the wrong window, I think... But all use of getComputedStyle I've encountered is conditioned on various browser sniffing, so changing this stuff is very likely to cause compat issues no matter what we do. :( -Boris
Received on Monday, 19 April 2010 15:27:22 UTC