Last Comment Bug 186516 - offsetWidth,clientWidth and scrollWidth properties return incorrect values with empty block elements
: offsetWidth,clientWidth and scrollWidth properties return incorrect values wi...
Status: RESOLVED FIXED
: testcase
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: -- normal with 1 vote (vote)
: mozilla1.8beta1
Assigned To: Boris Zbarsky [:bz] (Out June 25-July 6)
: Hixie (not reading bugmail)
Mentors:
: 198999 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-12-22 20:21 PST by tfriesen
Modified: 2013-04-04 13:53 PDT (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
testcase:An alert onload will show property values (975 bytes, text/html)
2002-12-22 20:23 PST, tfriesen
no flags Details
testcase:same as above but with content added to "div1" (979 bytes, text/html)
2002-12-22 20:49 PST, tfriesen
no flags Details
Patch (1.99 KB, patch)
2004-05-31 11:41 PDT, Boris Zbarsky [:bz] (Out June 25-July 6)
roc: review-
roc: superreview-
Details | Diff | Review
Per review comments (1.02 KB, patch)
2004-07-14 01:10 PDT, Boris Zbarsky [:bz] (Out June 25-July 6)
roc: review+
roc: superreview+
Details | Diff | Review

Description tfriesen 2002-12-22 20:21:22 PST
These IE compatible properties seem to return incorrect values when there is no
content in a block element.

In the following testcase,the document.body contains a empty DIV element named
"div1",no styling is applied to the document.

offsetWidth,clientWidth and scrollWidth all return zero for div1,
but using getComputedStyle() for the width property gives a value.
These properties should be returning the same width values as the document.body
since the width values are "auto".
clientWidth also returns zero in IE6 for some reason.

offWidth also returns zero for the document.body.
clientWidth and scrollWidth both give a value.
These values are both greater then the computed width of the document.body,so 
that does'nt seem right.

Is the computed width of document.body suppose to be less than the width of the
root element?

The testcase should work in IE as well
Comment 1 tfriesen 2002-12-22 20:23:42 PST
Created attachment 109972 [details]
testcase:An alert onload will show property values
Comment 2 tfriesen 2002-12-22 20:49:08 PST
Created attachment 109976 [details]
testcase:same as above but with content added to "div1"
Comment 3 Johnny Stenback (:jst, jst@mozilla.com) 2003-03-23 12:50:34 PST
Mass-reassigning bugs to dom_bugs@netscape.com
Comment 4 Mats Palmgren (:mats) 2003-06-18 12:38:14 PDT
*** Bug 198999 has been marked as a duplicate of this bug. ***
Comment 5 Boris Zbarsky [:bz] (Out June 25-July 6) 2004-05-30 22:54:49 PDT
The problem here is that the offset rect is computed by starting with an empty
rect and unioning it with every rect of the element (continuations, etc).

But in this case the element rect is 0 height, so empty.  Thus we fall into the
"both rects empty case" in UnionRect().

I'm guessing the best fix here is to copy the relevant code out of UnionRect and
do the union by hand.... roc, any better ideas?
Comment 6 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2004-05-31 06:12:35 PDT
nope, that sounds correct.
Comment 7 Boris Zbarsky [:bz] (Out June 25-July 6) 2004-05-31 11:41:42 PDT
Created attachment 149701 [details] [diff] [review]
Patch
Comment 8 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2004-06-01 19:59:20 PDT
Actually, I wonder if the right thing to do here is to special-case the empty
rect and if it is empty, set it to (first-in-flow.x, first-in-flow.y, 0, 0).
Comment 9 Boris Zbarsky [:bz] (Out June 25-July 6) 2004-06-01 20:04:33 PDT
You mean if the result is empty once we're done with the loop?
Comment 10 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2004-06-01 20:07:33 PDT
Yeah. So if during the loop we find a non-empty rect, we use that.
Comment 11 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2004-06-16 19:30:32 PDT
Comment on attachment 149701 [details] [diff] [review]
Patch

minusing while we wait for bz to come back and respond
Comment 12 Boris Zbarsky [:bz] (Out June 25-July 6) 2004-07-14 01:10:02 PDT
Created attachment 153125 [details] [diff] [review]
Per review comments
Comment 13 Boris Zbarsky [:bz] (Out June 25-July 6) 2004-07-18 14:56:41 PDT
Checked in.

Note You need to log in before you can comment on or make changes to this bug.