offsetWidth,clientWidth and scrollWidth properties return incorrect values with empty block elements

RESOLVED FIXED in mozilla1.8beta1

Status

()

Core
DOM
RESOLVED FIXED
15 years ago
4 years ago

People

(Reporter: tfriesen, Assigned: bz)

Tracking

({testcase})

Trunk
mozilla1.8beta1
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(3 attachments, 1 obsolete attachment)

(Reporter)

Description

15 years ago
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
(Reporter)

Comment 1

15 years ago
Created attachment 109972 [details]
testcase:An alert onload will show property values
(Reporter)

Comment 2

15 years ago
Created attachment 109976 [details]
testcase:same as above but with content added to "div1"

Updated

15 years ago
Keywords: testcase
Mass-reassigning bugs to dom_bugs@netscape.com
Assignee: jst → dom_bugs
*** Bug 198999 has been marked as a duplicate of this bug. ***
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?
nope, that sounds correct.
Created attachment 149701 [details] [diff] [review]
Patch
(Assignee)

Updated

13 years ago
Attachment #149701 - Flags: superreview?(roc)
Attachment #149701 - Flags: review?(roc)
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).
You mean if the result is empty once we're done with the loop?
Yeah. So if during the loop we find a non-empty rect, we use that.
Comment on attachment 149701 [details] [diff] [review]
Patch

minusing while we wait for bz to come back and respond
Attachment #149701 - Flags: superreview?(roc)
Attachment #149701 - Flags: superreview-
Attachment #149701 - Flags: review?(roc)
Attachment #149701 - Flags: review-
Created attachment 153125 [details] [diff] [review]
Per review comments
Attachment #149701 - Attachment is obsolete: true
(Assignee)

Updated

13 years ago
Attachment #153125 - Flags: superreview?(roc)
Attachment #153125 - Flags: review?(roc)
Attachment #153125 - Flags: superreview?(roc)
Attachment #153125 - Flags: superreview+
Attachment #153125 - Flags: review?(roc)
Attachment #153125 - Flags: review+
(Assignee)

Updated

13 years ago
Assignee: general → bzbarsky
Checked in.
Status: NEW → RESOLVED
Last Resolved: 13 years ago
OS: Windows ME → All
Hardware: PC → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.8beta
Component: DOM: Mozilla Extensions → DOM
Product: Core → Core
You need to log in before you can comment on or make changes to this bug.