Move Length and CSS length computation to float
authoreae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Apr 2012 16:27:15 +0000 (16:27 +0000)
committereae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Apr 2012 16:27:15 +0000 (16:27 +0000)
commit16a2ff3b0526ff7bb5e32d3dbbc0f5b99ce428e3
tree68b9f437ee941c9fb1be5bfc3f91e7fc534ef160
parent2fa4e4abc03a19be2d6a0fcb10548b8f8e57fe36
Move Length and CSS length computation to float
https://bugs.webkit.org/show_bug.cgi?id=84801

Source/WebCore:

Patch by Emil A Eklund  <eae@chromium.org> and Levi Weintraub <leviw@chromium.org> on 2012-04-26
Reviewed by Eric Seidel.

Change Length and CSS length computation to floating point. This gets us
closer to the goal of supporting subpixel layout and improves precision
for SVG which already uses floating point for its layout.

This change makes computedStyle return fractional values for pixel values
if a fraction is specified. It also changes the result of computations
where two or more values with fractional precision. Prior to this change
the result of Length(2.9) + Length(2.9) would be 4 as each value would be
floored. With this change the result is 5 as the addition is done with
floating point precision and then the result will be floored. Once we
enable subpixel layout the resulting value in this example would be 5.8.

Updated existing layout tests.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::zoomAdjustedPixelValue):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeLength):
* css/CSSPrimitiveValue.h:
(WebCore):
(WebCore::roundForImpreciseConversion):
Add specialized float version of roundForImpreciseConversion that matches
the int versions rounding logic.

If a value is sufficiently close to the next integer round it up to
ensure that a style rule such as "width: 4.999px" evaluates to 5px
instead of 4px. This is needed as, although Lengths are using floating
point, the layout system still uses integer precision and floors the
Length values.
This will change once we move to FractionalLayoutUnits but for now this
is needed to ensure compatibility with the existing system and tests.

Without this specialized rounding logic we fail a handful of tests
including acid3.

* platform/Length.h:
(WebCore::Length::value):
(Length):
(WebCore::Length::intValue):
* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::styleOrColLogicalWidth):

LayoutTests:

Reviewed by Eric Seidel.

Change Length and CSS length computation to floating point. This gets us
closer to the goal of supporting subpixel layout and improves precision
for SVG which already uses floating point for its layout.

This change makes computedStyle return fractional values for pixel values
if a fraction is specified. It also changes the result of computations
where two or more values with fractional precision. Prior to this change
the result of Length(2.9) + Length(2.9) would be 4 as each value would be
floored. with this change the result is 5 as the addition is done with
floating point precision and then the result will be floored. Once we
enable subpixel layout the resulting value in this example would be 5.8.

* fast/dom/length-attribute-mapping-expected.txt:
* fast/dom/length-attribute-mapping.html:
* platform/mac-snowleopard/fast/forms/001-expected.png:
* platform/mac-snowleopard/svg/zoom/page/zoom-replaced-intrinsic-ratio-001-expected.png:
* platform/mac/fast/forms/001-expected.txt:
* platform/mac/fast/html/details-position-expected.png:
* platform/mac/fast/html/details-position-expected.txt:
* platform/mac/fast/replaced/width100percent-checkbox-expected.png:
* platform/mac/fast/replaced/width100percent-checkbox-expected.txt:
* platform/mac/fast/replaced/width100percent-radio-expected.png:
* platform/mac/fast/replaced/width100percent-radio-expected.txt:
* platform/mac/mathml/presentation/fractions-expected.png:
* platform/mac/mathml/presentation/fractions-expected.txt:
* platform/mac/mathml/presentation/fractions-vertical-alignment-expected.png:
* platform/mac/mathml/presentation/fractions-vertical-alignment-expected.txt:
* platform/mac/mathml/presentation/mo-stretch-expected.png:
* platform/mac/mathml/presentation/mo-stretch-expected.txt:
* platform/mac/mathml/presentation/subsup-expected.png:
* platform/mac/mathml/presentation/subsup-expected.txt:
* platform/mac/svg/zoom/page/zoom-replaced-intrinsic-ratio-001-expected.txt:
* platform/mac/svg/zoom/page/zoom-svg-through-object-with-percentage-size-expected.txt:
* platform/mac/tables/mozilla/bugs/bug1318-expected.png:
* platform/mac/tables/mozilla/bugs/bug1318-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@115573 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/length-attribute-mapping-expected.txt
LayoutTests/fast/dom/length-attribute-mapping.html
LayoutTests/platform/mac-snowleopard/fast/forms/001-expected.png
LayoutTests/platform/mac-snowleopard/svg/zoom/page/zoom-replaced-intrinsic-ratio-001-expected.png
LayoutTests/platform/mac/fast/forms/001-expected.txt
LayoutTests/platform/mac/fast/html/details-position-expected.png
LayoutTests/platform/mac/fast/html/details-position-expected.txt
LayoutTests/platform/mac/fast/replaced/width100percent-checkbox-expected.png
LayoutTests/platform/mac/fast/replaced/width100percent-checkbox-expected.txt
LayoutTests/platform/mac/fast/replaced/width100percent-radio-expected.png
LayoutTests/platform/mac/fast/replaced/width100percent-radio-expected.txt
LayoutTests/platform/mac/mathml/presentation/fractions-expected.png
LayoutTests/platform/mac/mathml/presentation/fractions-expected.txt
LayoutTests/platform/mac/mathml/presentation/fractions-vertical-alignment-expected.png
LayoutTests/platform/mac/mathml/presentation/fractions-vertical-alignment-expected.txt
LayoutTests/platform/mac/mathml/presentation/mo-stretch-expected.png
LayoutTests/platform/mac/mathml/presentation/mo-stretch-expected.txt
LayoutTests/platform/mac/mathml/presentation/subsup-expected.txt
LayoutTests/platform/mac/svg/zoom/page/zoom-replaced-intrinsic-ratio-001-expected.txt
LayoutTests/platform/mac/svg/zoom/page/zoom-svg-through-object-with-percentage-size-expected.txt
LayoutTests/platform/mac/tables/mozilla/bugs/bug1318-expected.png
LayoutTests/platform/mac/tables/mozilla/bugs/bug1318-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/CSSPrimitiveValue.h
Source/WebCore/platform/Length.h
Source/WebCore/rendering/RenderTableCell.cpp