Closed Bug 412901 Opened 17 years ago Closed 17 years ago

getComputedStyle should return actual (rounded) values for border widths

Categories

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

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: roc, Assigned: roc)

Details

Attachments

(1 file)

We agreed in email this was a reasonable and useful thing to do.
Attached patch fixSplinter Review
Attachment #297708 - Flags: superreview?(dbaron)
Attachment #297708 - Flags: review?(dbaron)
Whiteboard: [needs review]
For the record, the reason this matters is jresig's testcase here:
http://dev.jquery.com/~john/ticket/ff3-offset/test/

He writes:

---------------------

There has been a change in Firefox 3 concerning the computation of borders and parent elements. For example, in Firefox 2 the result would've been 56 - in Firefox 3 it's now 57. This is fine - 57 is what all other browsers return.

However, both Firefox 2 and 3 return precise values for computed style values, meaning that if you set a border to a em or % value it will return a value up to multiple decimal places. No other browsers do this (they all round off to the nearest whole number).

The crux of the problem is that when trying to compute the width of an element (offsetWidth - computedLeftBorder - computedRightBorder) you get different values inbetween Firefox 3 and all other browsers, for example:

IE6, Opera9, Safari2, Safari3: 30 == 30: 56 - 13 - 13
FF2: 30.333399999999997 == 30 (rounds down to 30): 57 - 13.3333 - 13.3333
FF3: 29.333399999999997 == 30 (rounds down to 29): 56 - 13.3333 - 13.3333

---------------------

Basically, offsetWidth return the (rounded) actual border-box width, so if you want to determine the content width from it, you need to substract the actual border widths, and apparently Web authors expect getComputedStyle to return those widths. When it doesn't, you get the wrong result, as he describes.

[Note that you don't want to use offsetWidth anymore, you want to use getBoundingClientRect().width (when available in browsers) which returns more accurate (fractional) results in Gecko 1.9/FF3.]
These aren't used values; they're actual values.  What we're currently returning are used values.
Summary: getComputedStyle should return used values for border widths → getComputedStyle should return actual (rounded) values for border widths
Oh, so we use the actual values, not the used values? OK :-)
Flags: blocking1.9? → blocking1.9+
Priority: -- → P1
Comment on attachment 297708 [details] [diff] [review]
fix

r+sr=dbaron.

Could you also add a test that the border-width computes (getComputedStyle) to 0 if border-style is 'none' or 'hidden'?  (Maybe a second box in your existing test?)
Attachment #297708 - Flags: superreview?(dbaron)
Attachment #297708 - Flags: superreview+
Attachment #297708 - Flags: review?(dbaron)
Attachment #297708 - Flags: review+
checked in with updated test
Status: NEW → RESOLVED
Closed: 17 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Whiteboard: [needs review]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: