W3C home > Mailing lists > Public > www-style@w3.org > September 2009

Re: Proposal: getStyleAs(property, primitiveValue)

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Wed, 23 Sep 2009 14:02:54 -0700
Message-ID: <c9e12660909231402u72a9ab7ej47e9a3fd1e02ad6c@mail.gmail.com>
To: Řyvind Stenhaug <oyvinds@opera.com>
Cc: www-style <www-style@w3.org>
On Wed, Sep 23, 2009 at 10:38 AM, Řyvind Stenhaug <oyvinds@opera.com> wrote:
> On Tue, 22 Sep 2009 18:27:42 +0200, Garrett Smith <dhtmlkitchen@gmail.com>
> wrote:
>> * document.defaultView.getComputedStyle
>>  * Too verbose. The defaultView is unrelated to the Element (the DOM
>> spec says: "a computed style is related to an Element node").
> Isn't this somewhat circular, since document is found in AbstractView?

How does a program obtain a reference to an "abstract view" besides

> are there any browsers that need document.defaultView.getComputedStyle
> instead of just getComputedStyle?

There just might be. Actually, I happen to know a couple.

The DOM 2 spec does not say that there is a global function
"getComputedStyle". Why rely on it?

A few earlier browsers implemented document.defaultView as |window|.

Some authors then made the generalization that document.defaultView
/was/ window. They did this without any specification, probably
copying online tutorials and things that can be found from pop sites
like "ajaxian". It caught on like wildfire and document.defaultView
was being replaced by "window" in a lot of code. Now that in itself is
an interesting phenomenon. What reasonable explanation can be given
for the explosive popularity of favoring the nonstandard call to
getComputedStyle in global context? Probably
document.defaultView.getComputedStyle is too verbose and clunky and
getComputedStyle is shorter and simpler.

As a result of "what pages do", recent browser vendors have adapted to
make document.defaultView the window and we can see the change in
Safari 3, where document.defaultView is window, but was not in safari

It is unreasonable to make assertions of what "all browsers" do. It is
just as unreasonable to expect any one person to know what "all
browsers do." Though sometimes fair to make assertions that non
standard things exist, such as a global |window| property. A
scriptable browser not providing a window property would surely be
breaking a lot of sites that expect that, and so program can expect
that there be a window property.

I don't know which versions of Konqueror do what. I have not found an
emulator for recent versions of NetFront, so I cannot verify that,
either. There is also Danger (which Microsoft seems to have abducted),
Teleca, for which I cannot find an emulator, and I don't know how many

document.defaultView.getComputedStyle is standard and works.
window.getComputedStyle is nonstand. It "works" in a few browsers, but
is a poorer choice when compatibility is a concern.

>> A corresponding method to set a value would not seem to be necessary,
>> as any value could be set with:
>> x.style.color = "papayawhip";
> Well, not if there's an !important color declaration somewhere that affects
> x.

OK. What are you getting at?
Received on Wednesday, 23 September 2009 21:03:36 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:07:39 UTC