static PassRefPtrWillBeRawPtr<CSSValue> parseKeywordValue(CSSPropertyID propertyId, const String& string) { ASSERT(!string.isEmpty()); if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { // All properties accept the values of "initial" and "inherit". String lowerCaseString = string.lower(); if (lowerCaseString != "initial" && lowerCaseString != "inherit") return nullptr; // Parse initial/inherit shorthands using the CSSPropertyParser. if (shorthandForProperty(propertyId).length()) return nullptr; } CSSParserString cssString; cssString.init(string); CSSValueID valueID = cssValueKeywordID(cssString); if (!valueID) return nullptr; if (valueID == CSSValueInherit) return cssValuePool().createInheritedValue(); if (valueID == CSSValueInitial) return cssValuePool().createExplicitInitialValue(); if (CSSParserFastPaths::isValidKeywordPropertyAndValue(propertyId, valueID)) return cssValuePool().createIdentifierValue(valueID); return nullptr; }
CSSParserString CSSTokenizer::registerString(const String& string) { m_scope.storeString(string); CSSParserString result; result.init(string); return result; }
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()); }
static PassRefPtrWillBeRawPtr<CSSValue> parseColorValue(CSSPropertyID propertyId, const String& string, CSSParserMode cssParserMode) { ASSERT(!string.isEmpty()); bool quirksMode = isQuirksModeBehavior(cssParserMode); if (!isColorPropertyID(propertyId)) return nullptr; CSSParserString cssString; cssString.init(string); CSSValueID valueID = cssValueKeywordID(cssString); bool validPrimitive = false; if (valueID == CSSValueWebkitText) { validPrimitive = true; } else if (valueID == CSSValueCurrentcolor) { validPrimitive = true; } else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText)) { validPrimitive = true; } if (validPrimitive) return cssValuePool().createIdentifierValue(valueID); RGBA32 color; if (!CSSPropertyParser::fastParseColor(color, string, !quirksMode && string[0] != '#')) return nullptr; return cssValuePool().createColorValue(color); }
bool CSSVariableParser::isValidVariableName(const CSSParserToken& token) { if (token.type() != IdentToken) return false; CSSParserString value = token.value(); return value.length() >= 2 && value[0] == '-' && value[1] == '-'; }
CSSParserString CSSTokenizerInputStream::rangeAsCSSParserString(unsigned start, unsigned length) const { ASSERT(start + length <= m_stringLength); CSSParserString result; if (m_string->is8Bit()) result.init(m_string->characters8() + start, length); else result.init(m_string->characters16() + start, length); return result; }
bool CSSParser::parseSystemColor(RGBA32& color, const String& colorString) { CSSParserString cssColor; cssColor.init(colorString); CSSValueID id = cssValueKeywordID(cssColor); if (!CSSPropertyParser::isSystemColor(id)) return false; Color parsedColor = LayoutTheme::theme().systemColor(id); color = parsedColor.rgb(); return true; }
// http://dev.w3.org/csswg/css-syntax/#consume-ident-like-token CSSParserToken CSSTokenizer::consumeIdentLikeToken() { CSSParserString name = consumeName(); if (consumeIfNext('(')) { if (name.equalIgnoringASCIICase("url")) { // The spec is slightly different so as to avoid dropping whitespace // tokens, but they wouldn't be used and this is easier. consumeUntilNonWhitespace(); UChar next = m_input.nextInputChar(); if (next != '"' && next != '\'') return consumeUrlToken(); } return blockStart(LeftParenthesisToken, FunctionToken, name); } return CSSParserToken(IdentToken, name); }
template<typename CharacterType> void CSSVariableData::updateTokens(const CSSParserTokenRange& range) { const CharacterType* currentOffset = m_backingString.getCharacters<CharacterType>(); for (const CSSParserToken& token : range) { if (token.hasStringBacking()) { unsigned length = token.value().length(); CSSParserString parserString; parserString.init(currentOffset, length); m_tokens.append(token.copyWithUpdatedString(parserString)); currentOffset += length; } else { m_tokens.append(token); } } ASSERT(currentOffset == m_backingString.getCharacters<CharacterType>() + m_backingString.length()); }
void MediaQueryData::addParserValue(MediaQueryTokenType type, const MediaQueryToken& token) { CSSParserValue value; if (type == NumberToken || type == PercentageToken || type == DimensionToken) { value.setFromNumber(token.numericValue(), token.unitType()); value.isInt = (token.numericValueType() == IntegerValueType); } else if (type == DelimiterToken) { value.unit = CSSParserValue::Operator; value.iValue = token.delimiter(); } else { CSSParserFunction* function = new CSSParserFunction; function->name.init(token.value()); value.setFromFunction(function); CSSParserString tokenValue; tokenValue.init(token.value()); value.id = cssValueKeywordID(tokenValue); } m_valueList.addValue(value); }
void MediaQueryData::addParserValue(CSSParserTokenType type, const CSSParserToken& token) { CSSParserValue value; if (type == NumberToken || type == PercentageToken || type == DimensionToken) { value.setFromNumber(token.numericValue(), token.unitType()); value.isInt = (token.numericValueType() == IntegerValueType); } else if (type == DelimiterToken) { value.unit = CSSParserValue::Operator; value.iValue = token.delimiter(); value.id = CSSValueInvalid; value.isInt = false; } else { CSSParserString tokenValue; tokenValue.init(token.value()); value.unit = CSSPrimitiveValue::CSS_IDENT; value.string = tokenValue; value.id = cssValueKeywordID(tokenValue); value.isInt = false; } m_valueList.addValue(value); }
void BisonCSSParser::tokenToLowerCase(CSSParserString& token) { // Since it's our internal token, we know that we created it out // of our writable work buffers. Therefore the const_cast is just // ugly and not a potential crash. size_t length = token.length(); if (token.is8Bit()) { makeLower(token.characters8(), const_cast<LChar*>(token.characters8()), length); } else { makeLower(token.characters16(), const_cast<UChar*>(token.characters16()), length); } }
void CSSVariableData::consumeAndUpdateTokens(const CSSParserTokenRange& range) { StringBuilder stringBuilder; CSSParserTokenRange localRange = range; while (!localRange.atEnd()) { CSSParserToken token = localRange.consume(); if (token.hasStringBacking()) { CSSParserString value = token.value(); if (value.is8Bit()) stringBuilder.append(value.characters8(), value.length()); else stringBuilder.append(value.characters16(), value.length()); } } m_backingString = stringBuilder.toString(); if (m_backingString.is8Bit()) updateTokens<LChar>(range); else updateTokens<UChar>(range); }
static CSSParserString toParserString(const String& string) { CSSParserString result; result.init(string); return result; }