Changeset 49554 in webkit


Ignore:
Timestamp:
Oct 13, 2009 9:09:02 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-10-13 Evan Martin <evan@chromium.org>

Reviewed by Adam Barth.

Float formatting changes affect three tests:

  • large-number-round-trip now passes
  • opacity-float now passes and has more test cases
  • compound-2d-transforms output tweaked slightly

https://bugs.webkit.org/show_bug.cgi?id=18994

  • fast/css/large-number-round-trip-expected.txt:
  • fast/css/opacity-float-expected.txt:
  • fast/css/opacity-float.html:
  • platform/mac/fast/css/opacity-float-expected.txt: Removed.
  • transforms/2d/compound-2d-transforms-expected.txt:
  • transforms/2d/compound-2d-transforms.html:

2009-10-13 Evan Martin <evan@chromium.org>

Reviewed by Adam Barth.

Stringify CSS units manually (without printf) to make the formatting
locale-insensitive and obey CSS spec with respect to large values.

https://bugs.webkit.org/show_bug.cgi?id=18994

  • css/CSSPrimitiveValue.cpp: (WebCore::appendCSSDouble): (WebCore::formatWithUnits): (WebCore::CSSPrimitiveValue::cssText):
Location:
trunk
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r49552 r49554  
     12009-10-13  Evan Martin  <evan@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Float formatting changes affect three tests:
     6        - large-number-round-trip now passes
     7        - opacity-float now passes and has more test cases
     8        - compound-2d-transforms output tweaked slightly
     9       
     10        https://bugs.webkit.org/show_bug.cgi?id=18994
     11
     12        * fast/css/large-number-round-trip-expected.txt:
     13        * fast/css/opacity-float-expected.txt:
     14        * fast/css/opacity-float.html:
     15        * platform/mac/fast/css/opacity-float-expected.txt: Removed.
     16        * transforms/2d/compound-2d-transforms-expected.txt:
     17        * transforms/2d/compound-2d-transforms.html:
     18
    1192009-10-13  Zan Dobersek  <zandobersek@gmail.com>
    220
  • trunk/LayoutTests/fast/css/large-number-round-trip-expected.txt

    r49254 r49554  
    1 FAIL: read 90010000px back as 9.001e+07px, read again as 0px
     1PASS: read 90010000px back as 90010000px, read again as 90010000px
  • trunk/LayoutTests/fast/css/opacity-float-expected.txt

    r49253 r49554  
    22
    33PASS
     4PASS
     5PASS
     6PASS
     7PASS
     8PASS
     9PASS
     10PASS
     11PASS
     12PASS
     13PASS
     14PASS
     15PASS
     16PASS
     17
  • trunk/LayoutTests/fast/css/opacity-float.html

    r49253 r49554  
    1616
    1717<script>
    18 var opacity = document.getElementById('test').style.opacity.toString();
    19 if (opacity == '0.9')
    20     document.write('PASS');
    21 else
    22     document.write('FAIL: ' + opacity);
     18var test = document.getElementById('test');
     19
     20function doTest(expected, input) {
     21    test.style.opacity = input;
     22    var opacity = test.style.opacity.toString();
     23    if (opacity == expected)
     24        document.write('PASS');
     25    else
     26        document.write('FAIL: expected ' + expected + ', got ' + opacity);
     27    document.write('<br>');
     28}
     29
     30var tests = [['0.9', '0.9'],
     31             ['98765432198', '98765432198'],
     32             ['9870000', '9870000'],
     33             ['0.000321', '0.000321'],
     34             ['50.02', '50.02'],
     35             // Check we clip precision to six decimals.
     36             ['1234.567891', '1234.567891234']];
     37for (var i = 0; i < tests.length; i++)
     38    doTest(tests[i][0], tests[i][1]);
     39
     40// Test a too-small value.
     41doTest('0', '0.0000001');
     42// Test that a beyond-precision digit will be rounded in.
     43doTest('0.000001', '0.0000009');
     44
     45// Run the test list again with negatives.
     46for (var i = 0; i < tests.length; i++)
     47    doTest('-' + tests[i][0], '-' + tests[i][1]);
    2348</script>
  • trunk/LayoutTests/transforms/2d/compound-2d-transforms-expected.txt

    r36454 r49554  
    77transform "matrix(0.978148, 0.207912, -0.207912, 0.978148, 50, 20)" expected "matrix(0.978148, 0.207912, -0.207912, 0.978148, 50, 20)" : PASS
    88transform "translate(50px, 20px) rotate(12deg)" expected "matrix(0.978148, 0.207912, -0.207912, 0.978148, 50, 20)" : PASS
    9 transform "rotate(12deg) translate(50px, 20px)" expected "matrix(0.978148, 0.207912, -0.207912, 0.978148, 44.7491, 29.9585)" : PASS
    10 transform "rotate(12deg) translate(50px, 20px) scale(1.4)" expected "matrix(1.36941, 0.291076, -0.291076, 1.36941, 44.7491, 29.9585)" : PASS
    11 transform "scale(1.4) rotate(12deg) translate(50px, 20px) " expected "matrix(1.36941, 0.291076, -0.291076, 1.36941, 62.6488, 41.942)" : PASS
    12 transform "scale(1.4) translate(50px, 20px) rotate(12deg)" expected "matrix(1.36941, 0.291076, -0.291076, 1.36941, 70, 28)" : PASS
    13 transform "translate(50px, 20px) rotate(12deg) translateY(50px) scale(1.4)" expected "matrix(1.36941, 0.291076, -0.291076, 1.36941, 39.6044, 68.9074)" : PASS
    14 transform "rotate(12deg) translate(50px, 20px) scale(1.4) translate(-80px, 40px) skew(34deg) translate(10px, 10px) scale(0.7) skewY(-25deg) rotate(21deg) translateX(50px) scale(1.4, 1.8)" expected "matrix(1.20517, 0.148207, 0.258987, 2.04004, -13.3847, 85.31)" : PASS
     9transform "rotate(12deg) translate(50px, 20px)" expected "matrix(0.978148, 0.207912, -0.207912, 0.978148, 44.749146, 29.958537)" : PASS
     10transform "rotate(12deg) translate(50px, 20px) scale(1.4)" expected "matrix(1.369407, 0.291076, -0.291076, 1.369407, 44.749146, 29.958537)" : PASS
     11transform "scale(1.4) rotate(12deg) translate(50px, 20px) " expected "matrix(1.369407, 0.291076, -0.291076, 1.369407, 62.648805, 41.941951)" : PASS
     12transform "scale(1.4) translate(50px, 20px) rotate(12deg)" expected "matrix(1.369407, 0.291076, -0.291076, 1.369407, 70, 28)" : PASS
     13transform "translate(50px, 20px) rotate(12deg) translateY(50px) scale(1.4)" expected "matrix(1.369407, 0.291076, -0.291076, 1.369407, 39.604415, 68.90738)" : PASS
     14transform "rotate(12deg) translate(50px, 20px) scale(1.4) translate(-80px, 40px) skew(34deg) translate(10px, 10px) scale(0.7) skewY(-25deg) rotate(21deg) translateX(50px) scale(1.4, 1.8)" expected "matrix(1.205166, 0.148207, 0.258987, 2.040044, -13.384723, 85.309967)" : PASS
    1515transform ",rotate(12deg) translate(50px, 20px)" expected "none" : PASS
    1616transform "rotate(12deg), translate(50px, 20px)" expected "none" : PASS
  • trunk/LayoutTests/transforms/2d/compound-2d-transforms.html

    r36454 r49554  
    4444      // two functions
    4545      { 'transform' : 'translate(50px, 20px) rotate(12deg)',          'result' : 'matrix(0.978148, 0.207912, -0.207912, 0.978148, 50, 20)' },
    46       { 'transform' : 'rotate(12deg) translate(50px, 20px)',          'result' : 'matrix(0.978148, 0.207912, -0.207912, 0.978148, 44.7491, 29.9585)' },
     46      { 'transform' : 'rotate(12deg) translate(50px, 20px)',          'result' : 'matrix(0.978148, 0.207912, -0.207912, 0.978148, 44.749146, 29.958537)' },
    4747
    4848      // three functions
    49       { 'transform' : 'rotate(12deg) translate(50px, 20px) scale(1.4)',   'result' : 'matrix(1.36941, 0.291076, -0.291076, 1.36941, 44.7491, 29.9585)' },
    50       { 'transform' : 'scale(1.4) rotate(12deg) translate(50px, 20px) ',  'result' : 'matrix(1.36941, 0.291076, -0.291076, 1.36941, 62.6488, 41.942)' },
    51       { 'transform' : 'scale(1.4) translate(50px, 20px) rotate(12deg)',   'result' : 'matrix(1.36941, 0.291076, -0.291076, 1.36941, 70, 28)' },
    52       { 'transform' : 'translate(50px, 20px) rotate(12deg) translateY(50px) scale(1.4)',   'result' : 'matrix(1.36941, 0.291076, -0.291076, 1.36941, 39.6044, 68.9074)' },
     49      { 'transform' : 'rotate(12deg) translate(50px, 20px) scale(1.4)',   'result' : 'matrix(1.369407, 0.291076, -0.291076, 1.369407, 44.749146, 29.958537)' },
     50      { 'transform' : 'scale(1.4) rotate(12deg) translate(50px, 20px) ',  'result' : 'matrix(1.369407, 0.291076, -0.291076, 1.369407, 62.648805, 41.941951)' },
     51      { 'transform' : 'scale(1.4) translate(50px, 20px) rotate(12deg)',   'result' : 'matrix(1.369407, 0.291076, -0.291076, 1.369407, 70, 28)' },
     52      { 'transform' : 'translate(50px, 20px) rotate(12deg) translateY(50px) scale(1.4)',   'result' : 'matrix(1.369407, 0.291076, -0.291076, 1.369407, 39.604415, 68.90738)' },
    5353
    5454      // lots of functions
    5555      { 'transform' : 'rotate(12deg) translate(50px, 20px) scale(1.4) translate(-80px, 40px) skew(34deg) translate(10px, 10px) scale(0.7) skewY(-25deg) rotate(21deg) translateX(50px) scale(1.4, 1.8)',
    56         'result' : 'matrix(1.20517, 0.148207, 0.258987, 2.04004, -13.3847, 85.31)' },
     56        'result' : 'matrix(1.205166, 0.148207, 0.258987, 2.040044, -13.384723, 85.309967)' },
    5757       
    5858      // invalid compound functions
  • trunk/WebCore/ChangeLog

    r49553 r49554  
     12009-10-13  Evan Martin  <evan@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Stringify CSS units manually (without printf) to make the formatting
     6        locale-insensitive and obey CSS spec with respect to large values.
     7       
     8        https://bugs.webkit.org/show_bug.cgi?id=18994
     9
     10        * css/CSSPrimitiveValue.cpp:
     11        (WebCore::appendCSSDouble):
     12        (WebCore::formatWithUnits):
     13        (WebCore::CSSPrimitiveValue::cssText):
     14
    1152009-10-13  Evan Martin  <evan@chromium.org>
    216
  • trunk/WebCore/css/CSSPrimitiveValue.cpp

    r47230 r49554  
    685685}
    686686
     687static void appendCSSDouble(Vector<UChar>& vector, double value)
     688{
     689    // From the CSS specification section titled "Integers and real numbers",
     690    // real numbers are only formatted as [sign] [digits] "." [digits].
     691    // This differs from printf-style formatting in that exponents (e.g. 1.3e06)
     692    // are not allowed.  Since NaN/inf are also not valid CSS values this
     693    // function doesn't handle them.
     694
     695    // For compatibility with what was returned by older versions of
     696    // WebKit, we target 6 digits of precision.
     697    const int digitsAfterDecimalPoint = 6;
     698    long long rounded = llround(fabs(value) * 1000000.0);
     699    if (rounded == 0) {
     700        vector.append('0');
     701        return;
     702    }
     703
     704    char buf[24];
     705    int length = snprintf(buf, sizeof(buf), "%lld", rounded);
     706    int decimalPoint = length - digitsAfterDecimalPoint;
     707
     708    // We are matching printf("%g")'s behavior and must trim trailing zeros,
     709    // regardless of whether they're significant.
     710    while (length > 0 && length > decimalPoint && buf[length - 1] == '0')
     711        length--;
     712
     713    // Reserve an estimate of space for the number of digits we anticipate
     714    // along with a minus sign/initial zero/decimal point.
     715    vector.reserveCapacity(vector.size() + 3 + length);
     716
     717    if (value < 0)
     718        vector.append('-');
     719
     720    if (decimalPoint <= 0) {
     721        // Only digits after the decimal point.
     722        vector.append('0');
     723        vector.append('.');
     724        for (int i = decimalPoint; i < 0; i++)
     725            vector.append('0');
     726        for (int i = 0; i < length; i++)
     727            vector.append(buf[i]);
     728    } else if (length <= decimalPoint) {
     729        // Only digits before the decimal point.
     730        for (int i = 0; i < length; i++)
     731            vector.append(buf[i]);
     732    } else {
     733        // Digits before and after the decimal point.
     734        for (int i = 0; i < decimalPoint; i++)
     735            vector.append(buf[i]);
     736        vector.append('.');
     737        for (int i = decimalPoint; i < length; i++)
     738            vector.append(buf[i]);
     739    }
     740}
     741
     742static String formatWithUnits(double value, const char* units)
     743{
     744    Vector<UChar> result;
     745    appendCSSDouble(result, value);
     746    result.reserveCapacity(result.size() + strlen(units));
     747    for (int i = 0; units[i]; i++)
     748        result.append(units[i]);
     749    return String::adopt(result);
     750}
     751
    687752String CSSPrimitiveValue::cssText() const
    688753{
     
    696761        case CSS_NUMBER:
    697762        case CSS_PARSER_INTEGER:
    698             text = String::number(m_value.num);
     763            text = formatWithUnits(m_value.num, "");
    699764            break;
    700765        case CSS_PERCENTAGE:
    701             text = String::format("%.6lg%%", m_value.num);
     766            text = formatWithUnits(m_value.num, "%");
    702767            break;
    703768        case CSS_EMS:
    704             text = String::format("%.6lgem", m_value.num);
     769            text = formatWithUnits(m_value.num, "em");
    705770            break;
    706771        case CSS_EXS:
    707             text = String::format("%.6lgex", m_value.num);
     772            text = formatWithUnits(m_value.num, "ex");
    708773            break;
    709774        case CSS_REMS:
    710             text = String::format("%.6lgrem", m_value.num);
     775            text = formatWithUnits(m_value.num, "rem");
    711776            break;
    712777        case CSS_PX:
    713             text = String::format("%.6lgpx", m_value.num);
     778            text = formatWithUnits(m_value.num, "px");
    714779            break;
    715780        case CSS_CM:
    716             text = String::format("%.6lgcm", m_value.num);
     781            text = formatWithUnits(m_value.num, "cm");
    717782            break;
    718783        case CSS_MM:
    719             text = String::format("%.6lgmm", m_value.num);
     784            text = formatWithUnits(m_value.num, "mm");
    720785            break;
    721786        case CSS_IN:
    722             text = String::format("%.6lgin", m_value.num);
     787            text = formatWithUnits(m_value.num, "in");
    723788            break;
    724789        case CSS_PT:
    725             text = String::format("%.6lgpt", m_value.num);
     790            text = formatWithUnits(m_value.num, "pt");
    726791            break;
    727792        case CSS_PC:
    728             text = String::format("%.6lgpc", m_value.num);
     793            text = formatWithUnits(m_value.num, "pc");
    729794            break;
    730795        case CSS_DEG:
    731             text = String::format("%.6lgdeg", m_value.num);
     796            text = formatWithUnits(m_value.num, "deg");
    732797            break;
    733798        case CSS_RAD:
    734             text = String::format("%.6lgrad", m_value.num);
     799            text = formatWithUnits(m_value.num, "rad");
    735800            break;
    736801        case CSS_GRAD:
    737             text = String::format("%.6lggrad", m_value.num);
     802            text = formatWithUnits(m_value.num, "grad");
    738803            break;
    739804        case CSS_MS:
    740             text = String::format("%.6lgms", m_value.num);
     805            text = formatWithUnits(m_value.num, "ms");
    741806            break;
    742807        case CSS_S:
    743             text = String::format("%.6lgs", m_value.num);
     808            text = formatWithUnits(m_value.num, "s");
    744809            break;
    745810        case CSS_HZ:
    746             text = String::format("%.6lghz", m_value.num);
     811            text = formatWithUnits(m_value.num, "hz");
    747812            break;
    748813        case CSS_KHZ:
    749             text = String::format("%.6lgkhz", m_value.num);
     814            text = formatWithUnits(m_value.num, "khz");
    750815            break;
    751816        case CSS_TURN:
    752             text = String::format("%.6lgturn", m_value.num);
     817            text = formatWithUnits(m_value.num, "turn");
    753818            break;
    754819        case CSS_DIMENSION:
Note: See TracChangeset for help on using the changeset viewer.