Chromium Code Reviews| Index: sky/framework/fn.dart |
| diff --git a/sky/framework/fn.dart b/sky/framework/fn.dart |
| index 12bcb888f4cf2b0d6c7c850c218830d8bf0a17c1..69733725f236beb63c6c9494fbd0b8f8782c2cc0 100644 |
| --- a/sky/framework/fn.dart |
| +++ b/sky/framework/fn.dart |
| @@ -44,29 +44,43 @@ class EventMap { |
| class Style { |
| final String _className; |
| + final String _styles; |
| + final List<String> _classList; |
|
abarth-chromium
2015/03/13 20:47:40
Remove?
|
| + |
| static final Map<String, Style> _cache = new HashMap<String, Style>(); |
| - static int nextStyleId = 1; |
| + static int _nextStyleId = 1; |
| + |
| + static String _getNextClassName() { return "style${_nextStyleId++}"; } |
| - static String nextClassName(String styles) { |
| - assert(sky.document != null); |
| - String className = "style$nextStyleId"; |
| - nextStyleId++; |
| + factory Style(String styles) { |
| + return _getOrCreateStyle(styles); |
| + } |
| - sky.Element styleNode = sky.document.createElement('style'); |
| - styleNode.setChild(new sky.Text(".$className { $styles }")); |
| - sky.document.appendChild(styleNode); |
| + Style extend(Style other) { |
| + List<String> classList = new List.from(_classList)..addAll(other._classList); |
| + var cacheId = "${classList.join(' ')}"; |
| - return className; |
| + return _cache.putIfAbsent(cacheId, () { |
| + return new Style._internal(null, classList); |
| + }); |
| } |
| - factory Style(String styles) { |
| + static Style _getOrCreateStyle(String styles) { |
| return _cache.putIfAbsent(styles, () { |
| - return new Style._internal(nextClassName(styles)); |
| + var className = _getNextClassName(); |
| + var selector = ".$className"; |
| + sky.Element styleNode = sky.document.createElement('style'); |
| + styleNode.setChild(new sky.Text("$selector { $styles }")); |
| + sky.document.appendChild(styleNode); |
| + |
| + return new Style._internal(styles, [className]); |
| }); |
| } |
| - Style._internal(this._className); |
| + Style._internal(this._styles, List<String> classList) |
| + : _classList = classList, |
| + _className = classList.join(' '); |
| } |
| void _parentInsertBefore(sky.ParentNode parent, |
| @@ -140,11 +154,11 @@ abstract class Element extends Node { |
| Element({ |
| Object key, |
| List<Node> children, |
| - List<Style> styles, |
| + Style style, |
| this.inlineStyle |
| }) : super(key:key) { |
| - _class = styles == null ? '' : styles.map((s) => s._className).join(' '); |
| + _class = style == null ? '' : style._className; |
| _children = children == null ? _emptyList : children; |
| if (_isInCheckedMode) { |
| @@ -412,12 +426,12 @@ class Container extends Element { |
| Container({ |
| Object key, |
| List<Node> children, |
| - List<Style> styles, |
| + Style style, |
| String inlineStyle |
| }) : super( |
| key: key, |
| children: children, |
| - styles: styles, |
| + style: style, |
| inlineStyle: inlineStyle |
| ); |
| } |
| @@ -436,7 +450,7 @@ class Image extends Element { |
| Image({ |
| Object key, |
| List<Node> children, |
| - List<Style> styles, |
| + Style style, |
| String inlineStyle, |
| this.width, |
| this.height, |
| @@ -444,7 +458,7 @@ class Image extends Element { |
| }) : super( |
| key: key, |
| children: children, |
| - styles: styles, |
| + style: style, |
| inlineStyle: inlineStyle |
| ); |
| @@ -480,7 +494,7 @@ class Anchor extends Element { |
| Anchor({ |
| Object key, |
| List<Node> children, |
| - List<Style> styles, |
| + Style style, |
| String inlineStyle, |
| this.width, |
| this.height, |
| @@ -488,7 +502,7 @@ class Anchor extends Element { |
| }) : super( |
| key: key, |
| children: children, |
| - styles: styles, |
| + style: style, |
| inlineStyle: inlineStyle |
| ); |