Title: [207317] trunk/Source/WebCore
Revision
207317
Author
d...@apple.com
Date
2016-10-13 18:10:30 -0700 (Thu, 13 Oct 2016)

Log 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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (207316 => 207317)


--- trunk/Source/WebCore/ChangeLog	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/ChangeLog	2016-10-14 01:10:30 UTC (rev 207317)
@@ -1,3 +1,103 @@
+2016-10-13  Dean Jackson  <d...@apple.com>
+
+        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):
+
 2016-10-13  Nan Wang  <n_w...@apple.com>
 
         AX: [Mac] better accessibility support for Summary elements

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (207316 => 207317)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-10-14 01:10:30 UTC (rev 207317)
@@ -1297,6 +1297,7 @@
 		2EF1BFEA121C9F4200C27627 /* FileStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2EF1BFE8121C9F4200C27627 /* FileStream.cpp */; };
 		2EF1BFEB121C9F4200C27627 /* FileStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EF1BFE9121C9F4200C27627 /* FileStream.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2EF1BFF9121CB0CE00C27627 /* FileStreamClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EF1BFF8121CB0CE00C27627 /* FileStreamClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 3103B7DE1DB01556008BB890 /* ColorHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		3106036F14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */; };
 		3106037014327D2E00ABF4BA /* WebKitCSSFilterValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		310603741432819C00ABF4BA /* JSWebKitCSSFilterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 310603721432819C00ABF4BA /* JSWebKitCSSFilterValue.cpp */; };
@@ -8261,6 +8262,7 @@
 		2EF1BFE8121C9F4200C27627 /* FileStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileStream.cpp; sourceTree = "<group>"; };
 		2EF1BFE9121C9F4200C27627 /* FileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStream.h; sourceTree = "<group>"; };
 		2EF1BFF8121CB0CE00C27627 /* FileStreamClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStreamClient.h; sourceTree = "<group>"; };
+		3103B7DE1DB01556008BB890 /* ColorHash.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorHash.h; sourceTree = "<group>"; };
 		3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSFilterValue.cpp; sourceTree = "<group>"; };
 		3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSFilterValue.h; sourceTree = "<group>"; };
 		3106036E14327D2E00ABF4BA /* WebKitCSSFilterValue.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebKitCSSFilterValue.idl; sourceTree = "<group>"; };
@@ -20734,6 +20736,7 @@
 				CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */,
 				B27535380B053814002CE64F /* Color.cpp */,
 				B27535390B053814002CE64F /* Color.h */,
+				3103B7DE1DB01556008BB890 /* ColorHash.h */,
 				31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */,
 				31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */,
 				9382DF5710A8D5C900925652 /* ColorSpace.h */,
@@ -25386,6 +25389,7 @@
 				BCEC01C30C274DDD009F4EC9 /* JSScreen.h in Headers */,
 				FDA15ECE12B03F61003A583A /* JSScriptProcessorNode.h in Headers */,
 				CED06AD11C77754800FDFAF1 /* JSSecurityPolicyViolationEvent.h in Headers */,
+				3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */,
 				9BDA64D81B975CF2009C4387 /* JSShadowRoot.h in Headers */,
 				CD9DE17B17AAC75B00EA386D /* JSSourceBuffer.h in Headers */,
 				CD9DE17D17AAC75B00EA386D /* JSSourceBufferList.h in Headers */,

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -350,11 +350,11 @@
         m_value.string->ref();
 }
 
-CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
+CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)
     : CSSValue(PrimitiveClass)
 {
     m_primitiveUnitType = CSS_RGBCOLOR;
-    m_value.rgbcolor = color;
+    m_value.color = new Color(color);
 }
 
 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length)
@@ -574,6 +574,11 @@
         delete m_value.fontFamily;
         m_value.fontFamily = nullptr;
         break;
+    case CSS_RGBCOLOR:
+        ASSERT(m_value.color);
+        delete m_value.color;
+        m_value.color = nullptr;
+        break;
     case CSS_NUMBER:
     case CSS_PARSER_INTEGER:
     case CSS_PERCENTAGE:
@@ -605,7 +610,6 @@
     case CSS_DPCM:
     case CSS_FR:
     case CSS_IDENT:
-    case CSS_RGBCOLOR:
     case CSS_UNKNOWN:
     case CSS_UNICODE_RANGE:
     case CSS_PARSER_OPERATOR:
@@ -1028,7 +1032,7 @@
     }
 
     // FIMXE: This should not return a new object for each invocation.
-    return RGBColor::create(m_value.rgbcolor);
+    return RGBColor::create(m_value.color->rgb());
 }
 
 Pair* CSSPrimitiveValue::getPairValue(ExceptionCode& ec) const
@@ -1175,13 +1179,13 @@
     case CSS_LENGTH_REPEAT:
         return getLengthRepeatValue()->cssText();
 #endif
-    case CSS_RGBCOLOR:
     case CSS_PARSER_HEXCOLOR: {
-        RGBA32 rgbColor = m_value.rgbcolor;
-        if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR)
-            Color::parseHexColor((String)m_value.string, rgbColor);
-        return Color(rgbColor).cssText();
+        RGBA32 rgb;
+        Color::parseHexColor((String)m_value.string, rgb);
+        return Color(rgb).cssText();
     }
