Changeset 207342 in webkit
- Timestamp:
- Oct 14, 2016, 9:17:47 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207339 r207342 1 2016-10-14 Commit Queue <commit-queue@webkit.org> 2 3 Unreviewed, rolling out r207317. 4 https://bugs.webkit.org/show_bug.cgi?id=163448 5 6 This change caused an existing LayoutTest to fail on all 7 platforms (Requested by ryanhaddad on #webkit). 8 9 Reverted changeset: 10 11 "CSS parsing should use Color not RGBA32" 12 https://bugs.webkit.org/show_bug.cgi?id=163423 13 http://trac.webkit.org/changeset/207317 14 1 15 2016-10-14 Antti Koivisto <antti@apple.com> 2 16 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r207317 r207342 1298 1298 2EF1BFEB121C9F4200C27627 /* FileStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EF1BFE9121C9F4200C27627 /* FileStream.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1299 1299 2EF1BFF9121CB0CE00C27627 /* FileStreamClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EF1BFF8121CB0CE00C27627 /* FileStreamClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1300 3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 3103B7DE1DB01556008BB890 /* ColorHash.h */; settings = {ATTRIBUTES = (Private, ); }; };1301 1300 3106036F14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */; }; 1302 1301 3106037014327D2E00ABF4BA /* WebKitCSSFilterValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 8263 8262 2EF1BFE9121C9F4200C27627 /* FileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStream.h; sourceTree = "<group>"; }; 8264 8263 2EF1BFF8121CB0CE00C27627 /* FileStreamClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileStreamClient.h; sourceTree = "<group>"; }; 8265 3103B7DE1DB01556008BB890 /* ColorHash.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorHash.h; sourceTree = "<group>"; };8266 8264 3106036C14327D2E00ABF4BA /* WebKitCSSFilterValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSFilterValue.cpp; sourceTree = "<group>"; }; 8267 8265 3106036D14327D2E00ABF4BA /* WebKitCSSFilterValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSFilterValue.h; sourceTree = "<group>"; }; … … 20737 20735 B27535380B053814002CE64F /* Color.cpp */, 20738 20736 B27535390B053814002CE64F /* Color.h */, 20739 3103B7DE1DB01556008BB890 /* ColorHash.h */,20740 20737 31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */, 20741 20738 31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */, … … 25390 25387 FDA15ECE12B03F61003A583A /* JSScriptProcessorNode.h in Headers */, 25391 25388 CED06AD11C77754800FDFAF1 /* JSSecurityPolicyViolationEvent.h in Headers */, 25392 3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */,25393 25389 9BDA64D81B975CF2009C4387 /* JSShadowRoot.h in Headers */, 25394 25390 CD9DE17B17AAC75B00EA386D /* JSSourceBuffer.h in Headers */, -
trunk/Source/WebCore/css/CSSPrimitiveValue.cpp
r207317 r207342 351 351 } 352 352 353 CSSPrimitiveValue::CSSPrimitiveValue( const Color&color)353 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) 354 354 : CSSValue(PrimitiveClass) 355 355 { 356 356 m_primitiveUnitType = CSS_RGBCOLOR; 357 m_value. color = new Color(color);357 m_value.rgbcolor = color; 358 358 } 359 359 … … 575 575 m_value.fontFamily = nullptr; 576 576 break; 577 case CSS_RGBCOLOR:578 ASSERT(m_value.color);579 delete m_value.color;580 m_value.color = nullptr;581 break;582 577 case CSS_NUMBER: 583 578 case CSS_PARSER_INTEGER: … … 611 606 case CSS_FR: 612 607 case CSS_IDENT: 608 case CSS_RGBCOLOR: 613 609 case CSS_UNKNOWN: 614 610 case CSS_UNICODE_RANGE: … … 1033 1029 1034 1030 // FIMXE: This should not return a new object for each invocation. 1035 return RGBColor::create(m_value. color->rgb());1031 return RGBColor::create(m_value.rgbcolor); 1036 1032 } 1037 1033 … … 1180 1176 return getLengthRepeatValue()->cssText(); 1181 1177 #endif 1178 case CSS_RGBCOLOR: 1182 1179 case CSS_PARSER_HEXCOLOR: { 1183 RGBA32 rgb; 1184 Color::parseHexColor((String)m_value.string, rgb); 1185 return Color(rgb).cssText(); 1186 } 1187 case CSS_RGBCOLOR: 1188 return color().cssText(); 1180 RGBA32 rgbColor = m_value.rgbcolor; 1181 if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR) 1182 Color::parseHexColor((String)m_value.string, rgbColor); 1183 return Color(rgbColor).cssText(); 1184 } 1189 1185 case CSS_PAIR: 1190 1186 return getPairValue()->cssText(); … … 1356 1352 break; 1357 1353 case CSS_RGBCOLOR: 1358 result = CSSPrimitiveValue::create (*m_value.color);1354 result = CSSPrimitiveValue::createColor(m_value.rgbcolor); 1359 1355 break; 1360 1356 case CSS_DIMENSION: … … 1435 1431 #endif 1436 1432 case CSS_RGBCOLOR: 1437 return color() == other.color();1433 return m_value.rgbcolor == other.m_value.rgbcolor; 1438 1434 case CSS_PAIR: 1439 1435 return m_value.pair && other.m_value.pair && m_value.pair->equals(*other.m_value.pair); -
trunk/Source/WebCore/css/CSSPrimitiveValue.h
r207317 r207342 254 254 static Ref<CSSPrimitiveValue> createParserOperator(int parserOperator) { return adoptRef(*new CSSPrimitiveValue(parserOperator)); } 255 255 256 static Ref<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(*new CSSPrimitiveValue(rgbValue)); } 256 257 static Ref<CSSPrimitiveValue> create(double value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); } 257 258 static Ref<CSSPrimitiveValue> create(const String& value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); } … … 342 343 343 344 WEBCORE_EXPORT Counter* getCounterValue(ExceptionCode&) const; 344 Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? nullptr: m_value.counter; }345 Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; } 345 346 346 347 WEBCORE_EXPORT Rect* getRectValue(ExceptionCode&) const; 347 Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? nullptr: m_value.rect; }348 Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; } 348 349 349 350 Quad* getQuadValue(ExceptionCode&) const; 350 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? nullptr: m_value.quad; }351 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; } 351 352 352 353 #if ENABLE(CSS_SCROLL_SNAP) 353 354 LengthRepeat* getLengthRepeatValue(ExceptionCode&) const; 354 LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? nullptr: m_value.lengthRepeat; }355 LengthRepeat* getLengthRepeatValue() const { return m_primitiveUnitType != CSS_LENGTH_REPEAT ? 0 : m_value.lengthRepeat; } 355 356 #endif 356 357 357 358 WEBCORE_EXPORT RefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const; 358 const Color& color() const { ASSERT(m_primitiveUnitType == CSS_RGBCOLOR); return *m_value.color; }359 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; } 359 360 360 361 Pair* getPairValue(ExceptionCode&) const; … … 404 405 // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases. 405 406 CSSPrimitiveValue(int parserOperator); 406 CSSPrimitiveValue( const Color&);407 CSSPrimitiveValue(unsigned color); // RGB value 407 408 CSSPrimitiveValue(const Length&); 408 409 CSSPrimitiveValue(const Length&, const RenderStyle&); … … 464 465 LengthRepeat* lengthRepeat; 465 466 #endif 466 const Color*color;467 unsigned rgbcolor; 467 468 Pair* pair; 468 469 DashboardRegion* region; -
trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h
r207317 r207342 4940 4940 } 4941 4941 4942 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(const Color& color)4943 : CSSValue(PrimitiveClass)4944 {4945 m_primitiveUnitType = CSS_RGBCOLOR;4946 m_value.color = new Color(color);4947 }4948 4949 4942 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(CSSFontFamily fontFamily) 4950 4943 : CSSValue(PrimitiveClass) -
trunk/Source/WebCore/css/CSSValuePool.cpp
r207317 r207342 49 49 m_revertValue.construct(); 50 50 51 m_transparentColor.construct(Color (Color::transparent));52 m_whiteColor.construct(Color (Color::white));53 m_blackColor.construct(Color (Color::black));51 m_transparentColor.construct(Color::transparent); 52 m_whiteColor.construct(Color::white); 53 m_blackColor.construct(Color::black); 54 54 55 55 for (unsigned i = 0; i < numCSSValueKeywords; ++i) … … 74 74 } 75 75 76 Ref<CSSPrimitiveValue> CSSValuePool::createColorValue( const Color& color)76 Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue) 77 77 { 78 78 // These are the empty and deleted values of the hash table. 79 if ( color== Color::transparent)79 if (rgbValue == Color::transparent) 80 80 return m_transparentColor.get(); 81 if ( color== Color::white)81 if (rgbValue == Color::white) 82 82 return m_whiteColor.get(); 83 83 // Just because it is common. 84 if ( color== Color::black)84 if (rgbValue == Color::black) 85 85 return m_blackColor.get(); 86 86 … … 90 90 m_colorValueCache.remove(m_colorValueCache.begin()); 91 91 92 ColorValueCache::AddResult entry = m_colorValueCache.add( color, nullptr);92 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, nullptr); 93 93 if (entry.isNewEntry) 94 entry.iterator->value = CSSPrimitiveValue::create (color);94 entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue); 95 95 return *entry.iterator->value; 96 96 } -
trunk/Source/WebCore/css/CSSValuePool.h
r207317 r207342 35 35 #include "CSSUnsetValue.h" 36 36 #include "CSSValueKeywords.h" 37 #include "ColorHash.h"38 37 #include <utility> 39 38 #include <wtf/HashMap.h> … … 62 61 Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier); 63 62 Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier); 64 Ref<CSSPrimitiveValue> createColorValue( const Color&);63 Ref<CSSPrimitiveValue> createColorValue(unsigned rgbValue); 65 64 Ref<CSSPrimitiveValue> createValue(double value, CSSPrimitiveValue::UnitTypes); 66 65 Ref<CSSPrimitiveValue> createValue(const String& value, CSSPrimitiveValue::UnitTypes type) { return CSSPrimitiveValue::create(value, type); } … … 74 73 CSSValuePool(); 75 74 76 typedef HashMap< Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;75 typedef HashMap<unsigned, RefPtr<CSSPrimitiveValue>> ColorValueCache; 77 76 ColorValueCache m_colorValueCache; 78 77 -
trunk/Source/WebCore/css/StyleResolver.cpp
r207317 r207342 1832 1832 { 1833 1833 if (value.isRGBColor()) 1834 return value.color();1834 return Color(value.getRGBA32Value()); 1835 1835 1836 1836 const State& state = m_state; -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r207317 r207342 495 495 return declaration.addParsedProperty(CSSProperty(propertyId, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged; 496 496 } 497 Color color = CSSParser::fastParseColor(string, strict && string[0] != '#');498 if (! color.isValid())497 RGBA32 color; 498 if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#')) 499 499 return CSSParser::ParseResult::Error; 500 500 … … 1371 1371 } 1372 1372 1373 Color CSSParser::parseColor(const String& string, bool strict) 1373 // The color will only be changed when string contains a valid CSS color, so callers 1374 // can set it to a default color and ignore the boolean result. 1375 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict) 1374 1376 { 1375 1377 if (string.isEmpty()) 1376 return Color();1378 return false; 1377 1379 1378 1380 // First try creating a color specified by name, rgba(), rgb() or "#" syntax. 1379 Color color = fastParseColor(string, strict); 1380 if (color.isValid()) 1381 return color; 1381 if (fastParseColor(color, string, strict)) 1382 return true; 1382 1383 1383 1384 CSSParser parser(HTMLStandardMode); 1384 1385 1385 1386 // In case the fast-path parser didn't understand the color, try the full parser. 1386 if (!parser.parseColor FromString(string))1387 return Color();1387 if (!parser.parseColor(string)) 1388 return false; 1388 1389 1389 1390 CSSValue& value = *parser.m_parsedProperties.first().value(); 1390 1391 if (!is<CSSPrimitiveValue>(value)) 1391 return Color();1392 return false; 1392 1393 1393 1394 CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value); 1394 1395 if (!primitiveValue.isRGBColor()) 1395 return Color(); 1396 1397 return primitiveValue.color(); 1398 } 1399 1400 bool CSSParser::parseColorFromString(const String& string) 1396 return false; 1397 1398 color = primitiveValue.getRGBA32Value(); 1399 return true; 1400 } 1401 1402 bool CSSParser::parseColor(const String& string) 1401 1403 { 1402 1404 setupParser("@-webkit-decls{color:", string, "} "); … … 1407 1409 } 1408 1410 1409 Color CSSParser::parseSystemColor(const String& string, Document* document)1411 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document) 1410 1412 { 1411 1413 if (!document || !document->page()) 1412 return Color();1414 return false; 1413 1415 1414 1416 CSSParserString cssColor; … … 1416 1418 CSSValueID id = cssValueKeywordID(cssColor); 1417 1419 if (!validPrimitiveValueColor(id)) 1418 return Color(); 1419 1420 return document->page()->theme().systemColor(id); 1420 return false; 1421 1422 Color parsedColor = document->page()->theme().systemColor(id); 1423 if (!parsedColor.isValid()) 1424 return false; 1425 1426 color = parsedColor.rgb(); 1427 return true; 1421 1428 } 1422 1429 … … 7475 7482 7476 7483 template <typename CharacterType> 7477 static inline Color fastParseColorInternal(const CharacterType* characters, unsigned length , bool strict)7484 static inline bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length , bool strict) 7478 7485 { 7479 7486 CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::CSS_UNKNOWN; 7480 7487 7481 7488 if (!strict && length >= 3) { 7482 RGBA32 rgb;7483 7489 if (characters[0] == '#') { 7484 7490 if (Color::parseHexColor(characters + 1, length - 1, rgb)) 7485 return Color(rgb);7491 return true; 7486 7492 } else { 7487 7493 if (Color::parseHexColor(characters, length, rgb)) 7488 return Color(rgb);7494 return true; 7489 7495 } 7490 7496 } … … 7500 7506 7501 7507 if (!parseColorIntOrPercentage(current, end, ',', expect, red)) 7502 return Color();7508 return false; 7503 7509 if (!parseColorIntOrPercentage(current, end, ',', expect, green)) 7504 return Color();7510 return false; 7505 7511 if (!parseColorIntOrPercentage(current, end, ',', expect, blue)) 7506 return Color();7512 return false; 7507 7513 if (!parseAlphaValue(current, end, ')', alpha)) 7508 return Color();7514 return false; 7509 7515 if (current != end) 7510 return Color(); 7511 return Color(makeRGBA(red, green, blue, alpha)); 7516 return false; 7517 rgb = makeRGBA(red, green, blue, alpha); 7518 return true; 7512 7519 } 7513 7520 … … 7520 7527 int blue; 7521 7528 if (!parseColorIntOrPercentage(current, end, ',', expect, red)) 7522 return Color();7529 return false; 7523 7530 if (!parseColorIntOrPercentage(current, end, ',', expect, green)) 7524 return Color();7531 return false; 7525 7532 if (!parseColorIntOrPercentage(current, end, ')', expect, blue)) 7526 return Color();7533 return false; 7527 7534 if (current != end) 7528 return Color(); 7529 return Color(makeRGB(red, green, blue)); 7530 } 7531 7532 return Color(); 7535 return false; 7536 rgb = makeRGB(red, green, blue); 7537 return true; 7538 } 7539 7540 return false; 7533 7541 } 7534 7542 7535 7543 template<typename StringType> 7536 Color CSSParser::fastParseColor(const StringType& name, bool strict)7544 bool CSSParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict) 7537 7545 { 7538 7546 unsigned length = name.length(); 7547 bool parseResult; 7539 7548 7540 7549 if (!length) 7541 return Color(); 7542 7543 Color color; 7550 return false; 7551 7544 7552 if (name.is8Bit()) 7545 color = fastParseColorInternal(name.characters8(), length, strict);7553 parseResult = fastParseColorInternal(rgb, name.characters8(), length, strict); 7546 7554 else 7547 color = fastParseColorInternal(name.characters16(), length, strict);7548 7549 if ( color.isValid())7550 return color;7555 parseResult = fastParseColorInternal(rgb, name.characters16(), length, strict); 7556 7557 if (parseResult) 7558 return true; 7551 7559 7552 7560 // Try named colors. 7553 color.setNamedColor(name); 7554 return color; 7561 Color tc; 7562 tc.setNamedColor(name); 7563 if (tc.isValid()) { 7564 rgb = tc.rgb(); 7565 return true; 7566 } 7567 return false; 7555 7568 } 7556 7569 … … 7668 7681 RefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value) 7669 7682 { 7670 Color color = parseColorFromValue(value ? *value : *m_valueList->current());7671 if (! color.isValid())7683 RGBA32 c = Color::transparent; 7684 if (!parseColorFromValue(value ? *value : *m_valueList->current(), c)) 7672 7685 return nullptr; 7673 return CSSValuePool::singleton().createColorValue(c olor);7674 } 7675 7676 Color CSSParser::parseColorFromValue(CSSParserValue& value)7686 return CSSValuePool::singleton().createColorValue(c); 7687 } 7688 7689 bool CSSParser::parseColorFromValue(CSSParserValue& value, RGBA32& c) 7677 7690 { 7678 7691 if (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_NUMBER … … 7680 7693 String str = String::format("%06d", static_cast<int>((value.fValue+.5))); 7681 7694 // FIXME: This should be strict parsing for SVG as well. 7682 return fastParseColor(str, inStrictMode()); 7695 if (!fastParseColor(c, str, inStrictMode())) 7696 return false; 7683 7697 } else if (value.unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR 7684 7698 || value.unit == CSSPrimitiveValue::CSS_IDENT 7685 7699 || (inQuirksMode() && value.unit == CSSPrimitiveValue::CSS_DIMENSION)) { 7686 return fastParseColor(value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT); 7700 if (!fastParseColor(c, value.string, inStrictMode() && value.unit == CSSPrimitiveValue::CSS_IDENT)) 7701 return false; 7687 7702 } else if (value.unit == CSSParserValue::Function 7688 7703 && value.function->args … … 7691 7706 int colorValues[3]; 7692 7707 if (!parseRGBParameters(value, colorValues, false)) 7693 return Color();7694 return Color(makeRGB(colorValues[0], colorValues[1], colorValues[2]));7708 return false; 7709 c = makeRGB(colorValues[0], colorValues[1], colorValues[2]); 7695 7710 } else if (value.unit == CSSParserValue::Function 7696 7711 && value.function->args … … 7699 7714 int colorValues[4]; 7700 7715 if (!parseRGBParameters(value, colorValues, true)) 7701 return Color();7702 return Color(makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]));7716 return false; 7717 c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]); 7703 7718 } else if (value.unit == CSSParserValue::Function 7704 7719 && value.function->args … … 7707 7722 double colorValues[3]; 7708 7723 if (!parseHSLParameters(value, colorValues, false)) 7709 return Color();7710 return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0));7724 return false; 7725 c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0); 7711 7726 } else if (value.unit == CSSParserValue::Function 7712 7727 && value.function->args … … 7715 7730 double colorValues[4]; 7716 7731 if (!parseHSLParameters(value, colorValues, true)) 7717 return Color(); 7718 return Color(makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3])); 7719 } 7720 7721 return Color(); 7732 return false; 7733 c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]); 7734 } else 7735 return false; 7736 7737 return true; 7722 7738 } 7723 7739 -
trunk/Source/WebCore/css/parser/CSSParser.h
r207317 r207342 135 135 static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet); 136 136 137 static Color parseColor(const String&, bool strict = false);137 static bool parseColor(RGBA32& color, const String&, bool strict = false); 138 138 static bool isValidSystemColorValue(CSSValueID); 139 static Color parseSystemColor(const String&, Document*);139 static bool parseSystemColor(RGBA32& color, const String&, Document*); 140 140 static RefPtr<CSSValueList> parseFontFaceValue(const AtomicString&); 141 141 RefPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, ValueWithCalculation&); … … 279 279 bool parseHSLParameters(CSSParserValue&, double* colorValues, bool parseAlpha); 280 280 RefPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = nullptr); 281 Color parseColorFromValue(CSSParserValue&);281 bool parseColorFromValue(CSSParserValue&, RGBA32&); 282 282 void parseSelector(const String&, CSSSelectorList&); 283 283 284 284 template<typename StringType> 285 static Color fastParseColor(const StringType&, bool strict);285 static bool fastParseColor(RGBA32&, const StringType&, bool strict); 286 286 287 287 bool parseLineHeight(bool important); … … 619 619 bool parseFontFaceSrcLocal(CSSValueList&); 620 620 621 bool parseColor FromString(const String&);621 bool parseColor(const String&); 622 622 623 623 #if ENABLE(CSS_GRID_LAYOUT) -
trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp
r207317 r207342 412 412 413 413 template <typename CharacterType> 414 static Color fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)414 static bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length, bool quirksMode) 415 415 { 416 416 CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::UnitTypes::CSS_UNKNOWN; 417 417 418 if (length >= 4 && characters[0] == '#') { 419 // FIXME: Why doesn't this check if the parse worked? Is the fallback black? 420 RGBA32 rgb; 421 Color::parseHexColor(characters + 1, length - 1, rgb); 422 return Color(rgb); 423 } 418 if (length >= 4 && characters[0] == '#') 419 return Color::parseHexColor(characters + 1, length - 1, rgb); 424 420 425 421 if (quirksMode && (length == 3 || length == 6)) { 426 RGBA32 rgb;427 422 if (Color::parseHexColor(characters, length, rgb)) 428 return Color(rgb);423 return true; 429 424 } 430 425 … … 439 434 440 435 if (!parseColorIntOrPercentage(current, end, ',', expect, red)) 441 return Color();436 return false; 442 437 if (!parseColorIntOrPercentage(current, end, ',', expect, green)) 443 return Color();438 return false; 444 439 if (!parseColorIntOrPercentage(current, end, ',', expect, blue)) 445 return Color();440 return false; 446 441 if (!parseAlphaValue(current, end, ')', alpha)) 447 return Color();442 return false; 448 443 if (current != end) 449 return Color(); 450 return Color(makeRGBA(red, green, blue, alpha)); 444 return false; 445 rgb = makeRGBA(red, green, blue, alpha); 446 return true; 451 447 } 452 448 … … 459 455 int blue; 460 456 if (!parseColorIntOrPercentage(current, end, ',', expect, red)) 461 return Color();457 return false; 462 458 if (!parseColorIntOrPercentage(current, end, ',', expect, green)) 463 return Color();459 return false; 464 460 if (!parseColorIntOrPercentage(current, end, ')', expect, blue)) 465 return Color();461 return false; 466 462 if (current != end) 467 return Color(); 468 return Color(makeRGB(red, green, blue)); 469 } 470 471 return Color(); 463 return false; 464 rgb = makeRGB(red, green, blue); 465 return true; 466 } 467 468 return false; 472 469 } 473 470 … … 482 479 } 483 480 481 RGBA32 color; 484 482 bool quirksMode = isQuirksModeBehavior(parserMode); 485 483 486 484 // Fast path for hex colors and rgb()/rgba() colors 487 Color color;485 bool parseResult; 488 486 if (string.is8Bit()) 489 color = fastParseColorInternal(string.characters8(), string.length(), quirksMode);487 parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode); 490 488 else 491 color = fastParseColorInternal(string.characters16(), string.length(), quirksMode);492 if (! color.isValid())489 parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode); 490 if (!parseResult) 493 491 return nullptr; 494 492 return CSSValuePool::singleton().createColorValue(color); -
trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
r207317 r207342 510 510 if (!parseHexColor(range, color, acceptQuirkyColors) && !parseColorFunction(range, color)) 511 511 return nullptr; 512 return CSSPrimitiveValue::create (Color(color));512 return CSSPrimitiveValue::createColor(color); 513 513 } 514 514 -
trunk/Source/WebCore/css/parser/SVGCSSParser.cpp
r207317 r207342 132 132 parsedValue = SVGPaint::createColor(RenderTheme::defaultTheme()->systemColor(id)); 133 133 else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) { 134 RGBA32 c = Color::transparent; 134 135 if (m_valueList->next()) { 135 Color color = parseColorFromValue(*m_valueList->current()); 136 if (color.isValid()) 137 parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, color); 136 if (parseColorFromValue(*m_valueList->current(), c)) 137 parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, c); 138 138 else if (m_valueList->current()->id == CSSValueNone) 139 139 parsedValue = SVGPaint::createURIAndNone(valueWithCalculation.value().string); … … 287 287 RefPtr<SVGPaint> CSSParser::parseSVGPaint() 288 288 { 289 Color color = parseColorFromValue(*m_valueList->current());290 if (! color.isValid())289 RGBA32 c = Color::transparent; 290 if (!parseColorFromValue(*m_valueList->current(), c)) 291 291 return nullptr; 292 return SVGPaint::createColor( color);292 return SVGPaint::createColor(Color(c)); 293 293 } 294 294 295 295 RefPtr<SVGColor> CSSParser::parseSVGColor() 296 296 { 297 Color color = parseColorFromValue(*m_valueList->current());298 if (! color.isValid())297 RGBA32 c = Color::transparent; 298 if (!parseColorFromValue(*m_valueList->current(), c)) 299 299 return nullptr; 300 return SVGColor::createFromColor( color);300 return SVGColor::createFromColor(Color(c)); 301 301 } 302 302 -
trunk/Source/WebCore/editing/EditingStyle.cpp
r207317 r207342 383 383 } 384 384 385 static Color cssValueToColor(CSSValue* colorValue)385 static RGBA32 cssValueToRGBA(CSSValue* colorValue) 386 386 { 387 387 if (!is<CSSPrimitiveValue>(colorValue)) … … 390 390 CSSPrimitiveValue& primitiveColor = downcast<CSSPrimitiveValue>(*colorValue); 391 391 if (primitiveColor.isRGBColor()) 392 return primitiveColor. color();392 return primitiveColor.getRGBA32Value(); 393 393 394 return CSSParser::parseColor(colorValue->cssText()); 394 RGBA32 rgba = 0; 395 CSSParser::parseColor(rgba, colorValue->cssText()); 396 return rgba; 395 397 } 396 398 397 399 template<typename T> 398 static inline ColortextColorFromStyle(T& style)399 { 400 return cssValueTo Color(extractPropertyValue(style, CSSPropertyColor).get());400 static inline RGBA32 textColorFromStyle(T& style) 401 { 402 return cssValueToRGBA(extractPropertyValue(style, CSSPropertyColor).get()); 401 403 } 402 404 403 405 template<typename T> 404 static inline ColorbackgroundColorFromStyle(T& style)405 { 406 return cssValueTo Color(extractPropertyValue(style, CSSPropertyBackgroundColor).get());407 } 408 409 static inline ColorrgbaBackgroundColorInEffect(Node* node)410 { 411 return cssValueTo Color(backgroundColorInEffect(node).get());406 static inline RGBA32 backgroundColorFromStyle(T& style) 407 { 408 return cssValueToRGBA(extractPropertyValue(style, CSSPropertyBackgroundColor).get()); 409 } 410 411 static inline RGBA32 rgbaBackgroundColorInEffect(Node* node) 412 { 413 return cssValueToRGBA(backgroundColorInEffect(node).get()); 412 414 } 413 415 … … 1095 1097 1096 1098 if (hasTransparentBackgroundColor(m_mutableStyle.get()) 1097 || cssValueTo Color(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode()))1099 || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor).get()) == rgbaBackgroundColorInEffect(position.containerNode())) 1098 1100 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor); 1099 1101 … … 1839 1841 CSSPrimitiveValue& value = downcast<CSSPrimitiveValue>(*cssValue); 1840 1842 if (value.isRGBColor()) 1841 return value.color().hasAlpha();1843 return !alphaChannel(value.getRGBA32Value()); 1842 1844 return value.getValueID() == CSSValueTransparent; 1843 1845 } -
trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm
r207317 r207342 990 990 if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) { 991 991 if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor()) 992 return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value). color().rgb()), propertyId == CSSPropertyColor);992 return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor); 993 993 } 994 994 … … 996 996 if (RefPtr<CSSValue> value = inlineStylePropertyForElement(element, propertyId)) { 997 997 if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor()) 998 return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value). color().rgb()), propertyId == CSSPropertyColor);998 return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).getRGBA32Value()), propertyId == CSSPropertyColor); 999 999 if (value->isInheritedValue()) 1000 1000 inherit = true; -
trunk/Source/WebCore/html/HTMLBodyElement.cpp
r207317 r207342 159 159 document().resetActiveLinkColor(); 160 160 } else { 161 Color color = CSSParser::parseColor(value, !document().inQuirksMode());162 if ( color.isValid()) {161 RGBA32 color; 162 if (CSSParser::parseColor(color, value, !document().inQuirksMode())) { 163 163 if (name == linkAttr) 164 164 document().setLinkColor(color); -
trunk/Source/WebCore/html/canvas/CanvasGradient.cpp
r207317 r207342 51 51 } 52 52 53 void CanvasGradient::addColorStop(float value, const String& color String, ExceptionCode& ec)53 void CanvasGradient::addColorStop(float value, const String& color, ExceptionCode& ec) 54 54 { 55 55 if (!(value >= 0 && value <= 1.0f)) { … … 58 58 } 59 59 60 Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);61 if (! color.isValid()) {60 RGBA32 rgba = 0; 61 if (!parseColorOrCurrentColor(rgba, color, 0 /*canvas*/)) { 62 62 #if ENABLE(DASHBOARD_SUPPORT) 63 63 if (!m_dashboardCompatibilityMode) … … 69 69 } 70 70 71 m_gradient->addColorStop(value, color);71 m_gradient->addColorStop(value, Color(rgba)); 72 72 } 73 73 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r207317 r207342 405 405 406 406 if (style.isCurrentColor()) { 407 if (style.hasOverrideAlpha()) { 408 // FIXME: Should not use RGBA32 here. 409 style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha())); 410 } else 407 if (style.hasOverrideAlpha()) 408 style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha())); 409 else 411 410 style = CanvasStyle(currentColor(canvas())); 412 411 } else … … 432 431 433 432 if (style.isCurrentColor()) { 434 if (style.hasOverrideAlpha()) { 435 // FIXME: Should not use RGBA32 here. 436 style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()).rgb(), style.overrideAlpha())); 437 } else 433 if (style.hasOverrideAlpha()) 434 style = CanvasStyle(colorWithOverrideAlpha(currentColor(canvas()), style.overrideAlpha())); 435 else 438 436 style = CanvasStyle(currentColor(canvas())); 439 437 } else … … 581 579 } 582 580 583 void CanvasRenderingContext2D::setShadowColor(const String& color String)584 { 585 Color color = parseColorOrCurrentColor(colorString, canvas());586 if (! color.isValid())587 return; 588 if (state().shadowColor == color)589 return; 590 realizeSaves(); 591 modifiableState().shadowColor = color;581 void CanvasRenderingContext2D::setShadowColor(const String& color) 582 { 583 RGBA32 rgba; 584 if (!parseColorOrCurrentColor(rgba, color, canvas())) 585 return; 586 if (state().shadowColor == rgba) 587 return; 588 realizeSaves(); 589 modifiableState().shadowColor = rgba; 592 590 applyShadow(); 593 591 } … … 1251 1249 } 1252 1250 1253 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& colorString, Optional<float> alpha) 1254 { 1255 Color color = parseColorOrCurrentColor(colorString, canvas()); 1256 if (!colorString.isNull() && !color.isValid()) 1257 return; 1258 if (!color.isValid()) 1259 color = Color::transparent; 1260 // FIXME: Should not use RGBA32 here. 1261 setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(color.rgb(), alpha)); 1251 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, Optional<float> alpha) 1252 { 1253 RGBA32 rgba = Color::transparent; 1254 if (!color.isNull() && !parseColorOrCurrentColor(rgba, color, canvas())) 1255 return; 1256 setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(rgba, alpha)); 1262 1257 } 1263 1258 -
trunk/Source/WebCore/html/canvas/CanvasStyle.cpp
r207317 r207342 44 44 namespace WebCore { 45 45 46 static bool isCurrentColorString(const String& colorString) 47 { 48 return equalLettersIgnoringASCIICase(colorString, "currentcolor"); 49 } 50 51 static Color parseColor(const String& colorString, Document* document = nullptr) 52 { 53 Color color = CSSParser::parseColor(colorString); 54 if (color.isValid()) 55 return color; 56 57 return CSSParser::parseSystemColor(colorString, document); 58 } 59 60 Color currentColor(HTMLCanvasElement* canvas) 46 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, ParseFailed }; 47 48 static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorString, Document* document = nullptr) 49 { 50 if (equalLettersIgnoringASCIICase(colorString, "currentcolor")) 51 return ParsedCurrentColor; 52 if (CSSParser::parseColor(parsedColor, colorString)) 53 return ParsedRGBA; 54 if (CSSParser::parseSystemColor(parsedColor, colorString, document)) 55 return ParsedSystemColor; 56 return ParseFailed; 57 } 58 59 RGBA32 currentColor(HTMLCanvasElement* canvas) 61 60 { 62 61 if (!canvas || !canvas->inDocument() || !canvas->inlineStyle()) 63 62 return Color::black; 64 Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor)); 65 if (!color.isValid()) 66 return Color::black; 67 return color; 68 } 69 70 Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* canvas) 71 { 72 if (isCurrentColorString(colorString)) 73 return currentColor(canvas); 74 75 return parseColor(colorString, canvas ? &canvas->document() : nullptr); 63 RGBA32 rgba = Color::black; 64 CSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSSPropertyColor)); 65 return rgba; 66 } 67 68 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement* canvas) 69 { 70 ColorParseResult parseResult = parseColor(parsedColor, colorString, canvas ? &canvas->document() : 0); 71 switch (parseResult) { 72 case ParsedRGBA: 73 case ParsedSystemColor: 74 return true; 75 case ParsedCurrentColor: 76 parsedColor = currentColor(canvas); 77 return true; 78 case ParseFailed: 79 return false; 80 default: 81 ASSERT_NOT_REACHED(); 82 return false; 83 } 76 84 } 77 85 … … 126 134 } 127 135 128 CanvasStyle CanvasStyle::createFromString(const String& colorString, Document* document) 129 { 130 if (isCurrentColorString(colorString)) 136 CanvasStyle CanvasStyle::createFromString(const String& color, Document* document) 137 { 138 RGBA32 rgba; 139 ColorParseResult parseResult = parseColor(rgba, color, document); 140 switch (parseResult) { 141 case ParsedRGBA: 142 case ParsedSystemColor: 143 return CanvasStyle(rgba); 144 case ParsedCurrentColor: 131 145 return CanvasStyle(ConstructCurrentColor); 132 133 Color color = parseColor(colorString, document); 134 if (color.isValid()) 135 return CanvasStyle(color); 136 137 return CanvasStyle(); 138 } 139 140 CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& colorString, float alpha) 141 { 142 if (isCurrentColorString(colorString)) 146 case ParseFailed: 147 return CanvasStyle(); 148 default: 149 ASSERT_NOT_REACHED(); 150 return CanvasStyle(); 151 } 152 } 153 154 CanvasStyle CanvasStyle::createFromStringWithOverrideAlpha(const String& color, float alpha) 155 { 156 RGBA32 rgba; 157 ColorParseResult parseResult = parseColor(rgba, color); 158 switch (parseResult) { 159 case ParsedRGBA: 160 return CanvasStyle(colorWithOverrideAlpha(rgba, alpha)); 161 case ParsedCurrentColor: 143 162 return CanvasStyle(CurrentColorWithOverrideAlpha, alpha); 144 145 Color color = parseColor(colorString);146 if (color.isValid())147 return CanvasStyle(colorWithOverrideAlpha(color.rgb(), alpha));148 149 return CanvasStyle();163 case ParseFailed: 164 return CanvasStyle(); 165 default: 166 ASSERT_NOT_REACHED(); 167 return CanvasStyle(); 168 } 150 169 } 151 170 -
trunk/Source/WebCore/html/canvas/CanvasStyle.h
r207317 r207342 114 114 }; 115 115 116 ColorcurrentColor(HTMLCanvasElement*);117 Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement*);116 RGBA32 currentColor(HTMLCanvasElement*); 117 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement*); 118 118 119 119 inline CanvasStyle::CanvasStyle() -
trunk/Source/WebCore/platform/graphics/Color.h
r207317 r207342 142 142 explicit Color(const char*); 143 143 144 explicit Color(WTF::HashTableDeletedValueType)145 {146 m_colorData.rgbaAndFlags = 0xfffffffffffffffd;147 ASSERT(!isExtended());148 }149 150 bool isHashTableDeletedValue() const151 {152 return m_colorData.rgbaAndFlags == 0xfffffffffffffffd;153 }154 155 explicit Color(WTF::HashTableEmptyValueType)156 {157 m_colorData.rgbaAndFlags = 0xffffffffffffffb;158 ASSERT(!isExtended());159 }160 161 144 // FIXME: Add constructor for ExtendedColor type. 162 145 … … 202 185 void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); } 203 186 void setRGB(RGBA32); 204 uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }205 187 206 188 WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const; -
trunk/Source/WebCore/svg/SVGColor.cpp
r207317 r207342 52 52 // FIXME: Move this out of the SVGColor class? 53 53 // FIXME: Is it really OK to do stripWhitespace here instead of stripLeadingAndTrailingHTMLSpaces? 54 return CSSParser::parseColor(colorString.stripWhiteSpace()); 54 RGBA32 color; 55 if (CSSParser::parseColor(color, colorString.stripWhiteSpace())) 56 return color; 57 return Color(); 55 58 } 56 59
Note:
See TracChangeset
for help on using the changeset viewer.