Changeset 207317 in webkit


Ignore:
Timestamp:
Oct 13, 2016 6:10:30 PM (8 years ago)
Author:
dino@apple.com
Message:

CSS parsing should use Color not RGBA32
https://bugs.webkit.org/show_bug.cgi?id=163423
<rdar://problem/28766903>

Reviewed by Simon Fraser.

In order to allow CSS to use the ExtendedColor variant of
Color, we need to stop using RGBA32. This is a fairly big
change that goes through all the places in the parser
related to colors, and moves them from RGBA32 to Color.

No change in functionality, so covered by existing tests.

  • WebCore.xcodeproj/project.pbxproj: Add the new ColorHash.h file.
  • css/CSSPrimitiveValue.cpp: CSSPrimitiveValue now can hold a Color*

rather than an unsigned int for colors.
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::cleanup):
(WebCore::CSSPrimitiveValue::getRGBColorValue):
(WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText):
(WebCore::CSSPrimitiveValue::cloneForCSSOM):
(WebCore::CSSPrimitiveValue::equals):

  • css/CSSPrimitiveValue.h: Move to Color* and also use some

nullptrs.

  • css/CSSPrimitiveValueMappings.h:

(WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Add a new inline
constructor.

  • css/CSSValuePool.cpp: Move to Color.

(WebCore::CSSValuePool::CSSValuePool):
(WebCore::CSSValuePool::createColorValue):

  • css/CSSValuePool.h: Change the ColorValueCache to a new type.
  • css/StyleResolver.cpp: Move to Color.

(WebCore::StyleResolver::colorFromPrimitiveValue):

  • css/parser/CSSParser.cpp:

(WebCore::parseColorValue):
(WebCore::CSSParser::parseColor):
(WebCore::CSSParser::parseColorFromString):
(WebCore::CSSParser::parseSystemColor):
(WebCore::fastParseColorInternal):
(WebCore::CSSParser::fastParseColor):
(WebCore::CSSParser::parseColorFromValue):

  • css/parser/CSSParser.h:
  • css/parser/CSSParserFastPaths.cpp:

(WebCore::fastParseColorInternal):
(WebCore::CSSParserFastPaths::parseColor):

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::consumeColor):

  • css/parser/SVGCSSParser.cpp:

(WebCore::CSSParser::parseSVGValue):
(WebCore::CSSParser::parseSVGPaint):
(WebCore::CSSParser::parseSVGColor):

  • editing/EditingStyle.cpp:

(WebCore::cssValueToColor):
(WebCore::textColorFromStyle):
(WebCore::backgroundColorFromStyle):
(WebCore::rgbaBackgroundColorInEffect):
(WebCore::EditingStyle::prepareToApplyAt):
(WebCore::isTransparentColorValue):
(WebCore::cssValueToRGBA): Deleted.

  • editing/cocoa/HTMLConverter.mm:

(HTMLConverterCaches::colorPropertyValueForNode):

  • html/HTMLBodyElement.cpp:

(WebCore::HTMLBodyElement::parseAttribute):

  • html/canvas/CanvasGradient.cpp:

(WebCore::CanvasGradient::addColorStop):

  • html/canvas/CanvasRenderingContext2D.cpp: Ditto, but leave a FIXME to

remind myself to come back when colorWithOverrideAlpha has been updated.
(WebCore::CanvasRenderingContext2D::setStrokeStyle):
(WebCore::CanvasRenderingContext2D::setFillStyle):
(WebCore::CanvasRenderingContext2D::setShadowColor):
(WebCore::CanvasRenderingContext2D::setShadow):

  • html/canvas/CanvasStyle.cpp:

(WebCore::isCurrentColorString):
(WebCore::parseColor):
(WebCore::currentColor):
(WebCore::parseColorOrCurrentColor):
(WebCore::CanvasStyle::createFromString):
(WebCore::CanvasStyle::createFromStringWithOverrideAlpha):

  • html/canvas/CanvasStyle.h:
  • svg/SVGColor.cpp:

(WebCore::SVGColor::colorFromRGBColorString):

  • platform/graphics/Color.h: Add new constructors for the special

