Re: Fwd: cssom - clientTop, et v

On Mon, Mar 10, 2008 at 12:59 AM, Anne van Kesteren <annevk@opera.com> wrote:
> On Mon, 10 Mar 2008 06:24:46 +0100, Garrett Smith <dhtmlkitchen@gmail.com>
>  wrote:
>
> > Puts the 'px' in the wrong place. It complicate scripts that properly
>  > typecheck:-
>  >
>  > if(typeof el.currentStyle.borderRightWidth == "string") {
>  >
>  > }
>
>  Do you know of any site that does that? I'd love to have some pointers.

Do I know any sites that do that? Not off the top of my head, no.

However, assuming the return value is string would not necessarily be
the correct assumption.

var x = "opacity";
alert(typeof document.body.currentStyle[ x ])

IE: "undefined"
Opera: "string"

>
>
>
>  > The real "use case" for (3) is for hand-rolled javascript based
>  > animations. [...]
>
>  Indeed. There seem to be various other proposals for animations now that
>  make it worthwhile delaying extensions to the CSSOM. (CSS Animations and
>  SVG Animation.)

The CSS Animations are interesting. There are no behavioral hooks that
I know of. An onstart() or oncomplete() would be useful.

>
>
>
>  > I did not find the currentStyle specified in the CSSOM draft
>  > (http://www.w3.org/TR/cssom-view/), so I googled and found:
>  > http://dev.w3.org/csswg/cssom/
>  > This document appears to be outdated. Please confirm. What is the
>  > correct URI?
>
>  That is the correct URI. I'm not updating everything at the same time ;-)
>

OK. Thanks for the confirmation.

>
>  > [...]
>
> > Element.getComputedValueAs(property, desiredUnit), would avoid this
>  > painful and limited approach. It would open other possibilities.
>
>  How does that work for properties that don't take units, but keywords? Or
>  properties that take <color> values?
>

null. or empty string. null could mean "not supported". If the method
returns empty string, it might be a likely bug. I say this because
some browsers still return empty string for some valid css 1
propertyValues on a computed style.

For color, well, I guess you could allow for ("rgb" or "#") - that
might be useful.


>  >
>  > Case (1) el.cascadedStyle - get the cascaded style
>  >
>  > Keywords are not useful. "Inherit" is not useful.
>  > Implementations of currentStyle sometimes return keywords or "inherit".
>  >
>  > Why currentStyle's Keywords are Undesirable -
>  > In IE and Opera, currentStyle return values are not clearly defined
>  > and, in many cases, returns values that are undesirable. Such
>  > undesirable values are "auto", "", "inherit", "medium", "bold" and
>  > other keywords. When I get an undesirable value like "inherit", I
>  > usually want the inherited value. For animation, it's not possible to
>  > perform math on "inherit" -- i need a number. So I have to check the
>  > parentNode, then the parentNode of the parentNode, all the way up
>  > until I get a value. If the value is the keyword "red", I degrade. I
>  > do not believe in sending down the wire a javascript colorKeyword ->
>  > hex map. The browser should do the conversion.
>
>  That sounds reasonable. I've added a note about cascadedStyle.
>


That's not showing up here: http://dev.w3.org/csswg/cssom/



>
>  > Regarding "CSS Pixel" - Is this a floating point number, a floating
>  > point number as a string with "px", a rounded number, or a rounded
>  > number plus "px"?
>
>  A CSS pixel is a CSS pixel. The representation depends on the context.

I'm trying to understand if includes a decimal point or not. Can you
define CSS pixel?

Here - an example that draws my question:

<!DOCTYPE html >

<html>
<head><title></title>
</head>
<body>

<script>
document.body.style.fontSize = "13px";
document.body.style.borderTop = "1.5em solid";
document.writeln(window.getComputedStyle &&
getComputedStyle(document.body, "").borderTopWidth);
document.writeln(document.body.clientTop);
</script>
</body>
</html>

- result:

Opera 9.2: 20px 20
FF2: 19.5333px undefined
IE7: undefined 19
Saf3: 19px 19

What is a cssPixel?

My point about clientTop (the one you snipped) described that
clientTop is a rounded number, where as currentStyle is a string value
that includes units. This string value is not rounded, well in Opera
it is often floored, but that is a bug.


>
>
>  > [ getComputedStyle examples ]
>
> >
>  >> A new API doesn't solve any problems we have with the existing APIs. It
>  >> just adds more. Whether we like it or not, clientTop is part of the Web.
>  >
>  > Adding a new API creates fewer problems because the existing API can
>  > be replaced with something that is more consistent across browsers.
>
>  It can be not be replaced. Browsers have to support both. Hence, more
>  problems.
>

Correct. For a period of time, perhaps 2 years, browsers support both.
Scripts will also have to support both.

Problems of a new API can be significantly reduced with a test suite.
Not a post-hoc, ad-hoc acid test, but a conformance test before the
fact, to actually prevent problems.

I asked "Do you care to guess how many pages use offsetTop and offsetParent?"

Should I assume your answer is "no"?

Existing compatibility issues are an important consideration. That is
why I asked.

Garrett

>
>  --
>
>
> Anne van Kesteren

Received on Monday, 10 March 2008 09:08:00 UTC