Bug 15862 - pixelTop, pixelLeft, pixelWidth, pixelHeight: values should be number, not empty string
Summary: pixelTop, pixelLeft, pixelWidth, pixelHeight: values should be number, not em...
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 523.x (Safari 3)
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-06 13:54 PST by Garrett Smith
Modified: 2011-11-12 00:16 PST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Garrett Smith 2007-11-06 13:54:10 PST
pixelLeft, pixelWidth, et c: values should be numbers, the values should reflect the computedStyle.

javascript:alert(typeof document.body.style.pixelWidth);// "string" should be "number"

javascript:alert(document.body.style.pixelWidth);// empty, should be a positive number.
Comment 1 David Kilzer (:ddkilzer) 2007-11-06 23:19:14 PST
Thanks for the bug report, Garrett.  Could you provide links to documentation about these attributes?  Are they part of a standard, or MSIE extensions?

Comment 2 Vinay Anantharaman 2011-11-11 16:34:44 PST
These props were from an IE standard.

http://msdn.microsoft.com/en-us/library/ms531133%28v=vs.85%29.aspx

DOM Level 2 recommends using: document.body.style.top

This document has some recommendations for replacements for these IE specific props. 
https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM

Is there a specific reason why you need them?
Comment 3 Garrett Smith 2011-11-12 00:16:01 PST
(In reply to comment #2)
> These props were from an IE standard.
> 
> http://msdn.microsoft.com/en-us/library/ms531133%28v=vs.85%29.aspx
> 
Yep.

In a nutshell, my argument is that WebKit's implementation of pixelTop and friends should work just like Microsoft's or should not exist at all.

They're diffrerent from the IE versions and potentially cause more harm than good. Perhaps removal is a better option.

> DOM Level 2 recommends using: document.body.style.top

Totally different. pixelTop represents pixel value, rounded to a number. style.top is a string and a css length (em, %, etc).

> 
> This document has some recommendations for replacements for these IE specific props. 
> https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM
> 
> Is there a specific reason why you need them?
To get a pixel value. Though we can now get that from getBoundingClientRect. 

What is the justification for having a Microsoft property that works differently than Microsoft's definition of it? Seems like a mistake, no?

It is as if those properties were added for compatibility, but that there was a poor effort made to make these properties actually compatible with the Microsoft properties of the same names. That is why I suggested that these properties be fixed to match Microsoft's behavior. Here is an example that demonstrates some incompatibility:


if(document.body.style.pixelTop == 0) {
  // Code that works with pixelTop
}

When pixelTop is 0 or "", it is equal to 0, thus, the code will run in WebKit. This is a problem because WebKit's pixelTop works differently than Microsoft's. 

WebKit should either remove the "pixelTop and friends" properties or follow Microsoft's respective definitions of them. Making them strings seems not only useless but potentially harmful, as they could trip up a script that uses a feature check, as shown in the above example, having unexpected, divergent behavior in WebKit.