Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / parser / CSSParser.cpp
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.
4
5 #include "config.h"
6 #include "core/css/parser/CSSParser.h"
7
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"
13
14 namespace blink {
15
16 CSSParser::CSSParser(const CSSParserContext& context)
17     : m_bisonParser(context)
18 {
19 }
20
21 bool CSSParser::parseDeclaration(MutableStylePropertySet* propertySet, const String& declaration, CSSParserObserver* observer, StyleSheetContents* styleSheet)
22 {
23     return m_bisonParser.parseDeclaration(propertySet, declaration, observer, styleSheet);
24 }
25
26 void CSSParser::parseSelector(const String& selector, CSSSelectorList& selectorList)
27 {
28     m_bisonParser.parseSelector(selector, selectorList);
29 }
30
31 PassRefPtrWillBeRawPtr<StyleRuleBase> CSSParser::parseRule(const CSSParserContext& context, StyleSheetContents* styleSheet, const String& rule)
32 {
33     return BisonCSSParser(context).parseRule(styleSheet, rule);
34 }
35
36 void CSSParser::parseSheet(const CSSParserContext& context, StyleSheetContents* styleSheet, const String& text, const TextPosition& startPosition, CSSParserObserver* observer, bool logErrors)
37 {
38     BisonCSSParser(context).parseSheet(styleSheet, text, startPosition, observer, logErrors);
39 }
40
41 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode parserMode, StyleSheetContents* styleSheet)
42 {
43     if (parseFastPath(declaration, propertyID, string, important, parserMode))
44         return true;
45     CSSParserContext context(parserMode, 0);
46     if (styleSheet) {
47         context = styleSheet->parserContext();
48         context.setMode(parserMode);
49     }
50     return parseValue(declaration, propertyID, string, important, context);
51 }
52
53 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context)
54 {
55     return BisonCSSParser::parseValue(declaration, propertyID, string, important, context);
56 }
57
58 bool CSSParser::parseFastPath(MutableStylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode parserMode)
59 {
60     RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue(propertyID, string, parserMode);
61     if (!value)
62         return false;
63     declaration->addParsedProperty(CSSProperty(propertyID, value.release(), important));
64     return true;
65 }
66
67 PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID propertyID, const String& string, const CSSParserContext& context)
68 {
69     if (string.isEmpty())
70         return nullptr;
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);
76 }
77
78 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDeclaration(const String& styleString, Element* element)
79 {
80     return BisonCSSParser::parseInlineStyleDeclaration(styleString, element);
81 }
82
83 PassOwnPtr<Vector<double> > CSSParser::parseKeyframeKeyList(const String& keyList)
84 {
85     return BisonCSSParser(strictCSSParserContext()).parseKeyframeKeyList(keyList);
86 }
87
88 PassRefPtrWillBeRawPtr<StyleKeyframe> CSSParser::parseKeyframeRule(const CSSParserContext& context, StyleSheetContents* styleSheet, const String& rule)
89 {
90     return BisonCSSParser(context).parseKeyframeRule(styleSheet, rule);
91 }
92
93 bool CSSParser::parseSupportsCondition(const String& condition)
94 {
95     return BisonCSSParser(CSSParserContext(HTMLStandardMode, 0)).parseSupportsCondition(condition);
96 }
97
98 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
99 {
100     return BisonCSSParser::parseColor(color, string, strict);
101 }
102
103 StyleColor CSSParser::colorFromRGBColorString(const String& string)
104 {
105     return BisonCSSParser::colorFromRGBColorString(string);
106 }
107
108 bool CSSParser::parseSystemColor(RGBA32& color, const String& colorString)
109 {
110     return BisonCSSParser::parseSystemColor(color, colorString);
111 }
112
113 } // namespace blink