Bug 93445
Summary: | getComputedStyle for `opacity` loses precision | ||
---|---|---|---|
Product: | WebKit | Reporter: | dhtmlkitchen <dhtmlkitchen> |
Component: | CSS | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED WONTFIX | ||
Severity: | Normal | CC: | ap, simon.fraser |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Unspecified | ||
OS: | Unspecified | ||
URL: | javascript: var el = document.body; void(el.style.opacity = '0.95'); alert([el.style.opacity, getComputedStyle(el).opacity]); |
dhtmlkitchen@gmail.com
Reading `opacity` back from `getComputedStyle` results in a value that is not the value specified.
var el = document.body;
el.style.opacity = '0.95'; // Specified value.
el.style.opacity;// Specified value returned.
"0.95"
getComputedStyle(el).opacity; // Not the specified value.
"0.949999988079071"
With getComputedStyle(el).opacity, an internal number of the opacity is returned. Is it that '9.5' sets the opacity as a (lossy) binary number, which, when returned, is converted to a string?
Css3 spec says that the value returned must be "The same as the specified value after clipping the <alphavalue> to the range [0.0,1.0]."
Since the value returned ("0.949999988079071") is not the specified value ("9.5"), then this is a violation of a spec.
http://www.w3.org/TR/css3-color/#transparency
| Computed value: The same as the specified value
| after clipping the <alphavalue> to the range [0.0,1.0].
Version 5.1.1 (6534.51.22)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22"
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Alexey Proskuryakov
> Is it that '9.5' sets the opacity as a (lossy) binary number, which, when returned, is converted to a string?
Yes. As such, this really is the specified value, and no specs have been violated.
But perhaps there is something to do here that would swipe this under the carpet (like switching from float to double?), or something else I'm unaware of. So, keeping the bug open for experts to consider.
Simon Fraser (smfr)
I think some floating point rounding is acceptable, so I don't think this is a bug. <http://dev.w3.org/csswg/css3-values/#numeric-types> says "UAs should support reasonably useful ranges and precisions".
dhtmlkitchen@gmail.com
So 9.5., specified value, is out of reasonably useful?
dhtmlkitchen@gmail.com
Correction: ".95", not "9.5".