bool SizesAttributeParser::parse(CSSParserTokenRange range) { // Split on a comma token and parse the result tokens as (media-condition, length) pairs while (!range.atEnd()) { const CSSParserToken* mediaConditionStart = &range.peek(); // The length is the last component value before the comma which isn't whitespace or a comment const CSSParserToken* lengthTokenStart = &range.peek(); const CSSParserToken* lengthTokenEnd = &range.peek(); while (!range.atEnd() && range.peek().type() != CommaToken) { lengthTokenStart = &range.peek(); range.consumeComponentValue(); lengthTokenEnd = &range.peek(); range.consumeWhitespace(); } range.consume(); float length; if (!calculateLengthInPixels(range.makeSubRange(lengthTokenStart, lengthTokenEnd), length)) continue; RefPtrWillBeRawPtr<MediaQuerySet> mediaCondition = MediaQueryParser::parseMediaCondition(range.makeSubRange(mediaConditionStart, lengthTokenStart)); if (!mediaCondition || !mediaConditionMatches(mediaCondition)) continue; m_length = length; m_lengthWasSet = true; return true; } return false; }
bool CSSVariableData::checkVariablesForCyclesWithRange(CSSParserTokenRange range, CustomPropertyValueMap& customProperties, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const { while (!range.atEnd()) { if (range.peek().functionId() == CSSValueVar) { CSSParserTokenRange block = range.consumeBlock(); block.consumeWhitespace(); ASSERT(block.peek().type() == IdentToken); AtomicString variableName = block.consumeIncludingWhitespace().value().toAtomicString(); ASSERT(block.atEnd() || block.peek().type() == CommaToken); if (seenProperties.contains(variableName)) return false; RefPtr<CSSCustomPropertyValue> value = customProperties.get(variableName); if (value && value->containsVariables() && !value->checkVariablesForCycles(variableName, customProperties, seenProperties, invalidProperties)) return false; if (range.peek().type() == CommaToken) { // Fallback. range.consume(); return checkVariablesForCyclesWithRange(block, customProperties, seenProperties, invalidProperties); } } else range.consume(); } return true; }
PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::consumeAtRule(CSSParserTokenRange& range, AllowedRulesType allowedRules) { ASSERT(range.peek().type() == AtKeywordToken); const CSSParserString& name = range.consume().value(); const CSSParserToken* preludeStart = &range.peek(); while (!range.atEnd() && range.peek().type() != LeftBraceToken && range.peek().type() != SemicolonToken) range.consumeComponentValue(); CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); CSSAtRuleID id = cssAtRuleID(name); if (id != CSSAtRuleInvalid && m_context.useCounter()) countAtRule(m_context.useCounter(), id); if (range.atEnd() || range.peek().type() == SemicolonToken) { range.consume(); if (allowedRules == AllowCharsetRules && id == CSSAtRuleCharset) return consumeCharsetRule(prelude); if (allowedRules <= AllowImportRules && id == CSSAtRuleImport) return consumeImportRule(prelude); if (allowedRules <= AllowNamespaceRules && id == CSSAtRuleNamespace) return consumeNamespaceRule(prelude); return nullptr; // Parse error, unrecognised at-rule without block } CSSParserTokenRange block = range.consumeBlock(); if (allowedRules == KeyframeRules) return nullptr; // Parse error, no at-rules supported inside @keyframes if (allowedRules == NoRules) return nullptr; // Parse error, no at-rules supported inside declaration lists ASSERT(allowedRules <= RegularRules); switch (id) { case CSSAtRuleMedia: return consumeMediaRule(prelude, block); case CSSAtRuleSupports: return consumeSupportsRule(prelude, block); case CSSAtRuleViewport: return consumeViewportRule(prelude, block); case CSSAtRuleFontFace: return consumeFontFaceRule(prelude, block); case CSSAtRuleWebkitKeyframes: return consumeKeyframesRule(true, prelude, block); case CSSAtRuleKeyframes: return consumeKeyframesRule(false, prelude, block); case CSSAtRulePage: return consumePageRule(prelude, block); default: return nullptr; // Parse error, unrecognised at-rule with block } }
void CSSParserImpl::consumeDeclarationList(CSSParserTokenRange range, StyleRule::Type ruleType) { ASSERT(m_parsedProperties.isEmpty()); bool useObserver = m_observerWrapper && ruleType == StyleRule::Style; if (useObserver) { m_observerWrapper->observer().startRuleBody(m_observerWrapper->previousTokenStartOffset(range)); m_observerWrapper->skipCommentsBefore(range, true); } while (!range.atEnd()) { switch (range.peek().type()) { case WhitespaceToken: case SemicolonToken: range.consume(); break; case IdentToken: { const CSSParserToken* declarationStart = &range.peek(); if (useObserver) m_observerWrapper->yieldCommentsBefore(range); while (!range.atEnd() && range.peek().type() != SemicolonToken) range.consumeComponentValue(); consumeDeclaration(range.makeSubRange(declarationStart, &range.peek()), ruleType); if (useObserver) m_observerWrapper->skipCommentsBefore(range, false); break; } case AtKeywordToken: { RefPtrWillBeRawPtr<StyleRuleBase> rule = consumeAtRule(range, NoRules); ASSERT_UNUSED(rule, !rule); break; } default: // Parse error, unexpected token in declaration list while (!range.atEnd() && range.peek().type() != SemicolonToken) range.consumeComponentValue(); break; } } // Yield remaining comments if (useObserver) { m_observerWrapper->yieldCommentsBefore(range); m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(range)); } }
void CSSVariableResolver::resolveApplyAtRule(CSSParserTokenRange& range, Vector<CSSParserToken>& result) { ASSERT(range.peek().type() == AtKeywordToken && range.peek().valueEqualsIgnoringASCIICase("apply")); range.consumeIncludingWhitespace(); const CSSParserToken& variableName = range.consumeIncludingWhitespace(); // TODO(timloh): Should we actually be consuming this? if (range.peek().type() == SemicolonToken) range.consume(); CSSVariableData* variableData = valueForCustomProperty(variableName.value()); if (!variableData) return; // Invalid custom property CSSParserTokenRange rule = variableData->tokenRange(); rule.consumeWhitespace(); if (rule.peek().type() != LeftBraceToken) return; CSSParserTokenRange ruleContents = rule.consumeBlock(); rule.consumeWhitespace(); if (!rule.atEnd()) return; result.appendRange(ruleContents.begin(), ruleContents.end()); }
bool parseValueMultiplicativeExpression(CSSParserTokenRange& tokens, int depth, Value* result) { if (checkDepthAndIndex(&depth, tokens) != OK) return false; if (!parseValueTerm(tokens, depth, result)) return false; while (!tokens.atEnd()) { char operatorCharacter = operatorValue(tokens.peek()); if (operatorCharacter != CalcMultiply && operatorCharacter != CalcDivide) break; tokens.consumeIncludingWhitespace(); Value rhs; if (!parseValueTerm(tokens, depth, &rhs)) return false; result->value = CSSCalcBinaryOperation::createSimplified(result->value, rhs.value, static_cast<CalcOperator>(operatorCharacter)); if (!result->value) return false; } return true; }
bool parseAdditiveValueExpression(CSSParserTokenRange& tokens, int depth, Value* result) { if (checkDepthAndIndex(&depth, tokens) != OK) return false; if (!parseValueMultiplicativeExpression(tokens, depth, result)) return false; while (!tokens.atEnd()) { char operatorCharacter = operatorValue(tokens.peek()); if (operatorCharacter != CalcAdd && operatorCharacter != CalcSubtract) break; if ((&tokens.peek() - 1)->type() != WhitespaceToken) return false; // calc(1px+ 2px) is invalid tokens.consume(); if (tokens.peek().type() != WhitespaceToken) return false; // calc(1px +2px) is invalid tokens.consumeIncludingWhitespace(); Value rhs; if (!parseValueMultiplicativeExpression(tokens, depth, &rhs)) return false; result->value = CSSCalcBinaryOperation::createSimplified(result->value, rhs.value, static_cast<CalcOperator>(operatorCharacter)); if (!result->value) return false; } return true; }
PassRefPtrWillBeRawPtr<StyleRuleKeyframes> CSSParserImpl::consumeKeyframesRule(bool webkitPrefixed, CSSParserTokenRange prelude, CSSParserTokenRange block) { prelude.consumeWhitespace(); const CSSParserToken& nameToken = prelude.consumeIncludingWhitespace(); if (!prelude.atEnd()) return nullptr; // Parse error; expected single non-whitespace token in @keyframes header String name; if (nameToken.type() == IdentToken) { name = nameToken.value(); } else if (nameToken.type() == StringToken && webkitPrefixed) { if (m_context.useCounter()) m_context.useCounter()->count(UseCounter::QuotedKeyframesRule); name = nameToken.value(); } else { return nullptr; // Parse error; expected ident token in @keyframes header } if (m_observerWrapper) { unsigned endOffset = m_observerWrapper->endOffset(prelude); m_observerWrapper->observer().startRuleHeader(StyleRule::Keyframes, m_observerWrapper->startOffset(prelude)); m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset(prelude)); m_observerWrapper->observer().startRuleBody(endOffset); m_observerWrapper->observer().endRuleBody(endOffset); } RefPtrWillBeRawPtr<StyleRuleKeyframes> keyframeRule = StyleRuleKeyframes::create(); consumeRuleList(block, KeyframesRuleList, [keyframeRule](PassRefPtrWillBeRawPtr<StyleRuleBase> keyframe) { keyframeRule->parserAppendKeyframe(toStyleRuleKeyframe(keyframe.get())); }); keyframeRule->setName(name); keyframeRule->setVendorPrefixed(webkitPrefixed); return keyframeRule.release(); }
static bool parseRGBParameters(CSSParserTokenRange& range, RGBA32& result, bool parseAlpha) { ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba); CSSParserTokenRange args = consumeFunction(range); CSSPrimitiveValue* colorParameter = consumeInteger(args); if (!colorParameter) colorParameter = consumePercent(args, ValueRangeAll); if (!colorParameter) return false; const bool isPercent = colorParameter->isPercentage(); int colorArray[3]; colorArray[0] = clampRGBComponent(*colorParameter); for (int i = 1; i < 3; i++) { if (!consumeCommaIncludingWhitespace(args)) return false; colorParameter = isPercent ? consumePercent(args, ValueRangeAll) : consumeInteger(args); if (!colorParameter) return false; colorArray[i] = clampRGBComponent(*colorParameter); } if (parseAlpha) { if (!consumeCommaIncludingWhitespace(args)) return false; double alpha; if (!consumeNumberRaw(args, alpha)) return false; // Convert the floating pointer number of alpha to an integer in the range [0, 256), // with an equal distribution across all 256 values. int alphaComponent = static_cast<int>(clampTo<double>(alpha, 0.0, 1.0) * nextafter(256.0, 0.0)); result = makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent); } else { result = makeRGB(colorArray[0], colorArray[1], colorArray[2]); } return args.atEnd(); }
bool isValidVariableReference(CSSParserTokenRange range) { range.consumeWhitespace(); if (!CSSVariableParser::isValidVariableName(range.consumeIncludingWhitespace())) return false; if (range.atEnd()) return true; if (range.consume().type() != CommaToken) return false; if (range.atEnd()) return false; bool hasReferences = false; return classifyBlock(range, hasReferences); }
static bool parseHSLParameters(CSSParserTokenRange& range, RGBA32& result, bool parseAlpha) { ASSERT(range.peek().functionId() == CSSValueHsl || range.peek().functionId() == CSSValueHsla); CSSParserTokenRange args = consumeFunction(range); CSSPrimitiveValue* hslValue = consumeNumber(args, ValueRangeAll); if (!hslValue) return false; double colorArray[3]; colorArray[0] = (((hslValue->getIntValue() % 360) + 360) % 360) / 360.0; for (int i = 1; i < 3; i++) { if (!consumeCommaIncludingWhitespace(args)) return false; hslValue = consumePercent(args, ValueRangeAll); if (!hslValue) return false; double doubleValue = hslValue->getDoubleValue(); colorArray[i] = clampTo<double>(doubleValue, 0.0, 100.0) / 100.0; // Needs to be value between 0 and 1.0. } double alpha = 1.0; if (parseAlpha) { if (!consumeCommaIncludingWhitespace(args)) return false; if (!consumeNumberRaw(args, alpha)) return false; alpha = clampTo<double>(alpha, 0.0, 1.0); } result = makeRGBAFromHSLA(colorArray[0], colorArray[1], colorArray[2], alpha); return args.atEnd(); }
bool CSSVariableData::resolveVariableFallback(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const { if (range.atEnd()) return false; ASSERT(range.peek().type() == CommaToken); range.consume(); return resolveTokenRange(customProperties, range, result); }
bool CSSVariableResolver::resolveFallback(CSSParserTokenRange range, Vector<CSSParserToken>& result) { if (range.atEnd()) return false; ASSERT(range.peek().type() == CommaToken); range.consume(); return resolveTokenRange(range, result); }
PassRefPtrWillBeRawPtr<StyleRuleCharset> CSSParserImpl::consumeCharsetRule(CSSParserTokenRange prelude) { prelude.consumeWhitespace(); const CSSParserToken& string = prelude.consumeIncludingWhitespace(); if (string.type() != StringToken || !prelude.atEnd()) return nullptr; // Parse error, expected a single string return StyleRuleCharset::create(); }
PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::consumeAtRule(CSSParserTokenRange& range, AllowedRulesType allowedRules) { ASSERT(range.peek().type() == AtKeywordToken); const CSSParserString& name = range.consume().value(); const CSSParserToken* preludeStart = &range.peek(); while (!range.atEnd() && range.peek().type() != LeftBraceToken && range.peek().type() != SemicolonToken) range.consumeComponentValue(); CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); if (range.atEnd() || range.peek().type() == SemicolonToken) { range.consume(); if (allowedRules == AllowCharsetRules && name.equalIgnoringCase("charset")) return consumeCharsetRule(prelude); if (allowedRules <= AllowImportRules && name.equalIgnoringCase("import")) return consumeImportRule(prelude); if (allowedRules <= AllowNamespaceRules && name.equalIgnoringCase("namespace")) return consumeNamespaceRule(prelude); return nullptr; // Parse error, unrecognised at-rule without block } CSSParserTokenRange block = range.consumeBlock(); if (allowedRules == KeyframeRules) return nullptr; // Parse error, no at-rules supported inside @keyframes if (allowedRules == NoRules) return nullptr; // Parse error, no at-rules supported inside declaration lists ASSERT(allowedRules <= RegularRules); if (name.equalIgnoringCase("media")) return consumeMediaRule(prelude, block); if (name.equalIgnoringCase("supports")) return consumeSupportsRule(prelude, block); if (name.equalIgnoringCase("viewport")) return consumeViewportRule(prelude, block); if (name.equalIgnoringCase("font-face")) return consumeFontFaceRule(prelude, block); if (name.equalIgnoringCase("-webkit-keyframes")) return consumeKeyframesRule(true, prelude, block); if (name.equalIgnoringCase("keyframes")) return consumeKeyframesRule(false, prelude, block); if (name.equalIgnoringCase("page")) return consumePageRule(prelude, block); return nullptr; // Parse error, unrecognised at-rule with block }
std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeAttribute( CSSParserTokenRange& range) { ASSERT(range.peek().type() == LeftBracketToken); CSSParserTokenRange block = range.consumeBlock(); block.consumeWhitespace(); AtomicString namespacePrefix; AtomicString attributeName; if (!consumeName(block, attributeName, namespacePrefix)) return nullptr; block.consumeWhitespace(); if (m_context.isHTMLDocument()) attributeName = attributeName.lower(); AtomicString namespaceURI = determineNamespace(namespacePrefix); if (namespaceURI.isNull()) return nullptr; QualifiedName qualifiedName = namespacePrefix.isNull() ? QualifiedName(nullAtom, attributeName, nullAtom) : QualifiedName(namespacePrefix, attributeName, namespaceURI); std::unique_ptr<CSSParserSelector> selector = CSSParserSelector::create(); if (block.atEnd()) { selector->setAttribute(qualifiedName, CSSSelector::CaseSensitive); selector->setMatch(CSSSelector::AttributeSet); return selector; } selector->setMatch(consumeAttributeMatch(block)); const CSSParserToken& attributeValue = block.consumeIncludingWhitespace(); if (attributeValue.type() != IdentToken && attributeValue.type() != StringToken) return nullptr; selector->setValue(attributeValue.value().toAtomicString()); selector->setAttribute(qualifiedName, consumeAttributeFlags(block)); if (!block.atEnd()) return nullptr; return selector; }
PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> parseCalc(CSSParserTokenRange tokens) { Value result; tokens.consumeWhitespace(); bool ok = parseValueExpression(tokens, 0, &result); if (!ok || !tokens.atEnd()) return nullptr; return result.value; }
static ParseState checkDepthAndIndex(int* depth, CSSParserTokenRange tokens) { (*depth)++; if (tokens.atEnd()) return NoMoreTokens; if (*depth > maxExpressionDepth) return TooDeep; return OK; }
CSSSupportsParser::SupportsResult CSSSupportsParser::consumeCondition( CSSParserTokenRange range) { if (range.peek().type() == IdentToken) return consumeNegation(range); bool result; ClauseType clauseType = Unresolved; while (true) { SupportsResult nextResult = consumeConditionInParenthesis(range); if (nextResult == Invalid) return Invalid; bool nextSupported = nextResult; if (clauseType == Unresolved) result = nextSupported; else if (clauseType == Conjunction) result &= nextSupported; else result |= nextSupported; if (range.atEnd()) break; if (range.consumeIncludingWhitespace().type() != WhitespaceToken) return Invalid; if (range.atEnd()) break; const CSSParserToken& token = range.consume(); if (token.type() != IdentToken) return Invalid; if (clauseType == Unresolved) clauseType = token.value().length() == 3 ? Conjunction : Disjunction; if ((clauseType == Conjunction && !equalIgnoringASCIICase(token.value(), "and")) || (clauseType == Disjunction && !equalIgnoringASCIICase(token.value(), "or"))) return Invalid; if (range.consumeIncludingWhitespace().type() != WhitespaceToken) return Invalid; } return result ? Supported : Unsupported; }
static void observeSelectors(CSSParserObserverWrapper& wrapper, CSSParserTokenRange selectors) { // This is easier than hooking into the CSSSelectorParser selectors.consumeWhitespace(); CSSParserTokenRange originalRange = selectors; wrapper.observer().startRuleHeader(StyleRule::Style, wrapper.startOffset(originalRange)); while (!selectors.atEnd()) { const CSSParserToken* selectorStart = &selectors.peek(); while (!selectors.atEnd() && selectors.peek().type() != CommaToken) selectors.consumeComponentValue(); CSSParserTokenRange selector = selectors.makeSubRange(selectorStart, &selectors.peek()); selectors.consumeIncludingWhitespace(); wrapper.observer().observeSelector(wrapper.startOffset(selector), wrapper.endOffset(selector)); } wrapper.observer().endRuleHeader(wrapper.endOffset(originalRange)); }
bool CSSVariableData::resolveTokenRange(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const { bool success = true; while (!range.atEnd()) { if (range.peek().functionId() == CSSValueVar) success &= resolveVariableReference(customProperties, range.consumeBlock(), result); else result.append(range.consume()); } return success; }
PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::consumeQualifiedRule(CSSParserTokenRange& range, AllowedRulesType allowedRules) { const CSSParserToken* preludeStart = &range.peek(); while (!range.atEnd() && range.peek().type() != LeftBraceToken) range.consumeComponentValue(); if (range.atEnd()) return nullptr; // Parse error, EOF instead of qualified rule block CSSParserTokenRange prelude = range.makeSubRange(preludeStart, &range.peek()); CSSParserTokenRange block = range.consumeBlock(); if (allowedRules <= RegularRules) return consumeStyleRule(prelude, block); if (allowedRules == KeyframeRules) return consumeKeyframeStyleRule(prelude, block); ASSERT_NOT_REACHED(); return nullptr; }
PassRefPtrWillBeRawPtr<StyleRulePage> CSSParserImpl::consumePageRule(CSSParserTokenRange prelude, CSSParserTokenRange block) { // We only support a small subset of the css-page spec. prelude.consumeWhitespace(); AtomicString typeSelector; if (prelude.peek().type() == IdentToken) typeSelector = prelude.consume().value(); AtomicString pseudo; if (prelude.peek().type() == ColonToken) { prelude.consume(); if (prelude.peek().type() != IdentToken) return nullptr; // Parse error; expected ident token following colon in @page header pseudo = prelude.consume().value(); } prelude.consumeWhitespace(); if (!prelude.atEnd()) return nullptr; // Parse error; extra tokens in @page header OwnPtr<CSSParserSelector> selector; if (!typeSelector.isNull() && pseudo.isNull()) { selector = CSSParserSelector::create(QualifiedName(nullAtom, typeSelector, m_defaultNamespace)); } else { selector = CSSParserSelector::create(); if (!pseudo.isNull()) { selector->setMatch(CSSSelector::PagePseudoClass); selector->setValue(pseudo.lower()); if (selector->pseudoType() == CSSSelector::PseudoUnknown) return nullptr; // Parse error; unknown page pseudo-class } if (!typeSelector.isNull()) selector->prependTagSelector(QualifiedName(nullAtom, typeSelector, m_defaultNamespace)); } if (m_observerWrapper) { unsigned endOffset = m_observerWrapper->endOffset(prelude); m_observerWrapper->observer().startRuleHeader(StyleRule::Page, m_observerWrapper->startOffset(prelude)); m_observerWrapper->observer().endRuleHeader(endOffset); } selector->setForPage(); RefPtrWillBeRawPtr<StyleRulePage> pageRule = StyleRulePage::create(); Vector<OwnPtr<CSSParserSelector>> selectorVector; selectorVector.append(selector.release()); pageRule->parserAdoptSelectorVector(selectorVector); consumeDeclarationList(block, StyleRule::Style); pageRule->setProperties(createStylePropertySet(m_parsedProperties, m_context.mode())); m_parsedProperties.clear(); return pageRule.release(); }
PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParserImpl::parseRule(const String& string, const CSSParserContext& context, StyleSheetContents* styleSheet, AllowedRulesType allowedRules) { CSSParserImpl parser(context, styleSheet); CSSTokenizer::Scope scope(string); CSSParserTokenRange range = scope.tokenRange(); range.consumeWhitespace(); if (range.atEnd()) return nullptr; // Parse error, empty rule RefPtrWillBeRawPtr<StyleRuleBase> rule; if (range.peek().type() == AtKeywordToken) rule = parser.consumeAtRule(range, allowedRules); else rule = parser.consumeQualifiedRule(range, allowedRules); if (!rule) return nullptr; // Parse error, failed to consume rule range.consumeWhitespace(); if (!rule || !range.atEnd()) return nullptr; // Parse error, trailing garbage return rule; }
void CSSSelectorParser::parseSelector(CSSParserTokenRange range, const CSSParserContext& context, const AtomicString& defaultNamespace, StyleSheetContents* styleSheet, CSSSelectorList& output) { CSSSelectorParser parser(context, defaultNamespace, styleSheet); range.consumeWhitespace(); CSSSelectorList result; parser.consumeComplexSelectorList(range, result); if (range.atEnd()) { output.adopt(result); recordSelectorStats(context, output); } ASSERT(!(output.isValid() && parser.m_failedParsing)); }
CSSSupportsParser::SupportsResult CSSSupportsParser::consumeNegation( CSSParserTokenRange range) { ASSERT(range.peek().type() == IdentToken); if (!equalIgnoringASCIICase(range.consume().value(), "not")) return Invalid; if (range.consumeIncludingWhitespace().type() != WhitespaceToken) return Invalid; SupportsResult result = consumeConditionInParenthesis(range); range.consumeWhitespace(); if (!range.atEnd() || result == Invalid) return Invalid; return result ? Unsupported : Supported; }
CSSSelectorList CSSSelectorParser::parseSelector( CSSParserTokenRange range, const CSSParserContext& context, StyleSheetContents* styleSheet) { CSSSelectorParser parser(context, styleSheet); range.consumeWhitespace(); CSSSelectorList result = parser.consumeComplexSelectorList(range); if (!range.atEnd()) return CSSSelectorList(); recordSelectorStats(context, result); return result; }
bool CSSParserImpl::consumeRuleList(CSSParserTokenRange range, RuleListType ruleListType, const T callback) { AllowedRulesType allowedRules = RegularRules; switch (ruleListType) { case TopLevelRuleList: allowedRules = AllowCharsetRules; break; case RegularRuleList: allowedRules = RegularRules; break; case KeyframesRuleList: allowedRules = KeyframeRules; break; default: ASSERT_NOT_REACHED(); } bool seenRule = false; bool firstRuleValid = false; while (!range.atEnd()) { RefPtrWillBeRawPtr<StyleRuleBase> rule; switch (range.peek().type()) { case WhitespaceToken: range.consumeWhitespace(); continue; case AtKeywordToken: rule = consumeAtRule(range, allowedRules); break; case CDOToken: case CDCToken: if (ruleListType == TopLevelRuleList) { range.consume(); continue; } // fallthrough default: rule = consumeQualifiedRule(range, allowedRules); break; } if (!seenRule) { seenRule = true; firstRuleValid = rule; } if (rule) { allowedRules = computeNewAllowedRules(allowedRules, rule.get()); callback(rule.release()); } } return firstRuleValid; }
PassRefPtrWillBeRawPtr<CSSCustomPropertyDeclaration> CSSVariableParser::parseDeclarationValue(const AtomicString& variableName, CSSParserTokenRange range) { if (range.atEnd()) return nullptr; bool hasReferences; CSSValueID type = classifyVariableRange(range, hasReferences); if (type == CSSValueInvalid) return nullptr; if (type == CSSValueInternalVariableValue) return CSSCustomPropertyDeclaration::create(variableName, CSSVariableData::create(range, hasReferences)); return CSSCustomPropertyDeclaration::create(variableName, type); }
PassRefPtrWillBeRawPtr<StyleRuleNamespace> CSSParserImpl::consumeNamespaceRule(CSSParserTokenRange prelude) { prelude.consumeWhitespace(); AtomicString namespacePrefix; if (prelude.peek().type() == IdentToken) namespacePrefix = prelude.consumeIncludingWhitespace().value(); AtomicString uri(consumeStringOrURI(prelude)); prelude.consumeWhitespace(); if (uri.isNull() || !prelude.atEnd()) return nullptr; // Parse error, expected string or URI return StyleRuleNamespace::create(namespacePrefix, uri); }