Bug 126844 - Subpixel Layout: getComputedStyle rounds off fractional pixel values
Summary: Subpixel Layout: getComputedStyle rounds off fractional pixel values
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac (Intel) Unspecified
: P2 Normal
Assignee: zalan
URL: http://codepen.io/desandro/pen/CEfJF
Keywords: InRadar
Depends on:
Blocks: 126283
  Show dependency treegraph
Reported: 2014-01-12 08:14 PST by David DeSandro
Modified: 2014-06-10 19:56 PDT (History)
6 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description David DeSandro 2014-01-12 08:14:09 PST
See example http://codepen.io/desandro/pen/CEfJF

The value of getComputedStyle( elem ).width is returned as 199px for an element that has CSS `width: 66.666%`, and it's parent element has `width: 300px`. Other browsers keep the fractional pixel value, i.e. 199.98px.  I expected the value to either have the fractional pixel, or round up to the nearest integer, instead of rounding off any fractional pixel value.

I imagine this behavior might be by design, as it 199px is the rendered width of the element, and it prevents rounding errors to overshoot the true value.  That said, I thought it was worth documenting.

I have found that using `calc()` values for `width` produces closer-to-expected values. So for that example, changing width to `calc( 100% * 2 /3 )` returns `200px`. See http://codepen.io/desandro/pen/CKwfd
Comment 1 zalan 2014-01-19 18:27:47 PST
Comment 2 zalan 2014-06-10 19:56:06 PDT
getComputedStyle( box ).width now returns 199.984375px as expected. This has been fixed by one of the patches while transitioning to subpixel rendering.