OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of csslib.parser; | 5 part of csslib.parser; |
6 | 6 |
7 /** | 7 /** |
8 * CSS polyfill emits CSS to be understood by older parsers that which do not | 8 * CSS polyfill emits CSS to be understood by older parsers that which do not |
9 * understand (var, calc, etc.). | 9 * understand (var, calc, etc.). |
10 */ | 10 */ |
11 class PolyFill { | 11 class PolyFill { |
12 final Messages _messages; | 12 final Messages _messages; |
13 final bool _warningsAsErrors; | |
14 Map<String, VarDefinition> _allVarDefinitions = | 13 Map<String, VarDefinition> _allVarDefinitions = |
15 new Map<String, VarDefinition>(); | 14 new Map<String, VarDefinition>(); |
16 | 15 |
17 Set<StyleSheet> allStyleSheets = new Set<StyleSheet>(); | 16 Set<StyleSheet> allStyleSheets = new Set<StyleSheet>(); |
18 | 17 |
19 /** | 18 /** |
20 * [_pseudoElements] list of known pseudo attributes found in HTML, any | 19 * [_pseudoElements] list of known pseudo attributes found in HTML, any |
21 * CSS pseudo-elements 'name::custom-element' is mapped to the manged name | 20 * CSS pseudo-elements 'name::custom-element' is mapped to the manged name |
22 * associated with the pseudo-element key. | 21 * associated with the pseudo-element key. |
23 */ | 22 */ |
24 PolyFill(this._messages, this._warningsAsErrors); | 23 PolyFill(this._messages); |
25 | 24 |
26 /** | 25 /** |
27 * Run the analyzer on every file that is a style sheet or any component that | 26 * Run the analyzer on every file that is a style sheet or any component that |
28 * has a style tag. | 27 * has a style tag. |
29 */ | 28 */ |
30 void process(StyleSheet styleSheet, {List<StyleSheet> includes: null}) { | 29 void process(StyleSheet styleSheet, {List<StyleSheet> includes: null}) { |
31 if (includes != null) { | 30 if (includes != null) { |
32 processVarDefinitions(includes); | 31 processVarDefinitions(includes); |
33 } | 32 } |
34 processVars(styleSheet); | 33 processVars(styleSheet); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 super.visitDeclarationGroup(node); | 219 super.visitDeclarationGroup(node); |
221 } | 220 } |
222 } | 221 } |
223 | 222 |
224 /** Find terminal definition (non VarUsage implies real CSS value). */ | 223 /** Find terminal definition (non VarUsage implies real CSS value). */ |
225 VarDefinition _findTerminalVarDefinition( | 224 VarDefinition _findTerminalVarDefinition( |
226 Map<String, VarDefinition> varDefs, VarDefinition varDef) { | 225 Map<String, VarDefinition> varDefs, VarDefinition varDef) { |
227 var expressions = varDef.expression as Expressions; | 226 var expressions = varDef.expression as Expressions; |
228 for (var expr in expressions.expressions) { | 227 for (var expr in expressions.expressions) { |
229 if (expr is VarUsage) { | 228 if (expr is VarUsage) { |
230 var usageName = (expr as VarUsage).name; | 229 var usageName = expr.name; |
231 var foundDef = varDefs[usageName]; | 230 var foundDef = varDefs[usageName]; |
232 | 231 |
233 // If foundDef is unknown check if defaultValues; if it exist then resolve | 232 // If foundDef is unknown check if defaultValues; if it exist then resolve |
234 // to terminal value. | 233 // to terminal value. |
235 if (foundDef == null) { | 234 if (foundDef == null) { |
236 // We're either a VarUsage or terminal definition if in varDefs; | 235 // We're either a VarUsage or terminal definition if in varDefs; |
237 // either way replace VarUsage with it's default value because the | 236 // either way replace VarUsage with it's default value because the |
238 // VarDefinition isn't found. | 237 // VarDefinition isn't found. |
239 var defaultValues = (expr as VarUsage).defaultValues; | 238 var defaultValues = expr.defaultValues; |
240 var replaceExprs = expressions.expressions; | 239 var replaceExprs = expressions.expressions; |
241 assert(replaceExprs.length == 1); | 240 assert(replaceExprs.length == 1); |
242 replaceExprs.replaceRange(0, 1, defaultValues); | 241 replaceExprs.replaceRange(0, 1, defaultValues); |
243 return varDef; | 242 return varDef; |
244 } | 243 } |
245 if (foundDef is VarDefinition) { | 244 if (foundDef is VarDefinition) { |
246 return _findTerminalVarDefinition(varDefs, foundDef); | 245 return _findTerminalVarDefinition(varDefs, foundDef); |
247 } | 246 } |
248 } else { | 247 } else { |
249 // Return real CSS property. | 248 // Return real CSS property. |
250 return varDef; | 249 return varDef; |
251 } | 250 } |
252 } | 251 } |
253 | 252 |
254 // Didn't point to a var definition that existed. | 253 // Didn't point to a var definition that existed. |
255 return varDef; | 254 return varDef; |
256 } | 255 } |
OLD | NEW |