OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/parser/CSSParser.h" | 5 #include "core/css/parser/CSSParser.h" |
6 | 6 |
7 #include "core/css/CSSColorValue.h" | 7 #include "core/css/CSSColorValue.h" |
8 #include "core/css/CSSKeyframeRule.h" | 8 #include "core/css/CSSKeyframeRule.h" |
9 #include "core/css/StyleColor.h" | 9 #include "core/css/StyleColor.h" |
10 #include "core/css/StyleRule.h" | 10 #include "core/css/StyleRule.h" |
11 #include "core/css/StyleSheetContents.h" | 11 #include "core/css/StyleSheetContents.h" |
12 #include "core/css/parser/CSSParserFastPaths.h" | 12 #include "core/css/parser/CSSParserFastPaths.h" |
13 #include "core/css/parser/CSSParserImpl.h" | 13 #include "core/css/parser/CSSParserImpl.h" |
14 #include "core/css/parser/CSSPropertyParser.h" | 14 #include "core/css/parser/CSSPropertyParser.h" |
15 #include "core/css/parser/CSSSelectorParser.h" | 15 #include "core/css/parser/CSSSelectorParser.h" |
16 #include "core/css/parser/CSSSupportsParser.h" | 16 #include "core/css/parser/CSSSupportsParser.h" |
17 #include "core/css/parser/CSSTokenizer.h" | 17 #include "core/css/parser/CSSTokenizer.h" |
18 #include "core/css/parser/CSSVariableParser.h" | 18 #include "core/css/parser/CSSVariableParser.h" |
19 #include "core/layout/LayoutTheme.h" | 19 #include "core/layout/LayoutTheme.h" |
20 #include <memory> | 20 #include <memory> |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 | 23 |
24 bool CSSParser::parseDeclarationList(const CSSParserContext& context, | 24 bool CSSParser::parseDeclarationList(const CSSParserContext* context, |
25 MutableStylePropertySet* propertySet, | 25 MutableStylePropertySet* propertySet, |
26 const String& declaration) { | 26 const String& declaration) { |
27 return CSSParserImpl::parseDeclarationList(propertySet, declaration, context); | 27 return CSSParserImpl::parseDeclarationList(propertySet, declaration, context); |
28 } | 28 } |
29 | 29 |
30 void CSSParser::parseDeclarationListForInspector( | 30 void CSSParser::parseDeclarationListForInspector( |
31 const CSSParserContext& context, | 31 const CSSParserContext* context, |
32 const String& declaration, | 32 const String& declaration, |
33 CSSParserObserver& observer) { | 33 CSSParserObserver& observer) { |
34 CSSParserImpl::parseDeclarationListForInspector(declaration, context, | 34 CSSParserImpl::parseDeclarationListForInspector(declaration, context, |
35 observer); | 35 observer); |
36 } | 36 } |
37 | 37 |
38 CSSSelectorList CSSParser::parseSelector(const CSSParserContext& context, | 38 CSSSelectorList CSSParser::parseSelector(const CSSParserContext* context, |
39 StyleSheetContents* styleSheetContents, | 39 StyleSheetContents* styleSheetContents, |
40 const String& selector) { | 40 const String& selector) { |
41 CSSTokenizer tokenizer(selector); | 41 CSSTokenizer tokenizer(selector); |
42 return CSSSelectorParser::parseSelector(tokenizer.tokenRange(), context, | 42 return CSSSelectorParser::parseSelector(tokenizer.tokenRange(), context, |
43 styleSheetContents); | 43 styleSheetContents); |
44 } | 44 } |
45 | 45 |
46 CSSSelectorList CSSParser::parsePageSelector( | 46 CSSSelectorList CSSParser::parsePageSelector( |
47 const CSSParserContext& context, | 47 const CSSParserContext* context, |
48 StyleSheetContents* styleSheetContents, | 48 StyleSheetContents* styleSheetContents, |
49 const String& selector) { | 49 const String& selector) { |
50 CSSTokenizer tokenizer(selector); | 50 CSSTokenizer tokenizer(selector); |
51 return CSSParserImpl::parsePageSelector(tokenizer.tokenRange(), | 51 return CSSParserImpl::parsePageSelector(tokenizer.tokenRange(), |
52 styleSheetContents); | 52 styleSheetContents); |
53 } | 53 } |
54 | 54 |
55 StyleRuleBase* CSSParser::parseRule(const CSSParserContext& context, | 55 StyleRuleBase* CSSParser::parseRule(const CSSParserContext* context, |
56 StyleSheetContents* styleSheet, | 56 StyleSheetContents* styleSheet, |
57 const String& rule) { | 57 const String& rule) { |
58 return CSSParserImpl::parseRule(rule, context, styleSheet, | 58 return CSSParserImpl::parseRule(rule, context, styleSheet, |
59 CSSParserImpl::AllowImportRules); | 59 CSSParserImpl::AllowImportRules); |
60 } | 60 } |
61 | 61 |
62 void CSSParser::parseSheet(const CSSParserContext& context, | 62 void CSSParser::parseSheet(const CSSParserContext* context, |
63 StyleSheetContents* styleSheet, | 63 StyleSheetContents* styleSheet, |
64 const String& text, | 64 const String& text, |
65 bool deferPropertyParsing) { | 65 bool deferPropertyParsing) { |
66 return CSSParserImpl::parseStyleSheet(text, context, styleSheet, | 66 return CSSParserImpl::parseStyleSheet(text, context, styleSheet, |
67 deferPropertyParsing); | 67 deferPropertyParsing); |
68 } | 68 } |
69 | 69 |
70 void CSSParser::parseSheetForInspector(const CSSParserContext& context, | 70 void CSSParser::parseSheetForInspector(const CSSParserContext* context, |
71 StyleSheetContents* styleSheet, | 71 StyleSheetContents* styleSheet, |
72 const String& text, | 72 const String& text, |
73 CSSParserObserver& observer) { | 73 CSSParserObserver& observer) { |
74 return CSSParserImpl::parseStyleSheetForInspector(text, context, styleSheet, | 74 return CSSParserImpl::parseStyleSheetForInspector(text, context, styleSheet, |
75 observer); | 75 observer); |
76 } | 76 } |
77 | 77 |
78 MutableStylePropertySet::SetResult CSSParser::parseValue( | 78 MutableStylePropertySet::SetResult CSSParser::parseValue( |
79 MutableStylePropertySet* declaration, | 79 MutableStylePropertySet* declaration, |
80 CSSPropertyID unresolvedProperty, | 80 CSSPropertyID unresolvedProperty, |
81 const String& string, | 81 const String& string, |
82 bool important) { | |
83 return parseValue(declaration, unresolvedProperty, string, important, | |
84 static_cast<StyleSheetContents*>(nullptr)); | |
haraken
2017/01/12 04:51:13
What is this change for?
Bret
2017/01/13 02:15:28
There were some calls that were trying to pass in
| |
85 } | |
86 | |
87 MutableStylePropertySet::SetResult CSSParser::parseValue( | |
88 MutableStylePropertySet* declaration, | |
89 CSSPropertyID unresolvedProperty, | |
90 const String& string, | |
82 bool important, | 91 bool important, |
83 StyleSheetContents* styleSheet) { | 92 StyleSheetContents* styleSheet) { |
84 if (string.isEmpty()) { | 93 if (string.isEmpty()) { |
85 bool didParse = false; | 94 bool didParse = false; |
86 bool didChange = false; | 95 bool didChange = false; |
87 return MutableStylePropertySet::SetResult{didParse, didChange}; | 96 return MutableStylePropertySet::SetResult{didParse, didChange}; |
88 } | 97 } |
89 | 98 |
90 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); | 99 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); |
91 CSSParserMode parserMode = declaration->cssParserMode(); | 100 CSSParserMode parserMode = declaration->cssParserMode(); |
92 CSSValue* value = | 101 CSSValue* value = |
93 CSSParserFastPaths::maybeParseValue(resolvedProperty, string, parserMode); | 102 CSSParserFastPaths::maybeParseValue(resolvedProperty, string, parserMode); |
94 if (value) { | 103 if (value) { |
95 bool didParse = true; | 104 bool didParse = true; |
96 bool didChange = declaration->setProperty( | 105 bool didChange = declaration->setProperty( |
97 CSSProperty(resolvedProperty, *value, important)); | 106 CSSProperty(resolvedProperty, *value, important)); |
98 return MutableStylePropertySet::SetResult{didParse, didChange}; | 107 return MutableStylePropertySet::SetResult{didParse, didChange}; |
99 } | 108 } |
100 CSSParserContext context(parserMode, nullptr); | 109 CSSParserContext* context; |
101 if (styleSheet) { | 110 if (styleSheet) { |
102 context = styleSheet->parserContext(); | 111 context = new CSSParserContext(styleSheet->parserContext(), nullptr); |
103 context.setMode(parserMode); | 112 context->setMode(parserMode); |
113 } else { | |
114 context = new CSSParserContext(parserMode); | |
104 } | 115 } |
105 return parseValue(declaration, unresolvedProperty, string, important, | 116 return parseValue(declaration, unresolvedProperty, string, important, |
106 context); | 117 context); |
107 } | 118 } |
108 | 119 |
109 MutableStylePropertySet::SetResult CSSParser::parseValueForCustomProperty( | 120 MutableStylePropertySet::SetResult CSSParser::parseValueForCustomProperty( |
110 MutableStylePropertySet* declaration, | 121 MutableStylePropertySet* declaration, |
111 const AtomicString& propertyName, | 122 const AtomicString& propertyName, |
112 const PropertyRegistry* registry, | 123 const PropertyRegistry* registry, |
113 const String& value, | 124 const String& value, |
114 bool important, | 125 bool important, |
115 StyleSheetContents* styleSheet, | 126 StyleSheetContents* styleSheet, |
116 bool isAnimationTainted) { | 127 bool isAnimationTainted) { |
117 DCHECK(CSSVariableParser::isValidVariableName(propertyName)); | 128 DCHECK(CSSVariableParser::isValidVariableName(propertyName)); |
118 if (value.isEmpty()) { | 129 if (value.isEmpty()) { |
119 bool didParse = false; | 130 bool didParse = false; |
120 bool didChange = false; | 131 bool didChange = false; |
121 return MutableStylePropertySet::SetResult{didParse, didChange}; | 132 return MutableStylePropertySet::SetResult{didParse, didChange}; |
122 } | 133 } |
123 CSSParserMode parserMode = declaration->cssParserMode(); | 134 CSSParserMode parserMode = declaration->cssParserMode(); |
124 CSSParserContext context(parserMode, nullptr); | 135 CSSParserContext* context; |
125 if (styleSheet) { | 136 if (styleSheet) { |
126 context = styleSheet->parserContext(); | 137 context = new CSSParserContext(styleSheet->parserContext(), nullptr); |
127 context.setMode(parserMode); | 138 context->setMode(parserMode); |
139 } else { | |
140 context = new CSSParserContext(parserMode); | |
128 } | 141 } |
129 return CSSParserImpl::parseVariableValue(declaration, propertyName, registry, | 142 return CSSParserImpl::parseVariableValue(declaration, propertyName, registry, |
130 value, important, context, | 143 value, important, context, |
131 isAnimationTainted); | 144 isAnimationTainted); |
132 } | 145 } |
133 | 146 |
134 ImmutableStylePropertySet* CSSParser::parseCustomPropertySet( | 147 ImmutableStylePropertySet* CSSParser::parseCustomPropertySet( |
135 CSSParserTokenRange range) { | 148 CSSParserTokenRange range) { |
136 return CSSParserImpl::parseCustomPropertySet(range); | 149 return CSSParserImpl::parseCustomPropertySet(range); |
137 } | 150 } |
138 | 151 |
139 MutableStylePropertySet::SetResult CSSParser::parseValue( | 152 MutableStylePropertySet::SetResult CSSParser::parseValue( |
140 MutableStylePropertySet* declaration, | 153 MutableStylePropertySet* declaration, |
141 CSSPropertyID unresolvedProperty, | 154 CSSPropertyID unresolvedProperty, |
142 const String& string, | 155 const String& string, |
143 bool important, | 156 bool important, |
144 const CSSParserContext& context) { | 157 const CSSParserContext* context) { |
145 return CSSParserImpl::parseValue(declaration, unresolvedProperty, string, | 158 return CSSParserImpl::parseValue(declaration, unresolvedProperty, string, |
146 important, context); | 159 important, context); |
147 } | 160 } |
148 | 161 |
149 const CSSValue* CSSParser::parseSingleValue(CSSPropertyID propertyID, | 162 const CSSValue* CSSParser::parseSingleValue(CSSPropertyID propertyID, |
150 const String& string, | 163 const String& string, |
151 const CSSParserContext& context) { | 164 const CSSParserContext* context) { |
152 if (string.isEmpty()) | 165 if (string.isEmpty()) |
153 return nullptr; | 166 return nullptr; |
154 if (CSSValue* value = CSSParserFastPaths::maybeParseValue(propertyID, string, | 167 if (CSSValue* value = CSSParserFastPaths::maybeParseValue(propertyID, string, |
155 context.mode())) | 168 context->mode())) |
156 return value; | 169 return value; |
157 CSSTokenizer tokenizer(string); | 170 CSSTokenizer tokenizer(string); |
158 return CSSPropertyParser::parseSingleValue(propertyID, tokenizer.tokenRange(), | 171 return CSSPropertyParser::parseSingleValue(propertyID, tokenizer.tokenRange(), |
159 context); | 172 context); |
160 } | 173 } |
161 | 174 |
162 ImmutableStylePropertySet* CSSParser::parseInlineStyleDeclaration( | 175 ImmutableStylePropertySet* CSSParser::parseInlineStyleDeclaration( |
163 const String& styleString, | 176 const String& styleString, |
164 Element* element) { | 177 Element* element) { |
165 return CSSParserImpl::parseInlineStyleDeclaration(styleString, element); | 178 return CSSParserImpl::parseInlineStyleDeclaration(styleString, element); |
166 } | 179 } |
167 | 180 |
168 std::unique_ptr<Vector<double>> CSSParser::parseKeyframeKeyList( | 181 std::unique_ptr<Vector<double>> CSSParser::parseKeyframeKeyList( |
169 const String& keyList) { | 182 const String& keyList) { |
170 return CSSParserImpl::parseKeyframeKeyList(keyList); | 183 return CSSParserImpl::parseKeyframeKeyList(keyList); |
171 } | 184 } |
172 | 185 |
173 StyleRuleKeyframe* CSSParser::parseKeyframeRule(const CSSParserContext& context, | 186 StyleRuleKeyframe* CSSParser::parseKeyframeRule(const CSSParserContext* context, |
174 const String& rule) { | 187 const String& rule) { |
175 StyleRuleBase* keyframe = CSSParserImpl::parseRule( | 188 StyleRuleBase* keyframe = CSSParserImpl::parseRule( |
176 rule, context, nullptr, CSSParserImpl::KeyframeRules); | 189 rule, context, nullptr, CSSParserImpl::KeyframeRules); |
177 return toStyleRuleKeyframe(keyframe); | 190 return toStyleRuleKeyframe(keyframe); |
178 } | 191 } |
179 | 192 |
180 bool CSSParser::parseSupportsCondition(const String& condition) { | 193 bool CSSParser::parseSupportsCondition(const String& condition) { |
181 CSSTokenizer tokenizer(condition); | 194 CSSTokenizer tokenizer(condition); |
182 CSSParserImpl parser(strictCSSParserContext()); | 195 CSSParserImpl parser(strictCSSParserContext()); |
183 return CSSSupportsParser::supportsCondition(tokenizer.tokenRange(), parser) == | 196 return CSSSupportsParser::supportsCondition(tokenizer.tokenRange(), parser) == |
(...skipping 30 matching lines...) Expand all Loading... | |
214 if (!StyleColor::isSystemColor(id)) | 227 if (!StyleColor::isSystemColor(id)) |
215 return false; | 228 return false; |
216 | 229 |
217 color = LayoutTheme::theme().systemColor(id); | 230 color = LayoutTheme::theme().systemColor(id); |
218 return true; | 231 return true; |
219 } | 232 } |
220 | 233 |
221 const CSSValue* CSSParser::parseFontFaceDescriptor( | 234 const CSSValue* CSSParser::parseFontFaceDescriptor( |
222 CSSPropertyID propertyID, | 235 CSSPropertyID propertyID, |
223 const String& propertyValue, | 236 const String& propertyValue, |
224 const CSSParserContext& context) { | 237 const CSSParserContext* context) { |
225 StringBuilder builder; | 238 StringBuilder builder; |
226 builder.append("@font-face { "); | 239 builder.append("@font-face { "); |
227 builder.append(getPropertyNameString(propertyID)); | 240 builder.append(getPropertyNameString(propertyID)); |
228 builder.append(" : "); | 241 builder.append(" : "); |
229 builder.append(propertyValue); | 242 builder.append(propertyValue); |
230 builder.append("; }"); | 243 builder.append("; }"); |
231 StyleRuleBase* rule = parseRule(context, nullptr, builder.toString()); | 244 StyleRuleBase* rule = parseRule(context, nullptr, builder.toString()); |
232 if (!rule || !rule->isFontFaceRule()) | 245 if (!rule || !rule->isFontFaceRule()) |
233 return nullptr; | 246 return nullptr; |
234 return toStyleRuleFontFace(rule)->properties().getPropertyCSSValue( | 247 return toStyleRuleFontFace(rule)->properties().getPropertyCSSValue( |
235 propertyID); | 248 propertyID); |
236 } | 249 } |
237 | 250 |
238 } // namespace blink | 251 } // namespace blink |
OLD | NEW |