Exemplo n.º 1
0
CSSValueList::CSSValueList(CSSParserValueList* list)
    : m_isSpaceSeparated(true)
{
    if (list) {
        unsigned s = list->size();
        for (unsigned i = 0; i < s; ++i) {
            CSSParserValue* v = list->valueAt(i);
            append(v->createCSSValue());
        }
    }
}
Exemplo n.º 2
0
    bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result)
    {
        CSSParserValue* parserValue = tokens->valueAt(*index);
        if (parserValue->unit == CSSParserValue::Operator || parserValue->unit == CSSParserValue::Function)
            return false;

        RefPtr<CSSValue> value = parserValue->createCSSValue();
        if (!value || !value->isPrimitiveValue())
            return false;

        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value.get());
        result->value = CSSCalcPrimitiveValue::create(primitiveValue, parserValue->isInt);

        ++*index;
        return true;
    }
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
CSSParserValueList::CSSParserValueList(CSSParserTokenRange range)
: m_current(0)
{
    Vector<CSSParserValueList*> stack;
    Vector<int> bracketCounts;
    stack.append(this);
    bracketCounts.append(0);
    while (!range.atEnd()) {
        ASSERT(stack.size() == bracketCounts.size());
        ASSERT(!stack.isEmpty());
        const CSSParserToken& token = range.peek();
        if (token.type() != FunctionToken)
            range.consume();
        CSSParserValue value;
        switch (token.type()) {
        case FunctionToken: {
            if (token.valueEqualsIgnoringCase("url")) {
                range.consume();
                const CSSParserToken& next = range.consumeIncludingWhitespace();
                if (next.type() == BadStringToken || range.consume().type() != RightParenthesisToken) {
                    destroyAndClear();
                    return;
                }
                ASSERT(next.type() == StringToken);
                value.id = CSSValueInvalid;
                value.isInt = false;
                value.m_unit = CSSParserValue::URI;
                value.string = next.value();
                break;
            } else if (token.valueEqualsIgnoringCase("var")) {
                destroyAndClear();
                return;
            }

            value.id = CSSValueInvalid;
            value.isInt = false;

            CSSValueID id = token.functionId();
            if (id == CSSValueCalc || id == CSSValueWebkitCalc) {
                value.m_unit = CSSParserValue::CalcFunction;
                value.calcFunction = new CSSParserCalcFunction(range.consumeBlock());
                break;
            }
            range.consume();
            value.m_unit = CSSParserValue::Function;
            CSSParserFunction* function = new CSSParserFunction;
            function->id = id;
            CSSParserValueList* list = new CSSParserValueList;
            function->args = adoptPtr(list);

            value.function = function;

            stack.last()->addValue(value);
            stack.append(list);
            bracketCounts.append(0);
            continue;
        }
        case LeftParenthesisToken: {
            CSSParserValueList* list = new CSSParserValueList;
            value.setFromValueList(adoptPtr(list));
            stack.last()->addValue(value);
            stack.append(list);
            bracketCounts.append(0);
            continue;
        }
        case RightParenthesisToken: {
            if (bracketCounts.last() == 0) {
                stack.removeLast();
                bracketCounts.removeLast();
                if (bracketCounts.isEmpty()) {
                    destroyAndClear();
                    return;
                }
                continue;
            }
            bracketCounts.last()--;
            value.setFromOperator(')');
            break;
        }
        case IdentToken: {
            value.id = token.id();
            value.isInt = false;
            value.m_unit = CSSParserValue::Identifier;
            value.string = token.value();
            break;
        }
        case DimensionToken:
            if (token.unitType() == CSSPrimitiveValue::UnitType::Unknown) {
                // Unknown dimensions are handled as a list of two values
                value.m_unit = CSSParserValue::DimensionList;
                CSSParserValueList* list = new CSSParserValueList;
                value.valueList = list;
                value.id = CSSValueInvalid;

                CSSParserValue number;
                number.setFromNumber(token.numericValue(), CSSPrimitiveValue::UnitType::Number);
                number.isInt = (token.numericValueType() == IntegerValueType);
                list->addValue(number);

                CSSParserValue unit;
                unit.string = token.value();
                unit.m_unit = CSSParserValue::Identifier;
                list->addValue(unit);

                break;
            }
            // fallthrough
        case NumberToken:
        case PercentageToken:
            value.setFromNumber(token.numericValue(), token.unitType());
            value.isInt = (token.numericValueType() == IntegerValueType);
            break;
        case UnicodeRangeToken: {
            value.id = CSSValueInvalid;
            value.isInt = false;
            value.m_unicodeRange.start = token.unicodeRangeStart();
            value.m_unicodeRange.end = token.unicodeRangeEnd();
            value.m_unit = CSSParserValue::UnicodeRange;
            break;
        }
        case HashToken:
        case StringToken:
        case UrlToken: {
            value.id = CSSValueInvalid;
            value.isInt = false;
            if (token.type() == HashToken)
                value.m_unit = CSSParserValue::HexColor;
            else if (token.type() == StringToken)
                value.m_unit = CSSParserValue::String;
            else
                value.m_unit = CSSParserValue::URI;
            value.string = token.value();
            break;
        }
        case DelimiterToken:
            value.setFromOperator(token.delimiter());
            break;
        case CommaToken:
            value.setFromOperator(',');
            break;
        case LeftBracketToken:
            value.setFromOperator('[');
            break;
        case RightBracketToken:
            value.setFromOperator(']');
            break;
        case LeftBraceToken:
            value.setFromOperator('{');
            break;
        case RightBraceToken:
            value.setFromOperator('}');
            break;
        case WhitespaceToken:
            continue;
        case CommentToken:
        case EOFToken:
            ASSERT_NOT_REACHED();
        case CDOToken:
        case CDCToken:
        case AtKeywordToken:
        case IncludeMatchToken:
        case DashMatchToken:
        case PrefixMatchToken:
        case SuffixMatchToken:
        case SubstringMatchToken:
        case ColumnToken:
        case ColonToken:
        case SemicolonToken:
            destroyAndClear();
            return;
        case BadStringToken:
        case BadUrlToken:
            destroyAndClear();
            return;
        }
        stack.last()->addValue(value);
    }

    CSSParserValue rightParenthesis;
    rightParenthesis.setFromOperator(')');
    while (!stack.isEmpty()) {
        while (bracketCounts.last() > 0) {
            bracketCounts.last()--;
            stack.last()->addValue(rightParenthesis);
        }
        stack.removeLast();
        bracketCounts.removeLast();
    }
}
Exemplo n.º 6
0
void CSSParserValueList::addValue(const CSSParserValue& v)
{
    if (v.isVariable())
        m_variablesCount++;
    m_values.append(v);
}