+    case CSS_RGBCOLOR:
+        return color().cssText();
     case CSS_PAIR:
         return getPairValue()->cssText();
 #if ENABLE(DASHBOARD_SUPPORT)
@@ -1351,7 +1355,7 @@
         result = CSSPrimitiveValue::createIdentifier(m_value.valueID);
         break;
     case CSS_RGBCOLOR:
-        result = CSSPrimitiveValue::createColor(m_value.rgbcolor);
+        result = CSSPrimitiveValue::create(*m_value.color);
         break;
     case CSS_DIMENSION:
     case CSS_UNKNOWN:
@@ -1430,7 +1434,7 @@
         return m_value.lengthRepeat && other.m_value.lengthRepeat && m_value.lengthRepeat->equals(*other.m_value.lengthRepeat);
 #endif
     case CSS_RGBCOLOR:
-        return m_value.rgbcolor == other.m_value.rgbcolor;
+        return color() == other.color();
     case CSS_PAIR:
         return m_value.pair && other.m_value.pair && m_value.pair->equals(*other.m_value.pair);
 #if ENABLE(DASHBOARD_SUPPORT)

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (207316 => 207317)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.h	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -253,7 +253,6 @@
     static Ref<CSSPrimitiveValue> createIdentifier(CSSPropertyID propertyID) { return adoptRef(*new CSSPrimitiveValue(propertyID)); }
     static Ref<CSSPrimitiveValue> createParserOperator(int parserOperator) { return adoptRef(*new CSSPrimitiveValue(parserOperator)); }
 
-    static Ref<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(*new CSSPrimitiveValue(rgbValue)); }
     static Ref<CSSPrimitiveValue> create(double value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
     static Ref<CSSPrimitiveValue> create(const String& value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
     static Ref<CSSPrimitiveValue> create(const Length& value, const RenderStyle& style) { return adoptRef(*new CSSPrimitiveValue(value, style)); }
@@ -342,21 +341,21 @@
     WEBCORE_EXPORT String getStringValue() const;
 
     WEBCORE_EXPORT Counter* getCounterValue(ExceptionCode&) const;
-    Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; }
+    Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? nullptr : m_value.counter; }
 
     WEBCORE_EXPORT Rect* getRectValue(ExceptionCode&) const;
-    Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; }
+    Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? nullptr : m_value.rect; }
 
     Quad* getQuadValue(ExceptionCode&) const;
-    Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; }
+    Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? nullptr : m_value.quad; }
 
 #if ENABLE(CSS_SCROLL_SNAP)
     LengthRepeat* getLengthRepeatValue(ExceptionCode&) const;
-    LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? 0 : m_value.lengthRepeat; }
+    LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? nullptr : m_value.lengthRepeat; }
 #endif
 
     WEBCORE_EXPORT RefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const;
-    RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
+    const Color& color() const { ASSERT(m_primitiveUnitType == CSS_RGBCOLOR); return *m_value.color; }
 
     Pair* getPairValue(ExceptionCode&) const;
     Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? nullptr : m_value.pair; }
@@ -404,7 +403,7 @@
     CSSPrimitiveValue(CSSPropertyID);
     // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases.
     CSSPrimitiveValue(int parserOperator);
-    CSSPrimitiveValue(unsigned color); // RGB value
+    CSSPrimitiveValue(const Color&);
     CSSPrimitiveValue(const Length&);
     CSSPrimitiveValue(const Length&, const RenderStyle&);
     CSSPrimitiveValue(const LengthSize&, const RenderStyle&);
@@ -464,7 +463,7 @@
 #if ENABLE(CSS_SCROLL_SNAP)
         LengthRepeat* lengthRepeat;
 #endif
-        unsigned rgbcolor;
+        const Color* color;
         Pair* pair;
         DashboardRegion* region;
         CSSBasicShape* shape;

Modified: trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h (207316 => 207317)


--- trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -4939,6 +4939,13 @@
     return WM_LRTB;
 }
 
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)
+    : CSSValue(PrimitiveClass)
+{
+    m_primitiveUnitType = CSS_RGBCOLOR;
+    m_value.color = new Color(color);
+}
+
 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(CSSFontFamily fontFamily)
     : CSSValue(PrimitiveClass)
 {

Modified: trunk/Source/WebCore/css/CSSValuePool.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/CSSValuePool.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/CSSValuePool.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -48,9 +48,9 @@
     m_unsetValue.construct();
     m_revertValue.construct();
 
-    m_transparentColor.construct(Color::transparent);
-    m_whiteColor.construct(Color::white);
-    m_blackColor.construct(Color::black);
+    m_transparentColor.construct(Color(Color::transparent));
+    m_whiteColor.construct(Color(Color::white));
+    m_blackColor.construct(Color(Color::black));
 
     for (unsigned i = 0; i < numCSSValueKeywords; ++i)
         m_identifierValues[i].construct(static_cast<CSSValueID>(i));
@@ -73,15 +73,15 @@
     return CSSPrimitiveValue::createIdentifier(ident);
 }
 
-Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
+Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(const Color& color)
 {
     // These are the empty and deleted values of the hash table.
-    if (rgbValue == Color::transparent)
+    if (color == Color::transparent)
         return m_transparentColor.get();
-    if (rgbValue == Color::white)
+    if (color == Color::white)
         return m_whiteColor.get();
     // Just because it is common.
-    if (rgbValue == Color::black)
+    if (color == Color::black)
         return m_blackColor.get();
 
     // Remove one entry at random if the cache grows too large.
@@ -89,9 +89,9 @@
     if (m_colorValueCache.size() >= maximumColorCacheSize)
         m_colorValueCache.remove(m_colorValueCache.begin());
 
-    ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, nullptr);
+    ColorValueCache::AddResult entry = m_colorValueCache.add(color, nullptr);
     if (entry.isNewEntry)
-        entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue);
+        entry.iterator->value = CSSPrimitiveValue::create(color);
     return *entry.iterator->value;
 }
 

Modified: trunk/Source/WebCore/css/CSSValuePool.h (207316 => 207317)


--- trunk/Source/WebCore/css/CSSValuePool.h	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/CSSValuePool.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -34,6 +34,7 @@
 #include "CSSRevertValue.h"
 #include "CSSUnsetValue.h"
 #include "CSSValueKeywords.h"
+#include "ColorHash.h"
 #include <utility>
 #include <wtf/HashMap.h>
 #include <wtf/NeverDestroyed.h>
@@ -60,7 +61,7 @@
     Ref<CSSRevertValue> createRevertValue() { return m_revertValue.get(); }
     Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
     Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
-    Ref<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
+    Ref<CSSPrimitiveValue> createColorValue(const Color&);
     Ref<CSSPrimitiveValue> createValue(double value, CSSPrimitiveValue::UnitTypes);
     Ref<CSSPrimitiveValue> createValue(const String& value, CSSPrimitiveValue::UnitTypes type) { return CSSPrimitiveValue::create(value, type); }
     Ref<CSSPrimitiveValue> createValue(const Length& value, const RenderStyle& style) { return CSSPrimitiveValue::create(value, style); }
@@ -72,7 +73,7 @@
 private:
     CSSValuePool();
 
-    typedef HashMap<unsigned, RefPtr<CSSPrimitiveValue>> ColorValueCache;
+    typedef HashMap<Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;
     ColorValueCache m_colorValueCache;
 
     typedef HashMap<AtomicString, RefPtr<CSSValueList>> FontFaceValueCache;

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -1831,7 +1831,7 @@
 Color StyleResolver::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const
 {
     if (value.isRGBColor())
-        return Color(value.getRGBA32Value());
+        return value.color();
 
     const State& state = m_state;
     CSSValueID ident = value.getValueID();

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -494,8 +494,8 @@
         auto value = CSSValuePool::singleton().createIdentifierValue(valueID);
         return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
     }
-    RGBA32 color;
-    if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
+    Color color = CSSParser::fastParseColor(string, strict && string[0] != '#');
+    if (!color.isValid())
         return CSSParser::ParseResult::Error;
 
     auto value = CSSValuePool::singleton().createColorValue(color);
@@ -1370,36 +1370,34 @@
     return result;
 }
 
-// The color will only be changed when string contains a valid CSS color, so callers
-// can set it to a default color and ignore the boolean result.
-bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
+Color CSSParser::parseColor(const String& string, bool strict)
 {
     if (string.isEmpty())
-        return false;
+        return Color();
 
     // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
-    if (fastParseColor(color, string, strict))
-        return true;
+    Color color = fastParseColor(string, strict);
+    if (color.isValid())
+        return color;
 
     CSSParser parser(HTMLStandardMode);
 
     // In case the fast-path parser didn't understand the color, try the full parser.
-    if (!parser.parseColor(string))
-        return false;
+    if (!parser.parseColorFromString(string))
+        return Color();
 
     CSSValue& value = *parser.m_parsedProperties.first().value();
     if (!is<CSSPrimitiveValue>(value))
-        return false;
+        return Color();
 
     CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
     if (!primitiveValue.isRGBColor())
-        return false;
+        return Color();
 
-    color = primitiveValue.getRGBA32Value();
-    return true;
+    return primitiveValue.color();
 }
 
-bool CSSParser::parseColor(const String& string)
+bool CSSParser::parseColorFromString(const String& string)
 {
     setupParser("@-webkit-decls{color:", string, "} ");
     cssyyparse(this);
@@ -1408,23 +1406,18 @@
     return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
 }
 
-bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
+Color CSSParser::parseSystemColor(const String& string, Document* document)
 {
     if (!document || !document->page())
-        return false;
+        return Color();
 
     CSSParserString cssColor;
     cssColor.init(string);
     CSSValueID id = cssValueKeywordID(cssColor);
     if (!validPrimitiveValueColor(id))
-        return false;
+        return Color();
 
-    Color parsedColor = document->page()->theme().systemColor(id);
-    if (!parsedColor.isValid())
-        return false;
-
-    color = parsedColor.rgb();
-    return true;
+    return document->page()->theme().systemColor(id);
 }
 
 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
@@ -7481,17 +7474,18 @@
 }
 
 template <typename CharacterType>
-static inline bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length , bool strict)
+static inline Color fastParseColorInternal(const CharacterType* characters, unsigned length , bool strict)
 {
     CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::CSS_UNKNOWN;
-    
+
     if (!strict && length >= 3) {
+        RGBA32 rgb;
         if (characters[0] == '#') {
             if (Color::parseHexColor(characters + 1, length - 1, rgb))
-                return true;
+                return Color(rgb);
         } else {
             if (Color::parseHexColor(characters, length, rgb))
-                return true;
+                return Color(rgb);
         }
     }
 
@@ -7505,17 +7499,16 @@
         int alpha;
         
         if (!parseColorIntOrPercentage(current, end, ',', expect, red))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ',', expect, green))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
