Diff
Modified: trunk/Source/WebCore/ChangeLog (207341 => 207342)
--- trunk/Source/WebCore/ChangeLog 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/ChangeLog 2016-10-14 16:17:47 UTC (rev 207342)
@@ -1,3 +1,17 @@
+2016-10-14 Commit Queue <commit-qu...@webkit.org>
+
+ Unreviewed, rolling out r207317.
+ https://bugs.webkit.org/show_bug.cgi?id=163448
+
+ This change caused an existing LayoutTest to fail on all
+ platforms (Requested by ryanhaddad on #webkit).
+
+ Reverted changeset:
+
+ "CSS parsing should use Color not RGBA32"
+ https://bugs.webkit.org/show_bug.cgi?id=163423
+ http://trac.webkit.org/changeset/207317
+
2016-10-14 Antti Koivisto <an...@apple.com>
Share inline stylesheets between shadow trees
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (207341 => 207342)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-10-14 16:17:47 UTC (rev 207342)
@@ -1297,7 +1297,6 @@
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 */; };
@@ -8262,7 +8261,6 @@
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>"; };
@@ -20736,7 +20734,6 @@
CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */,
B27535380B053814002CE64F /* Color.cpp */,
B27535390B053814002CE64F /* Color.h */,
- 3103B7DE1DB01556008BB890 /* ColorHash.h */,
31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */,
31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */,
9382DF5710A8D5C900925652 /* ColorSpace.h */,
@@ -25389,7 +25386,6 @@
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 (207341 => 207342)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -350,11 +350,11 @@
m_value.string->ref();
}
-CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)
+CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
: CSSValue(PrimitiveClass)
{
m_primitiveUnitType = CSS_RGBCOLOR;
- m_value.color = new Color(color);
+ m_value.rgbcolor = color;
}
CSSPrimitiveValue::CSSPrimitiveValue(const Length& length)
@@ -574,11 +574,6 @@
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:
@@ -610,6 +605,7 @@
case CSS_DPCM:
case CSS_FR:
case CSS_IDENT:
+ case CSS_RGBCOLOR:
case CSS_UNKNOWN:
case CSS_UNICODE_RANGE:
case CSS_PARSER_OPERATOR:
@@ -1032,7 +1028,7 @@
}
// FIMXE: This should not return a new object for each invocation.
- return RGBColor::create(m_value.color->rgb());
+ return RGBColor::create(m_value.rgbcolor);
}
Pair* CSSPrimitiveValue::getPairValue(ExceptionCode& ec) const
@@ -1179,13 +1175,13 @@
case CSS_LENGTH_REPEAT:
return getLengthRepeatValue()->cssText();
#endif
+ case CSS_RGBCOLOR:
case CSS_PARSER_HEXCOLOR: {
- RGBA32 rgb;
- Color::parseHexColor((String)m_value.string, rgb);
- return Color(rgb).cssText();
+ RGBA32 rgbColor = m_value.rgbcolor;
+ if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR)
+ Color::parseHexColor((String)m_value.string, rgbColor);
+ return Color(rgbColor).cssText();
}
- case CSS_RGBCOLOR:
- return color().cssText();
case CSS_PAIR:
return getPairValue()->cssText();
#if ENABLE(DASHBOARD_SUPPORT)
@@ -1355,7 +1351,7 @@
result = CSSPrimitiveValue::createIdentifier(m_value.valueID);
break;
case CSS_RGBCOLOR:
- result = CSSPrimitiveValue::create(*m_value.color);
+ result = CSSPrimitiveValue::createColor(m_value.rgbcolor);
break;
case CSS_DIMENSION:
case CSS_UNKNOWN:
@@ -1434,7 +1430,7 @@
return m_value.lengthRepeat && other.m_value.lengthRepeat && m_value.lengthRepeat->equals(*other.m_value.lengthRepeat);
#endif
case CSS_RGBCOLOR:
- return color() == other.color();
+ return m_value.rgbcolor == other.m_value.rgbcolor;
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 (207341 => 207342)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -253,6 +253,7 @@
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)); }
@@ -341,21 +342,21 @@
WEBCORE_EXPORT String getStringValue() const;
WEBCORE_EXPORT Counter* getCounterValue(ExceptionCode&) const;
- Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? nullptr : m_value.counter; }
+ Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; }
WEBCORE_EXPORT Rect* getRectValue(ExceptionCode&) const;
- Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? nullptr : m_value.rect; }
+ Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; }
Quad* getQuadValue(ExceptionCode&) const;
- Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? nullptr : m_value.quad; }
+ Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; }
#if ENABLE(CSS_SCROLL_SNAP)
LengthRepeat* getLengthRepeatValue(ExceptionCode&) const;
- LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? nullptr : m_value.lengthRepeat; }
+ LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? 0 : m_value.lengthRepeat; }
#endif
WEBCORE_EXPORT RefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const;
- const Color& color() const { ASSERT(m_primitiveUnitType == CSS_RGBCOLOR); return *m_value.color; }
+ RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
Pair* getPairValue(ExceptionCode&) const;
Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? nullptr : m_value.pair; }
@@ -403,7 +404,7 @@
CSSPrimitiveValue(CSSPropertyID);
// FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases.
CSSPrimitiveValue(int parserOperator);
- CSSPrimitiveValue(const Color&);
+ CSSPrimitiveValue(unsigned color); // RGB value
CSSPrimitiveValue(const Length&);
CSSPrimitiveValue(const Length&, const RenderStyle&);
CSSPrimitiveValue(const LengthSize&, const RenderStyle&);
@@ -463,7 +464,7 @@
#if ENABLE(CSS_SCROLL_SNAP)
LengthRepeat* lengthRepeat;
#endif
- const Color* color;
+ unsigned rgbcolor;
Pair* pair;
DashboardRegion* region;
CSSBasicShape* shape;
Modified: trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h (207341 => 207342)
--- trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -4939,13 +4939,6 @@
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 (207341 => 207342)
--- trunk/Source/WebCore/css/CSSValuePool.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/CSSValuePool.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -48,9 +48,9 @@
m_unsetValue.construct();
m_revertValue.construct();
- m_transparentColor.construct(Color(Color::transparent));
- m_whiteColor.construct(Color(Color::white));
- m_blackColor.construct(Color(Color::black));
+ m_transparentColor.construct(Color::transparent);
+ m_whiteColor.construct(Color::white);
+ m_blackColor.construct(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(const Color& color)
+Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
{
// These are the empty and deleted values of the hash table.
- if (color == Color::transparent)
+ if (rgbValue == Color::transparent)
return m_transparentColor.get();
- if (color == Color::white)
+ if (rgbValue == Color::white)
return m_whiteColor.get();
// Just because it is common.
- if (color == Color::black)
+ if (rgbValue == 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(color, nullptr);
+ ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, nullptr);
if (entry.isNewEntry)
- entry.iterator->value = CSSPrimitiveValue::create(color);
+ entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue);
return *entry.iterator->value;
}
Modified: trunk/Source/WebCore/css/CSSValuePool.h (207341 => 207342)
--- trunk/Source/WebCore/css/CSSValuePool.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/CSSValuePool.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -34,7 +34,6 @@
#include "CSSRevertValue.h"
#include "CSSUnsetValue.h"
#include "CSSValueKeywords.h"
-#include "ColorHash.h"
#include <utility>
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
@@ -61,7 +60,7 @@
Ref<CSSRevertValue> createRevertValue() { return m_revertValue.get(); }
Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
- Ref<CSSPrimitiveValue> createColorValue(const Color&);
+ Ref<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
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); }
@@ -73,7 +72,7 @@
private:
CSSValuePool();
- typedef HashMap<Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;
+ typedef HashMap<unsigned, RefPtr<CSSPrimitiveValue>> ColorValueCache;
ColorValueCache m_colorValueCache;
typedef HashMap<AtomicString, RefPtr<CSSValueList>> FontFaceValueCache;
Modified: trunk/Source/WebCore/css/StyleResolver.cpp (207341 => 207342)
--- trunk/Source/WebCore/css/StyleResolver.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/StyleResolver.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -1831,7 +1831,7 @@
Color StyleResolver::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const
{
if (value.isRGBColor())
- return value.color();
+ return Color(value.getRGBA32Value());
const State& state = m_state;
CSSValueID ident = value.getValueID();
Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (207341 => 207342)
--- trunk/Source/WebCore/css/parser/CSSParser.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -494,8 +494,8 @@
auto value = CSSValuePool::singleton().createIdentifierValue(valueID);
return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
}
- Color color = CSSParser::fastParseColor(string, strict && string[0] != '#');
- if (!color.isValid())
+ RGBA32 color;
+ if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
return CSSParser::ParseResult::Error;
auto value = CSSValuePool::singleton().createColorValue(color);
@@ -1370,34 +1370,36 @@
return result;
}
-Color CSSParser::parseColor(const String& string, bool strict)
+// 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)
{
if (string.isEmpty())
- return Color();
+ return false;
// First try creating a color specified by name, rgba(), rgb() or "#" syntax.
- Color color = fastParseColor(string, strict);
- if (color.isValid())
- return color;
+ if (fastParseColor(color, string, strict))
+ return true;
CSSParser parser(HTMLStandardMode);
// In case the fast-path parser didn't understand the color, try the full parser.
- if (!parser.parseColorFromString(string))
- return Color();
+ if (!parser.parseColor(string))
+ return false;
CSSValue& value = *parser.m_parsedProperties.first().value();
if (!is<CSSPrimitiveValue>(value))
- return Color();
+ return false;
CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
if (!primitiveValue.isRGBColor())
- return Color();
+ return false;
- return primitiveValue.color();
+ color = primitiveValue.getRGBA32Value();
+ return true;
}
-bool CSSParser::parseColorFromString(const String& string)
+bool CSSParser::parseColor(const String& string)
{
setupParser("@-webkit-decls{color:", string, "} ");
cssyyparse(this);
@@ -1406,18 +1408,23 @@
return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
}
-Color CSSParser::parseSystemColor(const String& string, Document* document)
+bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
{
if (!document || !document->page())
- return Color();
+ return false;
CSSParserString cssColor;
cssColor.init(string);
CSSValueID id = cssValueKeywordID(cssColor);
if (!validPrimitiveValueColor(id))
- return Color();
+ return false;
- return document->page()->theme().systemColor(id);
+ Color parsedColor = document->page()->theme().systemColor(id);
+ if (!parsedColor.isValid())
+ return false;
+
+ color = parsedColor.rgb();
+ return true;
}
void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
@@ -7474,18 +7481,17 @@
}
template <typename CharacterType>
-static inline Color fastParseColorInternal(const CharacterType* characters, unsigned length , bool strict)
+static inline bool fastParseColorInternal(RGBA32& rgb, 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 Color(rgb);
+ return true;
} else {
if (Color::parseHexColor(characters, length, rgb))
- return Color(rgb);
+ return true;
}
}
@@ -7499,16 +7505,17 @@
int alpha;
if (!parseColorIntOrPercentage(current, end, ',', expect, red))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, green))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
- return Color();
+ return false;
if (!parseAlphaValue(current, end, ')', alpha))
- return Color();
+ return false;
if (current != end)
- return Color();
- return Color(makeRGBA(red, green, blue, alpha));
+ return false;
+ rgb = makeRGBA(red, green, blue, alpha);
+ return true;
}
// Try rgb() syntax.
@@ -7519,39 +7526,45 @@
int green;
int blue;
if (!parseColorIntOrPercentage(current, end, ',', expect, red))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, green))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
- return Color();
+ return false;
if (current != end)
- return Color();
- return Color(makeRGB(red, green, blue));
+ return false;
+ rgb = makeRGB(red, green, blue);
+ return true;
}
- return Color();
+ return false;
}
template<typename StringType>
-Color CSSParser::fastParseColor(const StringType& name, bool strict)
+bool CSSParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict)
{
unsigned length = name.length();
+ bool parseResult;
if (!length)
- return Color();
+ return false;
- Color color;
if (name.is8Bit())
- color = fastParseColorInternal(name.characters8(), length, strict);
+ parseResult = fastParseColorInternal(rgb, name.characters8(), length, strict);
else
- color = fastParseColorInternal(name.characters16(), length, strict);
+ parseResult = fastParseColorInternal(rgb, name.characters16(), length, strict);
- if (color.isValid())
- return color;
+ if (parseResult)
+ return true;
// Try named colors.
- color.setNamedColor(name);
- return color;
+ Color tc;
+ tc.setNamedColor(name);
+ if (tc.isValid()) {
+ rgb = tc.rgb();
+ return true;
+ }
+ return false;
}
inline double CSSParser::parsedDouble(ValueWithCalculation& valueWithCalculation)
@@ -7667,23 +7680,25 @@
RefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value)
{
- Color color = parseColorFromValue(value ? *value : *m_valueList->current());
- if (!color.isValid())
+ RGBA32 c = Color::transparent;
+ if (!parseColorFromValue(value ? *value : *m_valueList->current(), c))
return nullptr;
- return CSSValuePool::singleton().createColorValue(color);
+ return CSSValuePool::singleton().createColorValue(c);
}
-Color CSSParser::parseColorFromValue(CSSParserValue& value)
+bool CSSParser::parseColorFromValue(CSSParserValue& value, RGBA32& c)
{
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.
- return fastParseColor(str, inStrictMode());
+ if (!fastParseColor(c, str, inStrictMode()))
+ return false;
} else if (value.unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR
|| value.unit == CSSPrimitiveValue::CSS_IDENT
|| (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_DIMENSION)) {
- return fastParseColor(value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT);
+ if (!fastParseColor(c, value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT))
+ return false;
} else if (value.unit == CSSParserValue::Function
&& value.function->args
&& value.function->args->size() == 5 /* rgb + two commas */
@@ -7690,8 +7705,8 @@
&& equalLettersIgnoringASCIICase(value.function->name, "rgb(")) {
int colorValues[3];
if (!parseRGBParameters(value, colorValues, false))
- return Color();
- return Color(makeRGB(colorValues[0], colorValues[1], colorValues[2]));
+ return false;
+ c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
} else if (value.unit == CSSParserValue::Function
&& value.function->args
&& value.function->args->size() == 7 /* rgba + three commas */
@@ -7698,8 +7713,8 @@
&& equalLettersIgnoringASCIICase(value.function->name, "rgba(")) {
int colorValues[4];
if (!parseRGBParameters(value, colorValues, true))
- return Color();
- return Color(makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
+ return false;
+ c = 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 */
@@ -7706,8 +7721,8 @@
&& equalLettersIgnoringASCIICase(value.function->name, "hsl(")) {
double colorValues[3];
if (!parseHSLParameters(value, colorValues, false))
- return Color();
- return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0));
+ return false;
+ c = 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 */
@@ -7714,11 +7729,12 @@
&& equalLettersIgnoringASCIICase(value.function->name, "hsla(")) {
double colorValues[4];
if (!parseHSLParameters(value, colorValues, true))
- return Color();
- return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));
- }
+ return false;
+ c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
+ } else
+ return false;
- return Color();
+ return true;
}
// 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 (207341 => 207342)
--- trunk/Source/WebCore/css/parser/CSSParser.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/parser/CSSParser.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -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 Color parseColor(const String&, bool strict = false);
+ static bool parseColor(RGBA32& color, const String&, bool strict = false);
static bool isValidSystemColorValue(CSSValueID);
- static Color parseSystemColor(const String&, Document*);
+ static bool parseSystemColor(RGBA32& color, 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);
- Color parseColorFromValue(CSSParserValue&);
+ bool parseColorFromValue(CSSParserValue&, RGBA32&);
void parseSelector(const String&, CSSSelectorList&);
template<typename StringType>
- static Color fastParseColor(const StringType&, bool strict);
+ static bool fastParseColor(RGBA32&, const StringType&, bool strict);
bool parseLineHeight(bool important);
bool parseFontSize(bool important);
@@ -618,7 +618,7 @@
bool parseFontFaceSrcURI(CSSValueList&);
bool parseFontFaceSrcLocal(CSSValueList&);
- bool parseColorFromString(const String&);
+ bool parseColor(const String&);
#if ENABLE(CSS_GRID_LAYOUT)
bool parseIntegerOrCustomIdentFromGridPosition(RefPtr<CSSPrimitiveValue>& numericValue, RefPtr<CSSPrimitiveValue>& gridLineName);
Modified: trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp (207341 => 207342)
--- trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -411,21 +411,16 @@
}
template <typename CharacterType>
-static Color fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)
+static bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length, bool quirksMode)
{
CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::UnitTypes::CSS_UNKNOWN;
- 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 (length >= 4 && characters[0] == '#')
+ return Color::parseHexColor(characters + 1, length - 1, rgb);
if (quirksMode && (length == 3 || length == 6)) {
- RGBA32 rgb;
if (Color::parseHexColor(characters, length, rgb))
- return Color(rgb);
+ return true;
}
// Try rgba() syntax.
@@ -438,16 +433,17 @@
int alpha;
if (!parseColorIntOrPercentage(current, end, ',', expect, red))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, green))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
- return Color();
+ return false;
if (!parseAlphaValue(current, end, ')', alpha))
- return Color();
+ return false;
if (current != end)
- return Color();
- return Color(makeRGBA(red, green, blue, alpha));
+ return false;
+ rgb = makeRGBA(red, green, blue, alpha);
+ return true;
}
// Try rgb() syntax.
@@ -458,17 +454,18 @@
int green;
int blue;
if (!parseColorIntOrPercentage(current, end, ',', expect, red))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, green))
- return Color();
+ return false;
if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
- return Color();
+ return false;
if (current != end)
- return Color();
- return Color(makeRGB(red, green, blue));
+ return false;
+ rgb = makeRGB(red, green, blue);
+ return true;
}
- return Color();
+ return false;
}
RefPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, CSSParserMode parserMode)
@@ -481,15 +478,16 @@
return CSSPrimitiveValue::createIdentifier(valueID);
}
+ RGBA32 color;
bool quirksMode = isQuirksModeBehavior(parserMode);
// Fast path for hex colors and rgb()/rgba() colors
- Color color;
+ bool parseResult;
if (string.is8Bit())
- color = fastParseColorInternal(string.characters8(), string.length(), quirksMode);
+ parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode);
else
- color = fastParseColorInternal(string.characters16(), string.length(), quirksMode);
- if (!color.isValid())
+ parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode);
+ if (!parseResult)
return nullptr;
return CSSValuePool::singleton().createColorValue(color);
}
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (207341 => 207342)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -509,7 +509,7 @@
RGBA32 color = Color::transparent;
if (!parseHexColor(range, color, acceptQuirkyColors) && !parseColorFunction(range, color))
return nullptr;
- return CSSPrimitiveValue::create(Color(color));
+ return CSSPrimitiveValue::createColor(color);
}
static RefPtr<CSSPrimitiveValue> consumePositionComponent(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
Modified: trunk/Source/WebCore/css/parser/SVGCSSParser.cpp (207341 => 207342)
--- trunk/Source/WebCore/css/parser/SVGCSSParser.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/css/parser/SVGCSSParser.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -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()) {
- Color color = parseColorFromValue(*m_valueList->current());
- if (color.isValid())
- parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, color);
+ if (parseColorFromValue(*m_valueList->current(), c))
+ parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, c);
else if (m_valueList->current()->id == CSSValueNone)
parsedValue = SVGPaint::createURIAndNone(valueWithCalculation.value().string);
}
@@ -286,18 +286,18 @@
RefPtr<SVGPaint> CSSParser::parseSVGPaint()
{
- Color color = parseColorFromValue(*m_valueList->current());
- if (!color.isValid())
+ RGBA32 c = Color::transparent;
+ if (!parseColorFromValue(*m_valueList->current(), c))
return nullptr;
- return SVGPaint::createColor(color);
+ return SVGPaint::createColor(Color(c));
}
RefPtr<SVGColor> CSSParser::parseSVGColor()
{
- Color color = parseColorFromValue(*m_valueList->current());
- if (!color.isValid())
+ RGBA32 c = Color::transparent;
+ if (!parseColorFromValue(*m_valueList->current(), c))
return nullptr;
- return SVGColor::createFromColor(color);
+ return SVGColor::createFromColor(Color(c));
}
RefPtr<CSSValueList> CSSParser::parsePaintOrder()
Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (207341 => 207342)
--- trunk/Source/WebCore/editing/EditingStyle.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -382,7 +382,7 @@
{
}
-static Color cssValueToColor(CSSValue* colorValue)
+static RGBA32 cssValueToRGBA(CSSValue* colorValue)
{
if (!is<CSSPrimitiveValue>(colorValue))
return Color::transparent;
@@ -389,26 +389,28 @@
CSSPrimitiveValue& primitiveColor = downcast<CSSPrimitiveValue>(*colorValue);
if (primitiveColor.isRGBColor())
- return primitiveColor.color();
+ return primitiveColor.getRGBA32Value();
- return CSSParser::parseColor(colorValue->cssText());
+ RGBA32 rgba = 0;
+ CSSParser::parseColor(rgba, colorValue->cssText());
+ return rgba;
}
template<typename T>
-static inline Color textColorFromStyle(T& style)
+static inline RGBA32 textColorFromStyle(T& style)
{
- return cssValueToColor(extractPropertyValue(style, CSSPropertyColor).get());
+ return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get());
}
template<typename T>
-static inline Color backgroundColorFromStyle(T& style)
+static inline RGBA32 backgroundColorFromStyle(T& style)
{
- return cssValueToColor(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
+ return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get());
}
-static inline Color rgbaBackgroundColorInEffect(Node* node)
+static inline RGBA32 rgbaBackgroundColorInEffect(Node* node)
{
- return cssValueToColor(backgroundColorInEffect(node).get());
+ return cssValueToRGBA(backgroundColorInEffect(node).get());
}
static int textAlignResolvingStartAndEnd(int textAlign, int direction)
@@ -1094,7 +1096,7 @@
m_mutableStyle->removeProperty(CSSPropertyColor);
if (hasTransparentBackgroundColor(m_mutableStyle.get())
- || cssValueToColor(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
+ || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))
m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
if (is<CSSPrimitiveValue>(unicodeBidi.get())) {
@@ -1838,7 +1840,7 @@
return false;
CSSPrimitiveValue& value = downcast<CSSPrimitiveValue>(*cssValue);
if (value.isRGBColor())
- return value.color().hasAlpha();
+ return !alphaChannel(value.getRGBA32Value());
return value.getValueID() == CSSValueTransparent;
}
Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (207341 => 207342)
--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2016-10-14 16:17:47 UTC (rev 207342)
@@ -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).color().rgb()), propertyId == CSSPropertyColor);
+ return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), 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).color().rgb()), propertyId == CSSPropertyColor);
+ return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor);
if (value->isInheritedValue())
inherit = true;
}
Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (207341 => 207342)
--- trunk/Source/WebCore/html/HTMLBodyElement.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -158,8 +158,8 @@
else
document().resetActiveLinkColor();
} else {
- Color color = CSSParser::parseColor(value, !document().inQuirksMode());
- if (color.isValid()) {
+ RGBA32 color;
+ if (CSSParser::parseColor(color, value, !document().inQuirksMode())) {
if (name == linkAttr)
document().setLinkColor(color);
else if (name == vlinkAttr)
Modified: trunk/Source/WebCore/html/canvas/CanvasGradient.cpp (207341 => 207342)
--- trunk/Source/WebCore/html/canvas/CanvasGradient.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/html/canvas/CanvasGradient.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -50,7 +50,7 @@
{
}
-void CanvasGradient::addColorStop(float value, const String& colorString, ExceptionCode& ec)
+void CanvasGradient::addColorStop(float value, const String& color, ExceptionCode& ec)
{
if (!(value >= 0 && value <= 1.0f)) {
ec = INDEX_SIZE_ERR;
@@ -57,8 +57,8 @@
return;
}
- Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);
- if (!color.isValid()) {
+ RGBA32 rgba = 0;
+ if (!parseColorOrCurrentColor(rgba, color, 0 /*canvas*/)) {
#if ENABLE(DASHBOARD_SUPPORT)
if (!m_dashboardCompatibilityMode)
ec = SYNTAX_ERR;
@@ -68,7 +68,7 @@
return;
}
- m_gradient->addColorStop(value, color);
+ m_gradient->addColorStop(value, Color(rgba));
}
} // namespace
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (207341 => 207342)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -404,10 +404,9 @@
return;
if (style.isCurrentColor()) {
- if (style.hasOverrideAlpha()) {
- // FIXME: Should not use RGBA32 here.
- style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
- } else
+ if (style.hasOverrideAlpha())
+ style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
+ else
style = CanvasStyle(currentColor(canvas()));
} else
checkOrigin(style.canvasPattern());
@@ -431,10 +430,9 @@
return;
if (style.isCurrentColor()) {
- if (style.hasOverrideAlpha()) {
- // FIXME: Should not use RGBA32 here.
- style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha()));
- } else
+ if (style.hasOverrideAlpha())
+ style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha()));
+ else
style = CanvasStyle(currentColor(canvas()));
} else
checkOrigin(style.canvasPattern());
@@ -580,15 +578,15 @@
return Color(state().shadowColor).serialized();
}
-void CanvasRenderingContext2D::setShadowColor(const String& colorString)
+void CanvasRenderingContext2D::setShadowColor(const String& color)
{
- Color color = parseColorOrCurrentColor(colorString, canvas());
- if (!color.isValid())
+ RGBA32 rgba;
+ if (!parseColorOrCurrentColor(rgba, color, canvas()))
return;
- if (state().shadowColor == color)
+ if (state().shadowColor == rgba)
return;
realizeSaves();
- modifiableState().shadowColor = color;
+ modifiableState().shadowColor = rgba;
applyShadow();
}
@@ -1250,15 +1248,12 @@
}
}
-void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& colorString, Optional<float> alpha)
+void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, Optional<float> alpha)
{
- Color color = parseColorOrCurrentColor(colorString, canvas());
- if (!colorString.isNull() && !color.isValid())
+ RGBA32 rgba = Color::transparent;
+ if (!color.isNull() && !parseColorOrCurrentColor(rgba, color, canvas()))
return;
- if (!color.isValid())
- color = Color::transparent;
- // FIXME: Should not use RGBA32 here.
- setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(color.rgb(), alpha));
+ setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(rgba, alpha));
}
void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha)
Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.cpp (207341 => 207342)
--- trunk/Source/WebCore/html/canvas/CanvasStyle.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -43,36 +43,44 @@
namespace WebCore {
-static bool isCurrentColorString(const String& colorString)
-{
- return equalLettersIgnoringASCIICase(colorString, "currentcolor");
-}
+enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, ParseFailed };
-static Color parseColor(const String& colorString, Document* document = nullptr)
+static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorString, Document* document = nullptr)
{
- Color color = CSSParser::parseColor(colorString);
- if (color.isValid())
- return color;
-
- return CSSParser::parseSystemColor(colorString, document);
+ if (equalLettersIgnoringASCIICase(colorString, "currentcolor"))
+ return ParsedCurrentColor;
+ if (CSSParser::parseColor(parsedColor, colorString))
+ return ParsedRGBA;
+ if (CSSParser::parseSystemColor(parsedColor, colorString, document))
+ return ParsedSystemColor;
+ return ParseFailed;
}
-Color currentColor(HTMLCanvasElement* canvas)
+RGBA32 currentColor(HTMLCanvasElement* canvas)
{
if (!canvas || !canvas->inDocument() || !canvas->inlineStyle())
return Color::black;
- Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
- if (!color.isValid())
- return Color::black;
- return color;
+ RGBA32 rgba = Color::black;
+ CSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
+ return rgba;
}
-Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* canvas)
+bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement* canvas)
{
- if (isCurrentColorString(colorString))
- return currentColor(canvas);
-
- return parseColor(colorString, canvas ? &canvas->document() : nullptr);
+ 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;
+ }
}
CanvasStyle::CanvasStyle(Color color)
@@ -125,28 +133,39 @@
delete m_cmyka;
}
-CanvasStyle CanvasStyle::createFromString(const String& colorString, Document* document)
+CanvasStyle CanvasStyle::createFromString(const String& color, Document* document)
{
- if (isCurrentColorString(colorString))
+ RGBA32 rgba;
+ ColorParseResult parseResult = parseColor(rgba, color, document);
+ switch (parseResult) {
+ case ParsedRGBA:
+ case ParsedSystemColor:
+ return CanvasStyle(rgba);
+ case ParsedCurrentColor:
return CanvasStyle(ConstructCurrentColor);
-
- Color color = parseColor(colorString, document);
- if (color.isValid())
- return CanvasStyle(color);
-
- return CanvasStyle();
+ case ParseFailed:
+ return CanvasStyle();
+ default:
+ ASSERT_NOT_REACHED();
+ return CanvasStyle();
+ }
}
-CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& colorString, float alpha)
+CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& color, float alpha)
{
- if (isCurrentColorString(colorString))
+ RGBA32 rgba;
+ ColorParseResult parseResult = parseColor(rgba, color);
+ switch (parseResult) {
+ case ParsedRGBA:
+ return CanvasStyle(colorWithOverrideAlpha(rgba, alpha));
+ case ParsedCurrentColor:
return CanvasStyle(CurrentColorWithOverrideAlpha, alpha);
-
- Color color = parseColor(colorString);
- if (color.isValid())
- return CanvasStyle(colorWithOverrideAlpha(color.rgb(), alpha));
-
- return CanvasStyle();
+ case ParseFailed:
+ return CanvasStyle();
+ default:
+ ASSERT_NOT_REACHED();
+ return CanvasStyle();
+ }
}
bool CanvasStyle::isEquivalentColor(const CanvasStyle& other) const
Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.h (207341 => 207342)
--- trunk/Source/WebCore/html/canvas/CanvasStyle.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -113,8 +113,8 @@
Type m_type;
};
- Color currentColor(HTMLCanvasElement*);
- Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement*);
+ RGBA32 currentColor(HTMLCanvasElement*);
+ bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement*);
inline CanvasStyle::CanvasStyle()
: m_type(Invalid)
Modified: trunk/Source/WebCore/platform/graphics/Color.h (207341 => 207342)
--- trunk/Source/WebCore/platform/graphics/Color.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/platform/graphics/Color.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -141,23 +141,6 @@
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);
@@ -201,7 +184,6 @@
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;
Deleted: trunk/Source/WebCore/platform/graphics/ColorHash.h (207341 => 207342)
--- trunk/Source/WebCore/platform/graphics/ColorHash.h 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/platform/graphics/ColorHash.h 2016-10-14 16:17:47 UTC (rev 207342)
@@ -1,51 +0,0 @@
-/*
- * 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
Modified: trunk/Source/WebCore/svg/SVGColor.cpp (207341 => 207342)
--- trunk/Source/WebCore/svg/SVGColor.cpp 2016-10-14 15:58:16 UTC (rev 207341)
+++ trunk/Source/WebCore/svg/SVGColor.cpp 2016-10-14 16:17:47 UTC (rev 207342)
@@ -51,7 +51,10 @@
// 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?
- return CSSParser::parseColor(colorString.stripWhiteSpace());
+ RGBA32 color;
+ if (CSSParser::parseColor(color, colorString.stripWhiteSpace()))
+ return color;
+ return Color();
}
void SVGColor::setRGBColor(const String&, ExceptionCode& ec)