Changeset 55308 in webkit


Ignore:
Timestamp:
Feb 26, 2010 1:43:44 PM (14 years ago)
Author:
senorblanco@chromium.org
Message:

2010-02-24 Stephen White <senorblanco@chromium.org>

Reviewed by Darin Adler.

This CL implements a simple ad-hoc parser for CSS rgb() values.
If it fails, it returns false and the normal lex/yacc parser will
be invoked.


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

Covered by fast/canvas/canvas-bg.html, fast/canvas/canvas-bg-zoom.html,
and many more.

  • css/CSSParser.cpp: (WebCore::parseInt): (WebCore::CSSParser::parseColor):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r55306 r55308  
     12010-02-24  Stephen White  <senorblanco@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        This CL implements a simple ad-hoc parser for CSS rgb() values.
     6        If it fails, it returns false and the normal lex/yacc parser will
     7        be invoked.
     8       
     9        https://bugs.webkit.org/show_bug.cgi?id=35362
     10
     11        Covered by fast/canvas/canvas-bg.html, fast/canvas/canvas-bg-zoom.html,
     12        and many more.
     13
     14        * css/CSSParser.cpp:
     15        (WebCore::parseInt):
     16        (WebCore::CSSParser::parseColor):
     17
    1182010-02-26  Jarkko Sakkinen  <jarkko.sakkinen@tieto.com>
    219
  • trunk/WebCore/css/CSSParser.cpp

    r55066 r55308  
    34923492}
    34933493
     3494static inline bool isCSSWhitespace(UChar c)
     3495{
     3496    return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f';
     3497}
     3498
     3499static inline bool parseInt(const UChar*& string, const UChar* end, UChar terminator, int& value)
     3500{
     3501    const UChar* current = string;
     3502    int localValue = 0;
     3503    while (current != end && isCSSWhitespace(*current))
     3504        current++;
     3505    if (current == end || !isASCIIDigit(*current))
     3506        return false;
     3507    while (current != end && isASCIIDigit(*current))
     3508        localValue = localValue * 10 + *current++ - '0';
     3509    while (current != end && isCSSWhitespace(*current))
     3510        current++;
     3511    if (current == end || *current++ != terminator)
     3512        return false;
     3513    value = localValue;
     3514    string = current;
     3515    return true;
     3516}
     3517
    34943518bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict)
    34953519{
     
    35043528        return true;
    35053529    }
    3506 
     3530    if (name.startsWith("rgb(")) {
     3531        const UChar* current = name.characters() + 4;
     3532        const UChar* end = name.characters() + name.length();
     3533        int red;
     3534        int green;
     3535        int blue;
     3536        if (!parseInt(current, end, ',', red))
     3537            return false;
     3538        if (!parseInt(current, end, ',', green))
     3539            return false;
     3540        if (!parseInt(current, end, ')', blue))
     3541            return false;
     3542        if (current != end)
     3543            return false;
     3544        rgb = makeRGB(red, green, blue);
     3545        return true;
     3546    }
    35073547    return false;
    35083548}
     
    47034743}
    47044744
    4705 static inline bool isCSSWhitespace(UChar c)
    4706 {
    4707     return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f';
    4708 }
    4709 
    47104745void CSSParser::recheckAtKeyword(const UChar* str, int len)
    47114746{
Note: See TracChangeset for help on using the changeset viewer.