-            return false;
+            return Color();
         if (!parseAlphaValue(current, end, ')', alpha))
-            return false;
+            return Color();
         if (current != end)
-            return false;
-        rgb = makeRGBA(red, green, blue, alpha);
-        return true;
+            return Color();
+        return Color(makeRGBA(red, green, blue, alpha));
     }
 
     // Try rgb() syntax.
@@ -7526,45 +7519,39 @@
         int green;
         int blue;
         if (!parseColorIntOrPercentage(current, end, ',', expect, red))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ',', expect, green))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
-            return false;
+            return Color();
         if (current != end)
-            return false;
-        rgb = makeRGB(red, green, blue);
-        return true;
+            return Color();
+        return Color(makeRGB(red, green, blue));
     }
 
-    return false;
+    return Color();
 }
 
 template<typename StringType>
-bool CSSParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict)
+Color CSSParser::fastParseColor(const StringType& name, bool strict)
 {
     unsigned length = name.length();
-    bool parseResult;
 
     if (!length)
-        return false;
+        return Color();
 
+    Color color;
     if (name.is8Bit())
-        parseResult = fastParseColorInternal(rgb, name.characters8(), length, strict);
+        color = fastParseColorInternal(name.characters8(), length, strict);
     else
-        parseResult = fastParseColorInternal(rgb, name.characters16(), length, strict);
+        color = fastParseColorInternal(name.characters16(), length, strict);
 
-    if (parseResult)
-        return true;
+    if (color.isValid())
+        return color;
 
     // Try named colors.
-    Color tc;
-    tc.setNamedColor(name);
-    if (tc.isValid()) {
-        rgb = tc.rgb();
-        return true;
-    }
-    return false;
+    color.setNamedColor(name);
+    return color;
 }
     
 inline double CSSParser::parsedDouble(ValueWithCalculation& valueWithCalculation)
@@ -7680,25 +7667,23 @@
 
 RefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value)
 {
-    RGBA32 c = Color::transparent;
-    if (!parseColorFromValue(value ? *value : *m_valueList->current(), c))
+    Color color = parseColorFromValue(value ? *value : *m_valueList->current());
+    if (!color.isValid())
         return nullptr;
-    return CSSValuePool::singleton().createColorValue(c);
+    return CSSValuePool::singleton().createColorValue(color);
 }
 
-bool CSSParser::parseColorFromValue(CSSParserValue& value, RGBA32& c)
+Color CSSParser::parseColorFromValue(CSSParserValue& value)
 {
     if (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_NUMBER
         && value.fValue >= 0. && value.fValue < 1000000.) {
         String str = String::format("%06d", static_cast<int>((value.fValue+.5)));
         // FIXME: This should be strict parsing for SVG as well.
-        if (!fastParseColor(c, str, inStrictMode()))
-            return false;
+        return fastParseColor(str, inStrictMode());
     } else if (value.unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR
         || value.unit == CSSPrimitiveValue::CSS_IDENT
         || (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_DIMENSION)) {
-        if (!fastParseColor(c, value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT))
-            return false;
+        return fastParseColor(value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT);
     } else if (value.unit == CSSParserValue::Function
         && value.function->args
         && value.function->args->size() == 5 /* rgb + two commas */
@@ -7705,8 +7690,8 @@
         && equalLettersIgnoringASCIICase(value.function->name, "rgb(")) {
         int colorValues[3];
         if (!parseRGBParameters(value, colorValues, false))
-            return false;
-        c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
+            return Color();
+        return Color(makeRGB(colorValues[0], colorValues[1], colorValues[2]));
     } else if (value.unit == CSSParserValue::Function
         && value.function->args
         && value.function->args->size() == 7 /* rgba + three commas */
@@ -7713,8 +7698,8 @@
         && equalLettersIgnoringASCIICase(value.function->name, "rgba(")) {
         int colorValues[4];
         if (!parseRGBParameters(value, colorValues, true))
-            return false;
-        c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
+            return Color();
+        return Color(makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
     } else if (value.unit == CSSParserValue::Function
         && value.function->args
         && value.function->args->size() == 5 /* hsl + two commas */
@@ -7721,8 +7706,8 @@
         && equalLettersIgnoringASCIICase(value.function->name, "hsl(")) {
         double colorValues[3];
         if (!parseHSLParameters(value, colorValues, false))
-            return false;
-        c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0);
+            return Color();
+        return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0));
     } else if (value.unit == CSSParserValue::Function
         && value.function->args
         && value.function->args->size() == 7 /* hsla + three commas */
@@ -7729,12 +7714,11 @@
         && equalLettersIgnoringASCIICase(value.function->name, "hsla(")) {
         double colorValues[4];
         if (!parseHSLParameters(value, colorValues, true))
-            return false;
-        c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
-    } else
-        return false;
+            return Color();
+        return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
+    }
 
-    return true;
+    return Color();
 }
 
 // This class tracks parsing state for shadow values.  If it goes out of scope (e.g., due to an early return)

Modified: trunk/Source/WebCore/css/parser/CSSParser.h (207316 => 207317)


