Changeset 207342 in webkit


Ignore:
Timestamp:
Oct 14, 2016 9:17:47 AM (8 years ago)
Author:
Ryan Haddad
Message:

Unreviewed, rolling out r207317.
https://bugs.webkit.org/show_bug.cgi?id=163448

This change caused an existing LayoutTest to fail on all
platforms (Requested by ryanhaddad on #webkit).

Reverted changeset:

"CSS parsing should use Color not RGBA32"
https://bugs.webkit.org/show_bug.cgi?id=163423
http://trac.webkit.org/changeset/207317

Patch by Commit Queue <commit-queue@webkit.org> on 2016-10-14

Location:
trunk/Source/WebCore
Files:
1 deleted
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207339 r207342  
     12016-10-14  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r207317.
     4        https://bugs.webkit.org/show_bug.cgi?id=163448
     5
     6        This change caused an existing LayoutTest to fail on all
     7        platforms (Requested by ryanhaddad on #webkit).
     8
     9        Reverted changeset:
     10
     11        "CSS parsing should use Color not RGBA32"
     12        https://bugs.webkit.org/show_bug.cgi?id=163423
     13        http://trac.webkit.org/changeset/207317
     14
    1152016-10-14  Antti Koivisto  <antti@apple.com>
    216
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r207317 r207342  
    12981298                2EF1BFEB121C9F4200C27627 /* FileStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EF1BFE9121C9F4200C27627 /* FileStream.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12991299                2EF1BFF9121CB0CE00C27627 /* FileStreamClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EF1BFF8121CB0CE00C27627 /* FileStreamClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
    1300                 3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 3103B7DE1DB01556008BB890 /* ColorHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13011300                3106036F14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */; };
    13021301                3106037014327D2E00ABF4BA /* WebKitCSSFilterValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    82638262                2EF1BFE9121C9F4200C27627 /* FileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStream.h; sourceTree = "<group>"; };
    82648263                2EF1BFF8121CB0CE00C27627 /* FileStreamClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStreamClient.h; sourceTree = "<group>"; };
    8265                 3103B7DE1DB01556008BB890 /* ColorHash.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorHash.h; sourceTree = "<group>"; };
    82668264                3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSFilterValue.cpp; sourceTree = "<group>"; };
    82678265                3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSFilterValue.h; sourceTree = "<group>"; };
     
    2073720735                                B27535380B053814002CE64F /* Color.cpp */,
    2073820736                                B27535390B053814002CE64F /* Color.h */,
    20739                                 3103B7DE1DB01556008BB890 /* ColorHash.h */,
    2074020737                                31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */,
    2074120738                                31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */,
     
    2539025387                                FDA15ECE12B03F61003A583A /* JSScriptProcessorNode.h in Headers */,
    2539125388                                CED06AD11C77754800FDFAF1 /* JSSecurityPolicyViolationEvent.h in Headers */,
    25392                                 3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */,
    2539325389                                9BDA64D81B975CF2009C4387 /* JSShadowRoot.h in Headers */,
    2539425390                                CD9DE17B17AAC75B00EA386D /* JSSourceBuffer.h in Headers */,
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r207317 r207342  
    351351}
    352352
    353 CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)
     353CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
    354354    : CSSValue(PrimitiveClass)
    355355{
    356356    m_primitiveUnitType = CSS_RGBCOLOR;
    357     m_value.color = new Color(color);
     357    m_value.rgbcolor = color;
    358358}
    359359
     
    575575        m_value.fontFamily = nullptr;
    576576        break;
    577     case CSS_RGBCOLOR:
    578         ASSERT(m_value.color);
    579         delete m_value.color;
    580         m_value.color = nullptr;
    581         break;
    582577    case CSS_NUMBER:
    583578    case CSS_PARSER_INTEGER:
     
    611606    case CSS_FR:
    612607    case CSS_IDENT:
     608    case CSS_RGBCOLOR:
    613609    case CSS_UNKNOWN:
    614610    case CSS_UNICODE_RANGE:
     
    10331029
    10341030    // FIMXE: This should not return a new object for each invocation.
    1035     return RGBColor::create(m_value.color->rgb());
     1031    return RGBColor::create(m_value.rgbcolor);
    10361032}
    10371033
     
    11801176        return getLengthRepeatValue()->cssText();
    11811177#endif
     1178    case CSS_RGBCOLOR:
    11821179    case CSS_PARSER_HEXCOLOR: {
    1183         RGBA32 rgb;
    1184         Color::parseHexColor((String)m_value.string, rgb);
    1185         return Color(rgb).cssText();
    1186     }
    1187     case CSS_RGBCOLOR:
    1188         return color().cssText();
     1180        RGBA32 rgbColor = m_value.rgbcolor;
     1181        if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR)
     1182            Color::parseHexColor((String)m_value.string, rgbColor);
     1183        return Color(rgbColor).cssText();
     1184    }
    11891185    case CSS_PAIR:
    11901186        return getPairValue()->cssText();
     
    13561352        break;
    13571353    case CSS_RGBCOLOR:
    1358         result = CSSPrimitiveValue::create(*m_value.color);
     1354        result = CSSPrimitiveValue::createColor(m_value.rgbcolor);
    13591355        break;
    13601356    case CSS_DIMENSION:
     
    14351431#endif
    14361432    case CSS_RGBCOLOR:
    1437         return color() == other.color();
     1433        return m_value.rgbcolor == other.m_value.rgbcolor;
    14381434    case CSS_PAIR:
    14391435        return m_value.pair && other.m_value.pair && m_value.pair->equals(*other.m_value.pair);
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r207317 r207342  
    254254    static Ref<CSSPrimitiveValue> createParserOperator(int parserOperator) { return adoptRef(*new CSSPrimitiveValue(parserOperator)); }
    255255
     256    static Ref<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(*new CSSPrimitiveValue(rgbValue)); }
    256257    static Ref<CSSPrimitiveValue> create(double value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
    257258    static Ref<CSSPrimitiveValue> create(const String& value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
     
    342343
    343344    WEBCORE_EXPORT Counter* getCounterValue(ExceptionCode&) const;
    344     Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? nullptr : m_value.counter; }
     345    Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; }
    345346
    346347    WEBCORE_EXPORT Rect* getRectValue(ExceptionCode&) const;
    347     Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? nullptr : m_value.rect; }
     348    Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; }
    348349
    349350    Quad* getQuadValue(ExceptionCode&) const;
    350     Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? nullptr : m_value.quad; }
     351    Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; }
    351352
    352353#if ENABLE(CSS_SCROLL_SNAP)
    353354    LengthRepeat* getLengthRepeatValue(ExceptionCode&) const;
    354     LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? nullptr : m_value.lengthRepeat; }
     355    LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? 0 : m_value.lengthRepeat; }
    355356#endif
    356357
    357358    WEBCORE_EXPORT RefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const;
    358     const Color& color() const { ASSERT(m_primitiveUnitType == CSS_RGBCOLOR); return *m_value.color; }
     359    RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
    359360
    360361    Pair* getPairValue(ExceptionCode&) const;
     
    404405    // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases.
    405406    CSSPrimitiveValue(int parserOperator);
    406     CSSPrimitiveValue(const Color&);
     407    CSSPrimitiveValue(unsigned color); // RGB value
    407408    CSSPrimitiveValue(const Length&);
    408409    CSSPrimitiveValue(const Length&, const RenderStyle&);
     
    464465        LengthRepeat* lengthRepeat;
    465466#endif
    466         const Color* color;
     467        unsigned rgbcolor;
    467468        Pair* pair;
    468469        DashboardRegion* region;
  • trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h

    r207317 r207342  
    49404940}
    49414941
    4942 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)
    4943     : CSSValue(PrimitiveClass)
    4944 {
    4945     m_primitiveUnitType = CSS_RGBCOLOR;
    4946     m_value.color = new Color(color);
    4947 }
    4948 
    49494942template<> inline CSSPrimitiveValue::CSSPrimitiveValue(CSSFontFamily fontFamily)
    49504943    : CSSValue(PrimitiveClass)
  • trunk/Source/WebCore/css/CSSValuePool.cpp

    r207317 r207342  
    4949    m_revertValue.construct();
    5050
    51     m_transparentColor.construct(Color(Color::transparent));
    52     m_whiteColor.construct(Color(Color::white));
    53     m_blackColor.construct(Color(Color::black));
     51    m_transparentColor.construct(Color::transparent);
     52    m_whiteColor.construct(Color::white);
     53    m_blackColor.construct(Color::black);
    5454
    5555    for (unsigned i = 0; i < numCSSValueKeywords; ++i)
     
    7474}
    7575
    76 Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(const Color& color)
     76Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
    7777{
    7878    // These are the empty and deleted values of the hash table.
    79     if (color == Color::transparent)
     79    if (rgbValue == Color::transparent)
    8080        return m_transparentColor.get();
    81     if (color == Color::white)
     81    if (rgbValue == Color::white)
    8282        return m_whiteColor.get();
    8383    // Just because it is common.
    84     if (color == Color::black)
     84    if (rgbValue == Color::black)
    8585        return m_blackColor.get();
    8686
     
    9090        m_colorValueCache.remove(m_colorValueCache.begin());
    9191
    92     ColorValueCache::AddResult entry = m_colorValueCache.add(color, nullptr);
     92    ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, nullptr);
    9393    if (entry.isNewEntry)
    94         entry.iterator->value = CSSPrimitiveValue::create(color);
     94        entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue);
    9595    return *entry.iterator->value;
    9696}
  • trunk/Source/WebCore/css/CSSValuePool.h

    r207317 r207342  
    3535#include "CSSUnsetValue.h"
    3636#include "CSSValueKeywords.h"
    37 #include "ColorHash.h"
    3837#include <utility>
    3938#include <wtf/HashMap.h>
     
    6261    Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
    6362    Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
    64     Ref<CSSPrimitiveValue> createColorValue(const Color&);
     63    Ref<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
    6564    Ref<CSSPrimitiveValue> createValue(double value, CSSPrimitiveValue::UnitTypes);
    6665    Ref<CSSPrimitiveValue> createValue(const String& value, CSSPrimitiveValue::UnitTypes type) { return CSSPrimitiveValue::create(value, type); }
     
    7473    CSSValuePool();
    7574
    76     typedef HashMap<Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;
     75    typedef HashMap<unsigned, RefPtr<CSSPrimitiveValue>> ColorValueCache;
    7776    ColorValueCache m_colorValueCache;
    7877
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r207317 r207342  
    18321832{
    18331833    if (value.isRGBColor())
    1834         return value.color();
     1834        return Color(value.getRGBA32Value());
    18351835
    18361836    const State& state = m_state;
  • trunk/Source/WebCore/css/parser/CSSParser.cpp

    r207317 r207342  
    495495        return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
    496496    }
    497     Color color = CSSParser::fastParseColor(string, strict && string[0] != '#');
    498     if (!color.isValid())
     497    RGBA32 color;
     498    if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
    499499        return CSSParser::ParseResult::Error;
    500500
     
    13711371}
    13721372
    1373 Color CSSParser::parseColor(const String& string, bool strict)
     1373// The color will only be changed when string contains a valid CSS color, so callers
     1374// can set it to a default color and ignore the boolean result.
     1375bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
    13741376{
    13751377    if (string.isEmpty())
    1376         return Color();
     1378        return false;
    13771379
    13781380    // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
    1379     Color color = fastParseColor(string, strict);
    1380     if (color.isValid())
    1381         return color;
     1381    if (fastParseColor(color, string, strict))
     1382        return true;
    13821383
    13831384    CSSParser parser(HTMLStandardMode);
    13841385
    13851386    // In case the fast-path parser didn't understand the color, try the full parser.
    1386     if (!parser.parseColorFromString(string))
    1387         return Color();
     1387    if (!parser.parseColor(string))
     1388        return false;
    13881389
    13891390    CSSValue& value = *parser.m_parsedProperties.first().value();
    13901391    if (!is<CSSPrimitiveValue>(value))
    1391         return Color();
     1392        return false;
    13921393
    13931394    CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
    13941395    if (!primitiveValue.isRGBColor())
    1395         return Color();
    1396 
    1397     return primitiveValue.color();
    1398 }
    1399 
    1400 bool CSSParser::parseColorFromString(const String& string)
     1396        return false;
     1397
     1398    color = primitiveValue.getRGBA32Value();
     1399    return true;
     1400}
     1401
     1402bool CSSParser::parseColor(const String& string)
    14011403{
    14021404    setupParser("@-webkit-decls{color:", string, "} ");
     
    14071409}
    14081410
    1409 Color CSSParser::parseSystemColor(const String& string, Document* document)
     1411bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
    14101412{
    14111413    if (!document || !document->page())
    1412         return Color();
     1414        return false;
    14131415
    14141416    CSSParserString cssColor;
     
    14161418    CSSValueID id = cssValueKeywordID(cssColor);
    14171419    if (!validPrimitiveValueColor(id))
    1418         return Color();
    1419 
    1420     return document->page()->theme().systemColor(id);
     1420        return false;
     1421
     1422    Color parsedColor = document->page()->theme().systemColor(id);
     1423    if (!parsedColor.isValid())
     1424        return false;
     1425
     1426    color = parsedColor.rgb();
     1427    return true;
    14211428}
    14221429
     
    74757482
    74767483template <typename CharacterType>
    7477 static inline Color fastParseColorInternal(const CharacterType* characters, unsigned length , bool strict)
     7484static inline bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length , bool strict)
    74787485{
    74797486    CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::CSS_UNKNOWN;
    7480 
     7487   
    74817488    if (!strict && length >= 3) {
    7482         RGBA32 rgb;
    74837489        if (characters[0] == '#') {
    74847490            if (Color::parseHexColor(characters + 1, length - 1, rgb))
    7485                 return Color(rgb);
     7491                return true;
    74867492        } else {
    74877493            if (Color::parseHexColor(characters, length, rgb))
    7488                 return Color(rgb);
     7494                return true;
    74897495        }
    74907496    }
     
    75007506       
    75017507        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    7502             return Color();
     7508            return false;
    75037509        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    7504             return Color();
     7510            return false;
    75057511        if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
    7506             return Color();
     7512            return false;
    75077513        if (!parseAlphaValue(current, end, ')', alpha))
    7508             return Color();
     7514            return false;
    75097515        if (current != end)
    7510             return Color();
    7511         return Color(makeRGBA(red, green, blue, alpha));
     7516            return false;
     7517        rgb = makeRGBA(red, green, blue, alpha);
     7518        return true;
    75127519    }
    75137520
     
    75207527        int blue;
    75217528        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    7522             return Color();
     7529            return false;
    75237530        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    7524             return Color();
     7531            return false;
    75257532        if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
    7526             return Color();
     7533            return false;
    75277534        if (current != end)
    7528             return Color();
    7529         return Color(makeRGB(red, green, blue));
    7530     }
    7531 
    7532     return Color();
     7535            return false;
     7536        rgb = makeRGB(red, green, blue);
     7537        return true;
     7538    }
     7539
     7540    return false;
    75337541}
    75347542
    75357543template<typename StringType>
    7536 Color CSSParser::fastParseColor(const StringType& name, bool strict)
     7544bool CSSParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict)
    75377545{
    75387546    unsigned length = name.length();
     7547    bool parseResult;
    75397548
    75407549    if (!length)
    7541         return Color();
    7542 
    7543     Color color;
     7550        return false;
     7551
    75447552    if (name.is8Bit())
    7545         color = fastParseColorInternal(name.characters8(), length, strict);
     7553        parseResult = fastParseColorInternal(rgb, name.characters8(), length, strict);
    75467554    else
    7547         color = fastParseColorInternal(name.characters16(), length, strict);
    7548 
    7549     if (color.isValid())
    7550         return color;
     7555        parseResult = fastParseColorInternal(rgb, name.characters16(), length, strict);
     7556
     7557    if (parseResult)
     7558        return true;
    75517559
    75527560    // Try named colors.
    7553     color.setNamedColor(name);
    7554     return color;
     7561    Color tc;
     7562    tc.setNamedColor(name);
     7563    if (tc.isValid()) {
     7564        rgb = tc.rgb();
     7565        return true;
     7566    }
     7567    return false;
    75557568}
    75567569   
     
    76687681RefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value)
    76697682{
    7670     Color color = parseColorFromValue(value ? *value : *m_valueList->current());
    7671     if (!color.isValid())
     7683    RGBA32 c = Color::transparent;
     7684    if (!parseColorFromValue(value ? *value : *m_valueList->current(), c))
    76727685        return nullptr;
    7673     return CSSValuePool::singleton().createColorValue(color);
    7674 }
    7675 
    7676 Color CSSParser::parseColorFromValue(CSSParserValue& value)
     7686    return CSSValuePool::singleton().createColorValue(c);
     7687}
     7688
     7689bool CSSParser::parseColorFromValue(CSSParserValue& value, RGBA32& c)
    76777690{
    76787691    if (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_NUMBER
     
    76807693        String str = String::format("%06d", static_cast<int>((value.fValue+.5)));
    76817694        // FIXME: This should be strict parsing for SVG as well.
    7682         return fastParseColor(str, inStrictMode());
     7695        if (!fastParseColor(c, str, inStrictMode()))
     7696            return false;
    76837697    } else if (value.unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR
    76847698        || value.unit == CSSPrimitiveValue::CSS_IDENT
    76857699        || (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_DIMENSION)) {
    7686         return fastParseColor(value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT);
     7700        if (!fastParseColor(c, value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT))
     7701            return false;
    76877702    } else if (value.unit == CSSParserValue::Function
    76887703        && value.function->args
     
    76917706        int colorValues[3];
    76927707        if (!parseRGBParameters(value, colorValues, false))
    7693             return Color();
    7694         return Color(makeRGB(colorValues[0], colorValues[1], colorValues[2]));
     7708            return false;
     7709        c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
    76957710    } else if (value.unit == CSSParserValue::Function
    76967711        && value.function->args
     
    76997714        int colorValues[4];
    77007715        if (!parseRGBParameters(value, colorValues, true))
    7701             return Color();
    7702         return Color(makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
     7716            return false;
     7717        c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
    77037718    } else if (value.unit == CSSParserValue::Function
    77047719        && value.function->args
     
    77077722        double colorValues[3];
    77087723        if (!parseHSLParameters(value, colorValues, false))
    7709             return Color();
    7710         return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0));
     7724            return false;
     7725        c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0);
    77117726    } else if (value.unit == CSSParserValue::Function
    77127727        && value.function->args
     
    77157730        double colorValues[4];
    77167731        if (!parseHSLParameters(value, colorValues, true))
    7717             return Color();
    7718         return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
    7719     }
    7720 
    7721     return Color();
     7732            return false;
     7733        c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
     7734    } else
     7735        return false;
     7736
     7737    return true;
    77227738}
    77237739
  • trunk/Source/WebCore/css/parser/CSSParser.h

    r207317 r207342  
    135135    static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet);
    136136
    137     static Color parseColor(const String&, bool strict = false);
     137    static bool parseColor(RGBA32& color, const String&, bool strict = false);
    138138    static bool isValidSystemColorValue(CSSValueID);
    139     static Color parseSystemColor(const String&, Document*);
     139    static bool parseSystemColor(RGBA32& color, const String&, Document*);
    140140    static RefPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
    141141    RefPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, ValueWithCalculation&);
     
    279279    bool parseHSLParameters(CSSParserValue&, double* colorValues, bool parseAlpha);
    280280    RefPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = nullptr);
    281     Color parseColorFromValue(CSSParserValue&);
     281    bool parseColorFromValue(CSSParserValue&, RGBA32&);
    282282    void parseSelector(const String&, CSSSelectorList&);
    283283
    284284    template<typename StringType>
    285     static Color fastParseColor(const StringType&, bool strict);
     285    static bool fastParseColor(RGBA32&, const StringType&, bool strict);
    286286
    287287    bool parseLineHeight(bool important);
     
    619619    bool parseFontFaceSrcLocal(CSSValueList&);
    620620
    621     bool parseColorFromString(const String&);
     621    bool parseColor(const String&);
    622622
    623623#if ENABLE(CSS_GRID_LAYOUT)
  • trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp

    r207317 r207342  
    412412
    413413template <typename CharacterType>
    414 static Color fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)
     414static bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length, bool quirksMode)
    415415{
    416416    CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::UnitTypes::CSS_UNKNOWN;
    417417
    418     if (length >= 4 && characters[0] == '#') {
    419         // FIXME: Why doesn't this check if the parse worked? Is the fallback black?
    420         RGBA32 rgb;
    421         Color::parseHexColor(characters + 1, length - 1, rgb);
    422         return Color(rgb);
    423     }
     418    if (length >= 4 && characters[0] == '#')
     419        return Color::parseHexColor(characters + 1, length - 1, rgb);
    424420
    425421    if (quirksMode && (length == 3 || length == 6)) {
    426         RGBA32 rgb;
    427422        if (Color::parseHexColor(characters, length, rgb))
    428             return Color(rgb);
     423            return true;
    429424    }
    430425
     
    439434
    440435        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    441             return Color();
     436            return false;
    442437        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    443             return Color();
     438            return false;
    444439        if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
    445             return Color();
     440            return false;
    446441        if (!parseAlphaValue(current, end, ')', alpha))
    447             return Color();
     442            return false;
    448443        if (current != end)
    449             return Color();
    450         return Color(makeRGBA(red, green, blue, alpha));
     444            return false;
     445        rgb = makeRGBA(red, green, blue, alpha);
     446        return true;
    451447    }
    452448
     
    459455        int blue;
    460456        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    461             return Color();
     457            return false;
    462458        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    463             return Color();
     459            return false;
    464460        if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
    465             return Color();
     461            return false;
    466462        if (current != end)
    467             return Color();
    468         return Color(makeRGB(red, green, blue));
    469     }
    470 
    471     return Color();
     463            return false;
     464        rgb = makeRGB(red, green, blue);
     465        return true;
     466    }
     467
     468    return false;
    472469}
    473470
     
    482479    }
    483480
     481    RGBA32 color;
    484482    bool quirksMode = isQuirksModeBehavior(parserMode);
    485483
    486484    // Fast path for hex colors and rgb()/rgba() colors
    487     Color color;
     485    bool parseResult;
    488486    if (string.is8Bit())
    489         color = fastParseColorInternal(string.characters8(), string.length(), quirksMode);
     487        parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode);
    490488    else
    491         color = fastParseColorInternal(string.characters16(), string.length(), quirksMode);
    492     if (!color.isValid())
     489        parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode);
     490    if (!parseResult)
    493491        return nullptr;
    494492    return CSSValuePool::singleton().createColorValue(color);
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r207317 r207342  
    510510    if (!parseHexColor(range, color, acceptQuirkyColors) && !parseColorFunction(range, color))
    511511        return nullptr;
    512     return CSSPrimitiveValue::create(Color(color));
     512    return CSSPrimitiveValue::createColor(color);
    513513}
    514514
  • trunk/Source/WebCore/css/parser/SVGCSSParser.cpp

    r207317 r207342  
    132132                parsedValue = SVGPaint::createColor(RenderTheme::defaultTheme()->systemColor(id));
    133133            else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
     134                RGBA32 c = Color::transparent;
    134135                if (m_valueList->next()) {
    135                     Color color = parseColorFromValue(*m_valueList->current());
    136                     if (color.isValid())
    137                         parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, color);
     136                    if (parseColorFromValue(*m_valueList->current(), c))
     137                        parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, c);
    138138                    else if (m_valueList->current()->id == CSSValueNone)
    139139                        parsedValue = SVGPaint::createURIAndNone(valueWithCalculation.value().string);
     
    287287RefPtr<SVGPaint> CSSParser::parseSVGPaint()
    288288{
    289     Color color = parseColorFromValue(*m_valueList->current());
    290     if (!color.isValid())
     289    RGBA32 c = Color::transparent;
     290    if (!parseColorFromValue(*m_valueList->current(), c))
    291291        return nullptr;
    292     return SVGPaint::createColor(color);
     292    return SVGPaint::createColor(Color(c));
    293293}
    294294
    295295RefPtr<SVGColor> CSSParser::parseSVGColor()
    296296{
    297     Color color = parseColorFromValue(*m_valueList->current());
    298     if (!color.isValid())
     297    RGBA32 c = Color::transparent;
     298    if (!parseColorFromValue(*m_valueList->current(), c))
    299299        return nullptr;
    300     return SVGColor::createFromColor(color);
     300    return SVGColor::createFromColor(Color(c));
    301301}
    302302
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r207317 r207342  
    383383}
    384384
    385 static Color cssValueToColor(CSSValue* colorValue)
     385static RGBA32 cssValueToRGBA(CSSValue* colorValue)
    386386{
    387387    if (!is<CSSPrimitiveValue>(colorValue))
     
    390390    CSSPrimitiveValue& primitiveColor = downcast<CSSPrimitiveValue>(*colorValue);
    391391    if (primitiveColor.isRGBColor())
    392         return primitiveColor.color();
     392        return primitiveColor.getRGBA32Value();
    393393   
    394     return CSSParser::parseColor(colorValue->cssText());
     394    RGBA32 rgba = 0;
     395    CSSParser::parseColor(rgba, colorValue->cssText());
     396    return rgba;
    395397}
    396398
    397399template<typename T>
    398 static inline Color textColorFromStyle(T& style)
    399 {
    400     return cssValueToColor(extractPropertyValue(style, CSSPropertyColor).get());
     400static inline RGBA32 textColorFromStyle(T& style)
     401{
     402    return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get());
    401403}
    402404
    403405template<typename T>
    404 static inline Color backgroundColorFromStyle(T& style)
    405 {
    406     return cssValueToColor(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
    407 }
    408 
    409 static inline Color rgbaBackgroundColorInEffect(Node* node)
    410 {
    411     return cssValueToColor(backgroundColorInEffect(node).get());
     406static inline RGBA32 backgroundColorFromStyle(T& style)
     407{
     408    return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
     409}
     410
     411static inline RGBA32 rgbaBackgroundColorInEffect(Node* node)
     412{
     413    return cssValueToRGBA(backgroundColorInEffect(node).get());
    412414}
    413415
     
    10951097
    10961098    if (hasTransparentBackgroundColor(m_mutableStyle.get())
    1097         || cssValueToColor(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
     1099        || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
    10981100        m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
    10991101
     
    18391841    CSSPrimitiveValue& value = downcast<CSSPrimitiveValue>(*cssValue);
    18401842    if (value.isRGBColor())
    1841         return value.color().hasAlpha();
     1843        return !alphaChannel(value.getRGBA32Value());
    18421844    return value.getValueID() == CSSValueTransparent;
    18431845}
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r207317 r207342  
    990990    if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
    991991        if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
    992             return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
     992            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
    993993    }
    994994
     
    996996    if (RefPtr<CSSValue> value = inlineStylePropertyForElement(element, propertyId)) {
    997997        if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
    998             return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
     998            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
    999999        if (value->isInheritedValue())
    10001000            inherit = true;
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

    r207317 r207342  
    159159                document().resetActiveLinkColor();
    160160        } else {
    161             Color color = CSSParser::parseColor(value, !document().inQuirksMode());
    162             if (color.isValid()) {
     161            RGBA32 color;
     162            if (CSSParser::parseColor(color, value, !document().inQuirksMode())) {
    163163                if (name == linkAttr)
    164164                    document().setLinkColor(color);
  • trunk/Source/WebCore/html/canvas/CanvasGradient.cpp

    r207317 r207342  
    5151}
    5252
    53 void CanvasGradient::addColorStop(float value, const String& colorString, ExceptionCode& ec)
     53void CanvasGradient::addColorStop(float value, const String& color, ExceptionCode& ec)
    5454{
    5555    if (!(value >= 0 && value <= 1.0f)) {
     
    5858    }
    5959
    60     Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);
    61     if (!color.isValid()) {
     60    RGBA32 rgba = 0;
     61    if (!parseColorOrCurrentColor(rgba, color, 0 /*canvas*/)) {
    6262#if ENABLE(DASHBOARD_SUPPORT)
    6363        if (!m_dashboardCompatibilityMode)
     
    6969    }
    7070
    71     m_gradient->addColorStop(value, color);
     71    m_gradient->addColorStop(value, Color(rgba));
    7272}
    7373
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r207317 r207342  
    405405
    406406    if (style.isCurrentColor()) {
    407         if (style.hasOverrideAlpha()) {
    408             // FIXME: Should not use RGBA32 here.
    409             style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
    410         } else
     407        if (style.hasOverrideAlpha())
     408            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
     409        else
    411410            style = CanvasStyle(currentColor(canvas()));
    412411    } else
     
    432431
    433432    if (style.isCurrentColor()) {
    434         if (style.hasOverrideAlpha()) {
    435             // FIXME: Should not use RGBA32 here.
    436             style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
    437         } else
     433        if (style.hasOverrideAlpha())
     434            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
     435        else
    438436            style = CanvasStyle(currentColor(canvas()));
    439437    } else
     
    581579}
    582580
    583 void CanvasRenderingContext2D::setShadowColor(const String& colorString)
    584 {
    585     Color color = parseColorOrCurrentColor(colorString, canvas());
    586     if (!color.isValid())
    587         return;
    588     if (state().shadowColor == color)
    589         return;
    590     realizeSaves();
    591     modifiableState().shadowColor = color;
     581void CanvasRenderingContext2D::setShadowColor(const String& color)
     582{
     583    RGBA32 rgba;
     584    if (!parseColorOrCurrentColor(rgba, color, canvas()))
     585        return;
     586    if (state().shadowColor == rgba)
     587        return;
     588    realizeSaves();
     589    modifiableState().shadowColor = rgba;
    592590    applyShadow();
    593591}
     
    12511249}
    12521250
    1253 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& colorString, Optional<float> alpha)
    1254 {
    1255     Color color = parseColorOrCurrentColor(colorString, canvas());
    1256     if (!colorString.isNull() && !color.isValid())
    1257         return;
    1258     if (!color.isValid())
    1259         color = Color::transparent;
    1260     // FIXME: Should not use RGBA32 here.
    1261     setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(color.rgb(), alpha));
     1251void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, Optional<float> alpha)
     1252{
     1253    RGBA32 rgba = Color::transparent;
     1254    if (!color.isNull() && !parseColorOrCurrentColor(rgba, color, canvas()))
     1255        return;
     1256    setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(rgba, alpha));
    12621257}
    12631258
  • trunk/Source/WebCore/html/canvas/CanvasStyle.cpp

    r207317 r207342  
    4444namespace WebCore {
    4545
    46 static bool isCurrentColorString(const String& colorString)
    47 {
    48     return equalLettersIgnoringASCIICase(colorString, "currentcolor");
    49 }
    50 
    51 static Color parseColor(const String& colorString, Document* document = nullptr)
    52 {
    53     Color color = CSSParser::parseColor(colorString);
    54     if (color.isValid())
    55         return color;
    56 
    57     return CSSParser::parseSystemColor(colorString, document);
    58 }
    59 
    60 Color currentColor(HTMLCanvasElement* canvas)
     46enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, ParseFailed };
     47
     48static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorString, Document* document = nullptr)
     49{
     50    if (equalLettersIgnoringASCIICase(colorString, "currentcolor"))
     51        return ParsedCurrentColor;
     52    if (CSSParser::parseColor(parsedColor, colorString))
     53        return ParsedRGBA;
     54    if (CSSParser::parseSystemColor(parsedColor, colorString, document))
     55        return ParsedSystemColor;
     56    return ParseFailed;
     57}
     58
     59RGBA32 currentColor(HTMLCanvasElement* canvas)
    6160{
    6261    if (!canvas || !canvas->inDocument() || !canvas->inlineStyle())
    6362        return Color::black;
    64     Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
    65     if (!color.isValid())
    66         return Color::black;
    67     return color;
    68 }
    69 
    70 Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* canvas)
    71 {
    72     if (isCurrentColorString(colorString))
    73         return currentColor(canvas);
    74 
    75     return parseColor(colorString, canvas ? &canvas->document() : nullptr);
     63    RGBA32 rgba = Color::black;
     64    CSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
     65    return rgba;
     66}
     67
     68bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement* canvas)
     69{
     70    ColorParseResult parseResult = parseColor(parsedColor, colorString, canvas ? &canvas->document() : 0);
     71    switch (parseResult) {
     72    case ParsedRGBA:
     73    case ParsedSystemColor:
     74        return true;
     75    case ParsedCurrentColor:
     76        parsedColor = currentColor(canvas);
     77        return true;
     78    case ParseFailed:
     79        return false;
     80    default:
     81        ASSERT_NOT_REACHED();
     82        return false;
     83    }
    7684}
    7785
     
    126134}
    127135
    128 CanvasStyle CanvasStyle::createFromString(const String& colorString, Document* document)
    129 {
    130     if (isCurrentColorString(colorString))
     136CanvasStyle CanvasStyle::createFromString(const String& color, Document* document)
     137{
     138    RGBA32 rgba;
     139    ColorParseResult parseResult = parseColor(rgba, color, document);
     140    switch (parseResult) {
     141    case ParsedRGBA:
     142    case ParsedSystemColor:
     143        return CanvasStyle(rgba);
     144    case ParsedCurrentColor:
    131145        return CanvasStyle(ConstructCurrentColor);
    132 
    133     Color color = parseColor(colorString, document);
    134     if (color.isValid())
    135         return CanvasStyle(color);
    136 
    137     return CanvasStyle();
    138 }
    139 
    140 CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& colorString, float alpha)
    141 {
    142     if (isCurrentColorString(colorString))
     146    case ParseFailed:
     147        return CanvasStyle();
     148    default:
     149        ASSERT_NOT_REACHED();
     150        return CanvasStyle();
     151    }
     152}
     153
     154CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& color, float alpha)
     155{
     156    RGBA32 rgba;
     157    ColorParseResult parseResult = parseColor(rgba, color);
     158    switch (parseResult) {
     159    case ParsedRGBA:
     160        return CanvasStyle(colorWithOverrideAlpha(rgba, alpha));
     161    case ParsedCurrentColor:
    143162        return CanvasStyle(CurrentColorWithOverrideAlpha, alpha);
    144 
    145     Color color = parseColor(colorString);
    146     if (color.isValid())
    147         return CanvasStyle(colorWithOverrideAlpha(color.rgb(), alpha));
    148 
    149     return CanvasStyle();
     163    case ParseFailed:
     164        return CanvasStyle();
     165    default:
     166        ASSERT_NOT_REACHED();
     167        return CanvasStyle();
     168    }
    150169}
    151170
  • trunk/Source/WebCore/html/canvas/CanvasStyle.h

    r207317 r207342  
    114114    };
    115115
    116     Color currentColor(HTMLCanvasElement*);
    117     Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement*);
     116    RGBA32 currentColor(HTMLCanvasElement*);
     117    bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement*);
    118118
    119119    inline CanvasStyle::CanvasStyle()
  • trunk/Source/WebCore/platform/graphics/Color.h

    r207317 r207342  
    142142    explicit Color(const char*);
    143143
    144     explicit Color(WTF::HashTableDeletedValueType)
    145     {
    146         m_colorData.rgbaAndFlags = 0xfffffffffffffffd;
    147         ASSERT(!isExtended());
    148     }
    149 
    150     bool isHashTableDeletedValue() const
    151     {
    152         return m_colorData.rgbaAndFlags == 0xfffffffffffffffd;
    153     }
    154 
    155     explicit Color(WTF::HashTableEmptyValueType)
    156     {
    157         m_colorData.rgbaAndFlags = 0xffffffffffffffb;
    158         ASSERT(!isExtended());
    159     }
    160 
    161144    // FIXME: Add constructor for ExtendedColor type.
    162145
     
    202185    void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
    203186    void setRGB(RGBA32);
    204     uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }
    205187
    206188    WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
  • trunk/Source/WebCore/svg/SVGColor.cpp

    r207317 r207342  
    5252    // FIXME: Move this out of the SVGColor class?
    5353    // FIXME: Is it really OK to do stripWhitespace here instead of stripLeadingAndTrailingHTMLSpaces?
    54     return CSSParser::parseColor(colorString.stripWhiteSpace());
     54    RGBA32 color;
     55    if (CSSParser::parseColor(color, colorString.stripWhiteSpace()))
     56        return color;
     57    return Color();
    5558}
    5659
Note: See TracChangeset for help on using the changeset viewer.