OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 part of fn; | |
6 | |
7 class Style { | |
8 final String _className; | |
9 static final Map<String, Style> _cache = new HashMap<String, Style>(); | |
10 | |
11 static int nextStyleId = 1; | |
12 | |
13 static String nextClassName(String styles) { | |
14 assert(sky.document != null); | |
15 String className = "style$nextStyleId"; | |
16 nextStyleId++; | |
17 | |
18 sky.Element styleNode = sky.document.createElement('style'); | |
19 styleNode.setChild(new sky.Text(".$className { $styles }")); | |
20 sky.document.appendChild(styleNode); | |
21 | |
22 return className; | |
23 } | |
24 | |
25 factory Style(String styles) { | |
26 return _cache.putIfAbsent(styles, () { | |
27 return new Style._internal(nextClassName(styles)); | |
28 }); | |
29 } | |
30 | |
31 Style._internal(this._className); | |
32 } | |
OLD | NEW |