--- trunk/Source/WebCore/css/parser/CSSParser.h	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/parser/CSSParser.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -134,9 +134,9 @@
     static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&, StyleSheetContents*);
     static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet);
 
-    static bool parseColor(RGBA32& color, const String&, bool strict = false);
+    static Color parseColor(const String&, bool strict = false);
     static bool isValidSystemColorValue(CSSValueID);
-    static bool parseSystemColor(RGBA32& color, const String&, Document*);
+    static Color parseSystemColor(const String&, Document*);
     static RefPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
     RefPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, ValueWithCalculation&);
 
@@ -278,11 +278,11 @@
     bool parseRGBParameters(CSSParserValue&, int* colorValues, bool parseAlpha);
     bool parseHSLParameters(CSSParserValue&, double* colorValues, bool parseAlpha);
     RefPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = nullptr);
-    bool parseColorFromValue(CSSParserValue&, RGBA32&);
+    Color parseColorFromValue(CSSParserValue&);
     void parseSelector(const String&, CSSSelectorList&);
 
     template<typename StringType>
-    static bool fastParseColor(RGBA32&, const StringType&, bool strict);
+    static Color fastParseColor(const StringType&, bool strict);
 
     bool parseLineHeight(bool important);
     bool parseFontSize(bool important);
@@ -618,7 +618,7 @@
     bool parseFontFaceSrcURI(CSSValueList&);
     bool parseFontFaceSrcLocal(CSSValueList&);
 
-    bool parseColor(const String&);
+    bool parseColorFromString(const String&);
 
 #if ENABLE(CSS_GRID_LAYOUT)
     bool parseIntegerOrCustomIdentFromGridPosition(RefPtr<CSSPrimitiveValue>& numericValue, RefPtr<CSSPrimitiveValue>& gridLineName);

Modified: trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -411,16 +411,21 @@
 }
 
 template <typename CharacterType>
-static bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length, bool quirksMode)
+static Color fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)
 {
     CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::UnitTypes::CSS_UNKNOWN;
 
-    if (length >= 4 && characters[0] == '#')
-        return Color::parseHexColor(characters + 1, length - 1, rgb);
+    if (length >= 4 && characters[0] == '#') {
+        // FIXME: Why doesn't this check if the parse worked? Is the fallback black?
+        RGBA32 rgb;
+        Color::parseHexColor(characters + 1, length - 1, rgb);
+        return Color(rgb);
+    }
 
     if (quirksMode && (length == 3 || length == 6)) {
+        RGBA32 rgb;
         if (Color::parseHexColor(characters, length, rgb))
-            return true;
+            return Color(rgb);
     }
 
     // Try rgba() syntax.
@@ -433,17 +438,16 @@
         int alpha;
 
         if (!parseColorIntOrPercentage(current, end, ',', expect, red))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ',', expect, green))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
-            return false;
+            return Color();
         if (!parseAlphaValue(current, end, ')', alpha))
-            return false;
+            return Color();
         if (current != end)
-            return false;
-        rgb = makeRGBA(red, green, blue, alpha);
-        return true;
+            return Color();
+        return Color(makeRGBA(red, green, blue, alpha));
     }
 
     // Try rgb() syntax.
@@ -454,18 +458,17 @@
         int green;
         int blue;
         if (!parseColorIntOrPercentage(current, end, ',', expect, red))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ',', expect, green))
-            return false;
+            return Color();
         if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
-            return false;
+            return Color();
         if (current != end)
-            return false;
-        rgb = makeRGB(red, green, blue);
-        return true;
+            return Color();
+        return Color(makeRGB(red, green, blue));
     }
 
-    return false;
+    return Color();
 }
 
 RefPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, CSSParserMode parserMode)
@@ -478,16 +481,15 @@
         return CSSPrimitiveValue::createIdentifier(valueID);
     }
 
-    RGBA32 color;
     bool quirksMode = isQuirksModeBehavior(parserMode);
 
     // Fast path for hex colors and rgb()/rgba() colors
-    bool parseResult;
+    Color color;
     if (string.is8Bit())
-        parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode);
+        color = fastParseColorInternal(string.characters8(), string.length(), quirksMode);
     else
-        parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode);
-    if (!parseResult)
+        color = fastParseColorInternal(string.characters16(), string.length(), quirksMode);
+    if (!color.isValid())
         return nullptr;
     return CSSValuePool::singleton().createColorValue(color);
 }

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -509,7 +509,7 @@
     RGBA32 color = Color::transparent;
     if (!parseHexColor(range, color, acceptQuirkyColors) && !parseColorFunction(range, color))
         return nullptr;
-    return CSSPrimitiveValue::createColor(color);
+    return CSSPrimitiveValue::create(Color(color));
 }
 
 static RefPtr<CSSPrimitiveValue> consumePositionComponent(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)

Modified: trunk/Source/WebCore/css/parser/SVGCSSParser.cpp (207316 => 207317)


--- trunk/Source/WebCore/css/parser/SVGCSSParser.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/css/parser/SVGCSSParser.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -131,10 +131,10 @@
             else if (isValidSystemControlColorValue(id) || id == CSSValueMenu)
                 parsedValue = SVGPaint::createColor(RenderTheme::defaultTheme()->systemColor(id));
             else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
