OLD | NEW |
(Empty) | |
| 1 part of fn; |
| 2 |
| 3 class Style { |
| 4 final String _className; |
| 5 static Map<String, Style> _cache = null; |
| 6 |
| 7 static int nextStyleId = 1; |
| 8 |
| 9 static String nextClassName(String styles) { |
| 10 assert(sky.document != null); |
| 11 var className = "style$nextStyleId"; |
| 12 nextStyleId++; |
| 13 |
| 14 var styleNode = sky.document.createElement('style'); |
| 15 styleNode.setChild(new sky.Text(".$className { $styles }")); |
| 16 sky.document.appendChild(styleNode); |
| 17 |
| 18 return className; |
| 19 } |
| 20 |
| 21 factory Style(String styles) { |
| 22 if (_cache == null) { |
| 23 _cache = new HashMap<String, Style>(); |
| 24 } |
| 25 |
| 26 var style = _cache[styles]; |
| 27 if (style == null) { |
| 28 style = new Style._internal(nextClassName(styles)); |
| 29 _cache[styles] = style; |
| 30 } |
| 31 |
| 32 return style; |
| 33 } |
| 34 |
| 35 Style._internal(this._className); |
| 36 } |
OLD | NEW |