empty and deleted Color values used in HashTables.
(WebCore::Color::Color):
(WebCore::Color::isHashTableDeletedValue):
(WebCore::Color::asUint64): New accessor to get the raw uint64_t value.

  • platform/graphics/ColorHash.h: Added. Implement the traits for a Color HashTable.

(WTF::ColorHash::hash):
(WTF::ColorHash::equal):
(WTF::HashTraits<WebCore::Color>::emptyValue):
(WTF::HashTraits<WebCore::Color>::constructDeletedValue):
(WTF::HashTraits<WebCore::Color>::isDeletedValue):

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

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207314 r207317  
     12016-10-13  Dean Jackson  <dino@apple.com>
     2
     3        CSS parsing should use Color not RGBA32
     4        https://bugs.webkit.org/show_bug.cgi?id=163423
     5        <rdar://problem/28766903>
     6
     7        Reviewed by Simon Fraser.
     8
     9        In order to allow CSS to use the ExtendedColor variant of
     10        Color, we need to stop using RGBA32. This is a fairly big
     11        change that goes through all the places in the parser
     12        related to colors, and moves them from RGBA32 to Color.
     13
     14        No change in functionality, so covered by existing tests.
     15
     16        * WebCore.xcodeproj/project.pbxproj: Add the new ColorHash.h file.
     17
     18        * css/CSSPrimitiveValue.cpp: CSSPrimitiveValue now can hold a Color*
     19        rather than an unsigned int for colors.
     20        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
     21        (WebCore::CSSPrimitiveValue::cleanup):
     22        (WebCore::CSSPrimitiveValue::getRGBColorValue):
     23        (WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText):
     24        (WebCore::CSSPrimitiveValue::cloneForCSSOM):
     25        (WebCore::CSSPrimitiveValue::equals):
     26        * css/CSSPrimitiveValue.h: Move to Color* and also use some
     27        nullptrs.
     28        * css/CSSPrimitiveValueMappings.h:
     29        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Add a new inline
     30        constructor.
     31
     32        * css/CSSValuePool.cpp: Move to Color.
     33        (WebCore::CSSValuePool::CSSValuePool):
     34        (WebCore::CSSValuePool::createColorValue):
     35        * css/CSSValuePool.h: Change the ColorValueCache to a new type.
     36
     37        * css/StyleResolver.cpp: Move to Color.
     38        (WebCore::StyleResolver::colorFromPrimitiveValue):
     39        * css/parser/CSSParser.cpp:
     40        (WebCore::parseColorValue):
     41        (WebCore::CSSParser::parseColor):
     42        (WebCore::CSSParser::parseColorFromString):
     43        (WebCore::CSSParser::parseSystemColor):
     44        (WebCore::fastParseColorInternal):
     45        (WebCore::CSSParser::fastParseColor):
     46        (WebCore::CSSParser::parseColorFromValue):
     47        * css/parser/CSSParser.h:
     48        * css/parser/CSSParserFastPaths.cpp:
     49        (WebCore::fastParseColorInternal):
     50        (WebCore::CSSParserFastPaths::parseColor):
     51        * css/parser/CSSPropertyParserHelpers.cpp:
     52        (WebCore::CSSPropertyParserHelpers::consumeColor):
     53        * css/parser/SVGCSSParser.cpp:
     54        (WebCore::CSSParser::parseSVGValue):
     55        (WebCore::CSSParser::parseSVGPaint):
     56        (WebCore::CSSParser::parseSVGColor):
     57        * editing/EditingStyle.cpp:
     58        (WebCore::cssValueToColor):
     59        (WebCore::textColorFromStyle):
     60        (WebCore::backgroundColorFromStyle):
     61        (WebCore::rgbaBackgroundColorInEffect):
     62        (WebCore::EditingStyle::prepareToApplyAt):
     63        (WebCore::isTransparentColorValue):
     64        (WebCore::cssValueToRGBA): Deleted.
     65        * editing/cocoa/HTMLConverter.mm:
     66        (HTMLConverterCaches::colorPropertyValueForNode):
     67        * html/HTMLBodyElement.cpp:
     68        (WebCore::HTMLBodyElement::parseAttribute):
     69        * html/canvas/CanvasGradient.cpp:
     70        (WebCore::CanvasGradient::addColorStop):
     71        * html/canvas/CanvasRenderingContext2D.cpp: Ditto, but leave a FIXME to
     72        remind myself to come back when colorWithOverrideAlpha has been updated.
     73        (WebCore::CanvasRenderingContext2D::setStrokeStyle):
     74        (WebCore::CanvasRenderingContext2D::setFillStyle):
     75        (WebCore::CanvasRenderingContext2D::setShadowColor):
     76        (WebCore::CanvasRenderingContext2D::setShadow):
     77        * html/canvas/CanvasStyle.cpp:
     78        (WebCore::isCurrentColorString):
     79        (WebCore::parseColor):
     80        (WebCore::currentColor):
     81        (WebCore::parseColorOrCurrentColor):
     82        (WebCore::CanvasStyle::createFromString):
     83        (WebCore::CanvasStyle::createFromStringWithOverrideAlpha):
     84        * html/canvas/CanvasStyle.h:
     85        * svg/SVGColor.cpp:
     86        (WebCore::SVGColor::colorFromRGBColorString):
     87
     88        * platform/graphics/Color.h: Add new constructors for the special
     89        empty and deleted Color values used in HashTables.
     90        (WebCore::Color::Color):
     91        (WebCore::Color::isHashTableDeletedValue):
     92        (WebCore::Color::asUint64): New accessor to get the raw uint64_t value.
     93
     94        * platform/graphics/ColorHash.h: Added. Implement the traits for a Color HashTable.
     95        (WTF::ColorHash::hash):
     96        (WTF::ColorHash::equal):
     97        (WTF::HashTraits<WebCore::Color>::emptyValue):
     98        (WTF::HashTraits<WebCore::Color>::constructDeletedValue):
     99        (WTF::HashTraits<WebCore::Color>::isDeletedValue):
     100
    11012016-10-13  Nan Wang  <n_wang@apple.com>
    2102
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r207280 r207317  
    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, ); }; };
    13001301                3106036F14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */; };
    13011302                3106037014327D2E00ABF4BA /* WebKitCSSFilterValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    82628263                2EF1BFE9121C9F4200C27627 /* FileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStream.h; sourceTree = "<group>"; };
    82638264                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>"; };
    82648266                3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSFilterValue.cpp; sourceTree = "<group>"; };
    82658267                3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSFilterValue.h; sourceTree = "<group>"; };
     
    2073520737                                B27535380B053814002CE64F /* Color.cpp */,
    2073620738                                B27535390B053814002CE64F /* Color.h */,
     20739                                3103B7DE1DB01556008BB890 /* ColorHash.h */,
    2073720740                                31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */,
    2073820741                                31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */,
     
    2538725390                                FDA15ECE12B03F61003A583A /* JSScriptProcessorNode.h in Headers */,
    2538825391                                CED06AD11C77754800FDFAF1 /* JSSecurityPolicyViolationEvent.h in Headers */,
     25392                                3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */,
    2538925393                                9BDA64D81B975CF2009C4387 /* JSShadowRoot.h in Headers */,
    2539025394                                CD9DE17B17AAC75B00EA386D /* JSSourceBuffer.h in Headers */,
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r206603 r207317  
    351351}
    352352
    353 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
     353CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)
    354354    : CSSValue(PrimitiveClass)
    355355{
    356356    m_primitiveUnitType = CSS_RGBCOLOR;
    357     m_value.rgbcolor = color;
     357    m_value.color = new Color(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;
    577582    case CSS_NUMBER:
    578583    case CSS_PARSER_INTEGER:
     
    606611    case CSS_FR:
    607612    case CSS_IDENT:
    608     case CSS_RGBCOLOR:
    609613    case CSS_UNKNOWN:
    610614    case CSS_UNICODE_RANGE:
     
    10291033
    10301034    // FIMXE: This should not return a new object for each invocation.
    1031     return RGBColor::create(m_value.rgbcolor);
     1035    return RGBColor::create(m_value.color->rgb());
    10321036}
    10331037
     
    11761180        return getLengthRepeatValue()->cssText();
    11771181#endif
     1182    case CSS_PARSER_HEXCOLOR: {
     1183        RGBA32 rgb;
     1184        Color::parseHexColor((String)m_value.string, rgb);
     1185        return Color(rgb).cssText();
     1186    }
    11781187    case CSS_RGBCOLOR:
    1179     case CSS_PARSER_HEXCOLOR: {
    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     }
     1188        return color().cssText();
    11851189    case CSS_PAIR:
    11861190        return getPairValue()->cssText();
     
    13521356        break;
    13531357    case CSS_RGBCOLOR:
    1354         result = CSSPrimitiveValue::createColor(m_value.rgbcolor);
     1358        result = CSSPrimitiveValue::create(*m_value.color);
    13551359        break;
    13561360    case CSS_DIMENSION:
     
    14311435#endif
    14321436    case CSS_RGBCOLOR:
    1433         return m_value.rgbcolor == other.m_value.rgbcolor;
     1437        return color() == other.color();
    14341438    case CSS_PAIR:
    14351439        return m_value.pair && other.m_value.pair && m_value.pair->equals(*other.m_value.pair);
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r206603 r207317  
    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)); }
    257256    static Ref<CSSPrimitiveValue> create(double value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
    258257    static Ref<CSSPrimitiveValue> create(const String& value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
     
    343342
    344343    WEBCORE_EXPORT Counter* getCounterValue(ExceptionCode&) const;
    345     Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; }
     344    Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? nullptr : m_value.counter; }
    346345
    347346    WEBCORE_EXPORT Rect* getRectValue(ExceptionCode&) const;
    348     Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; }
     347    Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? nullptr : m_value.rect; }
    349348
    350349    Quad* getQuadValue(ExceptionCode&) const;
    351     Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; }
     350    Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? nullptr : m_value.quad; }
    352351
    353352#if ENABLE(CSS_SCROLL_SNAP)
    354353    LengthRepeat* getLengthRepeatValue(ExceptionCode&) const;
    355     LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? 0 : m_value.lengthRepeat; }
     354    LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? nullptr : m_value.lengthRepeat; }
    356355#endif
    357356
    358357    WEBCORE_EXPORT RefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const;
    359     RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
     358    const Color& color() const { ASSERT(m_primitiveUnitType == CSS_RGBCOLOR); return *m_value.color; }
    360359
    361360    Pair* getPairValue(ExceptionCode&) const;
     
    405404    // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases.
    406405    CSSPrimitiveValue(int parserOperator);
    407     CSSPrimitiveValue(unsigned color); // RGB value
     406    CSSPrimitiveValue(const Color&);
    408407    CSSPrimitiveValue(const Length&);
    409408    CSSPrimitiveValue(const Length&, const RenderStyle&);
     
    465464        LengthRepeat* lengthRepeat;
    466465#endif
    467         unsigned rgbcolor;
     466        const Color* color;
    468467        Pair* pair;
    469468        DashboardRegion* region;
  • trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h

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

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

    r194848 r207317  
    3535#include "CSSUnsetValue.h"
    3636#include "CSSValueKeywords.h"
     37#include "ColorHash.h"
    3738#include <utility>
    3839#include <wtf/HashMap.h>
     
    6162    Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
    6263    Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
    63     Ref<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
     64    Ref<CSSPrimitiveValue> createColorValue(const Color&);
    6465    Ref<CSSPrimitiveValue> createValue(double value, CSSPrimitiveValue::UnitTypes);
    6566    Ref<CSSPrimitiveValue> createValue(const String& value, CSSPrimitiveValue::UnitTypes type) { return CSSPrimitiveValue::create(value, type); }
     
    7374    CSSValuePool();
    7475
    75     typedef HashMap<unsigned, RefPtr<CSSPrimitiveValue>> ColorValueCache;
     76    typedef HashMap<Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;
    7677    ColorValueCache m_colorValueCache;
    7778
  • trunk/Source/WebCore/css/StyleResolver.cpp

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

    r206839 r207317  
    495495        return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
    496496    }
    497     RGBA32 color;
    498     if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
     497    Color color = CSSParser::fastParseColor(string, strict && string[0] != '#');
     498    if (!color.isValid())
    499499        return CSSParser::ParseResult::Error;
    500500
     
    13711371}
    13721372
    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.
    1375 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
     1373Color CSSParser::parseColor(const String& string, bool strict)
    13761374{
    13771375    if (string.isEmpty())
    1378         return false;
     1376        return Color();
    13791377
    13801378    // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
    1381     if (fastParseColor(color, string, strict))
    1382         return true;
     1379    Color color = fastParseColor(string, strict);
     1380    if (color.isValid())
     1381        return color;
    13831382
    13841383    CSSParser parser(HTMLStandardMode);
    13851384
    13861385    // In case the fast-path parser didn't understand the color, try the full parser.
    1387     if (!parser.parseColor(string))
    1388         return false;
     1386    if (!parser.parseColorFromString(string))
     1387        return Color();
    13891388
    13901389    CSSValue& value = *parser.m_parsedProperties.first().value();
    13911390    if (!is<CSSPrimitiveValue>(value))
    1392         return false;
     1391        return Color();
    13931392
    13941393    CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
    13951394    if (!primitiveValue.isRGBColor())
    1396         return false;
    1397 
    1398     color = primitiveValue.getRGBA32Value();
    1399     return true;
    1400 }
    1401 
    1402 bool CSSParser::parseColor(const String& string)
     1395        return Color();
     1396
     1397    return primitiveValue.color();
     1398}
     1399
     1400bool CSSParser::parseColorFromString(const String& string)
    14031401{
    14041402    setupParser("@-webkit-decls{color:", string, "} ");
     
    14091407}
    14101408
    1411 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
     1409Color CSSParser::parseSystemColor(const String& string, Document* document)
    14121410{
    14131411    if (!document || !document->page())
    1414         return false;
     1412        return Color();
    14151413
    14161414    CSSParserString cssColor;
     
    14181416    CSSValueID id = cssValueKeywordID(cssColor);
    14191417    if (!validPrimitiveValueColor(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;
     1418        return Color();
     1419
     1420    return document->page()->theme().systemColor(id);
    14281421}
    14291422
     
    74827475
    74837476template <typename CharacterType>
    7484 static inline bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length , bool strict)
     7477static inline Color fastParseColorInternal(const CharacterType* characters, unsigned length , bool strict)
    74857478{
    74867479    CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::CSS_UNKNOWN;
    7487    
     7480
    74887481    if (!strict && length >= 3) {
     7482        RGBA32 rgb;
    74897483        if (characters[0] == '#') {
    74907484            if (Color::parseHexColor(characters + 1, length - 1, rgb))
    7491                 return true;
     7485                return Color(rgb);
    74927486        } else {
    74937487            if (Color::parseHexColor(characters, length, rgb))
    7494                 return true;
     7488                return Color(rgb);
    74957489        }
    74967490    }
     
    75067500       
    75077501        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    7508             return false;
     7502            return Color();
    75097503        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    7510             return false;
     7504            return Color();
    75117505        if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
    7512             return false;
     7506            return Color();
    75137507        if (!parseAlphaValue(current, end, ')', alpha))
    7514             return false;
     7508            return Color();
    75157509        if (current != end)
    7516             return false;
    7517         rgb = makeRGBA(red, green, blue, alpha);
    7518         return true;
     7510            return Color();
     7511        return Color(makeRGBA(red, green, blue, alpha));
    75197512    }
    75207513
     
    75277520        int blue;
    75287521        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    7529             return false;
     7522            return Color();
    75307523        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    7531             return false;
     7524            return Color();
    75327525        if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
    7533             return false;
     7526            return Color();
    75347527        if (current != end)
    7535             return false;
    7536         rgb = makeRGB(red, green, blue);
    7537         return true;
    7538     }
    7539 
    7540     return false;
     7528            return Color();
     7529        return Color(makeRGB(red, green, blue));
     7530    }
     7531
     7532    return Color();
    75417533}
    75427534
    75437535template<typename StringType>
    7544 bool CSSParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict)
     7536Color CSSParser::fastParseColor(const StringType& name, bool strict)
    75457537{
    75467538    unsigned length = name.length();
    7547     bool parseResult;
    75487539
    75497540    if (!length)
    7550         return false;
    7551 
     7541        return Color();
     7542
     7543    Color color;
    75527544    if (name.is8Bit())
    7553         parseResult = fastParseColorInternal(rgb, name.characters8(), length, strict);
     7545        color = fastParseColorInternal(name.characters8(), length, strict);
    75547546    else
    7555         parseResult = fastParseColorInternal(rgb, name.characters16(), length, strict);
    7556 
    7557     if (parseResult)
    7558         return true;
     7547        color = fastParseColorInternal(name.characters16(), length, strict);
     7548
     7549    if (color.isValid())
     7550        return color;
    75597551
    75607552    // Try named colors.
    7561     Color tc;
    7562     tc.setNamedColor(name);
    7563     if (tc.isValid()) {
    7564         rgb = tc.rgb();
    7565         return true;
    7566     }
    7567     return false;
     7553    color.setNamedColor(name);
     7554    return color;
    75687555}
    75697556   
     
    76817668RefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value)
    76827669{
    7683     RGBA32 c = Color::transparent;
    7684     if (!parseColorFromValue(value ? *value : *m_valueList->current(), c))
     7670    Color color = parseColorFromValue(value ? *value : *m_valueList->current());
     7671    if (!color.isValid())
    76857672        return nullptr;
    7686     return CSSValuePool::singleton().createColorValue(c);
    7687 }
    7688 
    7689 bool CSSParser::parseColorFromValue(CSSParserValue& value, RGBA32& c)
     7673    return CSSValuePool::singleton().createColorValue(color);
     7674}
     7675
     7676Color CSSParser::parseColorFromValue(CSSParserValue& value)
    76907677{
    76917678    if (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_NUMBER
     
    76937680        String str = String::format("%06d", static_cast<int>((value.fValue+.5)));
    76947681        // FIXME: This should be strict parsing for SVG as well.
    7695         if (!fastParseColor(c, str, inStrictMode()))
    7696             return false;
     7682        return fastParseColor(str, inStrictMode());
    76977683    } else if (value.unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR
    76987684        || value.unit == CSSPrimitiveValue::CSS_IDENT
    76997685        || (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_DIMENSION)) {
    7700         if (!fastParseColor(c, value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT))
    7701             return false;
     7686        return fastParseColor(value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT);
    77027687    } else if (value.unit == CSSParserValue::Function
    77037688        && value.function->args
     
    77067691        int colorValues[3];
    77077692        if (!parseRGBParameters(value, colorValues, false))
    7708             return false;
    7709         c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
     7693            return Color();
     7694        return Color(makeRGB(colorValues[0], colorValues[1], colorValues[2]));
    77107695    } else if (value.unit == CSSParserValue::Function
    77117696        && value.function->args
     
    77147699        int colorValues[4];
    77157700        if (!parseRGBParameters(value, colorValues, true))
    7716             return false;
    7717         c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
     7701            return Color();
     7702        return Color(makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
    77187703    } else if (value.unit == CSSParserValue::Function
    77197704        && value.function->args
     
    77227707        double colorValues[3];
    77237708        if (!parseHSLParameters(value, colorValues, false))
    7724             return false;
    7725         c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0);
     7709            return Color();
     7710        return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0));
    77267711    } else if (value.unit == CSSParserValue::Function
    77277712        && value.function->args
     
    77307715        double colorValues[4];
    77317716        if (!parseHSLParameters(value, colorValues, true))
    7732             return false;
    7733         c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
    7734     } else
    7735         return false;
    7736 
    7737     return true;
     7717            return Color();
     7718        return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
     7719    }
     7720
     7721    return Color();
    77387722}
    77397723
  • trunk/Source/WebCore/css/parser/CSSParser.h

    r206753 r207317  
    135135    static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet);
    136136
    137     static bool parseColor(RGBA32& color, const String&, bool strict = false);
     137    static Color parseColor(const String&, bool strict = false);
    138138    static bool isValidSystemColorValue(CSSValueID);
    139     static bool parseSystemColor(RGBA32& color, const String&, Document*);
     139    static Color parseSystemColor(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     bool parseColorFromValue(CSSParserValue&, RGBA32&);
     281    Color parseColorFromValue(CSSParserValue&);
    282282    void parseSelector(const String&, CSSSelectorList&);
    283283
    284284    template<typename StringType>
    285     static bool fastParseColor(RGBA32&, const StringType&, bool strict);
     285    static Color fastParseColor(const StringType&, bool strict);
    286286
    287287    bool parseLineHeight(bool important);
     
    619619    bool parseFontFaceSrcLocal(CSSValueList&);
    620620
    621     bool parseColor(const String&);
     621    bool parseColorFromString(const String&);
    622622
    623623#if ENABLE(CSS_GRID_LAYOUT)
  • trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp

    r206181 r207317  
    412412
    413413template <typename CharacterType>
    414 static bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length, bool quirksMode)
     414static Color fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)
    415415{
    416416    CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::UnitTypes::CSS_UNKNOWN;
    417417
    418     if (length >= 4 && characters[0] == '#')
    419         return Color::parseHexColor(characters + 1, length - 1, rgb);
     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    }
    420424
    421425    if (quirksMode && (length == 3 || length == 6)) {
     426        RGBA32 rgb;
    422427        if (Color::parseHexColor(characters, length, rgb))
    423             return true;
     428            return Color(rgb);
    424429    }
    425430
     
    434439
    435440        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    436             return false;
     441            return Color();
    437442        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    438             return false;
     443            return Color();
    439444        if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
    440             return false;
     445            return Color();
    441446        if (!parseAlphaValue(current, end, ')', alpha))
    442             return false;
     447            return Color();
    443448        if (current != end)
    444             return false;
    445         rgb = makeRGBA(red, green, blue, alpha);
    446         return true;
     449            return Color();
     450        return Color(makeRGBA(red, green, blue, alpha));
    447451    }
    448452
     
    455459        int blue;
    456460        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    457             return false;
     461            return Color();
    458462        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    459             return false;
     463            return Color();
    460464        if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
    461             return false;
     465            return Color();
    462466        if (current != end)
    463             return false;
    464         rgb = makeRGB(red, green, blue);
    465         return true;
    466     }
    467 
    468     return false;
     467            return Color();
     468        return Color(makeRGB(red, green, blue));
     469    }
     470
     471    return Color();
    469472}
    470473
     
    479482    }
    480483
    481     RGBA32 color;
    482484    bool quirksMode = isQuirksModeBehavior(parserMode);
    483485
    484486    // Fast path for hex colors and rgb()/rgba() colors
    485     bool parseResult;
     487    Color color;
    486488    if (string.is8Bit())
    487         parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode);
     489        color = fastParseColorInternal(string.characters8(), string.length(), quirksMode);
    488490    else
    489         parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode);
    490     if (!parseResult)
     491        color = fastParseColorInternal(string.characters16(), string.length(), quirksMode);
     492    if (!color.isValid())
    491493        return nullptr;
    492494    return CSSValuePool::singleton().createColorValue(color);
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

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

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

    r206395 r207317  
    383383}
    384384
    385 static RGBA32 cssValueToRGBA(CSSValue* colorValue)
     385static Color cssValueToColor(CSSValue* colorValue)
    386386{
    387387    if (!is<CSSPrimitiveValue>(colorValue))
     
    390390    CSSPrimitiveValue& primitiveColor = downcast<CSSPrimitiveValue>(*colorValue);
    391391    if (primitiveColor.isRGBColor())
    392         return primitiveColor.getRGBA32Value();
     392        return primitiveColor.color();
    393393   
    394     RGBA32 rgba = 0;
    395     CSSParser::parseColor(rgba, colorValue->cssText());
    396     return rgba;
     394    return CSSParser::parseColor(colorValue->cssText());
    397395}
    398396
    399397template<typename T>
    400 static inline RGBA32 textColorFromStyle(T& style)
    401 {
    402     return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get());
     398static inline Color textColorFromStyle(T& style)
     399{
     400    return cssValueToColor(extractPropertyValue(style, CSSPropertyColor).get());
    403401}
    404402
    405403template<typename T>
    406 static inline RGBA32 backgroundColorFromStyle(T& style)
    407 {
    408     return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
    409 }
    410 
    411 static inline RGBA32 rgbaBackgroundColorInEffect(Node* node)
    412 {
    413     return cssValueToRGBA(backgroundColorInEffect(node).get());
     404static inline Color backgroundColorFromStyle(T& style)
     405{
     406    return cssValueToColor(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
     407}
     408
     409static inline Color rgbaBackgroundColorInEffect(Node* node)
     410{
     411    return cssValueToColor(backgroundColorInEffect(node).get());
    414412}
    415413
     
    10971095
    10981096    if (hasTransparentBackgroundColor(m_mutableStyle.get())
    1099         || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
     1097        || cssValueToColor(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
    11001098        m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
    11011099
     
    18411839    CSSPrimitiveValue& value = downcast<CSSPrimitiveValue>(*cssValue);
    18421840    if (value.isRGBColor())
    1843         return !alphaChannel(value.getRGBA32Value());
     1841        return value.color().hasAlpha();
    18441842    return value.getValueID() == CSSValueTransparent;
    18451843}
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r206802 r207317  
    990990    if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
    991991        if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
    992             return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
     992            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), 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).getRGBA32Value()), propertyId == CSSPropertyColor);
     998            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
    999999        if (value->isInheritedValue())
    10001000            inherit = true;
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

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

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

    r206538 r207317  
    405405
    406406    if (style.isCurrentColor()) {
    407         if (style.hasOverrideAlpha())
    408             style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
    409         else
     407        if (style.hasOverrideAlpha()) {
     408            // FIXME: Should not use RGBA32 here.
     409            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
     410        } else
    410411            style = CanvasStyle(currentColor(canvas()));
    411412    } else
     
    431432
    432433    if (style.isCurrentColor()) {
    433         if (style.hasOverrideAlpha())
    434             style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
    435         else
     434        if (style.hasOverrideAlpha()) {
     435            // FIXME: Should not use RGBA32 here.
     436            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
     437        } else
    436438            style = CanvasStyle(currentColor(canvas()));
    437439    } else
     
    579581}
    580582
    581 void 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;
     583void 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;
    590592    applyShadow();
    591593}
     
    12491251}
    12501252
    1251 void 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));
     1253void 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));
    12571262}
    12581263
  • trunk/Source/WebCore/html/canvas/CanvasStyle.cpp

    r205892 r207317  
    4444namespace WebCore {
    4545
    46 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, ParseFailed };
    47 
    48 static 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 
    59 RGBA32 currentColor(HTMLCanvasElement* canvas)
     46static bool isCurrentColorString(const String& colorString)
     47{
     48    return equalLettersIgnoringASCIICase(colorString, "currentcolor");
     49}
     50
     51static 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
     60Color currentColor(HTMLCanvasElement* canvas)
    6061{
    6162    if (!canvas || !canvas->inDocument() || !canvas->inlineStyle())
    6263        return Color::black;
    63     RGBA32 rgba = Color::black;
    64     CSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
    65     return rgba;
    66 }
    67 
    68 bool 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     }
     64    Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
     65    if (!color.isValid())
     66        return Color::black;
     67    return color;
     68}
     69
     70Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* canvas)
     71{
     72    if (isCurrentColorString(colorString))
     73        return currentColor(canvas);
     74
     75    return parseColor(colorString, canvas ? &canvas->document() : nullptr);
    8476}
    8577
     
    134126}
    135127
    136 CanvasStyle 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:
     128CanvasStyle CanvasStyle::createFromString(const String& colorString, Document* document)
     129{
     130    if (isCurrentColorString(colorString))
    145131        return CanvasStyle(ConstructCurrentColor);
    146     case ParseFailed:
    147         return CanvasStyle();
    148     default:
    149         ASSERT_NOT_REACHED();
    150         return CanvasStyle();
    151     }
    152 }
    153 
    154 CanvasStyle 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:
     132
     133    Color color = parseColor(colorString, document);
     134    if (color.isValid())
     135        return CanvasStyle(color);
     136
     137    return CanvasStyle();
     138}
     139
     140CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& colorString, float alpha)
     141{
     142    if (isCurrentColorString(colorString))
    162143        return CanvasStyle(CurrentColorWithOverrideAlpha, alpha);
    163     case ParseFailed:
    164         return CanvasStyle();
    165     default:
    166         ASSERT_NOT_REACHED();
    167         return CanvasStyle();
    168     }
     144
     145    Color color = parseColor(colorString);
     146    if (color.isValid())
     147        return CanvasStyle(colorWithOverrideAlpha(color.rgb(), alpha));
     148
     149    return CanvasStyle();
    169150}
    170151
  • trunk/Source/WebCore/html/canvas/CanvasStyle.h

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

    r207265 r207317  
    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
    144161    // FIXME: Add constructor for ExtendedColor type.
    145162
     
    185202    void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
    186203    void setRGB(RGBA32);
     204    uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }
    187205
    188206    WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
  • trunk/Source/WebCore/svg/SVGColor.cpp

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