-                RGBA32 c = Color::transparent;
                 if (m_valueList->next()) {
-                    if (parseColorFromValue(*m_valueList->current(), c))
-                        parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, c);
+                    Color color = parseColorFromValue(*m_valueList->current());
+                    if (color.isValid())
+                        parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, color);
                     else if (m_valueList->current()->id == CSSValueNone)
                         parsedValue = SVGPaint::createURIAndNone(valueWithCalculation.value().string);
                 }
@@ -286,18 +286,18 @@
 
 RefPtr<SVGPaint> CSSParser::parseSVGPaint()
 {
-    RGBA32 c = Color::transparent;
-    if (!parseColorFromValue(*m_valueList->current(), c))
+    Color color = parseColorFromValue(*m_valueList->current());
+    if (!color.isValid())
         return nullptr;
-    return SVGPaint::createColor(Color(c));
+    return SVGPaint::createColor(color);
 }
 
 RefPtr<SVGColor> CSSParser::parseSVGColor()
 {
-    RGBA32 c = Color::transparent;
-    if (!parseColorFromValue(*m_valueList->current(), c))
+    Color color = parseColorFromValue(*m_valueList->current());
+    if (!color.isValid())
         return nullptr;
-    return SVGColor::createFromColor(Color(c));
+    return SVGColor::createFromColor(color);
 }
 
 RefPtr<CSSValueList> CSSParser::parsePaintOrder()

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (207316 => 207317)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -382,7 +382,7 @@
 {
 }
 
-static RGBA32 cssValueToRGBA(CSSValue* colorValue)
+static Color cssValueToColor(CSSValue* colorValue)
 {
     if (!is<CSSPrimitiveValue>(colorValue))
         return Color::transparent;
@@ -389,28 +389,26 @@
     
     CSSPrimitiveValue& primitiveColor = downcast<CSSPrimitiveValue>(*colorValue);
     if (primitiveColor.isRGBColor())
-        return primitiveColor.getRGBA32Value();
+        return primitiveColor.color();
     
-    RGBA32 rgba = 0;
-    CSSParser::parseColor(rgba, colorValue->cssText());
-    return rgba;
+    return CSSParser::parseColor(colorValue->cssText());
 }
 
 template<typename T>
-static inline RGBA32 textColorFromStyle(T& style)
+static inline Color textColorFromStyle(T& style)
 {
-    return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get());
+    return cssValueToColor(extractPropertyValue(style, CSSPropertyColor).get());
 }
 
 template<typename T>
-static inline RGBA32 backgroundColorFromStyle(T& style)
+static inline Color backgroundColorFromStyle(T& style)
 {
-    return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
+    return cssValueToColor(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
 }
 
-static inline RGBA32 rgbaBackgroundColorInEffect(Node* node)
+static inline Color rgbaBackgroundColorInEffect(Node* node)
 {
-    return cssValueToRGBA(backgroundColorInEffect(node).get());
+    return cssValueToColor(backgroundColorInEffect(node).get());
 }
 
 static int textAlignResolvingStartAndEnd(int textAlign, int direction)
@@ -1096,7 +1094,7 @@
         m_mutableStyle->removeProperty(CSSPropertyColor);
 
     if (hasTransparentBackgroundColor(m_mutableStyle.get())
-        || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
+        || cssValueToColor(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
         m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
 
     if (is<CSSPrimitiveValue>(unicodeBidi.get())) {
@@ -1840,7 +1838,7 @@
         return false;
     CSSPrimitiveValue& value = downcast<CSSPrimitiveValue>(*cssValue);
     if (value.isRGBColor())
-        return !alphaChannel(value.getRGBA32Value());
+        return value.color().hasAlpha();
     return value.getValueID() == CSSValueTransparent;
 }
 

Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (207316 => 207317)


--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2016-10-14 01:10:30 UTC (rev 207317)
@@ -989,13 +989,13 @@
     Element& element = downcast<Element>(node);
     if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
         if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
-            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
+            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
     }
 
     bool inherit = false;
     if (RefPtr<CSSValue> value = inlineStylePropertyForElement(element, propertyId)) {
         if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
-            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
+            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
         if (value->isInheritedValue())
             inherit = true;
     }

Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (207316 => 207317)


--- trunk/Source/WebCore/html/HTMLBodyElement.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -158,8 +158,8 @@
             else
                 document().resetActiveLinkColor();
         } else {
-            RGBA32 color;
-            if (CSSParser::parseColor(color, value, !document().inQuirksMode())) {
+            Color color = CSSParser::parseColor(value, !document().inQuirksMode());
+            if (color.isValid()) {
                 if (name == linkAttr)
                     document().setLinkColor(color);
                 else if (name == vlinkAttr)

Modified: trunk/Source/WebCore/html/canvas/CanvasGradient.cpp (207316 => 207317)


--- trunk/Source/WebCore/html/canvas/CanvasGradient.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/html/canvas/CanvasGradient.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -50,7 +50,7 @@
 {
 }
 
-void CanvasGradient::addColorStop(float value, const String& color, ExceptionCode& ec)
+void CanvasGradient::addColorStop(float value, const String& colorString, ExceptionCode& ec)
 {
     if (!(value >= 0 && value <= 1.0f)) {
         ec = INDEX_SIZE_ERR;
@@ -57,8 +57,8 @@
         return;
     }
 
-    RGBA32 rgba = 0;
-    if (!parseColorOrCurrentColor(rgba, color, 0 /*canvas*/)) {
+    Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);
+    if (!color.isValid()) {
 #if ENABLE(DASHBOARD_SUPPORT)
         if (!m_dashboardCompatibilityMode)
             ec = SYNTAX_ERR;
@@ -68,7 +68,7 @@
         return;
     }
 
-    m_gradient->addColorStop(value, Color(rgba));
+    m_gradient->addColorStop(value, color);
 }
 
 } // namespace

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (207316 => 207317)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -404,9 +404,10 @@
         return;
 
     if (style.isCurrentColor()) {
-        if (style.hasOverrideAlpha())
-            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
-        else
+        if (style.hasOverrideAlpha()) {
+            // FIXME: Should not use RGBA32 here.
+            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
+        } else
             style = CanvasStyle(currentColor(canvas()));
     } else
         checkOrigin(style.canvasPattern());
@@ -430,9 +431,10 @@
         return;
 
     if (style.isCurrentColor()) {
-        if (style.hasOverrideAlpha())
-            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
-        else
+        if (style.hasOverrideAlpha()) {
+            // FIXME: Should not use RGBA32 here.
+            style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
+        } else
             style = CanvasStyle(currentColor(canvas()));
     } else
         checkOrigin(style.canvasPattern());
@@ -578,15 +580,15 @@
     return Color(state().shadowColor).serialized();
 }
 
-void CanvasRenderingContext2D::setShadowColor(const String& color)
+void CanvasRenderingContext2D::setShadowColor(const String& colorString)
 {
-    RGBA32 rgba;
-    if (!parseColorOrCurrentColor(rgba, color, canvas()))
+    Color color = parseColorOrCurrentColor(colorString, canvas());
+    if (!color.isValid())
         return;
-    if (state().shadowColor == rgba)
+    if (state().shadowColor == color)
         return;
     realizeSaves();
-    modifiableState().shadowColor = rgba;
+    modifiableState().shadowColor = color;
     applyShadow();
 }
 
@@ -1248,12 +1250,15 @@
     }
 }
 
