PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, bool quirksMode) { ASSERT(!string.isEmpty()); CSSParserString cssString; cssString.init(string); CSSValueID valueID = cssValueKeywordID(cssString); if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor || valueID == CSSValueGrey || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText)) return cssValuePool().createIdentifierValue(valueID); RGBA32 color; // Fast path for hex colors and rgb()/rgba() colors bool parseResult; if (string.is8Bit()) parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode); else parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode); if (parseResult) return cssValuePool().createColorValue(color); Color namedColor; if (!namedColor.setNamedColor(string)) return nullptr; return cssValuePool().createColorValue(namedColor.rgb()); }
CSSValue* CSSParserFastPaths::parseColor(const String& string, CSSParserMode parserMode) { ASSERT(!string.isEmpty()); CSSValueID valueID = cssValueKeywordID(string); if (StyleColor::isColorKeyword(valueID)) { if (!isValueAllowedInMode(valueID, parserMode)) return nullptr; return CSSIdentifierValue::create(valueID); } RGBA32 color; bool quirksMode = isQuirksModeBehavior(parserMode); // Fast path for hex colors and rgb()/rgba() colors bool parseResult; if (string.is8Bit()) parseResult = fastParseColorInternal(color, string.characters8(), string.length(), quirksMode); else parseResult = fastParseColorInternal(color, string.characters16(), string.length(), quirksMode); if (!parseResult) return nullptr; return CSSColorValue::create(color); }