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;
}
CSSParserString CSSTokenizer::registerString(const String& string)
{
    m_scope.storeString(string);
    CSSParserString result;
    result.init(string);
    return result;
}
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;
}
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 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;
}
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);
}
Exemple #9
0
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);
}
static CSSParserString toParserString(const String& string)
{
    CSSParserString result;
    result.init(string);
    return result;
}