-void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, Optional<float> alpha)
+void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& colorString, Optional<float> alpha)
 {
-    RGBA32 rgba = Color::transparent;
-    if (!color.isNull() && !parseColorOrCurrentColor(rgba, color, canvas()))
+    Color color = parseColorOrCurrentColor(colorString, canvas());
+    if (!colorString.isNull() && !color.isValid())
         return;
-    setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(rgba, alpha));
+    if (!color.isValid())
+        color = Color::transparent;
+    // FIXME: Should not use RGBA32 here.
+    setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(color.rgb(), alpha));
 }
 
 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha)

Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.cpp (207316 => 207317)


--- trunk/Source/WebCore/html/canvas/CanvasStyle.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -43,44 +43,36 @@
 
 namespace WebCore {
 
-enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, ParseFailed };
+static bool isCurrentColorString(const String& colorString)
+{
+    return equalLettersIgnoringASCIICase(colorString, "currentcolor");
+}
 
-static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorString, Document* document = nullptr)
+static Color parseColor(const String& colorString, Document* document = nullptr)
 {
-    if (equalLettersIgnoringASCIICase(colorString, "currentcolor"))
-        return ParsedCurrentColor;
-    if (CSSParser::parseColor(parsedColor, colorString))
-        return ParsedRGBA;
-    if (CSSParser::parseSystemColor(parsedColor, colorString, document))
-        return ParsedSystemColor;
-    return ParseFailed;
+    Color color = CSSParser::parseColor(colorString);
+    if (color.isValid())
+        return color;
+
+    return CSSParser::parseSystemColor(colorString, document);
 }
 
-RGBA32 currentColor(HTMLCanvasElement* canvas)
+Color currentColor(HTMLCanvasElement* canvas)
 {
     if (!canvas || !canvas->inDocument() || !canvas->inlineStyle())
         return Color::black;
-    RGBA32 rgba = Color::black;
-    CSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
-    return rgba;
+    Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
+    if (!color.isValid())
+        return Color::black;
+    return color;
 }
 
-bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement* canvas)
+Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* canvas)
 {
-    ColorParseResult parseResult = parseColor(parsedColor, colorString, canvas ? &canvas->document() : 0);
-    switch (parseResult) {
-    case ParsedRGBA:
-    case ParsedSystemColor:
-        return true;
-    case ParsedCurrentColor:
-        parsedColor = currentColor(canvas);
-        return true;
-    case ParseFailed:
-        return false;
-    default:
-        ASSERT_NOT_REACHED();
-        return false;
-    }
+    if (isCurrentColorString(colorString))
+        return currentColor(canvas);
+
+    return parseColor(colorString, canvas ? &canvas->document() : nullptr);
 }
 
 CanvasStyle::CanvasStyle(Color color)
@@ -133,39 +125,28 @@
         delete m_cmyka;
 }
 
-CanvasStyle CanvasStyle::createFromString(const String& color, Document* document)
+CanvasStyle CanvasStyle::createFromString(const String& colorString, Document* document)
 {
-    RGBA32 rgba;
-    ColorParseResult parseResult = parseColor(rgba, color, document);
-    switch (parseResult) {
-    case ParsedRGBA:
-    case ParsedSystemColor:
-        return CanvasStyle(rgba);
-    case ParsedCurrentColor:
+    if (isCurrentColorString(colorString))
         return CanvasStyle(ConstructCurrentColor);
-    case ParseFailed:
-        return CanvasStyle();
-    default:
-        ASSERT_NOT_REACHED();
-        return CanvasStyle();
-    }
+
+    Color color = parseColor(colorString, document);
+    if (color.isValid())
+        return CanvasStyle(color);
+
+    return CanvasStyle();
 }
 
-CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& color, float alpha)
+CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& colorString, float alpha)
 {
-    RGBA32 rgba;
-    ColorParseResult parseResult = parseColor(rgba, color);
-    switch (parseResult) {
-    case ParsedRGBA:
-        return CanvasStyle(colorWithOverrideAlpha(rgba, alpha));
-    case ParsedCurrentColor:
+    if (isCurrentColorString(colorString))
         return CanvasStyle(CurrentColorWithOverrideAlpha, alpha);
-    case ParseFailed:
-        return CanvasStyle();
-    default:
-        ASSERT_NOT_REACHED();
-        return CanvasStyle();
-    }
+
+    Color color = parseColor(colorString);
+    if (color.isValid())
+        return CanvasStyle(colorWithOverrideAlpha(color.rgb(), alpha));
+
+    return CanvasStyle();
 }
 
 bool CanvasStyle::isEquivalentColor(const CanvasStyle& other) const

Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.h (207316 => 207317)


--- trunk/Source/WebCore/html/canvas/CanvasStyle.h	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -113,8 +113,8 @@
         Type m_type;
     };
 
-    RGBA32 currentColor(HTMLCanvasElement*);
-    bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement*);
+    Color currentColor(HTMLCanvasElement*);
+    Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement*);
 
     inline CanvasStyle::CanvasStyle()
         : m_type(Invalid)

Modified: trunk/Source/WebCore/platform/graphics/Color.h (207316 => 207317)


--- trunk/Source/WebCore/platform/graphics/Color.h	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -141,6 +141,23 @@
     WEBCORE_EXPORT explicit Color(const String&);
     explicit Color(const char*);
 
+    explicit Color(WTF::HashTableDeletedValueType)
+    {
+        m_colorData.rgbaAndFlags = 0xfffffffffffffffd;
+        ASSERT(!isExtended());
+    }
+
+    bool isHashTableDeletedValue() const
+    {
+        return m_colorData.rgbaAndFlags == 0xfffffffffffffffd;
+    }
+
+    explicit Color(WTF::HashTableEmptyValueType)
+    {
+        m_colorData.rgbaAndFlags = 0xffffffffffffffb;
+        ASSERT(!isExtended());
+    }
+
     // FIXME: Add constructor for ExtendedColor type.
 
     Color(RGBA, ColorSpace);
@@ -184,6 +201,7 @@
     RGBA32 rgb() const { ASSERT(!isExtended()); return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32); }
     void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
     void setRGB(RGBA32);
+    uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }
 
     WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
     WEBCORE_EXPORT void getRGBA(double& r, double& g, double& b, double& a) const;

Added: trunk/Source/WebCore/platform/graphics/ColorHash.h (0 => 207317)


--- trunk/Source/WebCore/platform/graphics/ColorHash.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ColorHash.h	2016-10-14 01:10:30 UTC (rev 207317)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Color.h"
+#include <wtf/HashTraits.h>
+
+namespace WTF {
+
+struct ColorHash {
+    static unsigned hash(const WebCore::Color& key) { return intHash(key.asUint64()); }
+    static bool equal(const WebCore::Color& a, const WebCore::Color& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = true;
+};
+
+template<> struct DefaultHash<WebCore::Color> {
+    typedef ColorHash Hash;
+};
+
+template<> struct HashTraits<WebCore::Color> : GenericHashTraits<WebCore::Color> {
+    static const bool emptyValueIsZero = false;
+    static WebCore::Color emptyValue() { return WebCore::Color(HashTableEmptyValue); }
+
+    static void constructDeletedValue(WebCore::Color& slot) { new (NotNull, &slot) WebCore::Color(HashTableDeletedValue); }
+    static bool isDeletedValue(const WebCore::Color& value) { return value.isHashTableDeletedValue(); }
+};
+
+} // namespace WTF
Property changes on: trunk/Source/WebCore/platform/graphics/ColorHash.h
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Author Id Revision HeadURL \ No newline at end of property

Modified: trunk/Source/WebCore/svg/SVGColor.cpp (207316 => 207317)


--- trunk/Source/WebCore/svg/SVGColor.cpp	2016-10-14 00:27:25 UTC (rev 207316)
+++ trunk/Source/WebCore/svg/SVGColor.cpp	2016-10-14 01:10:30 UTC (rev 207317)
@@ -51,10 +51,7 @@
     // FIXME: Rework CSS parser so it exactly matches what the SVG specification requires?
     // FIXME: Move this out of the SVGColor class?
     // FIXME: Is it really OK to do stripWhitespace here instead of stripLeadingAndTrailingHTMLSpaces?
-    RGBA32 color;
-    if (CSSParser::parseColor(color, colorString.stripWhiteSpace()))
-        return color;
-    return Color();
+    return CSSParser::parseColor(colorString.stripWhiteSpace());
 }
 
 void SVGColor::setRGBColor(const String&, ExceptionCode& ec)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to