Changeset 200501 in webkit


Ignore:
Timestamp:
May 5, 2016 6:26:26 PM (8 years ago)
Author:
dino@apple.com
Message:

4 and 8 digit color attributes should use the crazypants algorithm, not the CSS one.
https://bugs.webkit.org/show_bug.cgi?id=157402
<rdar://problem/26131142>

Reviewed by Simon Fraser.

Source/WebCore:

Noel and Tab from Google alerted me to the fact I broke some legacy
HTML color attributes when I added support for 4 and 8 digit hex colors
in CSS. The fix is to favor the "crazy" parsing unless we know it is a 3 or 6
digit hex value (in which case we try the CSS algorithm first).

Covered by reverting an existing test.

  • html/HTMLElement.cpp:

(WebCore::HTMLElement::addHTMLColorToStyle):

LayoutTests:

Restore the version that was there before I added support for
4 and 8 digit hex colors in CSS.

  • fast/dom/attribute-legacy-colors-expected.txt:
  • fast/dom/script-tests/attribute-legacy-colors.js:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r200499 r200501  
     12016-05-05  Dean Jackson  <dino@apple.com>
     2
     3        4 and 8 digit color attributes should use the crazypants algorithm, not the CSS one.
     4        https://bugs.webkit.org/show_bug.cgi?id=157402
     5        <rdar://problem/26131142>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Restore the version that was there before I added support for
     10        4 and 8 digit hex colors in CSS.
     11
     12        * fast/dom/attribute-legacy-colors-expected.txt:
     13        * fast/dom/script-tests/attribute-legacy-colors.js:
     14
    1152016-05-05  Joseph Pecoraro  <pecoraro@apple.com>
    216
  • trunk/LayoutTests/fast/dom/attribute-legacy-colors-expected.txt

    r192023 r200501  
    1717PASS document.body.bgColor='f00';getComputedStyle(document.body).backgroundColor; is 'rgb(15, 0, 0)'
    1818PASS document.body.bgColor='ff0000';getComputedStyle(document.body).backgroundColor; is 'rgb(255, 0, 0)'
     19PASS document.body.bgColor='#00000000';getComputedStyle(document.body).backgroundColor; is 'rgb(0, 0, 0)'
    1920PASS document.body.bgColor='foo';getComputedStyle(document.body).backgroundColor; is 'rgb(15, 0, 0)'
    2021PASS document.body.bgColor='cheese';getComputedStyle(document.body).backgroundColor; is 'rgb(192, 238, 14)'
     
    3536PASS document.body.bgColor='#55';getComputedStyle(document.body).backgroundColor; is 'rgb(5, 5, 0)'
    3637PASS document.body.bgColor='#555';getComputedStyle(document.body).backgroundColor; is 'rgb(85, 85, 85)'
     38PASS document.body.bgColor='#5555';getComputedStyle(document.body).backgroundColor; is 'rgb(85, 85, 0)'
    3739PASS document.body.bgColor='#55555';getComputedStyle(document.body).backgroundColor; is 'rgb(85, 85, 80)'
    3840PASS document.body.bgColor='#555555';getComputedStyle(document.body).backgroundColor; is 'rgb(85, 85, 85)'
    3941PASS document.body.bgColor='#5555555';getComputedStyle(document.body).backgroundColor; is 'rgb(85, 85, 80)'
     42PASS document.body.bgColor='#55555555';getComputedStyle(document.body).backgroundColor; is 'rgb(85, 85, 85)'
    4043PASS document.body.bgColor='5';getComputedStyle(document.body).backgroundColor; is 'rgb(5, 0, 0)'
    4144PASS document.body.bgColor='55';getComputedStyle(document.body).backgroundColor; is 'rgb(5, 5, 0)'
  • trunk/LayoutTests/fast/dom/script-tests/attribute-legacy-colors.js

    r192023 r200501  
    1616        {'test':'f00', 'expected':[15, 0, 0]},
    1717        {'test':'ff0000', 'expected':[255, 0, 0]},
     18        {'test':'#00000000', 'expected':[0, 0, 0]},
    1819        {'test':'foo', 'expected':[15, 0, 0]},
    1920        {'test':'cheese', 'expected':[192, 238, 14]},
     
    3435        {'test':'#55', 'expected':[5, 5, 0]},
    3536        {'test':'#555', 'expected':[85, 85, 85]},
     37        {'test':'#5555', 'expected':[85, 85, 0]},
    3638        {'test':'#55555', 'expected':[85, 85, 80]},
    3739        {'test':'#555555', 'expected':[85, 85, 85]},
    3840        {'test':'#5555555', 'expected':[85, 85, 80]},
     41        {'test':'#55555555', 'expected':[85, 85, 85]},
    3942        {'test':'5', 'expected':[5, 0, 0]},
    4043        {'test':'55', 'expected':[5, 5, 0]},
  • trunk/Source/WebCore/ChangeLog

    r200495 r200501  
     12016-05-05  Dean Jackson  <dino@apple.com>
     2
     3        4 and 8 digit color attributes should use the crazypants algorithm, not the CSS one.
     4        https://bugs.webkit.org/show_bug.cgi?id=157402
     5        <rdar://problem/26131142>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Noel and Tab from Google alerted me to the fact I broke some legacy
     10        HTML color attributes when I added support for 4 and 8 digit hex colors
     11        in CSS. The fix is to favor the "crazy" parsing unless we know it is a 3 or 6
     12        digit hex value (in which case we try the CSS algorithm first).
     13
     14        Covered by reverting an existing test.
     15
     16        * html/HTMLElement.cpp:
     17        (WebCore::HTMLElement::addHTMLColorToStyle):
     18
    1192016-05-05  Brady Eidson  <beidson@apple.com>
    220
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r200041 r200501  
    11401140
    11411141    // If the string is a named CSS color or a 3/6-digit hex color, use that.
    1142     Color parsedColor(colorString);
    1143     if (!parsedColor.isValid())
    1144         parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
    1145 
    1146     style.setProperty(propertyID, CSSValuePool::singleton().createColorValue(parsedColor.rgb()));
     1142    // We can't use the default Color constructor because it accepts
     1143    // 4/8-digit hex, which conflict with some legacy HTML content using attributes.
     1144
     1145    Color color;
     1146
     1147    if ((colorString.length() == 4 || colorString.length() == 7) && colorString[0] == '#')
     1148        color = Color(colorString);
     1149    if (!color.isValid())
     1150        color.setNamedColor(colorString);
     1151    if (!color.isValid())
     1152        color.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
     1153
     1154    style.setProperty(propertyID, CSSValuePool::singleton().createColorValue(color.rgb()));
    11471155}
    11481156
Note: See TracChangeset for help on using the changeset viewer.