Closed Bug 81290 Opened 23 years ago Closed 23 years ago

offsetTop and offsetLeft gives wrong values in relative and absolute positioned parents

Categories

(Core :: DOM: CSS Object Model, defect)

defect
Not set
major

Tracking

()

VERIFIED FIXED
mozilla0.9.3

People

(Reporter: erik, Assigned: jst)

References

Details

(Whiteboard: [pdt+][nsBranch+][FIXED AND VERIFIED ON THE TRUNK])

Attachments

(4 files)

The offsetLeft and offsetTop values (and getComputedStyle...) should give the 
position in the current coordinate space and not the browser viewport space.

For example an absolute positioned element positioned at 100px left inside 
another element with either position absolute or relative (fixed as well I 
guess) should return an offsetLeft value of 100 and not 100 plus the offsetLeft 
of the parent.

This is important because an element that has position absolute or relative 
should not be moved by the following statement:

element.style.left = element.offsetLeft

The offsetLeft/Top should follow the same rules as style.left/top do when it 
comes to coordinate spaces.

Build tested on: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:0.9+) 
Gecko/20010510
The last test case shows that getComputedStyle seems to return the correct 
value for an absolutetly positioned element even when it is located inside an 
element defining its own coordinate space. Why that value is different from the 
offset value is beyond me.
Nominating for mozilla0.9.2, not sure we can fix this completely in time for
mozilla0.9.2, but we can fix at least parts of it, and IMO that's worth doing
since this breaks alot of "dhtml".
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.2
I think this is a duplicate of bug 34398.
*** Bug 86844 has been marked as a duplicate of this bug. ***
Attached patch Proposed fix.Splinter Review
The patch I just attached fixes .offsetXXX to work exactly like IE does in the
attached testcase, but now I need help. I need someone to apply the patch and
build mozilla with my patch and then go through all my, and vidur@netscape.com's
bugs (fixed, verified, unconfirmed, new, you name it) in bugzilla that have to
do with the .offsetXXX properties and make sure that I didn't break something
that used to work. Anyone up for doing that?
Ok, I applied the patch to 1.261 and merged with the changes from 1.262. Will
test and report in the appropriate bugs.
Moving to mozilla0.9.3
Target Milestone: mozilla0.9.2 → mozilla0.9.3
Fix checked in on the trunk, this should go onto the branch once we've let it
live on the trunk for a while.
Keywords: mozilla0.9.3
Hardware: PC → All
Whiteboard: [FIX ON THE TRUNK]
current status ?
Fixed on the mozilla trunk, waiting for approval to check this into the Netscape
RTM branch.
nsBranch ok, IE compatibility, code path exercised only in this special case so
should not cause problems elsewhere.
Keywords: nsBranch
Keywords: vtrunk
The testcases work fine.

Verified with build ID 20010070604.
Whiteboard: [FIX ON THE TRUNK] → [FIXED AND VERIFIED ON THE TRUNK]
This fix has baked on the trunk for more than a week.  The only codepath that is
affected by this change is the offsetTop and offsetLeft property getter/setters.
 These properties are not used by the scripts in the Mozilla suite of
applications so the possibility of regressions is low.  These properties were
partially implemented and shipped in Netscape 6.0 to match IE's behaviour.  With
this patch checked into Netscape 6.1, we will match IE's implementation much
more closely.  Web developers will be able to use these properties to create
reliable cross-browser content.

Marking nsBranch+.
Whiteboard: [FIXED AND VERIFIED ON THE TRUNK] → [nsBranch+][FIXED AND VERIFIED ON THE TRUNK]
Whiteboard: [nsBranch+][FIXED AND VERIFIED ON THE TRUNK] → [pdt+][nsBranch+][FIXED AND VERIFIED ON THE TRUNK]
Fix checked in on the branch.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Ian - pls verify this on the branch builds at your earliest convenience. Thanks.
Keywords: vtrunkvbranch
VERIFIED on branch per 
   http://bugzilla.mozilla.org/showattachment.cgi?attach_id=34822
Marking VERIFIED since trunk has already been verified.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: