1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/css/parser/CSSParser.h"
8 #include "core/css/CSSKeyframeRule.h"
9 #include "core/css/StyleColor.h"
10 #include "core/css/StyleRule.h"
11 #include "core/css/StyleSheetContents.h"
12 #include "core/css/parser/CSSParserFastPaths.h"
16 CSSParser::CSSParser(const CSSParserContext& context)
17 : m_bisonParser(context)
21 bool CSSParser::parseDeclaration(MutableStylePropertySet* propertySet, const String& declaration, CSSParserObserver* observer, StyleSheetContents* styleSheet)
23 return m_bisonParser.parseDeclaration(propertySet, declaration, observer, styleSheet);
26 void CSSParser::parseSelector(const String& selector, CSSSelectorList& selectorList)
28 m_bisonParser.parseSelector(selector, selectorList);
31 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParser::parseRule(const CSSParserContext& context, StyleSheetContents* styleSheet, const String& rule)
33 return BisonCSSParser(context).parseRule(styleSheet, rule);
36 void CSSParser::parseSheet(const CSSParserContext& context, StyleSheetContents* styleSheet, const String& text, const TextPosition& startPosition, CSSParserObserver* observer, bool logErrors)
38 BisonCSSParser(context).parseSheet(styleSheet, text, startPosition, observer, logErrors);
41 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode parserMode, StyleSheetContents* styleSheet)
43 if (parseFastPath(declaration, propertyID, string, important, parserMode))
45 CSSParserContext context(parserMode, 0);
47 context = styleSheet->parserContext();
48 context.setMode(parserMode);
50 return parseValue(declaration, propertyID, string, important, context);
53 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context)
55 return BisonCSSParser::parseValue(declaration, propertyID, string, important, context);
58 bool CSSParser::parseFastPath(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode parserMode)
60 RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue(propertyID, string, parserMode);
63 declaration->addParsedProperty(CSSProperty(propertyID, value.release(), important));
67 PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID propertyID, const String& string, const CSSParserContext& context)
71 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStylePropertySet::create();
72 bool success = parseFastPath(stylePropertySet.get(), propertyID, string, false, context.mode())
73 || parseValue(stylePropertySet.get(), propertyID, string, false, context);
74 ASSERT_UNUSED(success, success == stylePropertySet->hasProperty(propertyID));
75 return stylePropertySet->getPropertyCSSValue(propertyID);
78 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDeclaration(const String& styleString, Element* element)
80 return BisonCSSParser::parseInlineStyleDeclaration(styleString, element);
83 PassOwnPtr<Vector<double> > CSSParser::parseKeyframeKeyList(const String& keyList)
85 return BisonCSSParser(strictCSSParserContext()).parseKeyframeKeyList(keyList);
88 PassRefPtrWillBeRawPtr<StyleKeyframe> CSSParser::parseKeyframeRule(const CSSParserContext& context, StyleSheetContents* styleSheet, const String& rule)
90 return BisonCSSParser(context).parseKeyframeRule(styleSheet, rule);
93 bool CSSParser::parseSupportsCondition(const String& condition)
95 return BisonCSSParser(CSSParserContext(HTMLStandardMode, 0)).parseSupportsCondition(condition);
98 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
100 return BisonCSSParser::parseColor(color, string, strict);
103 StyleColor CSSParser::colorFromRGBColorString(const String& string)
105 return BisonCSSParser::colorFromRGBColorString(string);
108 bool CSSParser::parseSystemColor(RGBA32& color, const String& colorString)
110 return BisonCSSParser::parseSystemColor(color, colorString);